[mlpack-svn] r14415 - mlpack/trunk/src/mlpack/core/tree

fastlab-svn at coffeetalk-1.cc.gatech.edu fastlab-svn at coffeetalk-1.cc.gatech.edu
Thu Feb 28 14:12:39 EST 2013


Author: rcurtin
Date: 2013-02-28 14:12:39 -0500 (Thu, 28 Feb 2013)
New Revision: 14415

Modified:
   mlpack/trunk/src/mlpack/core/tree/hrectbound.hpp
   mlpack/trunk/src/mlpack/core/tree/hrectbound_impl.hpp
Log:
Clean up code a little, and allow returning of the metric associated with the
hyperrectangle bound.


Modified: mlpack/trunk/src/mlpack/core/tree/hrectbound.hpp
===================================================================
--- mlpack/trunk/src/mlpack/core/tree/hrectbound.hpp	2013-02-28 02:39:28 UTC (rev 14414)
+++ mlpack/trunk/src/mlpack/core/tree/hrectbound.hpp	2013-02-28 19:12:39 UTC (rev 14415)
@@ -11,6 +11,7 @@
 
 #include <mlpack/core.hpp>
 #include <mlpack/core/math/range.hpp>
+#include <mlpack/core/metrics/lmetric.hpp>
 
 namespace mlpack {
 namespace bound {
@@ -28,6 +29,9 @@
 class HRectBound
 {
  public:
+  //! This is the metric type that this bound is using.
+  typedef metric::LMetric<Power, TakeRoot> MetricType;
+
   /**
    * Empty constructor; creates a bound of dimensionality 0.
    */
@@ -39,15 +43,12 @@
    */
   HRectBound(const size_t dimension);
 
-  /***
-   * Copy constructor; necessary to prevent memory leaks.
-   */
+  //! Copy constructor; necessary to prevent memory leaks.
   HRectBound(const HRectBound& other);
-  HRectBound& operator=(const HRectBound& other); // Same as copy constructor.
+  //! Same as copy constructor; necessary to prevent memory leaks.
+  HRectBound& operator=(const HRectBound& other);
 
-  /**
-   * Destructor: clean up memory.
-   */
+  //! Destructor: clean up memory.
   ~HRectBound();
 
   /**
@@ -56,14 +57,13 @@
    */
   void Clear();
 
-  /** Gets the dimensionality */
+  //! Gets the dimensionality.
   size_t Dim() const { return dim; }
 
-  /**
-   * Sets and gets the range for a particular dimension.
-   */
-  math::Range& operator[](const size_t i);
-  const math::Range& operator[](const size_t i) const;
+  //! Get the range for a particular dimension.  No bounds checking.
+  math::Range& operator[](const size_t i) { return bounds[i]; }
+  //! Modify the range for a particular dimension.  No bounds checking.
+  const math::Range& operator[](const size_t i) const { return bounds[i]; }
 
   /**
    * Calculates the centroid of the range, placing it into the given vector.
@@ -145,6 +145,13 @@
    */
   std::string ToString() const;
 
+  /**
+   * 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>(); }
+
  private:
   //! The dimensionality of the bound.
   size_t dim;

Modified: mlpack/trunk/src/mlpack/core/tree/hrectbound_impl.hpp
===================================================================
--- mlpack/trunk/src/mlpack/core/tree/hrectbound_impl.hpp	2013-02-28 02:39:28 UTC (rev 14414)
+++ mlpack/trunk/src/mlpack/core/tree/hrectbound_impl.hpp	2013-02-28 19:12:39 UTC (rev 14415)
@@ -93,25 +93,6 @@
     bounds[i] = math::Range();
 }
 
-/**
- * Gets the range for a particular dimension.
- */
-template<int Power, bool TakeRoot>
-inline const math::Range& HRectBound<Power, TakeRoot>::operator[](
-    const size_t i) const
-{
-  return bounds[i];
-}
-
-/**
- * Sets the range for the given dimension.
- */
-template<int Power, bool TakeRoot>
-inline math::Range& HRectBound<Power, TakeRoot>::operator[](const size_t i)
-{
-  return bounds[i];
-}
-
 /***
  * Calculates the centroid of the range, placing it into the given vector.
  *




More information about the mlpack-svn mailing list