MLPACK  1.0.10
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 MetricType metric = MetricType());
91 
113  NeighborSearch(const typename TreeType::Mat& referenceSet,
114  const bool naive = false,
115  const bool singleMode = false,
116  const MetricType metric = MetricType());
117 
147  NeighborSearch(TreeType* referenceTree,
148  TreeType* queryTree,
149  const typename TreeType::Mat& referenceSet,
150  const typename TreeType::Mat& querySet,
151  const bool singleMode = false,
152  const MetricType metric = MetricType());
153 
181  NeighborSearch(TreeType* referenceTree,
182  const typename TreeType::Mat& referenceSet,
183  const bool singleMode = false,
184  const MetricType metric = MetricType());
185 
186 
191  ~NeighborSearch();
192 
205  void Search(const size_t k,
206  arma::Mat<size_t>& resultingNeighbors,
207  arma::mat& distances);
208 
209  // Returns a string representation of this object.
210  std::string ToString() const;
211 
212  private:
215  typename TreeType::Mat referenceCopy;
217  typename TreeType::Mat queryCopy;
218 
220  const typename TreeType::Mat& referenceSet;
222  const typename TreeType::Mat& querySet;
223 
225  TreeType* referenceTree;
227  TreeType* queryTree;
228 
230  bool treeOwner;
233 
235  bool naive;
238 
240  MetricType metric;
241 
243  std::vector<size_t> oldFromNewReferences;
245  std::vector<size_t> oldFromNewQueries;
246 }; // class NeighborSearch
247 
248 }; // namespace neighbor
249 }; // namespace mlpack
250 
251 // Include implementation.
252 #include "neighbor_search_impl.hpp"
253 
254 // Include convenience typedefs.
255 #include "typedef.hpp"
256 
257 #endif
bool hasQuerySet
Indicates if a separate query set was passed.
TreeType::Mat referenceCopy
Copy of reference dataset (if we need it, because tree building modifies it).
const TreeType::Mat & querySet
Query dataset (may not be given).
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: load.hpp:31
~NeighborSearch()
Delete the NeighborSearch object.
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:100
TreeType::Mat queryCopy
Copy of query dataset (if we need it, because tree building modifies it).
bool naive
Indicates if O(n^2) naive search is being used.
NeighborSearch(const typename TreeType::Mat &referenceSet, const typename TreeType::Mat &querySet, const bool naive=false, const bool singleMode=false, const MetricType metric=MetricType())
Initialize the NeighborSearch object, passing both a query and reference dataset. ...
MetricType metric
Instantiation of metric.
std::vector< size_t > oldFromNewQueries
Permutations of query points during tree building.
std::string ToString() const
bool treeOwner
If true, this object created the trees and is responsible for them.
const TreeType::Mat & referenceSet
Reference dataset.
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).