13 #ifndef MLPACK_METHODS_NEIGHBOR_SEARCH_NEIGHBOR_SEARCH_HPP 14 #define MLPACK_METHODS_NEIGHBOR_SEARCH_NEIGHBOR_SEARCH_HPP 34 template<
typename SortPolicy,
35 template<
typename TreeMetricType,
36 typename TreeStatType,
37 typename TreeMatType>
class TreeType,
38 template<typename RuleType> class DualTreeTraversalType,
39 template<typename RuleType> class SingleTreeTraversalType>
76 typename MatType = arma::mat,
77 template<
typename TreeMetricType,
78 typename TreeStatType,
80 template<
typename RuleType>
class DualTreeTraversalType =
83 MatType>::template DualTreeTraverser,
84 template<
typename RuleType>
class SingleTreeTraversalType =
86 NeighborSearchStat<SortPolicy>,
87 MatType>::template SingleTreeTraverser>
92 typedef TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>
Tree;
112 const double epsilon = 0,
113 const MetricType metric = MetricType());
140 const double epsilon = 0,
141 const MetricType metric = MetricType());
153 const double epsilon = 0,
154 const MetricType metric = MetricType());
201 void Train(MatType referenceSet);
212 void Train(Tree referenceTree);
231 void Search(
const MatType& querySet,
233 arma::Mat<size_t>& neighbors,
234 arma::mat& distances);
256 void Search(Tree& queryTree,
258 arma::Mat<size_t>& neighbors,
259 arma::mat& distances,
260 bool sameSet =
false);
276 void Search(
const size_t k,
277 arma::Mat<size_t>& neighbors,
278 arma::mat& distances);
296 arma::mat& realDistances);
309 static double Recall(arma::Mat<size_t>& foundNeighbors,
310 arma::Mat<size_t>& realNeighbors);
338 template<
typename Archive>
339 void serialize(Archive& ar,
const uint32_t version);
343 std::vector<size_t> oldFromNewReferences;
347 const MatType* referenceSet;
368 SingleTreeTraversalType>;
375 #include "neighbor_search_impl.hpp" const MatType & ReferenceSet() const
Access the reference dataset.
double Epsilon() const
Access the relative error to be considered in approximate search.
size_t Scores() const
Return the number of node combination scores during the last search.
const Tree & ReferenceTree() const
Access the reference tree.
Linear algebra utility functions, generally performed on matrices or vectors.
Extra data for each node in the tree.
The core includes that mlpack expects; standard C++ includes and Armadillo.
NeighborSearch(MatType referenceSet, const NeighborSearchMode mode=DUAL_TREE_MODE, const double epsilon=0, const MetricType metric=MetricType())
Initialize the NeighborSearch object, passing a reference dataset (this is the dataset which is searc...
LeafSizeNSWrapper wraps any NeighborSearch types that take a leaf size for tree construction.
The NeighborSearch class is a template class for performing distance-based neighbor searches...
static double EffectiveError(arma::mat &foundDistances, arma::mat &realDistances)
Calculate the average relative error (effective error) between the distances calculated and the true ...
double & Epsilon()
Modify the relative error to be considered in approximate search.
Tree & ReferenceTree()
Modify the reference tree.
static double Recall(arma::Mat< size_t > &foundNeighbors, arma::Mat< size_t > &realNeighbors)
Calculate the recall (% of neighbors found) given the list of found neighbors and the true set of nei...
NeighborSearchMode & SearchMode()
Modify the search mode.
NeighborSearchMode SearchMode() const
Access the search mode.
NeighborSearch & operator=(const NeighborSearch &other)
Copy the given NeighborSearch object.
TreeType< MetricType, NeighborSearchStat< SortPolicy >, MatType > Tree
Convenience typedef.
NearestNS NearestNeighborSort
Definition of generalized binary space partitioning tree (BinarySpaceTree).
void Search(const MatType &querySet, const size_t k, arma::Mat< size_t > &neighbors, arma::mat &distances)
For each point in the query set, compute the nearest neighbors and store the output in the given matr...
size_t BaseCases() const
Return the total number of base case evaluations performed during the last search.
void Train(MatType referenceSet)
Set the reference set to a new reference set, and build a tree if necessary.
BinarySpaceTree< MetricType, StatisticType, MatType, bound::HRectBound, MidpointSplit > KDTree
The standard midpoint-split kd-tree.
void serialize(Archive &ar, const uint32_t version)
Serialize the NeighborSearch model.
LMetric< 2, true > EuclideanDistance
The Euclidean (L2) distance.
NeighborSearchMode
NeighborSearchMode represents the different neighbor search modes available.
~NeighborSearch()
Delete the NeighborSearch object.