mlpack
range_search.hpp
Go to the documentation of this file.
1 
13 #ifndef MLPACK_METHODS_RANGE_SEARCH_RANGE_SEARCH_HPP
14 #define MLPACK_METHODS_RANGE_SEARCH_RANGE_SEARCH_HPP
15 
16 #include <mlpack/prereqs.hpp>
19 #include "range_search_stat.hpp"
20 
21 namespace mlpack {
22 namespace range {
23 
25 template<template<typename TreeMetricType,
26  typename TreeStatType,
27  typename TreeMatType> class TreeType>
29 
40 template<typename MetricType = metric::EuclideanDistance,
41  typename MatType = arma::mat,
42  template<typename TreeMetricType,
43  typename TreeStatType,
44  typename TreeMatType> class TreeType = tree::KDTree>
46 {
47  public:
49  typedef TreeType<MetricType, RangeSearchStat, MatType> Tree;
50 
67  RangeSearch(MatType referenceSet,
68  const bool naive = false,
69  const bool singleMode = false,
70  const MetricType metric = MetricType());
71 
94  RangeSearch(Tree* referenceTree,
95  const bool singleMode = false,
96  const MetricType metric = MetricType());
97 
108  RangeSearch(const bool naive = false,
109  const bool singleMode = false,
110  const MetricType metric = MetricType());
111 
118  RangeSearch(const RangeSearch& other);
119 
125  RangeSearch(RangeSearch&& other);
126 
132  RangeSearch& operator=(const RangeSearch& other);
133 
140 
145  ~RangeSearch();
146 
158  void Train(MatType referenceSet);
159 
163  void Train(Tree* referenceTree);
164 
192  void Search(const MatType& querySet,
193  const math::Range& range,
194  std::vector<std::vector<size_t>>& neighbors,
195  std::vector<std::vector<double>>& distances);
196 
233  void Search(Tree* queryTree,
234  const math::Range& range,
235  std::vector<std::vector<size_t>>& neighbors,
236  std::vector<std::vector<double>>& distances);
237 
267  void Search(const math::Range& range,
268  std::vector<std::vector<size_t>>& neighbors,
269  std::vector<std::vector<double>>& distances);
270 
272  bool SingleMode() const { return singleMode; }
274  bool& SingleMode() { return singleMode; }
275 
277  bool Naive() const { return naive; }
279  bool& Naive() { return naive; }
280 
282  size_t BaseCases() const { return baseCases; }
284  size_t Scores() const { return scores; }
285 
287  template<typename Archive>
288  void serialize(Archive& ar, const uint32_t version);
289 
291  const MatType& ReferenceSet() const { return *referenceSet; }
292 
294  Tree* ReferenceTree() { return referenceTree; }
295 
296  private:
298  std::vector<size_t> oldFromNewReferences;
300  Tree* referenceTree;
303  const MatType* referenceSet;
304 
306  bool treeOwner;
307 
309  bool naive;
311  bool singleMode;
312 
314  MetricType metric;
315 
317  size_t baseCases;
319  size_t scores;
320 
322  friend class LeafSizeRSWrapper<TreeType>;
323 };
324 
325 } // namespace range
326 } // namespace mlpack
327 
328 // Include implementation.
329 #include "range_search_impl.hpp"
330 
331 #endif
The RangeSearch class is a template class for performing range searches.
Definition: range_search.hpp:45
bool & SingleMode()
Modify whether single-tree search is being used.
Definition: range_search.hpp:274
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: cv.hpp:1
bool SingleMode() const
Get whether single-tree search is being used.
Definition: range_search.hpp:272
RangeSearch & operator=(const RangeSearch &other)
Deep copy the given RangeSearch model.
Definition: range_search_impl.hpp:172
The core includes that mlpack expects; standard C++ includes and Armadillo.
void serialize(Archive &ar, const uint32_t version)
Serialize the model.
Definition: range_search_impl.hpp:660
RangeSearch(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...
Definition: range_search_impl.hpp:50
Forward declaration.
Definition: range_search.hpp:28
A binary space partitioning tree, such as a KD-tree or a ball tree.
Definition: binary_space_tree.hpp:54
bool & Naive()
Modify whether naive search is being used.
Definition: range_search.hpp:279
~RangeSearch()
Destroy the RangeSearch object.
Definition: range_search_impl.hpp:235
size_t Scores() const
Get the number of scores during the last search.
Definition: range_search.hpp:284
void Train(MatType referenceSet)
Set the reference set to a new reference set, and build a tree if necessary.
Definition: range_search_impl.hpp:248
bool Naive() const
Get whether naive search is being used.
Definition: range_search.hpp:277
Tree * ReferenceTree()
Return the reference tree (or NULL if in naive mode).
Definition: range_search.hpp:294
const MatType & ReferenceSet() const
Return the reference set.
Definition: range_search.hpp:291
The L_p metric for arbitrary integer p, with an option to take the root.
Definition: lmetric.hpp:63
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.
Definition: range_search_impl.hpp:309
size_t BaseCases() const
Get the number of base cases during the last search.
Definition: range_search.hpp:282
TreeType< MetricType, RangeSearchStat, MatType > Tree
Convenience typedef.
Definition: range_search.hpp:49