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>
48 GREEDY_SINGLE_TREE_MODE
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>;
BinarySpaceTree< MetricType, StatisticType, MatType, bound::HRectBound, MidpointSplit > KDTree
The standard midpoint-split kd-tree.
Definition: typedef.hpp:63
size_t Scores() const
Return the number of node combination scores during the last search.
Definition: neighbor_search.hpp:317
double & Epsilon()
Modify the relative error to be considered in approximate search.
Definition: neighbor_search.hpp:327
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: cv.hpp:1
size_t BaseCases() const
Return the total number of base case evaluations performed during the last search.
Definition: neighbor_search.hpp:314
~NeighborSearch()
Delete the NeighborSearch object.
Definition: neighbor_search_impl.hpp:303
void Train(MatType referenceSet)
Set the reference set to a new reference set, and build a tree if necessary.
Definition: neighbor_search_impl.hpp:320
NeighborSearchMode SearchMode() const
Access the search mode.
Definition: neighbor_search.hpp:320
static double EffectiveError(arma::mat &foundDistances, arma::mat &realDistances)
Calculate the average relative error (effective error) between the distances calculated and the true ...
Definition: neighbor_search_impl.hpp:872
Extra data for each node in the tree.
Definition: neighbor_search_stat.hpp:26
The core includes that mlpack expects; standard C++ includes and Armadillo.
LeafSizeNSWrapper wraps any NeighborSearch types that take a leaf size for tree construction.
Definition: neighbor_search.hpp:40
The NeighborSearch class is a template class for performing distance-based neighbor searches...
Definition: neighbor_search.hpp:88
NeighborSearch & operator=(const NeighborSearch &other)
Copy the given NeighborSearch object.
Definition: neighbor_search_impl.hpp:215
void serialize(Archive &ar, const uint32_t version)
Serialize the NeighborSearch model.
Definition: neighbor_search_impl.hpp:942
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...
Definition: neighbor_search_impl.hpp:910
This class implements the necessary methods for the SortPolicy template parameter of the NeighborSear...
Definition: nearest_neighbor_sort.hpp:31
double Epsilon() const
Access the relative error to be considered in approximate search.
Definition: neighbor_search.hpp:325
Tree & ReferenceTree()
Modify the reference tree.
Definition: neighbor_search.hpp:335
TreeType< MetricType, NeighborSearchStat< SortPolicy >, MatType > Tree
Convenience typedef.
Definition: neighbor_search.hpp:92
The L_p metric for arbitrary integer p, with an option to take the root.
Definition: lmetric.hpp:63
Definition of generalized binary space partitioning tree (BinarySpaceTree).
NeighborSearchMode
NeighborSearchMode represents the different neighbor search modes available.
Definition: neighbor_search.hpp:43
const Tree & ReferenceTree() const
Access the reference tree.
Definition: neighbor_search.hpp:333
NeighborSearchMode & SearchMode()
Modify the search mode.
Definition: neighbor_search.hpp:322
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...
Definition: neighbor_search_impl.hpp:389
const MatType & ReferenceSet() const
Access the reference dataset.
Definition: neighbor_search.hpp:330
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...
Definition: neighbor_search_impl.hpp:58