mlpack  2.2.3
mlpack::neighbor::NeighborSearch< SortPolicy, MetricType, MatType, TreeType, DualTreeTraversalType, SingleTreeTraversalType > Class Template Reference

The NeighborSearch class is a template class for performing distance-based neighbor searches. More...

Public Types

typedef TreeType< MetricType, NeighborSearchStat< SortPolicy >, MatType > Tree
 Convenience typedef. More...

 

Public Member Functions

 NeighborSearch (const 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 searched). More...

 
 NeighborSearch (MatType &&referenceSet, const NeighborSearchMode mode=DUAL_TREE_MODE, const double epsilon=0, const MetricType metric=MetricType())
 Initialize the NeighborSearch object, taking ownership of the reference dataset (this is the dataset which is searched). More...

 
 NeighborSearch (const 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 the tree built on the points that will be searched). More...

 
 NeighborSearch (Tree &&referenceTree, const NeighborSearchMode mode=DUAL_TREE_MODE, const double epsilon=0, const MetricType metric=MetricType())
 Initialize the NeighborSearch object with the given pre-constructed reference tree (this is the tree built on the points that will be searched). More...

 
 NeighborSearch (const NeighborSearchMode mode=DUAL_TREE_MODE, const double epsilon=0, const MetricType metric=MetricType())
 Create a NeighborSearch object without any reference data. More...

 
mlpack_deprecated NeighborSearch (const MatType &referenceSet, const bool naive, const bool singleMode=false, const double epsilon=0, const MetricType metric=MetricType())
 Initialize the NeighborSearch object, passing a reference dataset (this is the dataset which is searched). More...

 
mlpack_deprecated NeighborSearch (MatType &&referenceSet, const bool naive, const bool singleMode=false, const double epsilon=0, const MetricType metric=MetricType())
 Initialize the NeighborSearch object, taking ownership of the reference dataset (this is the dataset which is searched). More...

 
mlpack_deprecated NeighborSearch (Tree *referenceTree, const bool singleMode, const double epsilon=0, const MetricType metric=MetricType())
 Initialize the NeighborSearch object with the given pre-constructed reference tree (this is the tree built on the points that will be searched). More...

 
mlpack_deprecated NeighborSearch (const bool naive, const bool singleMode=false, const double epsilon=0, const MetricType metric=MetricType())
 Create a NeighborSearch object without any reference data. More...

 
 NeighborSearch (const NeighborSearch &other)
 Copy the given NeighborSearch object (this may consume a lot of memory; be careful!). More...

 
 NeighborSearch (NeighborSearch &&other)
 Take possession of the given NeighborSearch object. More...

 
 ~NeighborSearch ()
 Delete the NeighborSearch object. More...

 
size_t BaseCases () const
 Return the total number of base case evaluations performed during the last search. More...

 
double Epsilon () const
 Access the relative error to be considered in approximate search. More...

 
double & Epsilon ()
 Modify the relative error to be considered in approximate search. More...

 
bool Greedy () const
 Access whether or not search is done in greedy mode. More...

 
bool & Greedy ()
 Modify whether or not search is done in greedy mode. More...

 
bool Naive () const
 Access whether or not search is done in naive linear scan mode. More...

 
bool & Naive ()
 Modify whether or not search is done in naive linear scan mode. More...

 
const MatType & ReferenceSet () const
 Access the reference dataset. More...

 
const TreeReferenceTree () const
 Access the reference tree. More...

 
TreeReferenceTree ()
 Modify the reference tree. More...

 
size_t Scores () const
 Return the number of node combination scores during the last search. More...

 
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 matrices. More...

 
mlpack_deprecated 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, storing the output in the given matrices. More...

 
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, storing the output in the given matrices. More...

 
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. More...

 
template
<
typename
Archive
>
void Serialize (Archive &ar, const unsigned int)
 Serialize the NeighborSearch model. More...

 
bool SingleMode () const
 Access whether or not search is done in single-tree mode. More...

 
bool & SingleMode ()
 Modify whether or not search is done in single-tree mode. More...

 
void Train (const MatType &referenceSet)
 Set the reference set to a new reference set, and build a tree if necessary. More...

 
void Train (MatType &&referenceSet)
 Set the reference set to a new reference set, taking ownership of the set, and build a tree if necessary. More...

 
mlpack_deprecated void Train (Tree *referenceTree)
 Set the reference tree to a new reference tree. More...

 
void Train (const Tree &referenceTree)
 Set the reference tree as a copy of the given reference tree. More...

 
void Train (Tree &&referenceTree)
 Set the reference tree to a new reference tree. More...

 

Static Public Member Functions

static double EffectiveError (arma::mat &foundDistances, arma::mat &realDistances)
 Calculate the average relative error (effective error) between the distances calculated and the true distances provided. More...

 
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 neighbors. More...

 

Private Member Functions

void UpdateSearchMode ()
 Updates searchMode to be according to naive, singleMode and greedy booleans. More...

 
void UpdateSearchModeFlags ()
 Updates naive, singleMode and greedy flags according to searchMode. More...

 

Private Attributes

size_t baseCases
 The total number of base cases. More...

 
double epsilon
 Indicates the relative error to be considered in approximate search. More...

 
bool greedy
 Indicates if greedy search is being used. More...

 
MetricType metric
 Instantiation of metric. More...

 
bool naive
 Indicates if O(n^2) naive search is being used. More...

 
std::vector< size_t > oldFromNewReferences
 Permutations of reference points during tree building. More...

 
const MatType * referenceSet
 Reference dataset. In some situations we may be the owner of this. More...

 
TreereferenceTree
 Pointer to the root of the reference tree. More...

 
size_t scores
 The total number of scores (applicable for non-naive search). More...

 
NeighborSearchMode searchMode
 Indicates the neighbor search mode. More...

 
bool setOwner
 If true, we own the reference set. More...

 
bool singleMode
 Indicates if single-tree search is being used (as opposed to dual-tree). More...

 
bool treeNeedsReset
 If this is true, the reference tree bounds need to be reset on a call to Search() without a query set. More...

 
bool treeOwner
 If true, this object created the trees and is responsible for them. More...

 

Detailed Description


template<typename SortPolicy = NearestNeighborSort, typename MetricType = mlpack::metric::EuclideanDistance, typename MatType = arma::mat, template< typename TreeMetricType, typename TreeStatType, typename TreeMatType > class TreeType = tree::KDTree, template< typename RuleType > class DualTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template DualTreeTraverser, template< typename RuleType > class SingleTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template SingleTreeTraverser>
class mlpack::neighbor::NeighborSearch< SortPolicy, MetricType, MatType, TreeType, DualTreeTraversalType, SingleTreeTraversalType >

The NeighborSearch class is a template class for performing distance-based neighbor searches.

It takes a query dataset and a reference dataset (or just a reference dataset) and, for each point in the query dataset, finds the k neighbors in the reference dataset which have the 'best' distance according to a given sorting policy. A constructor is given which takes only a reference dataset, and if that constructor is used, the given reference dataset is also used as the query dataset.

The template parameters SortPolicy and Metric define the sort function used and the metric (distance function) used. More information on those classes can be found in the NearestNeighborSort class and the kernel::ExampleKernel class.

