13#ifndef MLPACK_METHODS_NEIGHBOR_SEARCH_NEIGHBOR_SEARCH_HPP
14#define MLPACK_METHODS_NEIGHBOR_SEARCH_NEIGHBOR_SEARCH_HPP
34template<
typename SortPolicy>
71 typename MatType = arma::mat,
72 template<
typename TreeMetricType,
73 typename TreeStatType,
75 template<
typename RuleType>
class DualTreeTraversalType =
77 NeighborSearchStat<SortPolicy>,
78 MatType>::template DualTreeTraverser,
79 template<
typename RuleType>
class SingleTreeTraversalType =
81 NeighborSearchStat<SortPolicy>,
82 MatType>::template SingleTreeTraverser>
87 typedef TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>
Tree;
107 const double epsilon = 0,
108 const MetricType metric = MetricType());
135 const double epsilon = 0,
136 const MetricType metric = MetricType());
148 const double epsilon = 0,
149 const MetricType metric = MetricType());
228 arma::Mat<size_t>& neighbors,
229 arma::mat& distances);
253 arma::Mat<size_t>& neighbors,
254 arma::mat& distances,
255 bool sameSet =
false);
272 arma::Mat<size_t>& neighbors,
273 arma::mat& distances);
291 arma::mat& realDistances);
304 static double Recall(arma::Mat<size_t>& foundNeighbors,
305 arma::Mat<size_t>& realNeighbors);
333 template<
typename Archive>
338 std::vector<size_t> oldFromNewReferences;
342 const MatType* referenceSet;
362 template<
typename SortPol>
370#include "neighbor_search_impl.hpp"
Definition of generalized binary space partitioning tree (BinarySpaceTree).
The NeighborSearch class is a template class for performing distance-based neighbor searches.
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...
NeighborSearchMode SearchMode() const
Access the search mode.
~NeighborSearch()
Delete the NeighborSearch object.
void Train(MatType referenceSet)
Set the reference set to a new reference set, and build a tree if necessary.
const MatType & ReferenceSet() const
Access the reference dataset.
NeighborSearch(NeighborSearch &&other)
Construct the NeighborSearch object by taking ownership of the given NeighborSearch object.
size_t BaseCases() const
Return the total number of base case evaluations performed during the last search.
NeighborSearch(Tree referenceTree, const NeighborSearchMode mode=DUAL_TREE_MODE, const double epsilon=0, const MetricType metric=MetricType())
Initialize the NeighborSearch object with a copy of the given pre-constructed reference tree (this is...
size_t Scores() const
Return the number of node combination scores during the last search.
NeighborSearch & operator=(NeighborSearch &&other)
Take ownership of the given NeighborSearch object.
void Train(Tree referenceTree)
Set the reference tree to a new reference tree.
double & Epsilon()
Modify the relative error to be considered in approximate search.
void Search(const size_t k, arma::Mat< size_t > &neighbors, arma::mat &distances)
Search for the nearest neighbors of every point in the reference set.
NeighborSearch(const NeighborSearch &other)
Construct the NeighborSearch object by copying the given NeighborSearch object.
NeighborSearch & operator=(const NeighborSearch &other)
Copy the given NeighborSearch object.
NeighborSearchMode & SearchMode()
Modify the search mode.
Tree & ReferenceTree()
Modify the reference tree.
TreeType< MetricType, NeighborSearchStat< SortPolicy >, MatType > Tree
Convenience typedef.
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...
const Tree & ReferenceTree() const
Access the reference tree.
NeighborSearch(const NeighborSearchMode mode=DUAL_TREE_MODE, const double epsilon=0, const MetricType metric=MetricType())
Create a NeighborSearch object without any reference data.
void Search(Tree &queryTree, const size_t k, arma::Mat< size_t > &neighbors, arma::mat &distances, bool sameSet=false)
Given a pre-built query tree, search for the nearest neighbors of each point in the query tree,...
void serialize(Archive &ar, const unsigned int)
Serialize the NeighborSearch model.
double Epsilon() const
Access the relative error to be considered in approximate search.
static double EffectiveError(arma::mat &foundDistances, arma::mat &realDistances)
Calculate the average relative error (effective error) between the distances calculated and the true ...
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...
TrainVisitor sets the reference set to a new reference set on the given NSType.
LMetric< 2, true > EuclideanDistance
The Euclidean (L2) distance.
NeighborSearchMode
NeighborSearchMode represents the different neighbor search modes available.
@ GREEDY_SINGLE_TREE_MODE
NearestNS NearestNeighborSort
BinarySpaceTree< MetricType, StatisticType, MatType, bound::HRectBound, MidpointSplit > KDTree
The standard midpoint-split kd-tree.
Linear algebra utility functions, generally performed on matrices or vectors.
The core includes that mlpack expects; standard C++ includes and Armadillo.