mlpack  2.0.1
range_search.hpp
Go to the documentation of this file.
1 
15 #ifndef __MLPACK_METHODS_RANGE_SEARCH_RANGE_SEARCH_HPP
16 #define __MLPACK_METHODS_RANGE_SEARCH_RANGE_SEARCH_HPP
17 
18 #include <mlpack/core.hpp>
21 #include "range_search_stat.hpp"
22 
23 namespace mlpack {
24 namespace range {
25 
27 class RSModel;
28 
39 template<typename MetricType = metric::EuclideanDistance,
40  typename MatType = arma::mat,
41  template<typename TreeMetricType,
42  typename TreeStatType,
43  typename TreeMatType> class TreeType = tree::KDTree>
45 {
46  public:
48  typedef TreeType<MetricType, RangeSearchStat, MatType> Tree;
49 
66  RangeSearch(const MatType& referenceSet,
67  const bool naive = false,
68  const bool singleMode = false,
69  const MetricType metric = MetricType());
70 
90  RangeSearch(MatType&& referenceSet,
91  const bool naive = false,
92  const bool singleMode = false,
93  const MetricType metric = MetricType());
94 
120  const bool singleMode = false,
121  const MetricType metric = MetricType());
122 
133  RangeSearch(const bool naive = false,
134  const bool singleMode = false,
135  const MetricType metric = MetricType());
136 
141  ~RangeSearch();
142 
151  void Train(const MatType& referenceSet);
152 
161  void Train(MatType&& referenceSet);
162 
166  void Train(Tree* referenceTree);
167 
195  void Search(const MatType& querySet,
196  const math::Range& range,
197  std::vector<std::vector<size_t>>& neighbors,
198  std::vector<std::vector<double>>& distances);
199 
236  void Search(Tree* queryTree,
237  const math::Range& range,
238  std::vector<std::vector<size_t>>& neighbors,
239  std::vector<std::vector<double>>& distances);
240 
271  void Search(const math::Range& range,
272  std::vector<std::vector<size_t>>& neighbors,
273  std::vector<std::vector<double>>& distances);
274 
276  bool SingleMode() const { return singleMode; }
278  bool& SingleMode() { return singleMode; }
279 
281  bool Naive() const { return naive; }
283  bool& Naive() { return naive; }
284 
286  size_t BaseCases() const { return baseCases; }
288  size_t Scores() const { return scores; }
289 
291  template<typename Archive>
292  void Serialize(Archive& ar, const unsigned int version);
293 
295  const MatType& ReferenceSet() const { return *referenceSet; }
296 
298  Tree* ReferenceTree() { return referenceTree; }
299 
300  private:
302  std::vector<size_t> oldFromNewReferences;
307  const MatType* referenceSet;
308 
310  bool treeOwner;
312  bool setOwner;
313 
315  bool naive;
318 
320  MetricType metric;
321 
323  size_t baseCases;
325  size_t scores;
326 
328  friend RSModel;
329 };
330 
331 } // namespace range
332 } // namespace mlpack
333 
334 // Include implementation.
335 #include "range_search_impl.hpp"
336 
337 #endif
The RangeSearch class is a template class for performing range searches.
friend RSModel
For access to mappings when building models.
bool & SingleMode()
Modify whether single-tree search is being used.
bool singleMode
If true, single-tree computation is used.
Linear algebra utility functions, generally performed on matrices or vectors.
LMetric< 2, true > EuclideanDistance
The Euclidean (L2) distance.
Definition: lmetric.hpp:113
bool SingleMode() const
Get whether single-tree search is being used.
bool naive
If true, O(n^2) naive computation is used.
std::vector< size_t > oldFromNewReferences
Mappings to old reference indices (used when this object builds trees).
A binary space partitioning tree, such as a KD-tree or a ball tree.
bool & Naive()
Modify whether naive search is being used.
void Train(const MatType &referenceSet)
Set the reference set to a new reference set, and build a tree if necessary.
MetricType metric
Instantiated distance metric.
~RangeSearch()
Destroy the RangeSearch object.
size_t Scores() const
Get the number of scores during the last search.
RangeSearch(const MatType &referenceSet, const bool naive=false, const bool singleMode=false, const MetricType metric=MetricType())
Initialize the RangeSearch object with a given reference dataset (this is the dataset which is search...
bool Naive() const
Get whether naive search is being used.
Simple real-valued range.
Definition: range.hpp:21
bool setOwner
If true, we own the reference set.
size_t baseCases
The total number of base cases during the last search.
Tree * ReferenceTree()
Return the reference tree (or NULL if in naive mode).
Include all of the base components required to write MLPACK methods, and the main MLPACK Doxygen docu...
const MatType & ReferenceSet() const
Return the reference set.
Tree * referenceTree
Reference tree.
void Serialize(Archive &ar, const unsigned int version)
Serialize the model.
void Search(const MatType &querySet, const math::Range &range, std::vector< std::vector< size_t >> &neighbors, std::vector< std::vector< double >> &distances)
Search for all reference points in the given range for each point in the query set, returning the results in the neighbors and distances objects.
size_t scores
The total number of scores during the last search.
bool treeOwner
If true, this object is responsible for deleting the trees.
const MatType * referenceSet
Reference set (data should be accessed using this).
size_t BaseCases() const
Get the number of base cases during the last search.
TreeType< MetricType, RangeSearchStat, MatType > Tree
Convenience typedef.