[mlpack-git] master,mlpack-1.0.x: (a7febb0)

gitdub at big.cc.gt.atl.ga.us gitdub at big.cc.gt.atl.ga.us
Thu Mar 5 21:43:33 EST 2015


Repository : https://github.com/mlpack/mlpack

On branches: master,mlpack-1.0.x
Link       : https://github.com/mlpack/mlpack/compare/904762495c039e345beba14c1142fd719b3bd50e...f94823c800ad6f7266995c700b1b630d5ffdcf40

>---------------------------------------------------------------

commit a7febb0a2916f82ef322c35180c67444cc88f31f
Author: SreudianFlip <SreudianFlip at 9d5b8971-822b-0410-80eb-d18c1038ef23>
Date:   Mon Feb 10 19:23:35 2014 +0000


>---------------------------------------------------------------

a7febb0a2916f82ef322c35180c67444cc88f31f
 src/mlpack/core/tree/ballbound.hpp      | 13 ++++++++-
 src/mlpack/core/tree/ballbound_impl.hpp | 47 ++++++++++++++++-----------------
 src/mlpack/tests/CMakeLists.txt         |  5 ++++
 3 files changed, 40 insertions(+), 25 deletions(-)

diff --git a/src/mlpack/core/tree/ballbound.hpp b/src/mlpack/core/tree/ballbound.hpp
index 581b37a..eb966bc 100644
--- a/src/mlpack/core/tree/ballbound.hpp
+++ b/src/mlpack/core/tree/ballbound.hpp
@@ -19,10 +19,13 @@ namespace bound {
  *
  * @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:
@@ -39,6 +42,14 @@ class BallBound
    */
   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.
    *
diff --git a/src/mlpack/core/tree/ballbound_impl.hpp b/src/mlpack/core/tree/ballbound_impl.hpp
index 649e094..7f5bf89 100644
--- a/src/mlpack/core/tree/ballbound_impl.hpp
+++ b/src/mlpack/core/tree/ballbound_impl.hpp
@@ -18,8 +18,8 @@ namespace mlpack {
 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 @@ math::Range BallBound<VecType>::operator[](const size_t i) const
 /**
  * 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 @@ bool BallBound<VecType>::Contains(const VecType& point) const
  * 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 @@ void BallBound<VecType>::CalculateMidpoint(VecType& centroid) const
 /**
  * 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 @@ double BallBound<VecType>::MinDistance(const VecType& point) const
 /**
  * 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 @@ double BallBound<VecType>::MinDistance(const BallBound& other) const
 /**
  * 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 @@ double BallBound<VecType>::MaxDistance(const VecType& point) const
 /**
  * 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 @@ double BallBound<VecType>::MaxDistance(const BallBound& other) const
  *
  * 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 @@ math::Range BallBound<VecType>::RangeDistance(const VecType& point)
                                               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 @@ BallBound<VecType>::operator|=(
 /**
  * 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 @@ BallBound<VecType>::operator|=(const MatType& data)
 /**
  * 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;
diff --git a/src/mlpack/tests/CMakeLists.txt b/src/mlpack/tests/CMakeLists.txt
index 2bdac06..3d662f3 100644
--- a/src/mlpack/tests/CMakeLists.txt
+++ b/src/mlpack/tests/CMakeLists.txt
@@ -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-git mailing list