13 #ifndef MLPACK_METHODS_NEIGHBOR_SEARCH_NEIGHBOR_SEARCH_HPP 14 #define MLPACK_METHODS_NEIGHBOR_SEARCH_NEIGHBOR_SEARCH_HPP 34 template<
typename SortPolicy>
69 template<
typename SortPolicy = NearestNeighborSort,
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;
108 const double epsilon = 0,
109 const MetricType metric = MetricType());
130 const double epsilon = 0,
131 const MetricType metric = MetricType());
157 const Tree& referenceTree,
159 const double epsilon = 0,
160 const MetricType metric = MetricType());
187 Tree&& referenceTree,
189 const double epsilon = 0,
190 const MetricType metric = MetricType());
202 const double epsilon = 0,
203 const MetricType metric = MetricType());
229 const bool singleMode =
false,
230 const double epsilon = 0,
231 const MetricType metric = MetricType());
257 const bool singleMode =
false,
258 const double epsilon = 0,
259 const MetricType metric = MetricType());
290 const bool singleMode,
291 const double epsilon = 0,
292 const MetricType metric = MetricType());
308 const bool singleMode =
false,
309 const double epsilon = 0,
310 const MetricType metric = MetricType());
337 void Train(
const MatType& referenceSet);
347 void Train(MatType&& referenceSet);
395 void Search(
const MatType& querySet,
397 arma::Mat<size_t>& neighbors,
398 arma::mat& distances);
425 arma::Mat<size_t>& neighbors,
426 arma::mat& distances,
427 bool sameSet =
false);
451 arma::Mat<size_t>& neighbors,
452 arma::mat& distances,
453 bool sameSet =
false);
469 void Search(
const size_t k,
470 arma::Mat<size_t>& neighbors,
471 arma::mat& distances);
489 arma::mat& realDistances);
502 static double Recall(arma::Mat<size_t>& foundNeighbors,
503 arma::Mat<size_t>& realNeighbors);
515 bool Naive()
const {
return naive; }
553 template<
typename Archive>
554 void Serialize(Archive& ar,
const unsigned int );
558 std::vector<size_t> oldFromNewReferences;
562 const MatType* referenceSet;
595 void UpdateSearchMode();
600 void UpdateSearchModeFlags();
603 template<
typename SortPol>
611 #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.
bool & Greedy()
Modify whether or not search is done in greedy mode.
bool Greedy() const
Access whether or not search is done in greedy mode.
Linear algebra utility functions, generally performed on matrices or vectors.
bool SingleMode() const
Access whether or not search is done in single-tree mode.
The core includes that mlpack expects; standard C++ includes and Armadillo.
The NeighborSearch class is a template class for performing distance-based neighbor searches...
void Train(const MatType &referenceSet)
Set the reference set to a new reference set, and build a tree if necessary.
#define mlpack_deprecated
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...
TreeType< MetricType, NeighborSearchStat< SortPolicy >, MatType > Tree
Convenience typedef.
void Serialize(Archive &ar, const unsigned int)
Serialize the NeighborSearch model.
TrainVisitor sets the reference set to a new reference set on the given NSType.
bool & Naive()
Modify whether or not search is done in naive linear scan mode.
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 searc...
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.
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.
LMetric< 2, true > EuclideanDistance
The Euclidean (L2) distance.
bool & SingleMode()
Modify whether or not search is done in single-tree mode.
NeighborSearchMode
NeighborSearchMode represents the different neighbor search modes available.
~NeighborSearch()
Delete the NeighborSearch object.