mlpack  2.0.1
ra_model.hpp
Go to the documentation of this file.
1 
16 #ifndef __MLPACK_METHODS_RANN_RA_MODEL_HPP
17 #define __MLPACK_METHODS_RANN_RA_MODEL_HPP
18 
22 
23 #include "ra_search.hpp"
24 
25 namespace mlpack {
26 namespace neighbor {
27 
36 template<typename SortPolicy>
37 class RAModel
38 {
39  public:
44  enum TreeTypes
45  {
50  };
51 
52  private:
54  int treeType;
56  size_t leafSize;
57 
61  arma::mat q;
62 
64  template<template<typename TreeMetricType,
65  typename TreeStatType,
66  typename TreeMatType> class TreeType>
67  using RAType = RASearch<SortPolicy,
69  arma::mat,
71 
80 
81  public:
86  RAModel(int treeType = TreeTypes::KD_TREE, bool randomBasis = false);
87 
89  ~RAModel();
90 
92  template<typename Archive>
93  void Serialize(Archive& ar, const unsigned int /* version */);
94 
96  const arma::mat& Dataset() const;
97 
99  bool SingleMode() const;
101  bool& SingleMode();
102 
104  bool Naive() const;
106  bool& Naive();
107 
109  double Tau() const;
111  double& Tau();
112 
114  double Alpha() const;
116  double& Alpha();
117 
119  bool SampleAtLeaves() const;
121  bool& SampleAtLeaves();
122 
124  bool FirstLeafExact() const;
126  bool& FirstLeafExact();
127 
129  size_t SingleSampleLimit() const;
131  size_t& SingleSampleLimit();
132 
134  size_t LeafSize() const;
136  size_t& LeafSize();
137 
139  int TreeType() const;
141  int& TreeType();
142 
144  bool RandomBasis() const;
147  bool& RandomBasis();
148 
150  void BuildModel(arma::mat&& referenceSet,
151  const size_t leafSize,
152  const bool naive,
153  const bool singleMode);
154 
157  void Search(arma::mat&& querySet,
158  const size_t k,
159  arma::Mat<size_t>& neighbors,
160  arma::mat& distances);
161 
166  void Search(const size_t k,
167  arma::Mat<size_t>& neighbors,
168  arma::mat& distances);
169 
171  std::string TreeName() const;
172 };
173 
174 } // namespace neighbor
175 } // namespace mlpack
176 
177 #include "ra_model_impl.hpp"
178 
179 #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.
int treeType
The type of tree being used.
Definition: ra_model.hpp:54
LMetric< 2, true > EuclideanDistance
The Euclidean (L2) distance.
Definition: lmetric.hpp:113
RAType< tree::RStarTree > * rStarTreeRA
Non-NULL if the R* tree is used.
Definition: ra_model.hpp:79
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.
bool RandomBasis() const
Get whether or not a random basis is being 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:61
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:77
const arma::mat & Dataset() const
Expose the dataset.
bool randomBasis
If true, randomly project into a new basis.
Definition: ra_model.hpp:59
RAModel(int treeType=TreeTypes::KD_TREE, bool randomBasis=false)
Initialize the RAModel with the given type and whether or not a random basis should be used...
size_t LeafSize() const
Get the leaf size (only relevant when the kd-tree is used).
TreeTypes
The list of tree types we can use with RASearch.
Definition: ra_model.hpp:44
double Alpha() const
Get the desired success probability.
RAType< tree::StandardCoverTree > * coverTreeRA
Non-NULL if the cover tree is used.
Definition: ra_model.hpp:75
RAType< tree::KDTree > * kdTreeRA
Non-NULL if the kd-tree is used.
Definition: ra_model.hpp:73
The RASearch class: This class provides a generic manner to perform rank-approximate search via rando...
Definition: ra_search.hpp:73
size_t leafSize
The leaf size of the tree being used (useful only for the kd-tree).
Definition: ra_model.hpp:56
The RAModel class provides an abstraction for the RASearch class, abstracting away the TreeType param...
Definition: ra_model.hpp:37
int TreeType() const
Get the type of tree being used.