Template Parameters
SortPolicyThe sort policy for distances; see NearestNeighborSort.
MetricTypeThe metric to use for computation.
MatTypeThe type of data matrix.
TreeTypeThe tree type to use; must adhere to the TreeType API.
DualTreeTraversalTypeThe type of dual tree traversal to use (defaults to the tree's default traverser).
SingleTreeTraversalTypeThe type of single tree traversal to use (defaults to the tree's default traverser).

Definition at line 83 of file neighbor_search.hpp.

Member Typedef Documentation

◆ Tree

template<typename SortPolicy = NearestNeighborSort, typename MetricType = mlpack::metric::EuclideanDistance, typename MatType = arma::mat, template< typename TreeMetricType, typename TreeStatType, typename TreeMatType > class TreeType = tree::KDTree, template< typename RuleType > class DualTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template DualTreeTraverser, template< typename RuleType > class SingleTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template SingleTreeTraverser>
typedef TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType> mlpack::neighbor::NeighborSearch< SortPolicy, MetricType, MatType, TreeType, DualTreeTraversalType, SingleTreeTraversalType >::Tree

Convenience typedef.

Definition at line 87 of file neighbor_search.hpp.

Constructor & Destructor Documentation

◆ NeighborSearch() [1/11]

template<typename SortPolicy = NearestNeighborSort, typename MetricType = mlpack::metric::EuclideanDistance, typename MatType = arma::mat, template< typename TreeMetricType, typename TreeStatType, typename TreeMatType > class TreeType = tree::KDTree, template< typename RuleType > class DualTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template DualTreeTraverser, template< typename RuleType > class SingleTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template SingleTreeTraverser>
mlpack::neighbor::NeighborSearch< SortPolicy, MetricType, MatType, TreeType, DualTreeTraversalType, SingleTreeTraversalType >::NeighborSearch ( const 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 searched).

Optionally, perform the computation in a different mode. An initialized distance metric can be given, for cases where the metric has internal data (i.e. the distance::MahalanobisDistance class).

This method will copy the matrices to internal copies, which are rearranged during tree-building. You can avoid this extra copy by pre-constructing the trees and passing them using a different constructor, or by using the construct that takes an rvalue reference to the dataset.

Parameters
referenceSetSet of reference points.
modeNeighbor search mode.
epsilonRelative approximate error (non-negative).
metricAn optional instance of the MetricType class.

◆ NeighborSearch() [2/11]

template<typename SortPolicy = NearestNeighborSort, typename MetricType = mlpack::metric::EuclideanDistance, typename MatType = arma::mat, template< typename TreeMetricType, typename TreeStatType, typename TreeMatType > class TreeType = tree::KDTree, template< typename RuleType > class DualTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template DualTreeTraverser, template< typename RuleType > class SingleTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template SingleTreeTraverser>
mlpack::neighbor::NeighborSearch< SortPolicy, MetricType, MatType, TreeType, DualTreeTraversalType, SingleTreeTraversalType >::NeighborSearch ( MatType &&  referenceSet,
const NeighborSearchMode  mode = DUAL_TREE_MODE,
const double  epsilon = 0,
const MetricType  metric = MetricType() 
)

Initialize the NeighborSearch object, taking ownership of the reference dataset (this is the dataset which is searched).

Optionally, perform the computation in a different mode. An initialized distance metric can be given, for cases where the metric has internal data (i.e. the distance::MahalanobisDistance class).

This method will not copy the data matrix, but will take ownership of it, and depending on the type of tree used, may rearrange the points. If you would rather a copy be made, consider using the constructor that takes a const reference to the data instead.

Parameters
referenceSetSet of reference points.
modeNeighbor search mode.
epsilonRelative approximate error (non-negative).
metricAn optional instance of the MetricType class.

◆ NeighborSearch() [3/11]

template<typename SortPolicy = NearestNeighborSort, typename MetricType = mlpack::metric::EuclideanDistance, typename MatType = arma::mat, template< typename TreeMetricType, typename TreeStatType, typename TreeMatType > class TreeType = tree::KDTree, template< typename RuleType > class DualTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template DualTreeTraverser, template< typename RuleType > class SingleTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template SingleTreeTraverser>
mlpack::neighbor::NeighborSearch< SortPolicy, MetricType, MatType, TreeType, DualTreeTraversalType, SingleTreeTraversalType >::NeighborSearch ( const 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 the tree built on the points that will be searched).

Optionally, choose to use single-tree mode. Naive mode is not available as an option for this constructor. Additionally, an instantiated distance metric can be given, for cases where the distance metric holds data.

This method will copy the given tree. You can avoid this copy by using the construct that takes a rvalue reference to the tree.

Note
Mapping the points of the matrix back to their original indices is not done when this constructor is used, so if the tree type you are using maps points (like BinarySpaceTree), then you will have to perform the re-mapping manually.
Parameters
referenceTreePre-built tree for reference points.
modeNeighbor search mode.
epsilonRelative approximate error (non-negative).
metricInstantiated distance metric.

◆ NeighborSearch() [4/11]

template<typename SortPolicy = NearestNeighborSort, typename MetricType = mlpack::metric::EuclideanDistance, typename MatType = arma::mat, template< typename TreeMetricType, typename TreeStatType, typename TreeMatType > class TreeType = tree::KDTree, template< typename RuleType > class DualTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template DualTreeTraverser, template< typename RuleType > class SingleTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template SingleTreeTraverser>
mlpack::neighbor::NeighborSearch< SortPolicy, MetricType, MatType, TreeType, DualTreeTraversalType, SingleTreeTraversalType >::NeighborSearch ( Tree &&  referenceTree,
const NeighborSearchMode  mode = DUAL_TREE_MODE,
const double  epsilon = 0,
const MetricType  metric = MetricType() 
)

Initialize the NeighborSearch object with the given pre-constructed reference tree (this is the tree built on the points that will be searched).

Optionally, choose to use single-tree mode. Naive mode is not available as an option for this constructor. Additionally, an instantiated distance metric can be given, for cases where the distance metric holds data.

This method will take ownership of the given tree. There is no copying of the data matrices (because tree-building is not necessary), so this is the constructor to use when copies absolutely must be avoided.

Note
Mapping the points of the matrix back to their original indices is not done when this constructor is used, so if the tree type you are using maps points (like BinarySpaceTree), then you will have to perform the re-mapping manually.
Parameters
referenceTreePre-built tree for reference points.
modeNeighbor search mode.
epsilonRelative approximate error (non-negative).
metricInstantiated distance metric.

◆ NeighborSearch() [5/11]

template<typename SortPolicy = NearestNeighborSort, typename MetricType = mlpack::metric::EuclideanDistance, typename MatType = arma::mat, template< typename TreeMetricType, typename TreeStatType, typename TreeMatType > class TreeType = tree::KDTree, template< typename RuleType > class DualTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template DualTreeTraverser, template< typename RuleType > class SingleTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template SingleTreeTraverser>
mlpack::neighbor::NeighborSearch< SortPolicy, MetricType, MatType, TreeType, DualTreeTraversalType, SingleTreeTraversalType >::NeighborSearch ( const NeighborSearchMode  mode = DUAL_TREE_MODE,
const double  epsilon = 0,
const MetricType  metric = MetricType() 
)

Create a NeighborSearch object without any reference data.

If Search() is called before a reference set is set with Train(), an exception will be thrown.

Parameters
modeNeighbor search mode.
epsilonRelative approximate error (non-negative).
metricInstantiated metric.

◆ NeighborSearch() [6/11]

template<typename SortPolicy = NearestNeighborSort, typename MetricType = mlpack::metric::EuclideanDistance, typename MatType = arma::mat, template< typename TreeMetricType, typename TreeStatType, typename TreeMatType > class TreeType = tree::KDTree, template< typename RuleType > class DualTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template DualTreeTraverser, template< typename RuleType > class SingleTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template SingleTreeTraverser>
mlpack_deprecated mlpack::neighbor::NeighborSearch< SortPolicy, MetricType, MatType, TreeType, DualTreeTraversalType, SingleTreeTraversalType >::NeighborSearch ( const MatType &  referenceSet,
const bool  naive,
const bool  singleMode = false,
const double  epsilon = 0,
const MetricType  metric = MetricType() 
)

Initialize the NeighborSearch object, passing a reference dataset (this is the dataset which is searched).

Optionally, perform the computation in naive mode or single-tree mode. An initialized distance metric can be given, for cases where the metric has internal data (i.e. the distance::MahalanobisDistance class).

Deprecated. Will be removed in mlpack 3.0.0.

This method will copy the matrices to internal copies, which are rearranged during tree-building. You can avoid this extra copy by pre-constructing the trees and passing them using a different constructor, or by using the construct that takes an rvalue reference to the dataset.

Parameters
referenceSetSet of reference points.
naiveIf true, O(n^2) naive search will be used (as opposed to dual-tree search). This overrides singleMode (if it is set to true).
singleModeIf true, single-tree search will be used (as opposed to dual-tree search).
epsilonRelative approximate error (non-negative).
metricAn optional instance of the MetricType class.

◆ NeighborSearch() [7/11]

template<typename SortPolicy = NearestNeighborSort, typename MetricType = mlpack::metric::EuclideanDistance, typename MatType = arma::mat, template< typename TreeMetricType, typename TreeStatType, typename TreeMatType > class TreeType = tree::KDTree, template< typename RuleType > class DualTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template DualTreeTraverser, template< typename RuleType > class SingleTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template SingleTreeTraverser>
mlpack_deprecated mlpack::neighbor::NeighborSearch< SortPolicy, MetricType, MatType, TreeType, DualTreeTraversalType, SingleTreeTraversalType >::NeighborSearch ( MatType &&  referenceSet,
const bool  naive,
const bool  singleMode = false,
const double  epsilon = 0,
const MetricType  metric = MetricType() 
)

Initialize the NeighborSearch object, taking ownership of the reference dataset (this is the dataset which is searched).

Optionally, perform the computation in naive mode or single-tree mode. An initialized distance metric can be given, for cases where the metric has internal data (i.e. the distance::MahalanobisDistance class).

Deprecated. Will be removed in mlpack 3.0.0.

This method will not copy the data matrix, but will take ownership of it, and depending on the type of tree used, may rearrange the points. If you would rather a copy be made, consider using the constructor that takes a const reference to the data instead.

Parameters
referenceSetSet of reference points.
naiveIf true, O(n^2) naive search will be used (as opposed to dual-tree search). This overrides singleMode (if it is set to true).
singleModeIf true, single-tree search will be used (as opposed to dual-tree search).
epsilonRelative approximate error (non-negative).
metricAn optional instance of the MetricType class.

◆ NeighborSearch() [8/11]

template<typename SortPolicy = NearestNeighborSort, typename MetricType = mlpack::metric::EuclideanDistance, typename MatType = arma::mat, template< typename TreeMetricType, typename TreeStatType, typename TreeMatType > class TreeType = tree::KDTree, template< typename RuleType > class DualTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template DualTreeTraverser, template< typename RuleType > class SingleTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template SingleTreeTraverser>
mlpack_deprecated mlpack::neighbor::NeighborSearch< SortPolicy, MetricType, MatType, TreeType, DualTreeTraversalType, SingleTreeTraversalType >::NeighborSearch ( Tree referenceTree,
const bool  singleMode,
const double  epsilon = 0,
const MetricType  metric = MetricType() 
)

Initialize the NeighborSearch object with the given pre-constructed reference tree (this is the tree built on the points that will be searched).

Optionally, choose to use single-tree mode. Naive mode is not available as an option for this constructor. Additionally, an instantiated distance metric can be given, for cases where the distance metric holds data.

Deprecated. Will be removed in mlpack 3.0.0.

This method won't take ownership of the given tree. There is no copying of the data matrices in this constructor (because tree-building is not necessary), so this is the constructor to use when copies absolutely must be avoided.

Note
Mapping the points of the matrix back to their original indices is not done when this constructor is used, so if the tree type you are using maps points (like BinarySpaceTree), then you will have to perform the re-mapping manually.
Parameters
referenceTreePre-built tree for reference points.
singleModeWhether single-tree computation should be used (as opposed to dual-tree computation).
epsilonRelative approximate error (non-negative).
metricInstantiated distance metric.

◆ NeighborSearch() [9/11]

template<typename SortPolicy = NearestNeighborSort, typename MetricType = mlpack::metric::EuclideanDistance, typename MatType = arma::mat, template< typename TreeMetricType, typename TreeStatType, typename TreeMatType > class TreeType = tree::KDTree, template< typename RuleType > class DualTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template DualTreeTraverser, template< typename RuleType > class SingleTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template SingleTreeTraverser>
mlpack_deprecated mlpack::neighbor::NeighborSearch< SortPolicy, MetricType, MatType, TreeType, DualTreeTraversalType, SingleTreeTraversalType >::NeighborSearch ( const bool  naive,
const bool  singleMode = false,
const double  epsilon = 0,
const MetricType  metric = MetricType() 
)

Create a NeighborSearch object without any reference data.

If Search() is called before a reference set is set with Train(), an exception will be thrown.

Deprecated. Will be removed in mlpack 3.0.0.

Parameters
naiveWhether to use naive search.
singleModeWhether single-tree computation should be used (as opposed to dual-tree computation).
epsilonRelative approximate error (non-negative).
metricInstantiated metric.

◆ NeighborSearch() [10/11]

template<typename SortPolicy = NearestNeighborSort, typename MetricType = mlpack::metric::EuclideanDistance, typename MatType = arma::mat, template< typename TreeMetricType, typename TreeStatType, typename TreeMatType > class TreeType = tree::KDTree, template< typename RuleType > class DualTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template DualTreeTraverser, template< typename RuleType > class SingleTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template SingleTreeTraverser>
mlpack::neighbor::NeighborSearch< SortPolicy, MetricType, MatType, TreeType, DualTreeTraversalType, SingleTreeTraversalType >::NeighborSearch ( const NeighborSearch< SortPolicy, MetricType, MatType, TreeType, DualTreeTraversalType, SingleTreeTraversalType > &  other)

Copy the given NeighborSearch object (this may consume a lot of memory; be careful!).

◆ NeighborSearch() [11/11]

template<typename SortPolicy = NearestNeighborSort, typename MetricType = mlpack::metric::EuclideanDistance, typename MatType = arma::mat, template< typename TreeMetricType, typename TreeStatType, typename TreeMatType > class TreeType = tree::KDTree, template< typename RuleType > class DualTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template DualTreeTraverser, template< typename RuleType > class SingleTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template SingleTreeTraverser>
mlpack::neighbor::NeighborSearch< SortPolicy, MetricType, MatType, TreeType, DualTreeTraversalType, SingleTreeTraversalType >::NeighborSearch ( NeighborSearch< SortPolicy, MetricType, MatType, TreeType, DualTreeTraversalType, SingleTreeTraversalType > &&  other)

Take possession of the given NeighborSearch object.

◆ ~NeighborSearch()

template<typename SortPolicy = NearestNeighborSort, typename MetricType = mlpack::metric::EuclideanDistance, typename MatType = arma::mat, template< typename TreeMetricType, typename TreeStatType, typename TreeMatType > class TreeType = tree::KDTree, template< typename RuleType > class DualTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template DualTreeTraverser, template< typename RuleType > class SingleTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template SingleTreeTraverser>
mlpack::neighbor::NeighborSearch< SortPolicy, MetricType, MatType, TreeType, DualTreeTraversalType, SingleTreeTraversalType >::~NeighborSearch ( )

Delete the NeighborSearch object.

The tree is the only member we are responsible for deleting. The others will take care of themselves.

Member Function Documentation

◆ BaseCases()

template<typename SortPolicy = NearestNeighborSort, typename MetricType = mlpack::metric::EuclideanDistance, typename MatType = arma::mat, template< typename TreeMetricType, typename TreeStatType, typename TreeMatType > class TreeType = tree::KDTree, template< typename RuleType > class DualTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template DualTreeTraverser, template< typename RuleType > class SingleTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template SingleTreeTraverser>
size_t mlpack::neighbor::NeighborSearch< SortPolicy, MetricType, MatType, TreeType, DualTreeTraversalType, SingleTreeTraversalType >::BaseCases ( ) const
inline

Return the total number of base case evaluations performed during the last search.

Definition at line 507 of file neighbor_search.hpp.

References mlpack::neighbor::NeighborSearch< SortPolicy, MetricType, MatType, TreeType, DualTreeTraversalType, SingleTreeTraversalType >::baseCases.

◆ EffectiveError()

template<typename SortPolicy = NearestNeighborSort, typename MetricType = mlpack::metric::EuclideanDistance, typename MatType = arma::mat, template< typename TreeMetricType, typename TreeStatType, typename TreeMatType > class TreeType = tree::KDTree, template< typename RuleType > class DualTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template DualTreeTraverser, template< typename RuleType > class SingleTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template SingleTreeTraverser>
static double mlpack::neighbor::NeighborSearch< SortPolicy, MetricType, MatType, TreeType, DualTreeTraversalType, SingleTreeTraversalType >::EffectiveError ( arma::mat &  foundDistances,
arma::mat &  realDistances 
)
static

Calculate the average relative error (effective error) between the distances calculated and the true distances provided.

The input matrices must have the same size.

Cases where the true distance is zero (the same point) or the calculated distance is SortPolicy::WorstDistance() (didn't find enough points) will be ignored.

Parameters
foundDistancesMatrix storing lists of calculated distances for each query point.
realDistancesMatrix storing lists of true best distances for each query point.
Returns
Average relative error.

◆ Epsilon() [1/2]

template<typename SortPolicy = NearestNeighborSort, typename MetricType = mlpack::metric::EuclideanDistance, typename MatType = arma::mat, template< typename TreeMetricType, typename TreeStatType, typename TreeMatType > class TreeType = tree::KDTree, template< typename RuleType > class DualTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template DualTreeTraverser, template< typename RuleType > class SingleTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template SingleTreeTraverser>
double mlpack::neighbor::NeighborSearch< SortPolicy, MetricType, MatType, TreeType, DualTreeTraversalType, SingleTreeTraversalType >::Epsilon ( ) const
inline

Access the relative error to be considered in approximate search.

Definition at line 540 of file neighbor_search.hpp.

References mlpack::neighbor::NeighborSearch< SortPolicy, MetricType, MatType, TreeType, DualTreeTraversalType, SingleTreeTraversalType >::epsilon.

◆ Epsilon() [2/2]

template<typename SortPolicy = NearestNeighborSort, typename MetricType = mlpack::metric::EuclideanDistance, typename MatType = arma::mat, template< typename TreeMetricType, typename TreeStatType, typename TreeMatType > class TreeType = tree::KDTree, template< typename RuleType > class DualTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template DualTreeTraverser, template< typename RuleType > class SingleTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template SingleTreeTraverser>
double& mlpack::neighbor::NeighborSearch< SortPolicy, MetricType, MatType, TreeType, DualTreeTraversalType, SingleTreeTraversalType >::Epsilon ( )
inline

Modify the relative error to be considered in approximate search.

Definition at line 542 of file neighbor_search.hpp.

References mlpack::neighbor::NeighborSearch< SortPolicy, MetricType, MatType, TreeType, DualTreeTraversalType, SingleTreeTraversalType >::epsilon.

◆ Greedy() [1/2]

template<typename SortPolicy = NearestNeighborSort, typename MetricType = mlpack::metric::EuclideanDistance, typename MatType = arma::mat, template< typename TreeMetricType, typename TreeStatType, typename TreeMatType > class TreeType = tree::KDTree, template< typename RuleType > class DualTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template DualTreeTraverser, template< typename RuleType > class SingleTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template SingleTreeTraverser>
bool mlpack::neighbor::NeighborSearch< SortPolicy, MetricType, MatType, TreeType, DualTreeTraversalType, SingleTreeTraversalType >::Greedy ( ) const
inline

Access whether or not search is done in greedy mode.

Deprecated. Will be replaced in mlpack 3.0.0, by a new method: NeighborSearchMode SearchMode().

Definition at line 533 of file neighbor_search.hpp.

References mlpack::neighbor::NeighborSearch< SortPolicy, MetricType, MatType, TreeType, DualTreeTraversalType, SingleTreeTraversalType >::greedy.

◆ Greedy() [2/2]

template<typename SortPolicy = NearestNeighborSort, typename MetricType = mlpack::metric::EuclideanDistance, typename MatType = arma::mat, template< typename TreeMetricType, typename TreeStatType, typename TreeMatType > class TreeType = tree::KDTree, template< typename RuleType > class DualTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template DualTreeTraverser, template< typename RuleType > class SingleTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template SingleTreeTraverser>
bool& mlpack::neighbor::NeighborSearch< SortPolicy, MetricType, MatType, TreeType, DualTreeTraversalType, SingleTreeTraversalType >::Greedy ( )
inline

Modify whether or not search is done in greedy mode.

Deprecated. Will be replaced in mlpack 3.0.0, by a new method: NeighborSearchMode& SearchMode().

Definition at line 537 of file neighbor_search.hpp.

References mlpack::neighbor::NeighborSearch< SortPolicy, MetricType, MatType, TreeType, DualTreeTraversalType, SingleTreeTraversalType >::greedy.

◆ Naive() [1/2]

template<typename SortPolicy = NearestNeighborSort, typename MetricType = mlpack::metric::EuclideanDistance, typename MatType = arma::mat, template< typename TreeMetricType, typename TreeStatType, typename TreeMatType > class TreeType = tree::KDTree, template< typename RuleType > class DualTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template DualTreeTraverser, template< typename RuleType > class SingleTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template SingleTreeTraverser>
bool mlpack::neighbor::NeighborSearch< SortPolicy, MetricType, MatType, TreeType, DualTreeTraversalType, SingleTreeTraversalType >::Naive ( ) const
inline

Access whether or not search is done in naive linear scan mode.

Deprecated. Will be replaced in mlpack 3.0.0, by a new method: NeighborSearchMode SearchMode().

Definition at line 515 of file neighbor_search.hpp.

References mlpack::neighbor::NeighborSearch< SortPolicy, MetricType, MatType, TreeType, DualTreeTraversalType, SingleTreeTraversalType >::naive.

◆ Naive() [2/2]

template<typename SortPolicy = NearestNeighborSort, typename MetricType = mlpack::metric::EuclideanDistance, typename MatType = arma::mat, template< typename TreeMetricType, typename TreeStatType, typename TreeMatType > class TreeType = tree::KDTree, template< typename RuleType > class DualTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template DualTreeTraverser, template< typename RuleType > class SingleTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template SingleTreeTraverser>
bool& mlpack::neighbor::NeighborSearch< SortPolicy, MetricType, MatType, TreeType, DualTreeTraversalType, SingleTreeTraversalType >::Naive ( )
inline

Modify whether or not search is done in naive linear scan mode.

Deprecated. Will be replaced in mlpack 3.0.0, by a new method: NeighborSearchMode& SearchMode().

Definition at line 519 of file neighbor_search.hpp.

References mlpack::neighbor::NeighborSearch< SortPolicy, MetricType, MatType, TreeType, DualTreeTraversalType, SingleTreeTraversalType >::naive.

◆ Recall()

template<typename SortPolicy = NearestNeighborSort, typename MetricType = mlpack::metric::EuclideanDistance, typename MatType = arma::mat, template< typename TreeMetricType, typename TreeStatType, typename TreeMatType > class TreeType = tree::KDTree, template< typename RuleType > class DualTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template DualTreeTraverser, template< typename RuleType > class SingleTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template SingleTreeTraverser>
static double mlpack::neighbor::NeighborSearch< SortPolicy, MetricType, MatType, TreeType, DualTreeTraversalType, SingleTreeTraversalType >::Recall ( arma::Mat< size_t > &  foundNeighbors,
arma::Mat< size_t > &  realNeighbors 
)
static

Calculate the recall (% of neighbors found) given the list of found neighbors and the true set of neighbors.

The recall returned will be in the range [0, 1].

Parameters
foundNeighborsMatrix storing lists of calculated neighbors for each query point.
realNeighborsMatrix storing lists of true best neighbors for each query point.
Returns
Recall.

◆ ReferenceSet()

template<typename SortPolicy = NearestNeighborSort, typename MetricType = mlpack::metric::EuclideanDistance, typename MatType = arma::mat, template< typename TreeMetricType, typename TreeStatType, typename TreeMatType > class TreeType = tree::KDTree, template< typename RuleType > class DualTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template DualTreeTraverser, template< typename RuleType > class SingleTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template SingleTreeTraverser>
const MatType& mlpack::neighbor::NeighborSearch< SortPolicy, MetricType, MatType, TreeType, DualTreeTraversalType, SingleTreeTraversalType >::ReferenceSet ( ) const
inline

◆ ReferenceTree() [1/2]

template<typename SortPolicy = NearestNeighborSort, typename MetricType = mlpack::metric::EuclideanDistance, typename MatType = arma::mat, template< typename TreeMetricType, typename TreeStatType, typename TreeMatType > class TreeType = tree::KDTree, template< typename RuleType > class DualTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template DualTreeTraverser, template< typename RuleType > class SingleTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template SingleTreeTraverser>
const Tree& mlpack::neighbor::NeighborSearch< SortPolicy, MetricType, MatType, TreeType, DualTreeTraversalType, SingleTreeTraversalType >::ReferenceTree ( ) const
inline

◆ ReferenceTree() [2/2]

template<typename SortPolicy = NearestNeighborSort, typename MetricType = mlpack::metric::EuclideanDistance, typename MatType = arma::mat, template< typename TreeMetricType, typename TreeStatType, typename TreeMatType > class TreeType = tree::KDTree, template< typename RuleType > class DualTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template DualTreeTraverser, template< typename RuleType > class SingleTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template SingleTreeTraverser>
Tree& mlpack::neighbor::NeighborSearch< SortPolicy, MetricType, MatType, TreeType, DualTreeTraversalType, SingleTreeTraversalType >::ReferenceTree ( )
inline

◆ Scores()

template<typename SortPolicy = NearestNeighborSort, typename MetricType = mlpack::metric::EuclideanDistance, typename MatType = arma::mat, template< typename TreeMetricType, typename TreeStatType, typename TreeMatType > class TreeType = tree::KDTree, template< typename RuleType > class DualTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template DualTreeTraverser, template< typename RuleType > class SingleTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template SingleTreeTraverser>
size_t mlpack::neighbor::NeighborSearch< SortPolicy, MetricType, MatType, TreeType, DualTreeTraversalType, SingleTreeTraversalType >::Scores ( ) const
inline

Return the number of node combination scores during the last search.

Definition at line 510 of file neighbor_search.hpp.

References mlpack::neighbor::NeighborSearch< SortPolicy, MetricType, MatType, TreeType, DualTreeTraversalType, SingleTreeTraversalType >::scores.

◆ Search() [1/4]

template<typename SortPolicy = NearestNeighborSort, typename MetricType = mlpack::metric::EuclideanDistance, typename MatType = arma::mat, template< typename TreeMetricType, typename TreeStatType, typename TreeMatType > class TreeType = tree::KDTree, template< typename RuleType > class DualTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template DualTreeTraverser, template< typename RuleType > class SingleTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template SingleTreeTraverser>
void mlpack::neighbor::NeighborSearch< SortPolicy, MetricType, MatType, TreeType, DualTreeTraversalType, SingleTreeTraversalType >::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 matrices.

The matrices will be set to the size of n columns by k rows, where n is the number of points in the query dataset and k is the number of neighbors being searched for.

If querySet contains only a few query points, the extra cost of building a tree on the points for dual-tree search may not be warranted, and it may be worthwhile to set singleMode = false (either in the constructor or with SingleMode()).

Parameters
querySetSet of query points (can be just one point).
kNumber of neighbors to search for.
neighborsMatrix storing lists of neighbors for each query point.
distancesMatrix storing distances of neighbors for each query point.

◆ Search() [2/4]

template<typename SortPolicy = NearestNeighborSort, typename MetricType = mlpack::metric::EuclideanDistance, typename MatType = arma::mat, template< typename TreeMetricType, typename TreeStatType, typename TreeMatType > class TreeType = tree::KDTree, template< typename RuleType > class DualTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template DualTreeTraverser, template< typename RuleType > class SingleTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template SingleTreeTraverser>
mlpack_deprecated void mlpack::neighbor::NeighborSearch< SortPolicy, MetricType, MatType, TreeType, DualTreeTraversalType, SingleTreeTraversalType >::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, storing the output in the given matrices.

The matrices will be set to the size of n columns by k rows, where n is the number of points in the query dataset and k is the number of neighbors being searched for.

This method is deprecated and will be removed in mlpack 3.0.0! The Search() method taking a reference to the query tree is preferred.

Note that if you are calling Search() multiple times with a single query tree, you need to reset the bounds in the statistic of each query node, otherwise the result may be wrong! You can do this by calling TreeType::Stat()::Reset() on each node in the query tree.

Parameters
queryTreeTree built on query points.
kNumber of neighbors to search for.
neighborsMatrix storing lists of neighbors for each query point.
distancesMatrix storing distances of neighbors for each query point.
sameSetDenotes whether or not the reference and query sets are the same.

◆ Search() [3/4]

template<typename SortPolicy = NearestNeighborSort, typename MetricType = mlpack::metric::EuclideanDistance, typename MatType = arma::mat, template< typename TreeMetricType, typename TreeStatType, typename TreeMatType > class TreeType = tree::KDTree, template< typename RuleType > class DualTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template DualTreeTraverser, template< typename RuleType > class SingleTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template SingleTreeTraverser>
void mlpack::neighbor::NeighborSearch< SortPolicy, MetricType, MatType, TreeType, DualTreeTraversalType, SingleTreeTraversalType >::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, storing the output in the given matrices.

The matrices will be set to the size of n columns by k rows, where n is the number of points in the query dataset and k is the number of neighbors being searched for.

Note that if you are calling Search() multiple times with a single query tree, you need to reset the bounds in the statistic of each query node, otherwise the result may be wrong! You can do this by calling TreeType::Stat()::Reset() on each node in the query tree.

Parameters
queryTreeTree built on query points.
kNumber of neighbors to search for.
neighborsMatrix storing lists of neighbors for each query point.
distancesMatrix storing distances of neighbors for each query point.
sameSetDenotes whether or not the reference and query sets are the same.

◆ Search() [4/4]

template<typename SortPolicy = NearestNeighborSort, typename MetricType = mlpack::metric::EuclideanDistance, typename MatType = arma::mat, template< typename TreeMetricType, typename TreeStatType, typename TreeMatType > class TreeType = tree::KDTree, template< typename RuleType > class DualTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template DualTreeTraverser, template< typename RuleType > class SingleTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template SingleTreeTraverser>
void mlpack::neighbor::NeighborSearch< SortPolicy, MetricType, MatType, TreeType, DualTreeTraversalType, SingleTreeTraversalType >::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.

This is basically equivalent to calling any other overload of Search() with the reference set as the query set; so, this lets you do all-k-nearest-neighbors search. The results are stored in the given matrices. The matrices will be set to the size of n columns by k rows, where n is the number of points in the query dataset and k is the number of neighbors being searched for.

Parameters
kNumber of neighbors to search for.
neighborsMatrix storing lists of neighbors for each query point.
distancesMatrix storing distances of neighbors for each query point.

◆ Serialize()

template<typename SortPolicy = NearestNeighborSort, typename MetricType = mlpack::metric::EuclideanDistance, typename MatType = arma::mat, template< typename TreeMetricType, typename TreeStatType, typename TreeMatType > class TreeType = tree::KDTree, template< typename RuleType > class DualTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template DualTreeTraverser, template< typename RuleType > class SingleTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template SingleTreeTraverser>
template
<
typename
Archive
>
void mlpack::neighbor::NeighborSearch< SortPolicy, MetricType, MatType, TreeType, DualTreeTraversalType, SingleTreeTraversalType >::Serialize ( Archive &  ar,
const unsigned  int 
)

◆ SingleMode() [1/2]

template<typename SortPolicy = NearestNeighborSort, typename MetricType = mlpack::metric::EuclideanDistance, typename MatType = arma::mat, template< typename TreeMetricType, typename TreeStatType, typename TreeMatType > class TreeType = tree::KDTree, template< typename RuleType > class DualTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template DualTreeTraverser, template< typename RuleType > class SingleTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template SingleTreeTraverser>
bool mlpack::neighbor::NeighborSearch< SortPolicy, MetricType, MatType, TreeType, DualTreeTraversalType, SingleTreeTraversalType >::SingleMode ( ) const
inline

Access whether or not search is done in single-tree mode.

Deprecated. Will be replaced in mlpack 3.0.0, by a new method: NeighborSearchMode SearchMode().

Definition at line 524 of file neighbor_search.hpp.

References mlpack::neighbor::NeighborSearch< SortPolicy, MetricType, MatType, TreeType, DualTreeTraversalType, SingleTreeTraversalType >::singleMode.

◆ SingleMode() [2/2]

template<typename SortPolicy = NearestNeighborSort, typename MetricType = mlpack::metric::EuclideanDistance, typename MatType = arma::mat, template< typename TreeMetricType, typename TreeStatType, typename TreeMatType > class TreeType = tree::KDTree, template< typename RuleType > class DualTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template DualTreeTraverser, template< typename RuleType > class SingleTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template SingleTreeTraverser>
bool& mlpack::neighbor::NeighborSearch< SortPolicy, MetricType, MatType, TreeType, DualTreeTraversalType, SingleTreeTraversalType >::SingleMode ( )
inline

Modify whether or not search is done in single-tree mode.

Deprecated. Will be replaced in mlpack 3.0.0, by a new method: NeighborSearchMode& SearchMode().

Definition at line 528 of file neighbor_search.hpp.

References mlpack::neighbor::NeighborSearch< SortPolicy, MetricType, MatType, TreeType, DualTreeTraversalType, SingleTreeTraversalType >::singleMode.

◆ Train() [1/5]

template<typename SortPolicy = NearestNeighborSort, typename MetricType = mlpack::metric::EuclideanDistance, typename MatType = arma::mat, template< typename TreeMetricType, typename TreeStatType, typename TreeMatType > class TreeType = tree::KDTree, template< typename RuleType > class DualTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template DualTreeTraverser, template< typename RuleType > class SingleTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template SingleTreeTraverser>
void mlpack::neighbor::NeighborSearch< SortPolicy, MetricType, MatType, TreeType, DualTreeTraversalType, SingleTreeTraversalType >::Train ( const MatType &  referenceSet)

Set the reference set to a new reference set, and build a tree if necessary.

This method is called 'Train()' in order to match the rest of the mlpack abstractions, even though calling this "training" is maybe a bit of a stretch.

Parameters
referenceSetNew set of reference data.

◆ Train() [2/5]

template<typename SortPolicy = NearestNeighborSort, typename MetricType = mlpack::metric::EuclideanDistance, typename MatType = arma::mat, template< typename TreeMetricType, typename TreeStatType, typename TreeMatType > class TreeType = tree::KDTree, template< typename RuleType > class DualTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template DualTreeTraverser, template< typename RuleType > class SingleTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template SingleTreeTraverser>
void mlpack::neighbor::NeighborSearch< SortPolicy, MetricType, MatType, TreeType, DualTreeTraversalType, SingleTreeTraversalType >::Train ( MatType &&  referenceSet)

Set the reference set to a new reference set, taking ownership of the set, and build a tree if necessary.

This method is called 'Train()' in order to match the rest of the mlpack abstractions, even though calling this "training" is maybe a bit of a stretch.

Parameters
referenceSetNew set of reference data.

◆ Train() [3/5]

template<typename SortPolicy = NearestNeighborSort, typename MetricType = mlpack::metric::EuclideanDistance, typename MatType = arma::mat, template< typename TreeMetricType, typename TreeStatType, typename TreeMatType > class TreeType = tree::KDTree, template< typename RuleType > class DualTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template DualTreeTraverser, template< typename RuleType > class SingleTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template SingleTreeTraverser>
mlpack_deprecated void mlpack::neighbor::NeighborSearch< SortPolicy, MetricType, MatType, TreeType, DualTreeTraversalType, SingleTreeTraversalType >::Train ( Tree referenceTree)

Set the reference tree to a new reference tree.

This method is deprecated and will be removed in mlpack 3.0.0! Train() methods taking a reference to the reference tree are preferred.

Parameters
referenceTreePre-built tree for reference points.

◆ Train() [4/5]

template<typename SortPolicy = NearestNeighborSort, typename MetricType = mlpack::metric::EuclideanDistance, typename MatType = arma::mat, template< typename TreeMetricType, typename TreeStatType, typename TreeMatType > class TreeType = tree::KDTree, template< typename RuleType > class DualTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template DualTreeTraverser, template< typename RuleType > class SingleTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template SingleTreeTraverser>
void mlpack::neighbor::NeighborSearch< SortPolicy, MetricType, MatType, TreeType, DualTreeTraversalType, SingleTreeTraversalType >::Train ( const Tree referenceTree)

Set the reference tree as a copy of the given reference tree.

This method will copy the given tree. You can avoid this copy by using the Train() method that takes a rvalue reference to the tree.

Parameters
referenceTreePre-built tree for reference points.

◆ Train() [5/5]

template<typename SortPolicy = NearestNeighborSort, typename MetricType = mlpack::metric::EuclideanDistance, typename MatType = arma::mat, template< typename TreeMetricType, typename TreeStatType, typename TreeMatType > class TreeType = tree::KDTree, template< typename RuleType > class DualTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template DualTreeTraverser, template< typename RuleType > class SingleTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template SingleTreeTraverser>
void mlpack::neighbor::NeighborSearch< SortPolicy, MetricType, MatType, TreeType, DualTreeTraversalType, SingleTreeTraversalType >::Train ( Tree &&  referenceTree)

Set the reference tree to a new reference tree.

This method will take ownership of the given tree.

Parameters
referenceTreePre-built tree for reference points.

◆ UpdateSearchMode()

template<typename SortPolicy = NearestNeighborSort, typename MetricType = mlpack::metric::EuclideanDistance, typename MatType = arma::mat, template< typename TreeMetricType, typename TreeStatType, typename TreeMatType > class TreeType = tree::KDTree, template< typename RuleType > class DualTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template DualTreeTraverser, template< typename RuleType > class SingleTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template SingleTreeTraverser>
void mlpack::neighbor::NeighborSearch< SortPolicy, MetricType, MatType, TreeType, DualTreeTraversalType, SingleTreeTraversalType >::UpdateSearchMode ( )
private

Updates searchMode to be according to naive, singleMode and greedy booleans.

This is only necessary until the modifiers Naive(), SingleMode() and Greedy() are removed in mlpack 3.0.0.

◆ UpdateSearchModeFlags()

template<typename SortPolicy = NearestNeighborSort, typename MetricType = mlpack::metric::EuclideanDistance, typename MatType = arma::mat, template< typename TreeMetricType, typename TreeStatType, typename TreeMatType > class TreeType = tree::KDTree, template< typename RuleType > class DualTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template DualTreeTraverser, template< typename RuleType > class SingleTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template SingleTreeTraverser>
void mlpack::neighbor::NeighborSearch< SortPolicy, MetricType, MatType, TreeType, DualTreeTraversalType, SingleTreeTraversalType >::UpdateSearchModeFlags ( )
private

Updates naive, singleMode and greedy flags according to searchMode.

This is only necessary until the modifiers Naive(), SingleMode() and Greedy() are removed in mlpack 3.0.0.

Member Data Documentation

◆ baseCases

template<typename SortPolicy = NearestNeighborSort, typename MetricType = mlpack::metric::EuclideanDistance, typename MatType = arma::mat, template< typename TreeMetricType, typename TreeStatType, typename TreeMatType > class TreeType = tree::KDTree, template< typename RuleType > class DualTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template DualTreeTraverser, template< typename RuleType > class SingleTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template SingleTreeTraverser>
size_t mlpack::neighbor::NeighborSearch< SortPolicy, MetricType, MatType, TreeType, DualTreeTraversalType, SingleTreeTraversalType >::baseCases
private

◆ epsilon

template<typename SortPolicy = NearestNeighborSort, typename MetricType = mlpack::metric::EuclideanDistance, typename MatType = arma::mat, template< typename TreeMetricType, typename TreeStatType, typename TreeMatType > class TreeType = tree::KDTree, template< typename RuleType > class DualTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template DualTreeTraverser, template< typename RuleType > class SingleTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template SingleTreeTraverser>
double mlpack::neighbor::NeighborSearch< SortPolicy, MetricType, MatType, TreeType, DualTreeTraversalType, SingleTreeTraversalType >::epsilon
private

Indicates the relative error to be considered in approximate search.

Definition at line 578 of file neighbor_search.hpp.

Referenced by mlpack::neighbor::NeighborSearch< SortPolicy, MetricType, MatType, TreeType, DualTreeTraversalType, SingleTreeTraversalType >::Epsilon().

◆ greedy

template<typename SortPolicy = NearestNeighborSort, typename MetricType = mlpack::metric::EuclideanDistance, typename MatType = arma::mat, template< typename TreeMetricType, typename TreeStatType, typename TreeMatType > class TreeType = tree::KDTree, template< typename RuleType > class DualTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template DualTreeTraverser, template< typename RuleType > class SingleTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template SingleTreeTraverser>
bool mlpack::neighbor::NeighborSearch< SortPolicy, MetricType, MatType, TreeType, DualTreeTraversalType, SingleTreeTraversalType >::greedy
private

◆ metric

template<typename SortPolicy = NearestNeighborSort, typename MetricType = mlpack::metric::EuclideanDistance, typename MatType = arma::mat, template< typename TreeMetricType, typename TreeStatType, typename TreeMatType > class TreeType = tree::KDTree, template< typename RuleType > class DualTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template DualTreeTraverser, template< typename RuleType > class SingleTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template SingleTreeTraverser>
MetricType mlpack::neighbor::NeighborSearch< SortPolicy, MetricType, MatType, TreeType, DualTreeTraversalType, SingleTreeTraversalType >::metric
private

Instantiation of metric.

Definition at line 581 of file neighbor_search.hpp.

◆ naive

template<typename SortPolicy = NearestNeighborSort, typename MetricType = mlpack::metric::EuclideanDistance, typename MatType = arma::mat, template< typename TreeMetricType, typename TreeStatType, typename TreeMatType > class TreeType = tree::KDTree, template< typename RuleType > class DualTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template DualTreeTraverser, template< typename RuleType > class SingleTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template SingleTreeTraverser>
bool mlpack::neighbor::NeighborSearch< SortPolicy, MetricType, MatType, TreeType, DualTreeTraversalType, SingleTreeTraversalType >::naive
private

◆ oldFromNewReferences

template<typename SortPolicy = NearestNeighborSort, typename MetricType = mlpack::metric::EuclideanDistance, typename MatType = arma::mat, template< typename TreeMetricType, typename TreeStatType, typename TreeMatType > class TreeType = tree::KDTree, template< typename RuleType > class DualTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template DualTreeTraverser, template< typename RuleType > class SingleTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template SingleTreeTraverser>
std::vector<size_t> mlpack::neighbor::NeighborSearch< SortPolicy, MetricType, MatType, TreeType, DualTreeTraversalType, SingleTreeTraversalType >::oldFromNewReferences
private

Permutations of reference points during tree building.

Definition at line 558 of file neighbor_search.hpp.

◆ referenceSet

template<typename SortPolicy = NearestNeighborSort, typename MetricType = mlpack::metric::EuclideanDistance, typename MatType = arma::mat, template< typename TreeMetricType, typename TreeStatType, typename TreeMatType > class TreeType = tree::KDTree, template< typename RuleType > class DualTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template DualTreeTraverser, template< typename RuleType > class SingleTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template SingleTreeTraverser>
const MatType* mlpack::neighbor::NeighborSearch< SortPolicy, MetricType, MatType, TreeType, DualTreeTraversalType, SingleTreeTraversalType >::referenceSet
private

Reference dataset. In some situations we may be the owner of this.

Definition at line 562 of file neighbor_search.hpp.

Referenced by mlpack::neighbor::NeighborSearch< SortPolicy, MetricType, MatType, TreeType, DualTreeTraversalType, SingleTreeTraversalType >::ReferenceSet().

◆ referenceTree

template<typename SortPolicy = NearestNeighborSort, typename MetricType = mlpack::metric::EuclideanDistance, typename MatType = arma::mat, template< typename TreeMetricType, typename TreeStatType, typename TreeMatType > class TreeType = tree::KDTree, template< typename RuleType > class DualTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template DualTreeTraverser, template< typename RuleType > class SingleTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template SingleTreeTraverser>
Tree* mlpack::neighbor::NeighborSearch< SortPolicy, MetricType, MatType, TreeType, DualTreeTraversalType, SingleTreeTraversalType >::referenceTree
private

◆ scores

template<typename SortPolicy = NearestNeighborSort, typename MetricType = mlpack::metric::EuclideanDistance, typename MatType = arma::mat, template< typename TreeMetricType, typename TreeStatType, typename TreeMatType > class TreeType = tree::KDTree, template< typename RuleType > class DualTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template DualTreeTraverser, template< typename RuleType > class SingleTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template SingleTreeTraverser>
size_t mlpack::neighbor::NeighborSearch< SortPolicy, MetricType, MatType, TreeType, DualTreeTraversalType, SingleTreeTraversalType >::scores
private

The total number of scores (applicable for non-naive search).

Definition at line 586 of file neighbor_search.hpp.

Referenced by mlpack::neighbor::NeighborSearch< SortPolicy, MetricType, MatType, TreeType, DualTreeTraversalType, SingleTreeTraversalType >::Scores().

◆ searchMode

template<typename SortPolicy = NearestNeighborSort, typename MetricType = mlpack::metric::EuclideanDistance, typename MatType = arma::mat, template< typename TreeMetricType, typename TreeStatType, typename TreeMatType > class TreeType = tree::KDTree, template< typename RuleType > class DualTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template DualTreeTraverser, template< typename RuleType > class SingleTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template SingleTreeTraverser>
NeighborSearchMode mlpack::neighbor::NeighborSearch< SortPolicy, MetricType, MatType, TreeType, DualTreeTraversalType, SingleTreeTraversalType >::searchMode
private

Indicates the neighbor search mode.

Definition at line 570 of file neighbor_search.hpp.

◆ setOwner

template<typename SortPolicy = NearestNeighborSort, typename MetricType = mlpack::metric::EuclideanDistance, typename MatType = arma::mat, template< typename TreeMetricType, typename TreeStatType, typename TreeMatType > class TreeType = tree::KDTree, template< typename RuleType > class DualTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template DualTreeTraverser, template< typename RuleType > class SingleTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template SingleTreeTraverser>
bool mlpack::neighbor::NeighborSearch< SortPolicy, MetricType, MatType, TreeType, DualTreeTraversalType, SingleTreeTraversalType >::setOwner
private

If true, we own the reference set.

Definition at line 567 of file neighbor_search.hpp.

◆ singleMode

template<typename SortPolicy = NearestNeighborSort, typename MetricType = mlpack::metric::EuclideanDistance, typename MatType = arma::mat, template< typename TreeMetricType, typename TreeStatType, typename TreeMatType > class TreeType = tree::KDTree, template< typename RuleType > class DualTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template DualTreeTraverser, template< typename RuleType > class SingleTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template SingleTreeTraverser>
bool mlpack::neighbor::NeighborSearch< SortPolicy, MetricType, MatType, TreeType, DualTreeTraversalType, SingleTreeTraversalType >::singleMode
private

Indicates if single-tree search is being used (as opposed to dual-tree).

Definition at line 574 of file neighbor_search.hpp.

Referenced by mlpack::neighbor::NeighborSearch< SortPolicy, MetricType, MatType, TreeType, DualTreeTraversalType, SingleTreeTraversalType >::SingleMode().

◆ treeNeedsReset

template<typename SortPolicy = NearestNeighborSort, typename MetricType = mlpack::metric::EuclideanDistance, typename MatType = arma::mat, template< typename TreeMetricType, typename TreeStatType, typename TreeMatType > class TreeType = tree::KDTree, template< typename RuleType > class DualTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template DualTreeTraverser, template< typename RuleType > class SingleTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template SingleTreeTraverser>
bool mlpack::neighbor::NeighborSearch< SortPolicy, MetricType, MatType, TreeType, DualTreeTraversalType, SingleTreeTraversalType >::treeNeedsReset
private

If this is true, the reference tree bounds need to be reset on a call to Search() without a query set.

Definition at line 590 of file neighbor_search.hpp.

◆ treeOwner

template<typename SortPolicy = NearestNeighborSort, typename MetricType = mlpack::metric::EuclideanDistance, typename MatType = arma::mat, template< typename TreeMetricType, typename TreeStatType, typename TreeMatType > class TreeType = tree::KDTree, template< typename RuleType > class DualTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template DualTreeTraverser, template< typename RuleType > class SingleTreeTraversalType = TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>::template SingleTreeTraverser>
bool mlpack::neighbor::NeighborSearch< SortPolicy, MetricType, MatType, TreeType, DualTreeTraversalType, SingleTreeTraversalType >::treeOwner
private

If true, this object created the trees and is responsible for them.

Definition at line 565 of file neighbor_search.hpp.


The documentation for this class was generated from the following file: