[mlpack-svn] r16273 - in mlpack/trunk/src/mlpack: core/tree tests
fastlab-svn at coffeetalk-1.cc.gatech.edu
fastlab-svn at coffeetalk-1.cc.gatech.edu
Mon Feb 10 14:23:35 EST 2014
Author: SreudianFlip
Date: Mon Feb 10 14:23:35 2014
New Revision: 16273
Log:
Modified:
mlpack/trunk/src/mlpack/core/tree/ballbound.hpp
mlpack/trunk/src/mlpack/core/tree/ballbound_impl.hpp
mlpack/trunk/src/mlpack/tests/CMakeLists.txt
Modified: mlpack/trunk/src/mlpack/core/tree/ballbound.hpp
==============================================================================
--- mlpack/trunk/src/mlpack/core/tree/ballbound.hpp (original)
+++ mlpack/trunk/src/mlpack/core/tree/ballbound.hpp Mon Feb 10 14:23:35 2014
@@ -19,10 +19,13 @@
*
* @tparam VecType Type of vector (arma::vec or arma::spvec).
*/
-template<typename VecType = arma::vec>
+template<typename VecType = arma::vec , int Power = 2, bool TakeRoot = true>
class BallBound
{
public:
+ //! This is the metric type that this bound is using.
+ typedef metric::LMetric<Power, TakeRoot> MetricType;
+
typedef VecType Vec;
private:
@@ -38,7 +41,15 @@
* @param dimension Dimensionality of ball bound.
*/
BallBound(const size_t dimension) : radius(0), center(dimension) { }
-
+
+
+ /**
+ * Return the metric associated with this bound. Because it is an LMetric, it
+ * cannot store state, so we can make it on the fly. It is also static
+ * because the metric is only dependent on the template arguments.
+ */
+ static MetricType Metric() { return metric::LMetric<Power, TakeRoot>(); }
+
/**
* Create the ball bound with the specified radius and center.
*
Modified: mlpack/trunk/src/mlpack/core/tree/ballbound_impl.hpp
==============================================================================
--- mlpack/trunk/src/mlpack/core/tree/ballbound_impl.hpp (original)
+++ mlpack/trunk/src/mlpack/core/tree/ballbound_impl.hpp Mon Feb 10 14:23:35 2014
@@ -18,8 +18,8 @@
namespace bound {
//! Get the range in a certain dimension.
-template<typename VecType>
-math::Range BallBound<VecType>::operator[](const size_t i) const
+template<typename VecType , int Power, bool TakeRoot>
+math::Range BallBound<VecType, Power , TakeRoot>::operator[](const size_t i) const
{
if (radius < 0)
return math::Range();
@@ -30,8 +30,8 @@
/**
* Determines if a point is within the bound.
*/
-template<typename VecType>
-bool BallBound<VecType>::Contains(const VecType& point) const
+template<typename VecType, int Power, bool TakeRoot>
+bool BallBound<VecType,Power,TakeRoot>::Contains(const VecType& point) const
{
if (radius < 0)
return false;
@@ -46,8 +46,8 @@
* with DHrectBound, so it can plug in more directly if a "centroid"
* is needed.
*/
-template<typename VecType>
-void BallBound<VecType>::CalculateMidpoint(VecType& centroid) const
+template<typename VecType,int Power, bool TakeRoot>
+void BallBound<VecType, Power, TakeRoot>::CalculateMidpoint(VecType& centroid) const
{
centroid = center;
}
@@ -55,8 +55,8 @@
/**
* Calculates minimum bound-to-point squared distance.
*/
-template<typename VecType>
-double BallBound<VecType>::MinDistance(const VecType& point) const
+template<typename VecType, int Power, bool TakeRoot>
+double BallBound<VecType, Power , TakeRoot>::MinDistance(const VecType& point) const
{
if (radius < 0)
return DBL_MAX;
@@ -68,8 +68,8 @@
/**
* Calculates minimum bound-to-bound squared distance.
*/
-template<typename VecType>
-double BallBound<VecType>::MinDistance(const BallBound& other) const
+template<typename VecType, int Power, bool TakeRoot>
+double BallBound<VecType, Power , TakeRoot>::MinDistance(const BallBound& other) const
{
if (radius < 0)
return DBL_MAX;
@@ -84,8 +84,8 @@
/**
* Computes maximum distance.
*/
-template<typename VecType>
-double BallBound<VecType>::MaxDistance(const VecType& point) const
+template<typename VecType, int Power, bool TakeRoot>
+double BallBound<VecType, Power , TakeRoot>::MaxDistance(const VecType& point) const
{
if (radius < 0)
return DBL_MAX;
@@ -96,8 +96,8 @@
/**
* Computes maximum distance.
*/
-template<typename VecType>
-double BallBound<VecType>::MaxDistance(const BallBound& other) const
+template<typename VecType, int Power, bool TakeRoot>
+double BallBound<VecType, Power , TakeRoot>::MaxDistance(const BallBound& other) const
{
if (radius < 0)
return DBL_MAX;
@@ -111,8 +111,8 @@
*
* Example: bound1.MinDistanceSq(other) for minimum squared distance.
*/
-template<typename VecType>
-math::Range BallBound<VecType>::RangeDistance(const VecType& point)
+template<typename VecType, int Power, bool TakeRoot>
+math::Range BallBound<VecType, Power, TakeRoot>::RangeDistance(const VecType& point)
const
{
if (radius < 0)
@@ -124,9 +124,8 @@
dist + radius);
}
}
-
-template<typename VecType>
-math::Range BallBound<VecType>::RangeDistance(
+template<typename VecType, int Power, bool TakeRoot>
+math::Range BallBound<VecType, Power, TakeRoot>::RangeDistance(
const BallBound& other) const
{
if (radius < 0)
@@ -160,10 +159,10 @@
/**
* Expand the bound to include the given point.
*/
-template<typename VecType>
+template<typename VecType , int Power, bool TakeRoot>
template<typename MatType>
-const BallBound<VecType>&
-BallBound<VecType>::operator|=(const MatType& data)
+const BallBound<VecType,Power,TakeRoot>&
+BallBound<VecType,Power, TakeRoot>::operator|=(const MatType& data)
{
if (radius < 0)
{
@@ -193,8 +192,8 @@
/**
* Returns a string representation of this object.
*/
-template<typename VecType>
-std::string BallBound<VecType>::ToString() const
+template<typename VecType, int Power, bool TakeRoot>
+std::string BallBound<VecType,Power, TakeRoot>::ToString() const
{
std::ostringstream convert;
convert << "BallBound [" << this << "]" << std::endl;
Modified: mlpack/trunk/src/mlpack/tests/CMakeLists.txt
==============================================================================
--- mlpack/trunk/src/mlpack/tests/CMakeLists.txt (original)
+++ mlpack/trunk/src/mlpack/tests/CMakeLists.txt Mon Feb 10 14:23:35 2014
@@ -1,4 +1,9 @@
# MLPACK test executable.
+INCLUDE_DIRECTORIES(
+ $/usr/include/libxml2/libxml
+)
+
+
add_executable(mlpack_test
mlpack_test.cpp
allkfn_test.cpp
More information about the mlpack-svn
mailing list