MLPACK  1.0.11
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 #include "ra_query_stat.hpp"
44 
67 template<typename SortPolicy = NearestNeighborSort,
68  typename MetricType = mlpack::metric::SquaredEuclideanDistance,
69  typename TreeType = tree::BinarySpaceTree<bound::HRectBound<2, false>,
70  RAQueryStat<SortPolicy> > >
71 class RASearch
72 {
73  public:
95  RASearch(const typename TreeType::Mat& referenceSet,
96  const typename TreeType::Mat& querySet,
97  const bool naive = false,
98  const bool singleMode = false,
99  const MetricType metric = MetricType());
100 
123  RASearch(const typename TreeType::Mat& referenceSet,
124  const bool naive = false,
125  const bool singleMode = false,
126  const MetricType metric = MetricType());
127 
157  RASearch(TreeType* referenceTree,
158  TreeType* queryTree,
159  const typename TreeType::Mat& referenceSet,
160  const typename TreeType::Mat& querySet,
161  const bool singleMode = false,
162  const MetricType metric = MetricType());
163 
191  RASearch(TreeType* referenceTree,
192  const typename TreeType::Mat& referenceSet,
193  const bool singleMode = false,
194  const MetricType metric = MetricType());
195 
200  ~RASearch();
201 
238  void Search(const size_t k,
239  arma::Mat<size_t>& resultingNeighbors,
240  arma::mat& distances,
241  const double tau = 5,
242  const double alpha = 0.95,
243  const bool sampleAtLeaves = false,
244  const bool firstLeafExact = false,
245  const size_t singleSampleLimit = 20);
246 
254  void ResetQueryTree();
255 
256  // Returns a string representation of this object.
257  std::string ToString() const;
258 
259  private:
262  arma::mat referenceCopy;
264  arma::mat queryCopy;
265 
267  const arma::mat& referenceSet;
269  const arma::mat& querySet;
270 
272  TreeType* referenceTree;
274  TreeType* queryTree;
275 
277  bool treeOwner;
280 
282  bool naive;
285 
287  MetricType metric;
288 
290  std::vector<size_t> oldFromNewReferences;
292  std::vector<size_t> oldFromNewQueries;
293 
296 
301  void ResetRAQueryStat(TreeType* treeNode);
302 }; // class RASearch
303 
304 }; // namespace neighbor
305 }; // namespace mlpack
306 
307 // Include implementation.
308 #include "ra_search_impl.hpp"
309 
310 // Include convenient typedefs.
311 #include "ra_typedef.hpp"
312 
313 #endif
const arma::mat & querySet
Query dataset (may not be given).
Definition: ra_search.hpp:269
void ResetQueryTree()
This function recursively resets the RAQueryStat of the queryTree to set 'bound' to WorstDistance and...
MetricType metric
Instantiation of kernel.
Definition: ra_search.hpp:287
std::string ToString() const
LMetric< 2, false > SquaredEuclideanDistance
Definition: lmetric.hpp:100
void ResetRAQueryStat(TreeType *treeNode)
bool hasQuerySet
Indicates if a separate query set was passed.
Definition: ra_search.hpp:279
The RASearch class: This class provides a generic manner to perform rank-approximate search via rando...
Definition: ra_search.hpp:71
RASearch(const typename TreeType::Mat &referenceSet, const typename TreeType::Mat &querySet, const bool naive=false, const bool singleMode=false, const MetricType metric=MetricType())
Initialize the RASearch object, passing both a query and reference dataset.
const arma::mat & referenceSet
Reference dataset.
Definition: ra_search.hpp:267
arma::mat queryCopy
Copy of query dataset (if we need it, because tree building modifies it).
Definition: ra_search.hpp:264
TreeType * referenceTree
Pointer to the root of the reference tree.
Definition: ra_search.hpp:272
size_t numberOfPrunes
Total number of pruned nodes during the neighbor search.
Definition: ra_search.hpp:295
std::vector< size_t > oldFromNewReferences
Permutations of reference points during tree building.
Definition: ra_search.hpp:290
TreeType * queryTree
Pointer to the root of the query tree (might not exist).
Definition: ra_search.hpp:274
arma::mat referenceCopy
Copy of reference dataset (if we need it, because tree building modifies it).
Definition: ra_search.hpp:262
~RASearch()
Delete the RASearch object.
std::vector< size_t > oldFromNewQueries
Permutations of query points during tree building.
Definition: ra_search.hpp:292
bool treeOwner
If true, this object created the trees and is responsible for them.
Definition: ra_search.hpp:277
see subsection cli_alt_reg_tut Alternate DET regularization The usual regularized error f $R_ alpha(t)\f $of a node\f $t\f $is given by
Definition: det.txt:367
bool naive
Indicates if naive random sampling on the set is being used.
Definition: ra_search.hpp:282
bool singleMode
Indicates if single-tree search is being used (opposed to dual-tree).
Definition: ra_search.hpp:284
void Search(const size_t k, arma::Mat< size_t > &resultingNeighbors, arma::mat &distances, const double tau=5, const double alpha=0.95, const bool sampleAtLeaves=false, const bool firstLeafExact=false, const size_t singleSampleLimit=20)
Compute the rank approximate nearest neighbors and store the output in the given matrices.