14 #ifndef MLPACK_METHODS_RANN_RA_MODEL_HPP 15 #define MLPACK_METHODS_RANN_RA_MODEL_HPP 47 virtual const arma::mat&
Dataset()
const = 0;
65 virtual double Alpha()
const = 0;
67 virtual double&
Alpha() = 0;
70 virtual double Tau()
const = 0;
72 virtual double&
Tau() = 0;
80 virtual bool Naive()
const = 0;
82 virtual bool&
Naive() = 0;
85 virtual void Train(arma::mat&& referenceSet,
86 const size_t leafSize) = 0;
90 virtual void Search(arma::mat&& querySet,
92 arma::Mat<size_t>& neighbors,
94 const size_t leafSize) = 0;
98 virtual void Search(
const size_t k,
99 arma::Mat<size_t>& neighbors,
100 arma::mat& distances) = 0;
106 template<
template<
typename TreeMetricType,
107 typename TreeStatType,
108 typename TreeMatType>
class TreeType>
115 ra(singleMode, naive)
128 const arma::mat&
Dataset()
const {
return ra.ReferenceSet(); }
146 double Alpha()
const {
return ra.Alpha(); }
148 double&
Alpha() {
return ra.Alpha(); }
151 double Tau()
const {
return ra.Tau(); }
153 double&
Tau() {
return ra.Tau(); }
161 bool Naive()
const {
return ra.Naive(); }
163 bool&
Naive() {
return ra.Naive(); }
166 virtual void Train(arma::mat&& referenceSet,
171 virtual void Search(arma::mat&& querySet,
173 arma::Mat<size_t>& neighbors,
174 arma::mat& distances,
179 virtual void Search(
const size_t k,
180 arma::Mat<size_t>& neighbors,
181 arma::mat& distances);
184 template<
typename Archive>
205 template<
template<
typename TreeMetricType,
206 typename TreeStatType,
207 typename TreeMatType>
class TreeType>
229 virtual void Train(arma::mat&& referenceSet,
230 const size_t leafSize);
234 virtual void Search(arma::mat&& querySet,
236 arma::Mat<size_t>& neighbors,
237 arma::mat& distances,
238 const size_t leafSize);
241 template<
typename Archive>
331 template<
typename Archive>
332 void serialize(Archive& ar,
const uint32_t );
348 double Tau()
const {
return raSearch->
Tau(); }
350 double&
Tau() {
return raSearch->
Tau(); }
389 void InitializeModel(
const bool naive,
const bool singleMode);
392 void BuildModel(arma::mat&& referenceSet,
393 const size_t leafSize,
395 const bool singleMode);
399 void Search(arma::mat&& querySet,
401 arma::Mat<size_t>& neighbors,
402 arma::mat& distances);
408 void Search(
const size_t k,
409 arma::Mat<size_t>& neighbors,
410 arma::mat& distances);
413 std::string TreeName()
const;
bool & SampleAtLeaves()
Modify whether or not sampling is done at the leaves.
Definition: ra_model.hpp:360
double & Alpha()
Modify the value of alpha.
Definition: ra_model.hpp:148
double Alpha() const
Get the desired success probability.
Definition: ra_model.hpp:353
bool & SampleAtLeaves()
Modify whether to do sampling at leaves.
Definition: ra_model.hpp:143
void serialize(Archive &ar, const uint32_t)
Serialize the RASearch model.
Definition: ra_model.hpp:185
bool SingleMode() const
Get whether or not single-tree search is being used.
Definition: ra_model.hpp:338
bool & RandomBasis()
Modify whether or not a random basis is being used.
Definition: ra_model.hpp:386
bool Naive() const
Get whether or not naive search is being used.
Definition: ra_model.hpp:343
virtual RAWrapperBase * Clone() const =0
Create a new RAWrapperBase that is the same as this one.
double Tau() const
Get the value of tau.
Definition: ra_model.hpp:151
virtual const arma::mat & Dataset() const =0
Return a reference to the dataset.
RAWrapper(const bool singleMode, const bool naive)
Construct the RAWrapper object, initializing the internally-held RASearch object. ...
Definition: ra_model.hpp:114
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: cv.hpp:1
virtual bool Naive() const =0
Get whether naive search is being used.
RAType ra
The instantiated RASearch object that we are wrapping.
Definition: ra_model.hpp:197
virtual bool SingleMode() const =0
Get whether single-tree search is being used.
virtual double Tau() const =0
Get the value of tau.
size_t LeafSize() const
Get the leaf size (only relevant when the kd-tree is used).
Definition: ra_model.hpp:373
bool RandomBasis() const
Get whether or not a random basis is being used.
Definition: ra_model.hpp:383
bool SampleAtLeaves() const
Get whether to do sampling at leaves.
Definition: ra_model.hpp:141
bool & FirstLeafExact()
Modify whether or not we traverse to the first leaf without approximation.
Definition: ra_model.hpp:365
bool SingleMode() const
Get whether single-tree search is being used.
Definition: ra_model.hpp:156
bool & Naive()
Modify whether or not naive search is being used.
Definition: ra_model.hpp:345
size_t & SingleSampleLimit()
Modify the single sample limit.
Definition: ra_model.hpp:133
LeafSizeRAWrapper(const bool singleMode, const bool naive)
Construct the LeafSizeRAWrapper by delegating to the RAWrapper constructor.
Definition: ra_model.hpp:213
size_t & LeafSize()
Modify the leaf size (only relevant when the kd-tree is used).
Definition: ra_model.hpp:375
virtual bool SampleAtLeaves() const =0
Get whether to do sampling at leaves.
virtual bool FirstLeafExact() const =0
Get whether to do exact search at the first leaf.
double Tau() const
Get the rank-approximation in percentile of the data.
Definition: ra_model.hpp:348
double Alpha() const
Get the value of alpha.
Definition: ra_model.hpp:146
virtual RAWrapper * Clone() const
Create a copy of this RAWrapper object.
Definition: ra_model.hpp:125
virtual double Alpha() const =0
Get the value of alpha.
This class implements the necessary methods for the SortPolicy template parameter of the NeighborSear...
Definition: nearest_neighbor_sort.hpp:31
virtual void Search(arma::mat &&querySet, const size_t k, arma::Mat< size_t > &neighbors, arma::mat &distances, const size_t leafSize)=0
Perform bichromatic rank-approximate nearest neighbor search (i.e.
virtual ~RAWrapperBase()
Destruct the RAWrapperBase (nothing to do).
Definition: ra_model.hpp:44
bool SampleAtLeaves() const
Get whether or not sampling is done at the leaves.
Definition: ra_model.hpp:358
virtual LeafSizeRAWrapper * Clone() const
Return a copy of the LeafSizeRAWrapper.
Definition: ra_model.hpp:223
bool FirstLeafExact() const
Get whether or not we traverse to the first leaf without approximation.
Definition: ra_model.hpp:363
virtual void Train(arma::mat &&referenceSet, const size_t leafSize)=0
Train the RASearch model with the given parameters.
The L_p metric for arbitrary integer p, with an option to take the root.
Definition: lmetric.hpp:63
LeafSizeRAWrapper wraps any RASearch type that needs to be able to take the leaf size into account wh...
Definition: ra_model.hpp:208
TreeTypes
The list of tree types we can use with RASearch.
Definition: ra_model.hpp:264
bool Naive() const
Get whether naive search is being used.
Definition: ra_model.hpp:161
void serialize(Archive &ar, const uint32_t)
Serialize the RASearch model.
Definition: ra_model.hpp:242
const arma::mat & Dataset() const
Get a reference to the reference set.
Definition: ra_model.hpp:128
size_t SingleSampleLimit() const
Get the limit on the size of a node that can be approximated.
Definition: ra_model.hpp:368
bool & SingleMode()
Modify whether or not single-tree search is being used.
Definition: ra_model.hpp:340
The RASearch class: This class provides a generic manner to perform rank-approximate search via rando...
Definition: ra_search.hpp:77
bool FirstLeafExact() const
Get whether to do exact search at the first leaf.
Definition: ra_model.hpp:136
RAWrapper is a wrapper class for most RASearch types.
Definition: ra_model.hpp:109
virtual ~LeafSizeRAWrapper()
Delete the LeafSizeRAWrapper.
Definition: ra_model.hpp:220
virtual size_t SingleSampleLimit() const =0
Get the single sample limit.
double & Tau()
Modify the rank-approximation in percentile of the data.
Definition: ra_model.hpp:350
const arma::mat & Dataset() const
Expose the dataset.
Definition: ra_model.hpp:335
bool & Naive()
Modify whether naive search is being used.
Definition: ra_model.hpp:163
size_t SingleSampleLimit() const
Get the single sample limit.
Definition: ra_model.hpp:131
RAWrapperBase is a base wrapper class for holding all RASearch types supported by RAModel...
Definition: ra_model.hpp:32
virtual ~RAWrapper()
Delete the RAWrapper object.
Definition: ra_model.hpp:121
size_t & SingleSampleLimit()
Modify the limit on the size of a node that can be approximation.
Definition: ra_model.hpp:370
RAWrapperBase()
Create the RAWrapperBase object.
Definition: ra_model.hpp:37
double & Alpha()
Modify the desired success probability.
Definition: ra_model.hpp:355
The RAModel class provides an abstraction for the RASearch class, abstracting away the TreeType param...
Definition: ra_model.hpp:257
bool & SingleMode()
Modify whether single-tree search is being used.
Definition: ra_model.hpp:158
TreeTypes & TreeType()
Modify the type of tree being used.
Definition: ra_model.hpp:380
TreeTypes TreeType() const
Get the type of tree being used.
Definition: ra_model.hpp:378
double & Tau()
Modify the value of tau.
Definition: ra_model.hpp:153
bool & FirstLeafExact()
Modify whether to do exact search at the first leaf.
Definition: ra_model.hpp:138