14 #ifndef MLPACK_METHODS_RANN_RA_MODEL_HPP
15 #define MLPACK_METHODS_RANN_RA_MODEL_HPP
21 #include <boost/variant.hpp>
30 template<
typename SortPolicy,
31 template<
typename TreeMetricType,
32 typename TreeStatType,
33 typename TreeMatType>
class TreeType>
49 arma::Mat<size_t>& neighbors;
55 template<
typename RAType>
60 arma::Mat<size_t>& neighbors,
61 arma::mat& distances) :
74 template<
typename SortPolicy>
75 class BiSearchVisitor :
public boost::static_visitor<void>
79 const arma::mat& querySet;
83 arma::Mat<size_t>& neighbors;
87 const size_t leafSize;
90 template<
typename RAType>
91 void SearchLeaf(
RAType* ra)
const;
95 template<
template<
typename TreeMetricType,
96 typename TreeStatType,
97 typename TreeMatType>
class TreeType>
101 template<
template<
typename TreeMetricType,
102 typename TreeStatType,
103 typename TreeMatType>
class TreeType>
115 arma::Mat<size_t>& neighbors,
116 arma::mat& distances,
117 const size_t leafSize);
126 template<
typename SortPolicy>
131 arma::mat&& referenceSet;
136 template<
typename RAType>
137 void TrainLeaf(
RAType* ra)
const;
141 template<
template<
typename TreeMetricType,
142 typename TreeStatType,
143 typename TreeMatType>
class TreeType>
147 template<
template<
typename TreeMetricType,
148 typename TreeStatType,
149 typename TreeMatType>
class TreeType>
161 const size_t leafSize);
170 template<
typename RAType>
180 template<
typename RAType>
191 template<
typename RAType>
202 template<
typename RAType>
213 template<
typename RAType>
224 template<
typename RAType>
235 template<
typename RAType>
258 template<
typename RAType>
270 template<
typename SortPolicy>
304 boost::variant<RAType<SortPolicy, tree::KDTree>*,
354 template<
typename Archive>
413 const size_t leafSize,
415 const bool singleMode);
421 arma::Mat<size_t>& neighbors,
422 arma::mat& distances);
429 arma::Mat<size_t>& neighbors,
430 arma::mat& distances);
439 #include "ra_model_impl.hpp"
Exposes the Alpha() method of the given RAType.
double & operator()(RAType *ra) const
Return Alpha parameter.
void operator()(RATypeT< tree::Octree > *ra) const
Bichromatic search on the given RAType specialized for octrees.
BiSearchVisitor(const arma::mat &querySet, const size_t k, arma::Mat< size_t > &neighbors, arma::mat &distances, const size_t leafSize)
Construct the BiSearchVisitor.
void operator()(RATypeT< tree::KDTree > *ra) const
Bichromatic search on the given RAType specialized for KDTrees.
DeleteVisitor deletes the given NSType instance.
void operator()(RAType *ra) const
Delete the RAType Object.
Exposes the FirstLeafExact() method of the given RAType.
bool & operator()(RAType *ra) const
MonoSearchVisitor executes a monochromatic neighbor search on the given NSType.
void operator()(RAType *ra) const
Perform monochromatic nearest neighbor search.
MonoSearchVisitor(const size_t k, arma::Mat< size_t > &neighbors, arma::mat &distances)
Construct the MonoSearchVisitor object with the given parameters.
NaiveVisitor exposes the Naive() method of the given RAType.
bool & operator()(RAType *ra) const
Get a reference to the naive parameter of the given RASearch object.
The RAModel class provides an abstraction for the RASearch class, abstracting away the TreeType param...
size_t & LeafSize()
Modify the leaf size (only relevant when the kd-tree is used).
bool FirstLeafExact() const
Get whether or not we traverse to the first leaf without approximation.
RAModel(RAModel &&other)
Take ownership of the given RAModel.
bool Naive() const
Get whether or not naive search is being used.
void BuildModel(arma::mat &&referenceSet, const size_t leafSize, const bool naive, const bool singleMode)
Build the reference tree.
size_t SingleSampleLimit() const
Get the limit on the size of a node that can be approximated.
double Tau() const
Get the rank-approximation in percentile of the data.
double Alpha() const
Get the desired success probability.
TreeTypes & TreeType()
Modify the type of tree being used.
void Search(const size_t k, arma::Mat< size_t > &neighbors, arma::mat &distances)
Perform rank-approximate neighbor search, using the reference set as the query set.
TreeTypes
The list of tree types we can use with RASearch.
bool SingleMode() const
Get whether or not single-tree search is being used.
bool & RandomBasis()
Modify whether or not a random basis is being used.
~RAModel()
Clean memory, if necessary.
RAModel(const RAModel &other)
Copy the given RAModel.
std::string TreeName() const
Get the name of the tree type.
RAModel & operator=(RAModel &&other)
Take ownership of the given RAModel.
bool & SampleAtLeaves()
Modify whether or not sampling is done at the leaves.
RAModel(TreeTypes treeType=TreeTypes::KD_TREE, bool randomBasis=false)
Initialize the RAModel with the given type and whether or not a random basis should be used.
bool SampleAtLeaves() const
Get whether or not sampling is done at the leaves.
size_t LeafSize() const
Get the leaf size (only relevant when the kd-tree is used).
bool & FirstLeafExact()
Modify whether or not we traverse to the first leaf without approximation.
double & Alpha()
Modify the desired success probability.
double & Tau()
Modify the rank-approximation in percentile of the data.
bool & SingleMode()
Modify whether or not single-tree search is being used.
TreeTypes TreeType() const
Get the type of tree being used.
bool RandomBasis() const
Get whether or not a random basis is being used.
size_t & SingleSampleLimit()
Modify the limit on the size of a node that can be approximation.
void serialize(Archive &ar, const unsigned int)
Serialize the model.
RAModel & operator=(const RAModel &other)
Copy the given RAModel.
void Search(arma::mat &&querySet, const size_t k, arma::Mat< size_t > &neighbors, arma::mat &distances)
Perform rank-approximate neighbor search, taking ownership of the query set.
bool & Naive()
Modify whether or not naive search is being used.
const arma::mat & Dataset() const
Expose the dataset.
The RASearch class: This class provides a generic manner to perform rank-approximate search via rando...
ReferenceSetVisitor exposes the referenceSet of the given NSType.
const arma::mat & operator()(RAType *ra) const
Return the reference set.
Exposes the SampleAtLeaves() method of the given RAType.
bool & operator()(RAType *) const
Return SampleAtLeaves (whether or not sampling is done at leaves).
Exposes the SingleMode() method of the given RAType.
bool & operator()(RAType *ra) const
Get a reference to the SingleMode parameter of the given RASearch object.
Exposes the SingleSampleLimit() method of the given RAType.
size_t & operator()(RAType *ra) const
Exposes the Tau() method of the given RAType.
double & operator()(RAType *ra) const
Get a reference to the Tau parameter.
TrainVisitor sets the reference set to a new reference set on the given NSType.
void operator()(RATypeT< tree::Octree > *ra) const
Train on the given RAType specialized for Octrees.
TrainVisitor(arma::mat &&referenceSet, const size_t leafSize)
Construct the TrainVisitor object with the given reference set, leafSize for BinarySpaceTrees.
void operator()(RATypeT< tree::KDTree > *ra) const
Train on the given RAType specialized for KDTrees.
LMetric< 2, true > EuclideanDistance
The Euclidean (L2) distance.
RASearch< SortPolicy, metric::EuclideanDistance, arma::mat, TreeType > RAType
Alias template for RASearch.
Linear algebra utility functions, generally performed on matrices or vectors.