MLPACK  1.0.8
ra_search.hpp
Go to the documentation of this file.
1 
33 #ifndef __MLPACK_METHODS_RANN_RA_SEARCH_HPP
34 #define __MLPACK_METHODS_RANN_RA_SEARCH_HPP
35 
36 #include <mlpack/core.hpp>
37 
39 
42 
43 namespace mlpack {
44 namespace neighbor {
47 
56 template<typename SortPolicy>
58 {
59  private:
61  double bound;
62 
65 
66  public:
71  RAQueryStat() : bound(SortPolicy::WorstDistance()), numSamplesMade(0) { }
72 
76  template<typename TreeType>
77  RAQueryStat(const TreeType& /* node */) :
78  bound(SortPolicy::WorstDistance()),
80  { }
81 
83  double Bound() const { return bound; }
85  double& Bound() { return bound; }
86 
88  size_t NumSamplesMade() const { return numSamplesMade; }
90  size_t& NumSamplesMade() { return numSamplesMade; }
91 };
92 
113 template<typename SortPolicy = NearestNeighborSort,
114  typename MetricType = mlpack::metric::SquaredEuclideanDistance,
116  RAQueryStat<SortPolicy> > >
117 class RASearch
118 {
119  public:
141  RASearch(const typename TreeType::Mat& referenceSet,
142  const typename TreeType::Mat& querySet,
143  const bool naive = false,
144  const bool singleMode = false,
145  const size_t leafSize = 20,
146  const MetricType metric = MetricType());
147 
170  RASearch(const typename TreeType::Mat& referenceSet,
171  const bool naive = false,
172  const bool singleMode = false,
173  const size_t leafSize = 20,
174  const MetricType metric = MetricType());
175 
205  RASearch(TreeType* referenceTree,
206  TreeType* queryTree,
207  const typename TreeType::Mat& referenceSet,
208  const typename TreeType::Mat& querySet,
209  const bool singleMode = false,
210  const MetricType metric = MetricType());
211 
239  RASearch(TreeType* referenceTree,
240  const typename TreeType::Mat& referenceSet,
241  const bool singleMode = false,
242  const MetricType metric = MetricType());
243 
248  ~RASearch();
249 
286  void Search(const size_t k,
287  arma::Mat<size_t>& resultingNeighbors,
288  arma::mat& distances,
289  const double tau = 5,
290  const double alpha = 0.95,
291  const bool sampleAtLeaves = false,
292  const bool firstLeafExact = false,
293  const size_t singleSampleLimit = 20);
294 
302  void ResetQueryTree();
303 
304  private:
307  arma::mat referenceCopy;
309  arma::mat queryCopy;
310 
312  const arma::mat& referenceSet;
314  const arma::mat& querySet;
315 
317  TreeType* referenceTree;
319  TreeType* queryTree;
320 
325 
327  bool naive;
330 
332  MetricType metric;
333 
335  std::vector<size_t> oldFromNewReferences;
337  std::vector<size_t> oldFromNewQueries;
338 
341 
346  void ResetRAQueryStat(TreeType* treeNode);
347 }; // class RASearch
348 
349 }; // namespace neighbor
350 }; // namespace mlpack
351 
352 // Include implementation.
353 #include "ra_search_impl.hpp"
354 
355 // Include convenient typedefs.
356 #include "ra_typedef.hpp"
357 
358 #endif