mlpack  2.0.1
rs_model.hpp
Go to the documentation of this file.
1 
17 #ifndef __MLPACK_METHODS_RANGE_SEARCH_RS_MODEL_HPP
18 #define __MLPACK_METHODS_RANGE_SEARCH_RS_MODEL_HPP
19 
23 
24 #include "range_search.hpp"
25 
26 namespace mlpack {
27 namespace range {
28 
29 class RSModel
30 {
31  public:
32  enum TreeTypes
33  {
39  };
40 
41  private:
42  int treeType;
43  size_t leafSize;
44 
48  arma::mat q;
49 
51  template<template<typename TreeMetricType,
52  typename TreeStatType,
53  typename TreeMatType> class TreeType>
55 
56  // Only one of these pointers will be non-NULL.
67 
68  public:
76  RSModel(const int treeType = TreeTypes::KD_TREE,
77  const bool randomBasis = false);
78 
82  ~RSModel();
83 
85  template<typename Archive>
86  void Serialize(Archive& ar, const unsigned int /* version */);
87 
89  const arma::mat& Dataset() const;
90 
92  bool SingleMode() const;
94  bool& SingleMode();
95 
97  bool Naive() const;
99  bool& Naive();
100 
102  size_t LeafSize() const { return leafSize; }
104  size_t& LeafSize() { return leafSize; }
105 
107  int TreeType() const { return treeType; }
109  int& TreeType() { return treeType; }
110 
112  bool RandomBasis() const { return randomBasis; }
115  bool& RandomBasis() { return randomBasis; }
116 
126  void BuildModel(arma::mat&& referenceSet,
127  const size_t leafSize,
128  const bool naive,
129  const bool singleMode);
130 
141  void Search(arma::mat&& querySet,
142  const math::Range& range,
143  std::vector<std::vector<size_t>>& neighbors,
144  std::vector<std::vector<double>>& distances);
145 
155  void Search(const math::Range& range,
156  std::vector<std::vector<size_t>>& neighbors,
157  std::vector<std::vector<double>>& distances);
158 
159  private:
164  std::string TreeName() const;
165 
169  void CleanMemory();
170 };
171 
172 } // namespace range
173 } // namespace mlpack
174 
175 // Include implementation (of Serialize() and inline functions).
176 #include "rs_model_impl.hpp"
177 
178 #endif
The RangeSearch class is a template class for performing range searches.
void BuildModel(arma::mat &&referenceSet, const size_t leafSize, const bool naive, const bool singleMode)
Build the reference tree on the given dataset with the given parameters.
void Serialize(Archive &ar, const unsigned int)
Serialize the range search model.
RSType< tree::RStarTree > * rStarTreeRS
R* tree based range search object (NULL if not in use).
Definition: rs_model.hpp:64
RSType< tree::RTree > * rTreeRS
R tree based range search object (NULL if not in use).
Definition: rs_model.hpp:62
const arma::mat & Dataset() const
Expose the dataset.
Linear algebra utility functions, generally performed on matrices or vectors.
int & TreeType()
Modify the type of tree (don&#39;t do this after the model has been built).
Definition: rs_model.hpp:109
std::string TreeName() const
Return a string representing the name of the tree.
arma::mat q
Random projection matrix.
Definition: rs_model.hpp:48
bool & RandomBasis()
Modify whether a random basis is used (don&#39;t do this after the model has been built).
Definition: rs_model.hpp:115
bool SingleMode() const
Get whether the model is in single-tree search mode.
size_t LeafSize() const
Get the leaf size (applicable to everything but the cover tree).
Definition: rs_model.hpp:102
void CleanMemory()
Clean up memory.
RSType< tree::StandardCoverTree > * coverTreeRS
Cover tree based range search object (NULL if not in use).
Definition: rs_model.hpp:60
bool randomBasis
If true, we randomly project the data into a new basis before search.
Definition: rs_model.hpp:46
Simple real-valued range.
Definition: range.hpp:21
int TreeType() const
Get the type of tree.
Definition: rs_model.hpp:107
bool Naive() const
Get whether the model is in naive search mode.
RSModel(const int treeType=TreeTypes::KD_TREE, const bool randomBasis=false)
Initialize the RSModel with the given type and whether or not a random basis should be used...
bool RandomBasis() const
Get whether a random basis is used.
Definition: rs_model.hpp:112
~RSModel()
Clean memory, if necessary.
size_t & LeafSize()
Modify the leaf size (applicable to everything but the cover tree).
Definition: rs_model.hpp:104
void Search(arma::mat &&querySet, const math::Range &range, std::vector< std::vector< size_t >> &neighbors, std::vector< std::vector< double >> &distances)
Perform range search.
RSType< tree::KDTree > * kdTreeRS
kd-tree based range search object (NULL if not in use).
Definition: rs_model.hpp:58
RSType< tree::BallTree > * ballTreeRS
Ball tree based range search object (NULL if not in use).
Definition: rs_model.hpp:66