ra_search.hpp
Go to the documentation of this file.00001
00033 #ifndef __MLPACK_METHODS_RANN_RA_SEARCH_HPP
00034 #define __MLPACK_METHODS_RANN_RA_SEARCH_HPP
00035
00036 #include <mlpack/core.hpp>
00037
00038 #include <mlpack/core/tree/binary_space_tree.hpp>
00039
00040 #include <mlpack/core/metrics/lmetric.hpp>
00041 #include <mlpack/methods/neighbor_search/sort_policies/nearest_neighbor_sort.hpp>
00042
00043 namespace mlpack {
00044 namespace neighbor {
00047
00056 template<typename SortPolicy>
00057 class RAQueryStat
00058 {
00059 private:
00061 double bound;
00062
00064 size_t numSamplesMade;
00065
00066 public:
00071 RAQueryStat() : bound(SortPolicy::WorstDistance()), numSamplesMade(0) { }
00072
00076 template<typename TreeType>
00077 RAQueryStat(const TreeType& ) :
00078 bound(SortPolicy::WorstDistance()),
00079 numSamplesMade(0)
00080 { }
00081
00083 double Bound() const { return bound; }
00085 double& Bound() { return bound; }
00086
00088 size_t NumSamplesMade() const { return numSamplesMade; }
00090 size_t& NumSamplesMade() { return numSamplesMade; }
00091 };
00092
00113 template<typename SortPolicy = NearestNeighborSort,
00114 typename MetricType = mlpack::metric::SquaredEuclideanDistance,
00115 typename TreeType = tree::BinarySpaceTree<bound::HRectBound<2, false>,
00116 RAQueryStat<SortPolicy> > >
00117 class RASearch
00118 {
00119 public:
00141 RASearch(const typename TreeType::Mat& referenceSet,
00142 const typename TreeType::Mat& querySet,
00143 const bool naive = false,
00144 const bool singleMode = false,
00145 const size_t leafSize = 20,
00146 const MetricType metric = MetricType());
00147
00170 RASearch(const typename TreeType::Mat& referenceSet,
00171 const bool naive = false,
00172 const bool singleMode = false,
00173 const size_t leafSize = 20,
00174 const MetricType metric = MetricType());
00175
00205 RASearch(TreeType* referenceTree,
00206 TreeType* queryTree,
00207 const typename TreeType::Mat& referenceSet,
00208 const typename TreeType::Mat& querySet,
00209 const bool singleMode = false,
00210 const MetricType metric = MetricType());
00211
00239 RASearch(TreeType* referenceTree,
00240 const typename TreeType::Mat& referenceSet,
00241 const bool singleMode = false,
00242 const MetricType metric = MetricType());
00243
00248 ~RASearch();
00249
00286 void Search(const size_t k,
00287 arma::Mat<size_t>& resultingNeighbors,
00288 arma::mat& distances,
00289 const double tau = 5,
00290 const double alpha = 0.95,
00291 const bool sampleAtLeaves = false,
00292 const bool firstLeafExact = false,
00293 const size_t singleSampleLimit = 20);
00294
00302 void ResetQueryTree();
00303
00304 private:
00307 arma::mat referenceCopy;
00309 arma::mat queryCopy;
00310
00312 const arma::mat& referenceSet;
00314 const arma::mat& querySet;
00315
00317 TreeType* referenceTree;
00319 TreeType* queryTree;
00320
00322 bool ownReferenceTree;
00324 bool ownQueryTree;
00325
00327 bool naive;
00329 bool singleMode;
00330
00332 MetricType metric;
00333
00335 std::vector<size_t> oldFromNewReferences;
00337 std::vector<size_t> oldFromNewQueries;
00338
00340 size_t numberOfPrunes;
00341
00346 void ResetRAQueryStat(TreeType* treeNode);
00347 };
00348
00349 };
00350 };
00351
00352
00353 #include "ra_search_impl.hpp"
00354
00355
00356 #include "ra_typedef.hpp"
00357
00358 #endif