[mlpack-svn] r13355 - mlpack/trunk/src/mlpack/methods/neighbor_search/sort_policies

fastlab-svn at coffeetalk-1.cc.gatech.edu fastlab-svn at coffeetalk-1.cc.gatech.edu
Tue Aug 7 01:26:33 EDT 2012


Author: rcurtin
Date: 2012-08-07 01:26:32 -0400 (Tue, 07 Aug 2012)
New Revision: 13355

Modified:
   mlpack/trunk/src/mlpack/methods/neighbor_search/sort_policies/furthest_neighbor_sort.hpp
   mlpack/trunk/src/mlpack/methods/neighbor_search/sort_policies/furthest_neighbor_sort_impl.hpp
   mlpack/trunk/src/mlpack/methods/neighbor_search/sort_policies/nearest_neighbor_sort.hpp
   mlpack/trunk/src/mlpack/methods/neighbor_search/sort_policies/nearest_neighbor_sort_impl.hpp
Log:
Add new methods for calculating the best distances when the distance between the
center and the point (or center of the other node) is already known.


Modified: mlpack/trunk/src/mlpack/methods/neighbor_search/sort_policies/furthest_neighbor_sort.hpp
===================================================================
--- mlpack/trunk/src/mlpack/methods/neighbor_search/sort_policies/furthest_neighbor_sort.hpp	2012-08-07 05:26:02 UTC (rev 13354)
+++ mlpack/trunk/src/mlpack/methods/neighbor_search/sort_policies/furthest_neighbor_sort.hpp	2012-08-07 05:26:32 UTC (rev 13355)
@@ -62,6 +62,17 @@
                                        const TreeType* referenceNode);
 
   /**
+   * Return the best possible distance between two nodes, given that the
+   * distance between the centers of the two nodes has already been calculated.
+   * This is used in conjunction with trees that have self-children (like cover
+   * trees).
+   */
+  template<typename TreeType>
+  static double BestNodeToNodeDistance(const TreeType* queryNode,
+                                       const TreeType* referenceNode,
+                                       const double centerToCenterDistance);
+
+  /**
    * Return the best possible distance between a node and a point.  In our case,
    * this is the maximum distance between the tree node and the point using the
    * given distance function.
@@ -71,6 +82,17 @@
                                         const TreeType* referenceNode);
 
   /**
+   * Return the best possible distance between a point and a node, given that
+   * the distance between the point and the center of the node has already been
+   * calculated.  This is used in conjunction with trees that have
+   * self-children (like cover trees).
+   */
+  template<typename TreeType>
+  static double BestPointToNodeDistance(const arma::vec& queryPoint,
+                                        const TreeType* referenceNode,
+                                        const double pointToCenterDistance);
+
+  /**
    * Return what should represent the worst possible distance with this
    * particular sort policy.  In our case, this should be the minimum possible
    * distance, 0.

Modified: mlpack/trunk/src/mlpack/methods/neighbor_search/sort_policies/furthest_neighbor_sort_impl.hpp
===================================================================
--- mlpack/trunk/src/mlpack/methods/neighbor_search/sort_policies/furthest_neighbor_sort_impl.hpp	2012-08-07 05:26:02 UTC (rev 13354)
+++ mlpack/trunk/src/mlpack/methods/neighbor_search/sort_policies/furthest_neighbor_sort_impl.hpp	2012-08-07 05:26:32 UTC (rev 13355)
@@ -22,6 +22,15 @@
 }
 
 template<typename TreeType>
+inline double FurthestNeighborSort::BestNodeToNodeDistance(
+    const TreeType* queryNode,
+    const TreeType* referenceNode,
+    const double centerToCenterDistance)
+{
+  return queryNode->MaxDistance(referenceNode, centerToCenterDistance);
+}
+
+template<typename TreeType>
 inline double FurthestNeighborSort::BestPointToNodeDistance(
     const arma::vec& point,
     const TreeType* referenceNode)
@@ -31,6 +40,15 @@
   return referenceNode->MaxDistance(point);
 }
 
+template<typename TreeType>
+inline double FurthestNeighborSort::BestPointToNodeDistance(
+    const arma::vec& point,
+    const TreeType* referenceNode,
+    const double pointToCenterDistance)
+{
+  return referenceNode->MaxDistance(point, pointToCenterDistance);
+}
+
 }; // namespace neighbor
 }; // namespace mlpack
 

Modified: mlpack/trunk/src/mlpack/methods/neighbor_search/sort_policies/nearest_neighbor_sort.hpp
===================================================================
--- mlpack/trunk/src/mlpack/methods/neighbor_search/sort_policies/nearest_neighbor_sort.hpp	2012-08-07 05:26:02 UTC (rev 13354)
+++ mlpack/trunk/src/mlpack/methods/neighbor_search/sort_policies/nearest_neighbor_sort.hpp	2012-08-07 05:26:32 UTC (rev 13355)
@@ -66,6 +66,16 @@
                                        const TreeType* referenceNode);
 
   /**
+   * Return the best possible distance between two nodes, given that the
+   * distance between the centers of the two nodes has already been calculated.
+   * This is used in conjunction with trees that have self-children (like cover
+   * trees).
+   */
+  template<typename TreeType>
+  static double BestNodeToNodeDistance(const TreeType* queryNode,
+                                       const TreeType* referenceNode,
+                                       const double centerToCenterDistance);
+  /**
    * Return the best possible distance between a node and a point.  In our case,
    * this is the minimum distance between the tree node and the point using the
    * given distance function.
@@ -75,6 +85,17 @@
                                         const TreeType* referenceNode);
 
   /**
+   * Return the best possible distance between a point and a node, given that
+   * the distance between the point and the center of the node has already been
+   * calculated.  This is used in conjunction with trees that have
+   * self-children (like cover trees).
+   */
+  template<typename TreeType>
+  static double BestPointToNodeDistance(const arma::vec& queryPoint,
+                                        const TreeType* referenceNode,
+                                        const double pointToCenterDistance);
+
+  /**
    * Return what should represent the worst possible distance with this
    * particular sort policy.  In our case, this should be the maximum possible
    * distance, DBL_MAX.

Modified: mlpack/trunk/src/mlpack/methods/neighbor_search/sort_policies/nearest_neighbor_sort_impl.hpp
===================================================================
--- mlpack/trunk/src/mlpack/methods/neighbor_search/sort_policies/nearest_neighbor_sort_impl.hpp	2012-08-07 05:26:02 UTC (rev 13354)
+++ mlpack/trunk/src/mlpack/methods/neighbor_search/sort_policies/nearest_neighbor_sort_impl.hpp	2012-08-07 05:26:32 UTC (rev 13355)
@@ -22,6 +22,15 @@
 }
 
 template<typename TreeType>
+inline double NearestNeighborSort::BestNodeToNodeDistance(
+    const TreeType* queryNode,
+    const TreeType* referenceNode,
+    const double centerToCenterDistance)
+{
+  return queryNode->MinDistance(referenceNode, centerToCenterDistance);
+}
+
+template<typename TreeType>
 inline double NearestNeighborSort::BestPointToNodeDistance(
     const arma::vec& point,
     const TreeType* referenceNode)
@@ -31,6 +40,15 @@
   return referenceNode->MinDistance(point);
 }
 
+template<typename TreeType>
+inline double NearestNeighborSort::BestPointToNodeDistance(
+    const arma::vec& point,
+    const TreeType* referenceNode,
+    const double pointToCenterDistance)
+{
+  return referenceNode->MinDistance(point, pointToCenterDistance);
+}
+
 }; // namespace neighbor
 }; // namespace mlpack
 




More information about the mlpack-svn mailing list