Go to the documentation of this file.
13 #ifndef MLPACK_METHODS_NEIGHBOR_SEARCH_NEIGHBOR_SEARCH_RULES_HPP
14 #define MLPACK_METHODS_NEIGHBOR_SEARCH_NEIGHBOR_SEARCH_RULES_HPP
34 template<
typename SortPolicy,
typename MetricType,
typename TreeType>
51 const typename TreeType::Mat&
querySet,
64 void GetResults(arma::Mat<size_t>& neighbors, arma::mat& distances);
74 double BaseCase(
const size_t queryIndex,
const size_t referenceIndex);
84 double Score(
const size_t queryIndex, TreeType& referenceNode);
92 size_t GetBestChild(
const size_t queryIndex, TreeType& referenceNode);
100 size_t GetBestChild(
const TreeType& queryNode, TreeType& referenceNode);
114 TreeType& referenceNode,
115 const double oldScore)
const;
125 double Score(TreeType& queryNode, TreeType& referenceNode);
139 TreeType& referenceNode,
140 const double oldScore)
const;
178 return !SortPolicy::IsBetter(c2.first, c1.first);
183 typedef std::priority_queue<Candidate, std::vector<Candidate>, CandidateCmp>
230 const size_t neighbor,
231 const double distance);
238 #include "neighbor_search_rules_impl.hpp"
240 #endif // MLPACK_METHODS_NEIGHBOR_SEARCH_NEIGHBOR_SEARCH_RULES_HPP
const size_t k
Number of neighbors to search for.
size_t scores
The number of scores that have been performed.
TraversalInfoType traversalInfo
Traversal info for the parent combination; this is updated by the traversal before each call to Score...
const double epsilon
Relative error to be considered in approximate search.
size_t lastReferenceIndex
The last reference point BaseCase() was called with.
tree::TraversalInfo< TreeType > TraversalInfoType
Convenience typedef.
The TraversalInfo class holds traversal information which is used in dual-tree (and single-tree) trav...
NeighborSearchRules(const typename TreeType::Mat &referenceSet, const typename TreeType::Mat &querySet, const size_t k, MetricType &metric, const double epsilon=0, const bool sameSet=false)
Construct the NeighborSearchRules object.
std::pair< double, size_t > Candidate
Candidate represents a possible candidate neighbor (distance, index).
size_t & Scores()
Modify the number of scores that have been performed.
double BaseCase(const size_t queryIndex, const size_t referenceIndex)
Get the distance from the query point to the reference point.
std::vector< CandidateList > candidates
Set of candidate neighbors for each point.
size_t lastQueryIndex
The last query point BaseCase() was called with.
double Rescore(const size_t queryIndex, TreeType &referenceNode, const double oldScore) const
Re-evaluate the score for recursion order.
bool operator()(const Candidate &c1, const Candidate &c2)
size_t GetBestChild(const TreeType &queryNode, TreeType &referenceNode)
Get the child node with the best score.
double Score(const size_t queryIndex, TreeType &referenceNode)
Get the score for recursion order.
const TreeType::Mat & referenceSet
The reference set.
Linear algebra utility functions, generally performed on matrices or vectors.
const TreeType::Mat & querySet
The query set.
TraversalInfoType & TraversalInfo()
Modify the traversal info.
size_t GetBestChild(const size_t queryIndex, TreeType &referenceNode)
Get the child node with the best score.
double CalculateBound(TreeType &queryNode) const
Recalculate the bound for a given query node.
void GetResults(arma::Mat< size_t > &neighbors, arma::mat &distances)
Store the list of candidates for each query point in the given matrices.
double lastBaseCase
The last base case result.
bool sameSet
Denotes whether or not the reference and query sets are the same.
size_t MinimumBaseCases() const
Get the minimum number of base cases we need to perform to have acceptable results.
void InsertNeighbor(const size_t queryIndex, const size_t neighbor, const double distance)
Helper function to insert a point into the list of candidate points.
MetricType & metric
The instantiated metric.
Compare two candidates based on the distance.
size_t BaseCases() const
Get the number of base cases that have been performed.
size_t baseCases
The number of base cases that have been performed.
const TraversalInfoType & TraversalInfo() const
Get the traversal info.
The NeighborSearchRules class is a template helper class used by NeighborSearch class when performing...
std::priority_queue< Candidate, std::vector< Candidate >, CandidateCmp > CandidateList
Use a priority queue to represent the list of candidate neighbors.
double Score(TreeType &queryNode, TreeType &referenceNode)
Get the score for recursion order.
double Rescore(TreeType &queryNode, TreeType &referenceNode, const double oldScore) const
Re-evaluate the score for recursion order.
size_t & BaseCases()
Modify the number of base cases that have been performed.
size_t Scores() const
Get the number of scores that have been performed.