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

fastlab-svn at coffeetalk-1.cc.gatech.edu fastlab-svn at coffeetalk-1.cc.gatech.edu
Wed Mar 13 16:44:32 EDT 2013


Author: rcurtin
Date: 2013-03-13 16:44:31 -0400 (Wed, 13 Mar 2013)
New Revision: 14546

Modified:
   mlpack/trunk/src/mlpack/core/tree/hrectbound.hpp
   mlpack/trunk/src/mlpack/core/tree/hrectbound_impl.hpp
Log:
Add Diameter() function, which is useful for obtaining the furthest descendant
distance.


Modified: mlpack/trunk/src/mlpack/core/tree/hrectbound.hpp
===================================================================
--- mlpack/trunk/src/mlpack/core/tree/hrectbound.hpp	2013-03-13 20:34:37 UTC (rev 14545)
+++ mlpack/trunk/src/mlpack/core/tree/hrectbound.hpp	2013-03-13 20:44:31 UTC (rev 14546)
@@ -141,6 +141,11 @@
   bool Contains(const VecType& point) const;
 
   /**
+   * Returns the diameter of the hyperrectangle (that is, the longest diagonal).
+   */
+  double Diameter() const;
+
+  /**
    * Returns a string representation of this object.
    */
   std::string ToString() const;

Modified: mlpack/trunk/src/mlpack/core/tree/hrectbound_impl.hpp
===================================================================
--- mlpack/trunk/src/mlpack/core/tree/hrectbound_impl.hpp	2013-03-13 20:34:37 UTC (rev 14545)
+++ mlpack/trunk/src/mlpack/core/tree/hrectbound_impl.hpp	2013-03-13 20:44:31 UTC (rev 14546)
@@ -366,6 +366,22 @@
 }
 
 /**
+ * Returns the diameter of the hyperrectangle (that is, the longest diagonal).
+ */
+template<int Power, bool TakeRoot>
+double HRectBound<Power, TakeRoot>::Diameter() const
+{
+  double d = 0;
+  for (size_t i = 0; i < dim; ++i)
+    d += std::pow(bounds[i].Hi() - bounds[i].Lo(), (double) Power);
+
+  if (TakeRoot)
+    return std::pow(d, 1.0 / (double) Power);
+  else
+    return d;
+}
+
+/**
  * Returns a string representation of this object.
  */
 template<int Power, bool TakeRoot>




More information about the mlpack-svn mailing list