[mlpack-git] mlpack-1.0.x: Backport fixes for NeighborSearch from trunk. (64fda16)

gitdub at big.cc.gt.atl.ga.us gitdub at big.cc.gt.atl.ga.us
Wed Jan 7 11:57:11 EST 2015


Repository : https://github.com/mlpack/mlpack

On branch  : mlpack-1.0.x
Link       : https://github.com/mlpack/mlpack/compare/0000000000000000000000000000000000000000...904762495c039e345beba14c1142fd719b3bd50e

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

commit 64fda1629d71dc6b2a49e5c85e92f54a2ca225f2
Author: Ryan Curtin <ryan at ratml.org>
Date:   Tue Aug 26 16:21:20 2014 +0000

    Backport fixes for NeighborSearch from trunk.


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

64fda1629d71dc6b2a49e5c85e92f54a2ca225f2
 .../methods/neighbor_search/neighbor_search_rules_impl.hpp  | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/src/mlpack/methods/neighbor_search/neighbor_search_rules_impl.hpp b/src/mlpack/methods/neighbor_search/neighbor_search_rules_impl.hpp
index bdafbb1..20172d3 100644
--- a/src/mlpack/methods/neighbor_search/neighbor_search_rules_impl.hpp
+++ b/src/mlpack/methods/neighbor_search/neighbor_search_rules_impl.hpp
@@ -355,17 +355,20 @@ inline double NeighborSearchRules<SortPolicy, MetricType, TreeType>::
 
   // Add triangle inequality adjustment to best distance.  It is possible this
   // could be tighter for some certain types of trees.
-  bestDistance += queryNode.FurthestPointDistance() +
-      queryNode.FurthestDescendantDistance();
+  bestDistance = SortPolicy::CombineWorst(bestDistance,
+      queryNode.FurthestPointDistance() +
+      queryNode.FurthestDescendantDistance());
 
   // Loop over children of the node, and use their cached information to
   // assemble bounds.
   for (size_t i = 0; i < queryNode.NumChildren(); ++i)
   {
     const double firstBound = queryNode.Child(i).Stat().FirstBound();
-    const double adjustedSecondBound = queryNode.Child(i).Stat().SecondBound() +
-        2 * (queryNode.FurthestDescendantDistance() -
-             queryNode.Child(i).FurthestDescendantDistance());
+    const double adjustment = std::max(0.0,
+        queryNode.FurthestDescendantDistance() -
+        queryNode.Child(i).FurthestDescendantDistance());
+    const double adjustedSecondBound = SortPolicy::CombineWorst(
+        queryNode.Child(i).Stat().SecondBound(), 2 * adjustment);
 
     if (SortPolicy::IsBetter(worstDistance, firstBound))
       worstDistance = firstBound;



More information about the mlpack-git mailing list