mlpack  2.2.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 class TrainVisitor;
26 
37 template<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(const MatType& referenceSet,
65  const bool naive = false,
66  const bool singleMode = false,
67  const MetricType metric = MetricType());
68 
88  RangeSearch(MatType&& referenceSet,
89  const bool naive = false,
90  const bool singleMode = false,
91  const MetricType metric = MetricType());
92 
117  RangeSearch(Tree* referenceTree,
118  const bool singleMode = false,
119  const MetricType metric = MetricType());
120 
131  RangeSearch(const bool naive = false,
132  const bool singleMode = false,
133  const MetricType metric = MetricType());
134 
139  RangeSearch(const RangeSearch& other);
140 
144  RangeSearch(RangeSearch&& other);
145 
150  ~RangeSearch();
151 
160  void Train(const MatType& referenceSet);
161 
170  void Train(MatType&& referenceSet);
171 
175  void Train(Tree* referenceTree);
176 
204  void Search(const MatType& querySet,
205  const math::Range& range,
206  std::vector<std::vector<size_t>>& neighbors,
207  std::vector<std::vector<double>>& distances);
208 
245  void Search(Tree* queryTree,
246  const math::Range& range,
247  std::vector<std::vector<size_t>>& neighbors,
248  std::vector<std::vector<double>>& distances);
249 
280  void Search(const math::Range& range,
281  std::vector<std::vector<size_t>>& neighbors,
282  std::vector<std::vector<double>>& distances);
283 
285  bool SingleMode() const { return singleMode; }
287  bool& SingleMode() { return singleMode; }
288 
290  bool Naive() const { return naive; }
292  bool& Naive() { return naive; }
293 
295  size_t BaseCases() const { return baseCases; }
297  size_t Scores() const { return scores; }
298 
300  template<typename Archive>
301  void Serialize(Archive& ar, const unsigned int version);
302 
304  const MatType& ReferenceSet() const { return *referenceSet; }
305 
307  Tree* ReferenceTree() { return referenceTree; }
308 
309  private:
311  std::vector<size_t> oldFromNewReferences;
313  Tree* referenceTree;
316  const MatType* referenceSet;
317 
319  bool treeOwner;
321  bool setOwner;
322 
324  bool naive;
326  bool singleMode;
327 
329  MetricType metric;
330 
332  size_t baseCases;
334  size_t scores;
335 
337  friend class TrainVisitor;
338 };
339 
340 } // namespace range
341 } // namespace mlpack
342 
343 // Include implementation.
344 #include "range_search_impl.hpp"
345 
346 #endif
The RangeSearch class is a template class for performing range searches.
bool & Naive()
Modify whether naive search is being used.
Tree * ReferenceTree()
Return the reference tree (or NULL if in naive mode).
void Serialize(Archive &ar, const unsigned int version)
Serialize the model.
size_t BaseCases() const
Get the number of base cases during the last search.
The core includes that mlpack expects; standard C++ includes and Armadillo.
A binary space partitioning tree, such as a KD-tree or a ball tree.
bool SingleMode() const
Get whether single-tree search is being used.
bool & SingleMode()
Modify whether single-tree search is being used.
~RangeSearch()
Destroy the RangeSearch object.
TrainVisitor sets the reference set to a new reference set on the given RSType.
Definition: rs_model.hpp:130
TreeType< MetricType, RangeSearchStat, MatType > Tree
Convenience typedef.
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.
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...
void Train(const MatType &referenceSet)
Set the reference set to a new reference set, and build a tree if necessary.
const MatType & ReferenceSet() const
Return the reference set.
size_t Scores() const
Get the number of scores during the last search.
LMetric< 2, true > EuclideanDistance
The Euclidean (L2) distance.
Definition: lmetric.hpp:112
bool Naive() const
Get whether naive search is being used.