mlpack  master
ra_model.hpp
Go to the documentation of this file.
1 
14 #ifndef MLPACK_METHODS_RANN_RA_MODEL_HPP
15 #define MLPACK_METHODS_RANN_RA_MODEL_HPP
16 
21 
22 #include "ra_search.hpp"
23 
24 namespace mlpack {
25 namespace neighbor {
26 
35 template<typename SortPolicy>
36 class RAModel
37 {
38  public:
43  enum TreeTypes
44  {
55  };
56 
57  private:
61  size_t leafSize;
62 
66  arma::mat q;
67 
69  template<template<typename TreeMetricType,
70  typename TreeStatType,
71  typename TreeMatType> class TreeType>
72  using RAType = RASearch<SortPolicy,
74  arma::mat,
76 
97 
98  public:
103  RAModel(TreeTypes treeType = TreeTypes::KD_TREE, bool randomBasis = false);
104 
110  RAModel(const RAModel& other);
111 
117  RAModel(RAModel&& other);
118 
124  RAModel& operator=(const RAModel& other);
125 
131  RAModel& operator=(RAModel&& other);
132 
134  ~RAModel();
135 
137  template<typename Archive>
138  void Serialize(Archive& ar, const unsigned int /* version */);
139 
141  const arma::mat& Dataset() const;
142 
144  bool SingleMode() const;
146  bool& SingleMode();
147 
149  bool Naive() const;
151  bool& Naive();
152 
154  double Tau() const;
156  double& Tau();
157 
159  double Alpha() const;
161  double& Alpha();
162 
164  bool SampleAtLeaves() const;
166  bool& SampleAtLeaves();
167 
169  bool FirstLeafExact() const;
171  bool& FirstLeafExact();
172 
174  size_t SingleSampleLimit() const;
176  size_t& SingleSampleLimit();
177 
179  size_t LeafSize() const;
181  size_t& LeafSize();
182 
184  TreeTypes TreeType() const;
186  TreeTypes& TreeType();
187 
189  bool RandomBasis() const;
192  bool& RandomBasis();
193 
195  void BuildModel(arma::mat&& referenceSet,
196  const size_t leafSize,
197  const bool naive,
198  const bool singleMode);
199 
202  void Search(arma::mat&& querySet,
203  const size_t k,
204  arma::Mat<size_t>& neighbors,
205  arma::mat& distances);
206 
211  void Search(const size_t k,
212  arma::Mat<size_t>& neighbors,
213  arma::mat& distances);
214 
216  std::string TreeName() const;
217 };
218 
219 } // namespace neighbor
220 } // namespace mlpack
221 
222 #include "ra_model_impl.hpp"
223 
224 #endif
bool SampleAtLeaves() const
Get whether or not sampling is done at the leaves.
void Serialize(Archive &ar, const unsigned int)
Serialize the model.
double Tau() const
Get the rank-approximation in percentile of the data.
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: binarize.hpp:18
RAType< tree::RPlusPlusTree > * rPlusPlusTreeRA
Non-NULL if the R++ tree is used.
Definition: ra_model.hpp:92
LMetric< 2, true > EuclideanDistance
The Euclidean (L2) distance.
Definition: lmetric.hpp:112
RAType< tree::RStarTree > * rStarTreeRA
Non-NULL if the R* tree is used.
Definition: ra_model.hpp:84
RAType< tree::UBTree > * ubTreeRA
Non-NULL if the UB tree is used.
Definition: ra_model.hpp:94
bool FirstLeafExact() const
Get whether or not we traverse to the first leaf without approximation.
void BuildModel(arma::mat &&referenceSet, const size_t leafSize, const bool naive, const bool singleMode)
Build the reference tree.
~RAModel()
Clean memory, if necessary.
bool Naive() const
Get whether or not naive search is being used.
std::string TreeName() const
Get the name of the tree type.
TreeTypes treeType
The type of tree being used.
Definition: ra_model.hpp:59
bool RandomBasis() const
Get whether or not a random basis is being used.
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 SingleMode() const
Get whether or not single-tree search is being used.
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.
arma::mat q
The basis to project into.
Definition: ra_model.hpp:66
size_t SingleSampleLimit() const
Get the limit on the size of a node that can be approximated.
RAType< tree::RTree > * rTreeRA
Non-NULL if the R tree is used.
Definition: ra_model.hpp:82
RAType< tree::Octree > * octreeRA
Non-NULL if the octree is used.
Definition: ra_model.hpp:96
const arma::mat & Dataset() const
Expose the dataset.
bool randomBasis
If true, randomly project into a new basis.
Definition: ra_model.hpp:64
RAModel & operator=(const RAModel &other)
Copy the given RAModel.
TreeTypes TreeType() const
Get the type of tree being used.
size_t LeafSize() const
Get the leaf size (only relevant when the kd-tree is used).
RAType< tree::RPlusTree > * rPlusTreeRA
Non-NULL if the R+ tree is used.
Definition: ra_model.hpp:90
TreeTypes
The list of tree types we can use with RASearch.
Definition: ra_model.hpp:43
double Alpha() const
Get the desired success probability.
RAType< tree::HilbertRTree > * hilbertRTreeRA
Non-NULL if the Hilbert R tree is used.
Definition: ra_model.hpp:88
RAType< tree::StandardCoverTree > * coverTreeRA
Non-NULL if the cover tree is used.
Definition: ra_model.hpp:80
RAType< tree::KDTree > * kdTreeRA
Non-NULL if the kd-tree is used.
Definition: ra_model.hpp:78
The RASearch class: This class provides a generic manner to perform rank-approximate search via rando...
Definition: ra_search.hpp:71
test cpp RESULT_VARIABLE MEX_RESULT_TRASH OUTPUT_VARIABLE MEX_OUTPUT ERROR_VARIABLE MEX_ERROR_TRASH string(REGEX MATCH"Warning: You are using"MEX_WARNING"${MEX_OUTPUT}") if(MEX_WARNING) string(REGEX REPLACE".*using [a-zA-Z]* version \"([0-9.]*)[^\"]*\".*""\\1"OTHER_COMPILER_VERSION"$
Definition: CMakeLists.txt:18
size_t leafSize
The leaf size of the tree being used (useful only for the kd-tree).
Definition: ra_model.hpp:61
The RAModel class provides an abstraction for the RASearch class, abstracting away the TreeType param...
Definition: ra_model.hpp:36
RAType< tree::XTree > * xTreeRA
Non-NULL if the X tree is used.
Definition: ra_model.hpp:86