mlpack
furthest_neighbor_sort.hpp
Go to the documentation of this file.
1 
13 #ifndef MLPACK_METHODS_NEIGHBOR_SEARCH_FURTHEST_NEIGHBOR_SORT_HPP
14 #define MLPACK_METHODS_NEIGHBOR_SEARCH_FURTHEST_NEIGHBOR_SORT_HPP
15 
16 #include <mlpack/prereqs.hpp>
17 
18 namespace mlpack {
19 namespace neighbor {
20 
28 {
29  public:
39  static inline bool IsBetter(const double value, const double ref)
40  {
41  return (value >= ref);
42  }
43 
49  template<typename TreeType>
50  static double BestNodeToNodeDistance(const TreeType* queryNode,
51  const TreeType* referenceNode);
52 
59  template<typename TreeType>
60  static double BestNodeToNodeDistance(const TreeType* queryNode,
61  const TreeType* referenceNode,
62  const double centerToCenterDistance);
63 
76  template<typename TreeType>
77  static double BestNodeToNodeDistance(const TreeType* queryNode,
78  const TreeType* referenceNode,
79  const TreeType* referenceChildNode,
80  const double centerToCenterDistance);
81 
87  template<typename VecType, typename TreeType>
88  static double BestPointToNodeDistance(const VecType& queryPoint,
89  const TreeType* referenceNode);
90 
97  template<typename VecType, typename TreeType>
98  static double BestPointToNodeDistance(const VecType& queryPoint,
99  const TreeType* referenceNode,
100  const double pointToCenterDistance);
101 
106  template<typename VecType, typename TreeType>
107  static size_t GetBestChild(const VecType& queryPoint, TreeType& referenceNode)
108  {
109  return referenceNode.GetFurthestChild(queryPoint);
110  };
111 
116  template<typename TreeType>
117  static size_t GetBestChild(const TreeType& queryNode, TreeType& referenceNode)
118  {
119  return referenceNode.GetFurthestChild(queryNode);
120  };
121 
129  static inline double WorstDistance() { return 0; }
130 
138  static inline double BestDistance() { return DBL_MAX; }
139 
143  static inline double CombineBest(const double a, const double b)
144  {
145  if (a == DBL_MAX || b == DBL_MAX)
146  return DBL_MAX;
147  return a + b;
148  }
149 
153  static inline double CombineWorst(const double a, const double b)
154  { return std::max(a - b, 0.0); }
155 
164  static inline double Relax(const double value, const double epsilon)
165  {
166  if (value == 0)
167  return 0;
168  if (value == DBL_MAX || epsilon >= 1)
169  return DBL_MAX;
170  return (1 / (1 - epsilon)) * value;
171  }
172 
178  static inline double ConvertToScore(const double distance)
179  {
180  if (distance == DBL_MAX)
181  return 0.0;
182  else if (distance == 0.0)
183  return DBL_MAX;
184  else
185  return (1.0 / distance);
186  }
187 
193  static inline double ConvertToDistance(const double score)
194  {
195  return ConvertToScore(score);
196  }
197 };
198 
199 // Due to an internal MinGW compiler bug (string table overflow) we have to
200 // truncate the class name. For backward compatibility we setup an alias here.
202 
203 } // namespace neighbor
204 } // namespace mlpack
205 
206 // Include implementation of templated functions.
207 #include "furthest_neighbor_sort_impl.hpp"
208 
209 #endif
static size_t GetBestChild(const TreeType &queryNode, TreeType &referenceNode)
Return the best child according to this sort policy.
Definition: furthest_neighbor_sort.hpp:117
static double ConvertToDistance(const double score)
Convert the given score back to a distance.
Definition: furthest_neighbor_sort.hpp:193
static double ConvertToScore(const double distance)
Convert the given distance to a score.
Definition: furthest_neighbor_sort.hpp:178
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: cv.hpp:1
static double CombineWorst(const double a, const double b)
Return the worst combination of the two distances.
Definition: furthest_neighbor_sort.hpp:153
The core includes that mlpack expects; standard C++ includes and Armadillo.
static double BestPointToNodeDistance(const VecType &queryPoint, const TreeType *referenceNode)
Return the best possible distance between a node and a point.
Definition: furthest_neighbor_sort_impl.hpp:50
static double CombineBest(const double a, const double b)
Return the best combination of the two distances.
Definition: furthest_neighbor_sort.hpp:143
This class implements the necessary methods for the SortPolicy template parameter of the NeighborSear...
Definition: furthest_neighbor_sort.hpp:27
static size_t GetBestChild(const VecType &queryPoint, TreeType &referenceNode)
Return the best child according to this sort policy.
Definition: furthest_neighbor_sort.hpp:107
static double Relax(const double value, const double epsilon)
Return the given value relaxed.
Definition: furthest_neighbor_sort.hpp:164
static bool IsBetter(const double value, const double ref)
Return whether or not value is "better" than ref.
Definition: furthest_neighbor_sort.hpp:39
static double BestDistance()
Return what should represent the best possible distance with this particular sort policy...
Definition: furthest_neighbor_sort.hpp:138
static double WorstDistance()
Return what should represent the worst possible distance with this particular sort policy...
Definition: furthest_neighbor_sort.hpp:129
static double BestNodeToNodeDistance(const TreeType *queryNode, const TreeType *referenceNode)
Return the best possible distance between two nodes.
Definition: furthest_neighbor_sort_impl.hpp:20