mlpack  1.0.12
ra_search.hpp
Go to the documentation of this file.
1 
25 #ifndef __MLPACK_METHODS_RANN_RA_SEARCH_HPP
26 #define __MLPACK_METHODS_RANN_RA_SEARCH_HPP
27 
28 #include <mlpack/core.hpp>
29 
31 
34 
35 #include "ra_query_stat.hpp"
36 
59 template<typename SortPolicy = NearestNeighborSort,
60  typename MetricType = mlpack::metric::SquaredEuclideanDistance,
61  typename TreeType = tree::BinarySpaceTree<bound::HRectBound<2, false>,
62  RAQueryStat<SortPolicy> > >
63 class RASearch
64 {
65  public:
87  RASearch(const typename TreeType::Mat& referenceSet,
88  const typename TreeType::Mat& querySet,
89  const bool naive = false,
90  const bool singleMode = false,
91  const MetricType metric = MetricType());
92 
115  RASearch(const typename TreeType::Mat& referenceSet,
116  const bool naive = false,
117  const bool singleMode = false,
118  const MetricType metric = MetricType());
119 
149  RASearch(TreeType* referenceTree,
150  TreeType* queryTree,
151  const typename TreeType::Mat& referenceSet,
152  const typename TreeType::Mat& querySet,
153  const bool singleMode = false,
154  const MetricType metric = MetricType());
155 
183  RASearch(TreeType* referenceTree,
184  const typename TreeType::Mat& referenceSet,
185  const bool singleMode = false,
186  const MetricType metric = MetricType());
187 
192  ~RASearch();
193 
230  void Search(const size_t k,
231  arma::Mat<size_t>& resultingNeighbors,
232  arma::mat& distances,
233  const double tau = 5,
234  const double alpha = 0.95,
235  const bool sampleAtLeaves = false,
236  const bool firstLeafExact = false,
237  const size_t singleSampleLimit = 20);
238 
246  void ResetQueryTree();
247 
248  // Returns a string representation of this object.
249  std::string ToString() const;
250 
251  private:
254  arma::mat referenceCopy;
256  arma::mat queryCopy;
257 
259  const arma::mat& referenceSet;
261  const arma::mat& querySet;
262 
264  TreeType* referenceTree;
266  TreeType* queryTree;
267 
269  bool treeOwner;
272 
274  bool naive;
277 
279  MetricType metric;
280 
282  std::vector<size_t> oldFromNewReferences;
284  std::vector<size_t> oldFromNewQueries;
285 
288 
293  void ResetRAQueryStat(TreeType* treeNode);
294 }; // class RASearch
295 
296 }; // namespace neighbor
297 }; // namespace mlpack
298 
299 // Include implementation.
300 #include "ra_search_impl.hpp"
301 
302 // Include convenient typedefs.
303 #include "ra_typedef.hpp"
304 
305 #endif
const arma::mat & querySet
Query dataset (may not be given).
Definition: ra_search.hpp:261
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:279
std::string ToString() const
LMetric< 2, false > SquaredEuclideanDistance
Definition: lmetric.hpp:92
void ResetRAQueryStat(TreeType *treeNode)
bool hasQuerySet
Indicates if a separate query set was passed.
Definition: ra_search.hpp:271
The RASearch class: This class provides a generic manner to perform rank-approximate search via rando...
Definition: ra_search.hpp:63
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:259
arma::mat queryCopy
Copy of query dataset (if we need it, because tree building modifies it).
Definition: ra_search.hpp:256
TreeType * referenceTree
Pointer to the root of the reference tree.
Definition: ra_search.hpp:264
size_t numberOfPrunes
Total number of pruned nodes during the neighbor search.
Definition: ra_search.hpp:287
std::vector< size_t > oldFromNewReferences
Permutations of reference points during tree building.
Definition: ra_search.hpp:282
TreeType * queryTree
Pointer to the root of the query tree (might not exist).
Definition: ra_search.hpp:266
arma::mat referenceCopy
Copy of reference dataset (if we need it, because tree building modifies it).
Definition: ra_search.hpp:254
~RASearch()
Delete the RASearch object.
std::vector< size_t > oldFromNewQueries
Permutations of query points during tree building.
Definition: ra_search.hpp:284
bool treeOwner
If true, this object created the trees and is responsible for them.
Definition: ra_search.hpp:269
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:274
bool singleMode
Indicates if single-tree search is being used (opposed to dual-tree).
Definition: ra_search.hpp:276
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.