mlpack
nearest_neighbor_sort.hpp
Go to the documentation of this file.
1 
13 #ifndef MLPACK_METHODS_NEIGHBOR_SEARCH_NEAREST_NEIGHBOR_SORT_HPP
14 #define MLPACK_METHODS_NEIGHBOR_SEARCH_NEAREST_NEIGHBOR_SORT_HPP
15 
16 #include <mlpack/prereqs.hpp>
17 
18 namespace mlpack {
19 namespace neighbor {
20 
31 class NearestNS
32 {
33  public:
43  static inline bool IsBetter(const double value, const double ref)
44  {
45  return (value <= ref);
46  }
47 
53  template<typename TreeType>
54  static double BestNodeToNodeDistance(const TreeType* queryNode,
55  const TreeType* referenceNode);
56 
63  template<typename TreeType>
64  static double BestNodeToNodeDistance(const TreeType* queryNode,
65  const TreeType* referenceNode,
66  const double centerToCenterDistance);
67 
80  template<typename TreeType>
81  static double BestNodeToNodeDistance(const TreeType* queryNode,
82  const TreeType* referenceNode,
83  const TreeType* referenceChildNode,
84  const double centerToCenterDistance);
85 
91  template<typename VecType, typename TreeType>
92  static double BestPointToNodeDistance(const VecType& queryPoint,
93  const TreeType* referenceNode);
94 
101  template<typename VecType, typename TreeType>
102  static double BestPointToNodeDistance(const VecType& queryPoint,
103  const TreeType* referenceNode,
104  const double pointToCenterDistance);
105 
110  template<typename VecType, typename TreeType>
111  static size_t GetBestChild(const VecType& queryPoint, TreeType& referenceNode)
112  {
113  return referenceNode.GetNearestChild(queryPoint);
114  };
115 
120  template<typename TreeType>
121  static size_t GetBestChild(const TreeType& queryNode, TreeType& referenceNode)
122  {
123  return referenceNode.GetNearestChild(queryNode);
124  };
125 
133  static inline double WorstDistance() { return DBL_MAX; }
134 
142  static inline double BestDistance() { return 0.0; }
143 
147  static inline double CombineBest(const double a, const double b)
148  {
149  return std::max(a - b, 0.0);
150  }
151 
155  static inline double CombineWorst(const double a, const double b)
156  {
157  if (a == DBL_MAX || b == DBL_MAX)
158  return DBL_MAX;
159  return a + b;
160  }
161 
170  static inline double Relax(const double value, const double epsilon)
171  {
172  if (value == DBL_MAX)
173  return DBL_MAX;
174  return (1 / (1 + epsilon)) * value;
175  }
176 
182  static inline double ConvertToScore(const double distance)
183  {
184  return distance;
185  }
186 
192  static inline double ConvertToDistance(const double score)
193  {
194  return score;
195  }
196 };
197 
198 // Due to an internal MinGW compiler bug (string table overflow) we have to
199 // truncate the class name. For backward compatibility we setup an alias here.
201 
202 } // namespace neighbor
203 } // namespace mlpack
204 
205 // Include implementation of templated functions.
207 
208 #endif
static double Relax(const double value, const double epsilon)
Return the given value relaxed.
Definition: nearest_neighbor_sort.hpp:170
static double BestDistance()
Return what should represent the best possible distance with this particular sort policy...
Definition: nearest_neighbor_sort.hpp:142
static double WorstDistance()
Return what should represent the worst possible distance with this particular sort policy...
Definition: nearest_neighbor_sort.hpp:133
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: cv.hpp:1
static double ConvertToScore(const double distance)
Convert the given distance into a score.
Definition: nearest_neighbor_sort.hpp:182
static double ConvertToDistance(const double score)
Convert the given score to a distance.
Definition: nearest_neighbor_sort.hpp:192
static double CombineWorst(const double a, const double b)
Return the worst combination of the two distances.
Definition: nearest_neighbor_sort.hpp:155
The core includes that mlpack expects; standard C++ includes and Armadillo.
static size_t GetBestChild(const TreeType &queryNode, TreeType &referenceNode)
Return the best child according to this sort policy.
Definition: nearest_neighbor_sort.hpp:121
static double CombineBest(const double a, const double b)
Return the best combination of the two distances.
Definition: nearest_neighbor_sort.hpp:147
static bool IsBetter(const double value, const double ref)
Return whether or not value is "better" than ref.
Definition: nearest_neighbor_sort.hpp:43
This class implements the necessary methods for the SortPolicy template parameter of the NeighborSear...
Definition: nearest_neighbor_sort.hpp:31
static double BestPointToNodeDistance(const VecType &queryPoint, const TreeType *referenceNode)
Return the best possible distance between a node and a point.
Definition: nearest_neighbor_sort_impl.hpp:50
static double BestNodeToNodeDistance(const TreeType *queryNode, const TreeType *referenceNode)
Return the best possible distance between two nodes.
Definition: nearest_neighbor_sort_impl.hpp:20
static size_t GetBestChild(const VecType &queryPoint, TreeType &referenceNode)
Return the best child according to this sort policy.
Definition: nearest_neighbor_sort.hpp:111