23 #ifndef MLPACK_METHODS_RANN_RA_SEARCH_HPP 24 #define MLPACK_METHODS_RANN_RA_SEARCH_HPP 40 template<
typename SortPolicy>
65 template<
typename SortPolicy = NearestNeighborSort,
67 typename MatType = arma::mat,
68 template<
typename TreeMetricType,
69 typename TreeStatType,
75 typedef TreeType<MetricType, RAQueryStat<SortPolicy>, MatType>
Tree;
122 RASearch(
const MatType& referenceSet,
123 const bool naive =
false,
124 const bool singleMode =
false,
125 const double tau = 5,
126 const double alpha = 0.95,
127 const bool sampleAtLeaves =
false,
128 const bool firstLeafExact =
false,
129 const size_t singleSampleLimit = 20,
130 const MetricType metric = MetricType());
177 const bool naive =
false,
178 const bool singleMode =
false,
179 const double tau = 5,
180 const double alpha = 0.95,
181 const bool sampleAtLeaves =
false,
182 const bool firstLeafExact =
false,
183 const size_t singleSampleLimit = 20,
184 const MetricType metric = MetricType());
235 const bool singleMode =
false,
236 const double tau = 5,
237 const double alpha = 0.95,
238 const bool sampleAtLeaves =
false,
239 const bool firstLeafExact =
false,
240 const size_t singleSampleLimit = 20,
241 const MetricType metric = MetricType());
263 const bool singleMode =
false,
264 const double tau = 5,
265 const double alpha = 0.95,
266 const bool sampleAtLeaves =
false,
267 const bool firstLeafExact =
false,
268 const size_t singleSampleLimit = 20,
269 const MetricType metric = MetricType());
286 void Train(
const MatType& referenceSet);
297 void Train(MatType&& referenceSet);
315 void Search(
const MatType& querySet,
317 arma::Mat<size_t>& neighbors,
318 arma::mat& distances);
345 arma::Mat<size_t>& neighbors,
346 arma::mat& distances);
360 void Search(
const size_t k,
361 arma::Mat<size_t>& neighbors,
362 arma::mat& distances);
383 bool Naive()
const {
return naive; }
393 double Tau()
const {
return tau; }
395 double&
Tau() {
return tau; }
398 double Alpha()
const {
return alpha; }
418 template<
typename Archive>
419 void Serialize(Archive& ar,
const unsigned int );
423 std::vector<size_t> oldFromNewReferences;
427 const MatType* referenceSet;
449 size_t singleSampleLimit;
462 #include "ra_search_impl.hpp" size_t SingleSampleLimit() const
Get the limit on the size of a node that can be approximated.
bool SampleAtLeaves() const
Get whether or not sampling is done at the leaves.
Linear algebra utility functions, generally performed on matrices or vectors.
The core includes that mlpack expects; standard C++ includes and Armadillo.
RASearch(const MatType &referenceSet, const bool naive=false, const bool singleMode=false, const double tau=5, const double alpha=0.95, const bool sampleAtLeaves=false, const bool firstLeafExact=false, const size_t singleSampleLimit=20, const MetricType metric=MetricType())
Initialize the RASearch object, passing both a reference dataset (this is the dataset that will be se...
A binary space partitioning tree, such as a KD-tree or a ball tree.
bool & SingleMode()
Modify whether or not single-tree search is used.
size_t & SingleSampleLimit()
Modify the limit on the size of a node that can be approximation.
double & Tau()
Modify the rank-approximation in percentile of the data.
TreeType< MetricType, RAQueryStat< SortPolicy >, MatType > Tree
Convenience typedef.
bool Naive() const
Get whether or not naive (brute-force) search is used.
void Serialize(Archive &ar, const unsigned int)
Serialize the object.
bool FirstLeafExact() const
Get whether or not we traverse to the first leaf without approximation.
void ResetQueryTree(Tree *queryTree) const
This function recursively resets the RAQueryStat of the given query tree to set 'bound' to SortPolicy...
bool SingleMode() const
Get whether or not single-tree search is used.
bool & Naive()
Modify whether or not naive (brute-force) search is used.
bool & FirstLeafExact()
Modify whether or not we traverse to the first leaf without approximation.
The RASearch class: This class provides a generic manner to perform rank-approximate search via rando...
bool & SampleAtLeaves()
Modify whether or not sampling is done at the leaves.
const MatType & ReferenceSet() const
Access the reference set.
void Train(const MatType &referenceSet)
"Train" the model on the given reference set.
void Search(const MatType &querySet, const size_t k, arma::Mat< size_t > &neighbors, arma::mat &distances)
Compute the rank approximate nearest neighbors of each query point in the query set and store the out...
BinarySpaceTree< MetricType, StatisticType, MatType, bound::HRectBound, MidpointSplit > KDTree
The standard midpoint-split kd-tree.
LMetric< 2, true > EuclideanDistance
The Euclidean (L2) distance.
~RASearch()
Delete the RASearch object.
The RAModel class provides an abstraction for the RASearch class, abstracting away the TreeType param...
double & Alpha()
Modify the desired success probability.
double Tau() const
Get the rank-approximation in percentile of the data.
double Alpha() const
Get the desired success probability.