mlpack  2.2.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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:
59  TreeTypes treeType;
61  size_t leafSize;
62 
64  bool randomBasis;
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,
75  TreeType>;
76 
78  RAType<tree::KDTree>* kdTreeRA;
80  RAType<tree::StandardCoverTree>* coverTreeRA;
82  RAType<tree::RTree>* rTreeRA;
84  RAType<tree::RStarTree>* rStarTreeRA;
86  RAType<tree::XTree>* xTreeRA;
88  RAType<tree::HilbertRTree>* hilbertRTreeRA;
90  RAType<tree::RPlusTree>* rPlusTreeRA;
92  RAType<tree::RPlusPlusTree>* rPlusPlusTreeRA;
94  RAType<tree::UBTree>* ubTreeRA;
96  RAType<tree::Octree>* octreeRA;
97 
98  public:
103  RAModel(TreeTypes treeType = TreeTypes::KD_TREE, bool randomBasis = false);
104 
106  ~RAModel();
107 
109  template<typename Archive>
110  void Serialize(Archive& ar, const unsigned int /* version */);
111 
113  const arma::mat& Dataset() const;
114 
116  bool SingleMode() const;
118  bool& SingleMode();
119 
121  bool Naive() const;
123  bool& Naive();
124 
126  double Tau() const;
128  double& Tau();
129 
131  double Alpha() const;
133  double& Alpha();
134 
136  bool SampleAtLeaves() const;
138  bool& SampleAtLeaves();
139 
141  bool FirstLeafExact() const;
143  bool& FirstLeafExact();
144 
146  size_t SingleSampleLimit() const;
148  size_t& SingleSampleLimit();
149 
151  size_t LeafSize() const;
153  size_t& LeafSize();
154 
156  TreeTypes TreeType() const;
158  TreeTypes& TreeType();
159 
161  bool RandomBasis() const;
164  bool& RandomBasis();
165 
167  void BuildModel(arma::mat&& referenceSet,
168  const size_t leafSize,
169  const bool naive,
170  const bool singleMode);
171 
174  void Search(arma::mat&& querySet,
175  const size_t k,
176  arma::Mat<size_t>& neighbors,
177  arma::mat& distances);
178 
183  void Search(const size_t k,
184  arma::Mat<size_t>& neighbors,
185  arma::mat& distances);
186 
188  std::string TreeName() const;
189 };
190 
191 } // namespace neighbor
192 } // namespace mlpack
193 
194 #include "ra_model_impl.hpp"
195 
196 #endif
bool SampleAtLeaves() const
Get whether or not sampling is done at the leaves.
size_t SingleSampleLimit() const
Get the limit on the size of a node that can be approximated.
void BuildModel(arma::mat &&referenceSet, const size_t leafSize, const bool naive, const bool singleMode)
Build the reference tree.
size_t LeafSize() const
Get the leaf size (only relevant when the kd-tree is 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 FirstLeafExact() const
Get whether or not we traverse to the first leaf without approximation.
bool Naive() const
Get whether or not naive search is being used.
double Alpha() const
Get the desired success probability.
const arma::mat & Dataset() const
Expose the dataset.
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.
std::string TreeName() const
Get the name of the tree type.
bool SingleMode() const
Get whether or not single-tree search is being used.
~RAModel()
Clean memory, if necessary.
The RASearch class: This class provides a generic manner to perform rank-approximate search via rando...
Definition: ra_search.hpp:71
TreeTypes
The list of tree types we can use with RASearch.
Definition: ra_model.hpp:43
double Tau() const
Get the rank-approximation in percentile of the data.
LMetric< 2, true > EuclideanDistance
The Euclidean (L2) distance.
Definition: lmetric.hpp:112
The RAModel class provides an abstraction for the RASearch class, abstracting away the TreeType param...
Definition: ra_model.hpp:36
bool RandomBasis() const
Get whether or not a random basis is being used.
void Serialize(Archive &ar, const unsigned int)
Serialize the model.
TreeTypes TreeType() const
Get the type of tree being used.