[mlpack-svn] r15011 - mlpack/trunk/src/mlpack/core/tree/cover_tree

fastlab-svn at coffeetalk-1.cc.gatech.edu fastlab-svn at coffeetalk-1.cc.gatech.edu
Sun May 5 22:10:53 EDT 2013


Author: rcurtin
Date: 2013-05-05 22:10:53 -0400 (Sun, 05 May 2013)
New Revision: 15011

Modified:
   mlpack/trunk/src/mlpack/core/tree/cover_tree/cover_tree.hpp
   mlpack/trunk/src/mlpack/core/tree/cover_tree/cover_tree_impl.hpp
Log:
Two functions which are useful for RangeSearch.


Modified: mlpack/trunk/src/mlpack/core/tree/cover_tree/cover_tree.hpp
===================================================================
--- mlpack/trunk/src/mlpack/core/tree/cover_tree/cover_tree.hpp	2013-05-03 22:55:46 UTC (rev 15010)
+++ mlpack/trunk/src/mlpack/core/tree/cover_tree/cover_tree.hpp	2013-05-06 02:10:53 UTC (rev 15011)
@@ -281,6 +281,22 @@
   //! the center to the point has already been calculated.
   double MaxDistance(const arma::vec& other, const double distance) const;
 
+  //! Return the minimum and maximum distance to another node.
+  math::Range RangeDistance(const CoverTree* other) const;
+
+  //! Return the minimum and maximum distance to another node given that the
+  //! point-to-point distance has already been calculated.
+  math::Range RangeDistance(const CoverTree* other, const double distance)
+      const;
+
+  //! Return the minimum and maximum distance to another point.
+  math::Range RangeDistance(const arma::vec& other) const;
+
+  //! Return the minimum and maximum distance to another point given that the
+  //! point-to-point distance has already been calculated.
+  math::Range RangeDistance(const arma::vec& other, const double distance)
+      const;
+
   //! Returns true: this tree does have self-children.
   static bool HasSelfChildren() { return true; }
 

Modified: mlpack/trunk/src/mlpack/core/tree/cover_tree/cover_tree_impl.hpp
===================================================================
--- mlpack/trunk/src/mlpack/core/tree/cover_tree/cover_tree_impl.hpp	2013-05-03 22:55:46 UTC (rev 15010)
+++ mlpack/trunk/src/mlpack/core/tree/cover_tree/cover_tree_impl.hpp	2013-05-06 02:10:53 UTC (rev 15011)
@@ -499,7 +499,62 @@
   return distance + furthestDescendantDistance;
 }
 
+//! Return the minimum and maximum distance to another node.
 template<typename MetricType, typename RootPointPolicy, typename StatisticType>
+double CoverTree<MetricType, RootPointPolicy, StatisticType>::RangeDistance(
+    const CoverTree* other) const
+{
+  const double distance = metric->Evaluate(dataset.unsafe_col(point),
+      other->Dataset().unsafe_col(other->Point()));
+
+  math::Range result;
+  result.Lo() = distance - furthestDescendantDistance -
+      other->FurthestDescendantDistance();
+  result.Hi() = distance + furthestDescendantDistance +
+      other->FurthestDescendantDistance();
+
+  return result;
+}
+
+//! Return the minimum and maximum distance to another node given that the
+//! point-to-point distance has already been calculated.
+template<typename MetricType, typename RootPointPolicy, typename StatisticType>
+double CoverTree<MetricType, RootPointPolicy, StatisticType>::RangeDistance(
+    const CoverTree* other,
+    const double distance) const
+{
+  math::Range result;
+  result.Lo() = distance - furthestDescendantDistance -
+      other->FurthestDescendantDistance();
+  result.Hi() = distance + furthestDescendantDistance +
+      other->FurthestDescendantDistance();
+
+  return result;
+}
+
+//! Return the minimum and maximum distance to another point.
+template<typename MetricType, typename RootPointPolicy, typename StatisticType>
+double CoverTree<MetricType, RootPointPolicy, StatisticType>::RangeDistance(
+    const arma::vec& other) const
+{
+  const double distance = metric->Evaluate(dataset.unsafe_col(point), other);
+
+  return math::Range(distance - furthestDescendantDistance,
+                     distance + furthestDescendantDistance);
+}
+
+//! Return the minimum and maximum distance to another point given that the
+//! point-to-point distance has already been calculated.
+template<typename MetricType, typename RootPointPolicy, typename StatisticType>
+double CoverTree<MetricType, RootPointPolicy, StatisticType>::RangeDistance(
+    const arma::vec& other,
+    const double distance) const
+{
+  return math::Range(distance - furthestDescendantDistance,
+                     distance + furthestDescendantDistance);
+}
+
+template<typename MetricType, typename RootPointPolicy, typename StatisticType>
 size_t CoverTree<MetricType, RootPointPolicy, StatisticType>::SplitNearFar(
     arma::Col<size_t>& indices,
     arma::vec& distances,




More information about the mlpack-svn mailing list