[mlpack-git] master: Fix unusual bug that pruned too tightly. (3781ccb)

gitdub at mlpack.org gitdub at mlpack.org
Thu Apr 14 14:45:37 EDT 2016


Repository : https://github.com/mlpack/mlpack
On branch  : master
Link       : https://github.com/mlpack/mlpack/compare/08ffa1b0c6d0a9fa05e2eb3dc9a993ea7fa97d54...3781ccbe93bb4cb886978b4c865ff9b42f5dbc56

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

commit 3781ccbe93bb4cb886978b4c865ff9b42f5dbc56
Author: Ryan Curtin <ryan at ratml.org>
Date:   Thu Apr 14 14:42:26 2016 -0400

    Fix unusual bug that pruned too tightly.
    
    It is possible, in very weird and occasional situations (in this case, by using
    mlpack_allkfn with phy.csv and cover trees), that a point in a candidate
    reference node would have the exact same distance as the bound distance.  But in
    this case the reference node should not be pruned, since that point in the
    candidate reference node can still update the results!  That could happen if,
    for instance, the results array for a particular point isn't completely full
    yet.


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

3781ccbe93bb4cb886978b4c865ff9b42f5dbc56
 src/mlpack/methods/neighbor_search/neighbor_search_rules_impl.hpp   | 2 +-
 .../neighbor_search/sort_policies/furthest_neighbor_sort.hpp        | 6 +++---
 .../methods/neighbor_search/sort_policies/nearest_neighbor_sort.hpp | 6 +++---
 3 files changed, 7 insertions(+), 7 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 f4d3712..0d5f6dc 100644
--- a/src/mlpack/methods/neighbor_search/neighbor_search_rules_impl.hpp
+++ b/src/mlpack/methods/neighbor_search/neighbor_search_rules_impl.hpp
@@ -231,7 +231,7 @@ inline double NeighborSearchRules<SortPolicy, MetricType, TreeType>::Score(
   }
 
   // Can we prune?
-  if (SortPolicy::IsBetter(bestDistance, adjustedScore))
+  if (!SortPolicy::IsBetter(adjustedScore, bestDistance))
   {
     if (!(tree::TreeTraits<TreeType>::FirstPointIsCentroid && score == 0.0))
     {
diff --git a/src/mlpack/methods/neighbor_search/sort_policies/furthest_neighbor_sort.hpp b/src/mlpack/methods/neighbor_search/sort_policies/furthest_neighbor_sort.hpp
index b2ff1ca..a4694ae 100644
--- a/src/mlpack/methods/neighbor_search/sort_policies/furthest_neighbor_sort.hpp
+++ b/src/mlpack/methods/neighbor_search/sort_policies/furthest_neighbor_sort.hpp
@@ -42,16 +42,16 @@ class FurthestNeighborSort
 
   /**
    * Return whether or not value is "better" than ref.  In this case, that means
-   * that the value is greater than the reference.
+   * that the value is greater than or equal to the reference.
    *
    * @param value Value to compare
    * @param ref Value to compare with
    *
-   * @return bool indicating whether or not (value > ref).
+   * @return bool indicating whether or not (value >= ref).
    */
   static inline bool IsBetter(const double value, const double ref)
   {
-    return (value > ref);
+    return (value >= ref);
   }
 
   /**
diff --git a/src/mlpack/methods/neighbor_search/sort_policies/nearest_neighbor_sort.hpp b/src/mlpack/methods/neighbor_search/sort_policies/nearest_neighbor_sort.hpp
index 8fdf321..0783b84 100644
--- a/src/mlpack/methods/neighbor_search/sort_policies/nearest_neighbor_sort.hpp
+++ b/src/mlpack/methods/neighbor_search/sort_policies/nearest_neighbor_sort.hpp
@@ -46,16 +46,16 @@ class NearestNeighborSort
 
   /**
    * Return whether or not value is "better" than ref.  In this case, that means
-   * that the value is less than the reference.
+   * that the value is less than or equal to the reference.
    *
    * @param value Value to compare
    * @param ref Value to compare with
    *
-   * @return bool indicating whether or not (value < ref).
+   * @return bool indicating whether or not (value <= ref).
    */
   static inline bool IsBetter(const double value, const double ref)
   {
-    return (value < ref);
+    return (value <= ref);
   }
 
   /**




More information about the mlpack-git mailing list