mlpack  1.0.12
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 
32 template<typename MetricType = mlpack::metric::EuclideanDistance,
36 {
37  public:
57  RangeSearch(const typename TreeType::Mat& referenceSet,
58  const typename TreeType::Mat& querySet,
59  const bool naive = false,
60  const bool singleMode = false,
61  const MetricType metric = MetricType());
62 
82  RangeSearch(const typename TreeType::Mat& referenceSet,
83  const bool naive = false,
84  const bool singleMode = false,
85  const MetricType metric = MetricType());
86 
116  RangeSearch(TreeType* referenceTree,
117  TreeType* queryTree,
118  const typename TreeType::Mat& referenceSet,
119  const typename TreeType::Mat& querySet,
120  const bool singleMode = false,
121  const MetricType metric = MetricType());
122 
150  RangeSearch(TreeType* referenceTree,
151  const typename TreeType::Mat& referenceSet,
152  const bool singleMode = false,
153  const MetricType metric = MetricType());
154 
159  ~RangeSearch();
160 
187  void Search(const math::Range& range,
188  std::vector<std::vector<size_t> >& neighbors,
189  std::vector<std::vector<double> >& distances);
190 
191  // Returns a string representation of this object.
192  std::string ToString() const;
193 
194  private:
196  typename TreeType::Mat referenceCopy;
198  typename TreeType::Mat queryCopy;
199 
201  const typename TreeType::Mat& referenceSet;
203  const typename TreeType::Mat& querySet;
204 
206  TreeType* referenceTree;
208  TreeType* queryTree;
209 
211  std::vector<size_t> oldFromNewReferences;
213  std::vector<size_t> oldFromNewQueries;
214 
216  bool treeOwner;
220 
222  bool naive;
225 
227  MetricType metric;
228 
230  size_t numPrunes;
231 };
232 
233 }; // namespace range
234 }; // namespace mlpack
235 
236 // Include implementation.
237 #include "range_search_impl.hpp"
238 
239 #endif
The RangeSearch class is a template class for performing range searches.
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: load.hpp:23
LMetric< 2, true > EuclideanDistance
Definition: lmetric.hpp:97
~RangeSearch()
Destroy the RangeSearch object.
std::vector< size_t > oldFromNewReferences
Mappings to old reference indices (used when this object builds trees).
size_t numPrunes
The number of pruned nodes during computation.
A binary space partitioning tree, such as a KD-tree or a ball tree.
bool naive
If true, O(n^2) naive computation is used.
TreeType * referenceTree
Reference tree.
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, returning the results in the neighbors and distances object...
TreeType::Mat referenceCopy
Copy of reference matrix; used when a tree is built internally.
Statistic class for RangeSearch, to be set to the StatisticType of the tree type that range search is...
std::string ToString() const
TreeType::Mat queryCopy
Copy of query matrix; used when a tree is built internally.
bool hasQuerySet
If true, a query set was passed; if false, the query set is the reference set.
const TreeType::Mat & referenceSet
Reference set (data should be accessed using this).
std::vector< size_t > oldFromNewQueries
Mappings to old query indices (used when this object builds trees).
const TreeType::Mat & querySet
Query set (data should be accessed using this).
TreeType * queryTree
Query tree (may be NULL).
RangeSearch(const typename TreeType::Mat &referenceSet, const typename TreeType::Mat &querySet, const bool naive=false, const bool singleMode=false, const MetricType metric=MetricType())
Initialize the RangeSearch object with a different reference set and a query set. ...
MetricType metric
Instantiated distance metric.
bool treeOwner
If true, this object is responsible for deleting the trees.
bool singleMode
If true, single-tree computation is used.
Simple real-valued range.
Definition: range.hpp:23