mlpack 3.4.2
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
21namespace mlpack {
22namespace range {
23
25class TrainVisitor;
26
37template<typename MetricType = metric::EuclideanDistance,
38 typename MatType = arma::mat,
39 template<typename TreeMetricType,
40 typename TreeStatType,
41 typename TreeMatType> class TreeType = tree::KDTree>
43{
44 public:
46 typedef TreeType<MetricType, RangeSearchStat, MatType> Tree;
47
64 RangeSearch(MatType referenceSet,
65 const bool naive = false,
66 const bool singleMode = false,
67 const MetricType metric = MetricType());
68
91 RangeSearch(Tree* referenceTree,
92 const bool singleMode = false,
93 const MetricType metric = MetricType());
94
105 RangeSearch(const bool naive = false,
106 const bool singleMode = false,
107 const MetricType metric = MetricType());
108
116
123
131
137
149 void Train(MatType referenceSet);
150
154 void Train(Tree* referenceTree);
155
183 void Search(const MatType& querySet,
184 const math::Range& range,
185 std::vector<std::vector<size_t>>& neighbors,
186 std::vector<std::vector<double>>& distances);
187
224 void Search(Tree* queryTree,
225 const math::Range& range,
226 std::vector<std::vector<size_t>>& neighbors,
227 std::vector<std::vector<double>>& distances);
228
258 void Search(const math::Range& range,
259 std::vector<std::vector<size_t>>& neighbors,
260 std::vector<std::vector<double>>& distances);
261
263 bool SingleMode() const { return singleMode; }
265 bool& SingleMode() { return singleMode; }
266
268 bool Naive() const { return naive; }
270 bool& Naive() { return naive; }
271
273 size_t BaseCases() const { return baseCases; }
275 size_t Scores() const { return scores; }
276
278 template<typename Archive>
279 void serialize(Archive& ar, const unsigned int version);
280
282 const MatType& ReferenceSet() const { return *referenceSet; }
283
285 Tree* ReferenceTree() { return referenceTree; }
286
287 private:
289 std::vector<size_t> oldFromNewReferences;
291 Tree* referenceTree;
294 const MatType* referenceSet;
295
297 bool treeOwner;
298
300 bool naive;
302 bool singleMode;
303
305 MetricType metric;
306
308 size_t baseCases;
310 size_t scores;
311
313 friend class TrainVisitor;
314};
315
316} // namespace range
317} // namespace mlpack
318
319// Include implementation.
320#include "range_search_impl.hpp"
321
322#endif
Simple real-valued range.
Definition: range.hpp:35
The RangeSearch class is a template class for performing range searches.
Tree * ReferenceTree()
Return the reference tree (or NULL if in naive mode).
~RangeSearch()
Destroy the RangeSearch object.
void Train(MatType referenceSet)
Set the reference set to a new reference set, and build a tree if necessary.
void Search(Tree *queryTree, const math::Range &range, std::vector< std::vector< size_t > > &neighbors, std::vector< std::vector< double > > &distances)
Given a pre-built query tree, search for all reference points in the given range for each point in th...
bool Naive() const
Get whether naive search is being used.
const MatType & ReferenceSet() const
Return the reference set.
void Train(Tree *referenceTree)
Set the reference tree to a new reference tree.
size_t BaseCases() const
Get the number of base cases during the last search.
size_t Scores() const
Get the number of scores during the last search.
void Search(const math::Range &range, std::vector< std::vector< size_t > > &neighbors, std::vector< std::vector< double > > &distances)
Search for all points in the given range for each point in the reference set (which was passed to the...
TreeType< MetricType, RangeSearchStat, MatType > Tree
Convenience typedef.
void serialize(Archive &ar, const unsigned int version)
Serialize the model.
RangeSearch(Tree *referenceTree, const bool singleMode=false, const MetricType metric=MetricType())
Initialize the RangeSearch object with the given pre-constructed reference tree (this is the tree bui...
bool SingleMode() const
Get whether single-tree search is being used.
RangeSearch(const bool naive=false, const bool singleMode=false, const MetricType metric=MetricType())
Initialize the RangeSearch object without any reference data.
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...
RangeSearch & operator=(RangeSearch other)
Copy the given RangeSearch model.
bool & Naive()
Modify whether naive search is being used.
bool & SingleMode()
Modify whether single-tree search is being used.
RangeSearch(RangeSearch &&other)
Construct the RangeSearch model by taking ownership of the given 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,...
RangeSearch(const RangeSearch &other)
Construct the RangeSearch model as a copy of the given model.
TrainVisitor sets the reference set to a new reference set on the given RSType.
Definition: rs_model.hpp:126
A binary space partitioning tree, such as a KD-tree or a ball tree.
LMetric< 2, true > EuclideanDistance
The Euclidean (L2) distance.
Definition: lmetric.hpp:112
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: cv.hpp:1
The core includes that mlpack expects; standard C++ includes and Armadillo.