15 #ifndef __MLPACK_METHODS_NEIGHBOR_SEARCH_NEIGHBOR_SEARCH_HPP 16 #define __MLPACK_METHODS_NEIGHBOR_SEARCH_NEIGHBOR_SEARCH_HPP 37 template<
typename SortPolicy>
63 typename MatType = arma::mat,
64 template<
typename TreeMetricType,
65 typename TreeStatType,
67 template<
typename RuleType>
class TraversalType =
70 MatType>::template DualTreeTraverser>
75 typedef TreeType<MetricType, NeighborSearchStat<SortPolicy>, MatType>
Tree;
97 const bool naive =
false,
99 const MetricType
metric = MetricType());
121 const bool naive =
false,
123 const MetricType
metric = MetricType());
152 const MetricType
metric = MetricType());
166 const MetricType
metric = MetricType());
183 void Train(
const MatType& referenceSet);
193 void Train(MatType&& referenceSet);
198 void Train(Tree* referenceTree);
217 void Search(
const MatType& querySet,
219 arma::Mat<size_t>& neighbors,
220 arma::mat& distances);
235 void Search(Tree* queryTree,
237 arma::Mat<size_t>& neighbors,
238 arma::mat& distances);
254 void Search(
const size_t k,
255 arma::Mat<size_t>& neighbors,
256 arma::mat& distances);
279 template<
typename Archive>
280 void Serialize(Archive& ar,
const unsigned int );
320 #include "neighbor_search_impl.hpp" bool Naive() const
Access whether or not search is done in naive linear scan mode.
BinarySpaceTree< MetricType, StatisticType, MatType, bound::HRectBound, MidpointSplit > KDTree
The standard midpoint-split kd-tree.
void Train(const 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.
std::vector< size_t > oldFromNewReferences
Permutations of reference points during tree building.
Linear algebra utility functions, generally performed on matrices or vectors.
LMetric< 2, true > EuclideanDistance
The Euclidean (L2) distance.
bool treeNeedsReset
If this is true, the reference tree bounds need to be reset on a call to Search() without a query set...
size_t BaseCases() const
Return the total number of base case evaluations performed during the last search.
Extra data for each node in the tree.
The NeighborSearch class is a template class for performing distance-based neighbor searches...
const MatType * referenceSet
Reference dataset. In some situations we may be the owner of this.
size_t scores
The total number of scores (applicable for non-naive search).
size_t baseCases
The total number of base cases.
bool & SingleMode()
Modify whether or not search is done in single-tree mode.
void Serialize(Archive &ar, const unsigned int)
Serialize the NeighborSearch model.
Tree * referenceTree
Pointer to the root of the reference tree.
This class implements the necessary methods for the SortPolicy template parameter of the NeighborSear...
bool singleMode
Indicates if single-tree search is being used (as opposed to dual-tree).
size_t Scores() const
Return the number of node combination scores during the last search.
bool setOwner
If true, we own the reference set.
bool naive
Indicates if O(n^2) naive search is being used.
bool treeOwner
If true, this object created the trees and is responsible for them.
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...
Include all of the base components required to write MLPACK methods, and the main MLPACK Doxygen docu...
TreeType< MetricType, NeighborSearchStat< SortPolicy >, MatType > Tree
Convenience typedef.
bool SingleMode() const
Access whether or not search is done in single-tree mode.
MetricType metric
Instantiation of metric.
NeighborSearch(const MatType &referenceSet, const bool naive=false, const bool singleMode=false, const MetricType metric=MetricType())
Initialize the NeighborSearch object, passing a reference dataset (this is the dataset which is searc...
~NeighborSearch()
Delete the NeighborSearch object.
bool & Naive()
Modify whether or not search is done in naive linear scan mode.