mlpack  1.0.12
neighbor_search.hpp
Go to the documentation of this file.
1 
15 #ifndef __MLPACK_METHODS_NEIGHBOR_SEARCH_NEIGHBOR_SEARCH_HPP
16 #define __MLPACK_METHODS_NEIGHBOR_SEARCH_NEIGHBOR_SEARCH_HPP
17 
18 #include <mlpack/core.hpp>
19 #include <vector>
20 #include <string>
21 
23 
25 #include "neighbor_search_stat.hpp"
27 
28 namespace mlpack {
29 namespace neighbor {
32 
51 template<typename SortPolicy = NearestNeighborSort,
52  typename MetricType = mlpack::metric::SquaredEuclideanDistance,
53  typename TreeType = tree::BinarySpaceTree<bound::HRectBound<2>,
54  NeighborSearchStat<SortPolicy> > >
56 {
57  public:
78  NeighborSearch(const typename TreeType::Mat& referenceSet,
79  const typename TreeType::Mat& querySet,
80  const bool naive = false,
81  const bool singleMode = false,
82  const MetricType metric = MetricType());
83 
105  NeighborSearch(const typename TreeType::Mat& referenceSet,
106  const bool naive = false,
107  const bool singleMode = false,
108  const MetricType metric = MetricType());
109 
139  NeighborSearch(TreeType* referenceTree,
140  TreeType* queryTree,
141  const typename TreeType::Mat& referenceSet,
142  const typename TreeType::Mat& querySet,
143  const bool singleMode = false,
144  const MetricType metric = MetricType());
145 
173  NeighborSearch(TreeType* referenceTree,
174  const typename TreeType::Mat& referenceSet,
175  const bool singleMode = false,
176  const MetricType metric = MetricType());
177 
178 
183  ~NeighborSearch();
184 
197  void Search(const size_t k,
198  arma::Mat<size_t>& resultingNeighbors,
199  arma::mat& distances);
200 
201  // Returns a string representation of this object.
202  std::string ToString() const;
203 
204  private:
207  typename TreeType::Mat referenceCopy;
209  typename TreeType::Mat queryCopy;
210 
212  const typename TreeType::Mat& referenceSet;
214  const typename TreeType::Mat& querySet;
215 
217  TreeType* referenceTree;
219  TreeType* queryTree;
220 
222  bool treeOwner;
225 
227  bool naive;
230 
232  MetricType metric;
233 
235  std::vector<size_t> oldFromNewReferences;
237  std::vector<size_t> oldFromNewQueries;
238 }; // class NeighborSearch
239 
240 }; // namespace neighbor
241 }; // namespace mlpack
242 
243 // Include implementation.
244 #include "neighbor_search_impl.hpp"
245 
246 // Include convenience typedefs.
247 #include "typedef.hpp"
248 
249 #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:23
~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:92
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).