mlpack  3.0.4
 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(MatType referenceSet,
65  const bool naive = false,
66  const bool singleMode = false,
67  const MetricType metric = MetricType());
68 
93  RangeSearch(Tree* referenceTree,
94  const bool singleMode = false,
95  const MetricType metric = MetricType());
96 
107  RangeSearch(const bool naive = false,
108  const bool singleMode = false,
109  const MetricType metric = MetricType());
110 
117  RangeSearch(const RangeSearch& other);
118 
124  RangeSearch(RangeSearch&& other);
125 
133 
138  ~RangeSearch();
139 
151  void Train(MatType referenceSet);
152 
156  void Train(Tree* referenceTree);
157 
185  void Search(const MatType& querySet,
186  const math::Range& range,
187  std::vector<std::vector<size_t>>& neighbors,
188  std::vector<std::vector<double>>& distances);
189 
226  void Search(Tree* queryTree,
227  const math::Range& range,
228  std::vector<std::vector<size_t>>& neighbors,
229  std::vector<std::vector<double>>& distances);
230 
261  void Search(const math::Range& range,
262  std::vector<std::vector<size_t>>& neighbors,
263  std::vector<std::vector<double>>& distances);
264 
266  bool SingleMode() const { return singleMode; }
268  bool& SingleMode() { return singleMode; }
269 
271  bool Naive() const { return naive; }
273  bool& Naive() { return naive; }
274 
276  size_t BaseCases() const { return baseCases; }
278  size_t Scores() const { return scores; }
279 
281  template<typename Archive>
282  void serialize(Archive& ar, const unsigned int version);
283 
285  const MatType& ReferenceSet() const { return *referenceSet; }
286 
288  Tree* ReferenceTree() { return referenceTree; }
289 
290  private:
292  std::vector<size_t> oldFromNewReferences;
294  Tree* referenceTree;
297  const MatType* referenceSet;
298 
300  bool treeOwner;
301 
303  bool naive;
305  bool singleMode;
306 
308  MetricType metric;
309 
311  size_t baseCases;
313  size_t scores;
314 
316  friend class TrainVisitor;
317 };
318 
319 } // namespace range
320 } // namespace mlpack
321 
322 // Include implementation.
323 #include "range_search_impl.hpp"
324 
325 #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).
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.
RangeSearch & operator=(RangeSearch other)
Copy the given RangeSearch model.
A binary space partitioning tree, such as a KD-tree or a ball tree.
void Train(MatType referenceSet)
Set the reference set to a new reference set, and build a tree if necessary.
bool SingleMode() const
Get whether single-tree search is being used.
bool & SingleMode()
Modify whether single-tree search is being used.
void serialize(Archive &ar, const unsigned int version)
Serialize the model.
~RangeSearch()
Destroy the RangeSearch object.
TrainVisitor sets the reference set to a new reference set on the given RSType.
Definition: rs_model.hpp:125
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(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...
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.