[mlpack-git] master, mlpack-1.0.x: Add MinimumBoundDistance(). This represents the minimum distance between the center of a node and any edge of the bound. Note that for ball bounds, this is equivalent to the furthest descendant distance. (98dcfd6)

gitdub at big.cc.gt.atl.ga.us gitdub at big.cc.gt.atl.ga.us
Thu Mar 5 21:52:44 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 98dcfd600d79302bcdddb18a39fbe6d1a95a6517
Author: Ryan Curtin <ryan at ratml.org>
Date:   Thu Jul 10 14:02:09 2014 +0000

    Add MinimumBoundDistance().
    This represents the minimum distance between the center of a node and any edge
    of the bound.  Note that for ball bounds, this is equivalent to the furthest
    descendant distance.


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

98dcfd600d79302bcdddb18a39fbe6d1a95a6517
 .../tree/binary_space_tree/binary_space_tree.hpp   |  8 +++++-
 .../binary_space_tree/binary_space_tree_impl.hpp   | 30 ++++++++++++++++++++++
 src/mlpack/core/tree/cover_tree/cover_tree.hpp     |  4 +++
 .../core/tree/rectangle_tree/rectangle_tree.hpp    |  5 ++++
 4 files changed, 46 insertions(+), 1 deletion(-)

diff --git a/src/mlpack/core/tree/binary_space_tree/binary_space_tree.hpp b/src/mlpack/core/tree/binary_space_tree/binary_space_tree.hpp
index 0356f8e..eadd300 100644
--- a/src/mlpack/core/tree/binary_space_tree/binary_space_tree.hpp
+++ b/src/mlpack/core/tree/binary_space_tree/binary_space_tree.hpp
@@ -66,8 +66,11 @@ class BinarySpaceTree
   size_t splitDimension;
   //! The distance from the centroid of this node to the centroid of the parent.
   double parentDistance;
-  //! The worst possible distance to the furthest descendant, cached to speed things up.
+  //! The worst possible distance to the furthest descendant, cached to speed
+  //! things up.
   double furthestDescendantDistance;
+  //! The minimum distance from the center to any edge of the bound.
+  double minimumBoundDistance;
   //! The dataset.
   MatType& dataset;
 
@@ -308,6 +311,9 @@ class BinarySpaceTree
    */
   double FurthestDescendantDistance() const;
 
+  //! Return the minimum distance from the center of the node to any bound edge.
+  double MinimumBoundDistance() const;
+
   //! Return the distance from the center of this node to the center of the
   //! parent node.
   double ParentDistance() const { return parentDistance; }
diff --git a/src/mlpack/core/tree/binary_space_tree/binary_space_tree_impl.hpp b/src/mlpack/core/tree/binary_space_tree/binary_space_tree_impl.hpp
index 77d949b..f8eb5cf 100644
--- a/src/mlpack/core/tree/binary_space_tree/binary_space_tree_impl.hpp
+++ b/src/mlpack/core/tree/binary_space_tree/binary_space_tree_impl.hpp
@@ -238,6 +238,7 @@ BinarySpaceTree<BoundType, StatisticType, MatType, SplitType>::BinarySpaceTree(
     splitDimension(other.splitDimension),
     parentDistance(other.parentDistance),
     furthestDescendantDistance(other.furthestDescendantDistance),
+    minimumBoundDistance(other.minimumBoundDistance),
     dataset(other.dataset)
 {
   // Create left and right children (if any).
@@ -462,6 +463,17 @@ inline double BinarySpaceTree<BoundType, StatisticType, MatType, SplitType>::
   return furthestDescendantDistance;
 }
 
+//! Return the minimum distance from the center to any bound edge.
+template<typename BoundType,
+         typename StatisticType,
+         typename MatType,
+         typename SplitType>
+inline double BinarySpaceTree<BoundType, StatisticType, MatType, SplitType>::
+    MinimumBoundDistance() const
+{
+  return minimumBoundDistance;
+}
+
 /**
  * Return the specified child.
  */
@@ -560,6 +572,15 @@ void BinarySpaceTree<BoundType, StatisticType, MatType, SplitType>::SplitNode(
   // Calculate the furthest descendant distance.
   furthestDescendantDistance = 0.5 * bound.Diameter();
 
+  // Find the minimum distance to any bound edge.
+  minimumBoundDistance = DBL_MAX;
+  for (size_t i = 0; i < bound.Dim(); ++i)
+  {
+    const double dist = std::max(bound[i].Hi() - bound[i].Lo(), 0.0);
+    if (dist < minimumBoundDistance)
+      minimumBoundDistance = dist;
+  }
+
   // Now, check if we need to split at all.
   if (count <= maxLeafSize)
     return; // We can't split this.
@@ -616,6 +637,15 @@ void BinarySpaceTree<BoundType, StatisticType, MatType, SplitType>::SplitNode(
   // Calculate the furthest descendant distance.
   furthestDescendantDistance = 0.5 * bound.Diameter();
 
+  // Find the minimum distance to any bound edge.
+  minimumBoundDistance = DBL_MAX;
+  for (size_t i = 0; i < bound.Dim(); ++i)
+  {
+    const double dist = std::max(bound[i].Hi() - bound[i].Lo(), 0.0);
+    if (dist < minimumBoundDistance)
+      minimumBoundDistance = dist;
+  }
+
   // First, check if we need to split at all.
   if (count <= maxLeafSize)
     return; // We can't split this.
diff --git a/src/mlpack/core/tree/cover_tree/cover_tree.hpp b/src/mlpack/core/tree/cover_tree/cover_tree.hpp
index 088588a..bad4b8b 100644
--- a/src/mlpack/core/tree/cover_tree/cover_tree.hpp
+++ b/src/mlpack/core/tree/cover_tree/cover_tree.hpp
@@ -320,6 +320,10 @@ class CoverTree
   //! descendant.
   double& FurthestDescendantDistance() { return furthestDescendantDistance; }
 
+  //! Get the minimum distance from the center to any bound edge (this is the
+  //! same as furthestDescendantDistance).
+  double MinimumBoundDistance() const { return furthestDescendantDistance; }
+
   //! Get the centroid of the node and store it in the given vector.
   void Centroid(arma::vec& centroid) const { centroid = dataset.col(point); }
 
diff --git a/src/mlpack/core/tree/rectangle_tree/rectangle_tree.hpp b/src/mlpack/core/tree/rectangle_tree/rectangle_tree.hpp
index 76f879e..564454c 100644
--- a/src/mlpack/core/tree/rectangle_tree/rectangle_tree.hpp
+++ b/src/mlpack/core/tree/rectangle_tree/rectangle_tree.hpp
@@ -265,6 +265,11 @@ class RectangleTree
    */
   double FurthestDescendantDistance() const;
 
+  //! Return the minimum distance from the center to any edge of the bound.
+  //! Currently, this returns 0, which doesn't break algorithms, but it isn't
+  //! necessarily correct, either.
+  double MinimumBoundDistance() const { return 0.0; }
+
   //! Return the distance from the center of this node to the center of the
   //! parent node.
   double ParentDistance() const { return parentDistance; }



More information about the mlpack-git mailing list