MLPACK  1.0.8
neighbor_search.hpp
Go to the documentation of this file.
1 
23 #ifndef __MLPACK_METHODS_NEIGHBOR_SEARCH_NEIGHBOR_SEARCH_HPP
24 #define __MLPACK_METHODS_NEIGHBOR_SEARCH_NEIGHBOR_SEARCH_HPP
25 
26 #include <mlpack/core.hpp>
27 #include <vector>
28 #include <string>
29 
31 
33 #include "neighbor_search_stat.hpp"
35 
36 namespace mlpack {
37 namespace neighbor {
40 
59 template<typename SortPolicy = NearestNeighborSort,
60  typename MetricType = mlpack::metric::SquaredEuclideanDistance,
61  typename TreeType = tree::BinarySpaceTree<bound::HRectBound<2>,
62  NeighborSearchStat<SortPolicy> > >
64 {
65  public:
86  NeighborSearch(const typename TreeType::Mat& referenceSet,
87  const typename TreeType::Mat& querySet,
88  const bool naive = false,
89  const bool singleMode = false,
90  const size_t leafSize = 20,
91  const MetricType metric = MetricType());
92 
114  NeighborSearch(const typename TreeType::Mat& referenceSet,
115  const bool naive = false,
116  const bool singleMode = false,
117  const size_t leafSize = 20,
118  const MetricType metric = MetricType());
119 
149  NeighborSearch(TreeType* referenceTree,
150  TreeType* queryTree,
151  const typename TreeType::Mat& referenceSet,
152  const typename TreeType::Mat& querySet,
153  const bool singleMode = false,
154  const MetricType metric = MetricType());
155 
183  NeighborSearch(TreeType* referenceTree,
184  const typename TreeType::Mat& referenceSet,
185  const bool singleMode = false,
186  const MetricType metric = MetricType());
187 
188 
193  ~NeighborSearch();
194 
207  void Search(const size_t k,
208  arma::Mat<size_t>& resultingNeighbors,
209  arma::mat& distances);
210 
211  private:
214  arma::mat referenceCopy;
216  arma::mat queryCopy;
217 
219  const arma::mat& referenceSet;
221  const arma::mat& querySet;
222 
224  TreeType* referenceTree;
226  TreeType* queryTree;
227 
229  bool treeOwner;
232 
234  bool naive;
237 
239  MetricType metric;
240 
242  std::vector<size_t> oldFromNewReferences;
244  std::vector<size_t> oldFromNewQueries;
245 
248 }; // class NeighborSearch
249 
250 }; // namespace neighbor
251 }; // namespace mlpack
252 
253 // Include implementation.
254 #include "neighbor_search_impl.hpp"
255 
256 // Include convenience typedefs.
257 #include "typedef.hpp"
258 
259 #endif
bool hasQuerySet
Indicates if a separate query set was passed.
arma::mat referenceCopy
Copy of reference dataset (if we need it, because tree building modifies it).
~NeighborSearch()
Delete the NeighborSearch object.
const arma::mat & referenceSet
Reference dataset.
The NeighborSearch class is a template class for performing distance-based neighbor searches...
std::vector< size_t > oldFromNewReferences
Permutations of reference points during tree building.
LMetric< 2, false > SquaredEuclideanDistance
Definition: lmetric.hpp:99
const arma::mat & querySet
Query dataset (may not be given).
bool naive
Indicates if O(n^2) naive search is being used.
MetricType metric
Instantiation of metric.
std::vector< size_t > oldFromNewQueries
Permutations of query points during tree building.
NeighborSearch(const typename TreeType::Mat &referenceSet, const typename TreeType::Mat &querySet, const bool naive=false, const bool singleMode=false, const size_t leafSize=20, const MetricType metric=MetricType())
Initialize the NeighborSearch object, passing both a query and reference dataset. ...
bool treeOwner
If true, this object created the trees and is responsible for them.
size_t numberOfPrunes
Total number of pruned nodes during the neighbor search.
bool singleMode
Indicates if single-tree search is being used (opposed to dual-tree).
TreeType * referenceTree
Pointer to the root of the reference tree.
void Search(const size_t k, arma::Mat< size_t > &resultingNeighbors, arma::mat &distances)
Compute the nearest neighbors and store the output in the given matrices.
TreeType * queryTree
Pointer to the root of the query tree (might not exist).
arma::mat queryCopy
Copy of query dataset (if we need it, because tree building modifies it).