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);
113 double Rescore(
const size_t queryIndex,
114 TreeType& referenceNode,
115 const double oldScore)
const;
125 double Score(TreeType& queryNode, TreeType& referenceNode);
138 double Rescore(TreeType& queryNode,
139 TreeType& referenceNode,
140 const double oldScore)
const;
176 bool operator()(
const Candidate& c1,
const Candidate& c2)
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);
240 #endif // MLPACK_METHODS_NEIGHBOR_SEARCH_NEIGHBOR_SEARCH_RULES_HPP std::priority_queue< Candidate, std::vector< Candidate >, CandidateCmp > CandidateList
Use a priority queue to represent the list of candidate neighbors.
Definition: neighbor_search_rules.hpp:184
std::vector< CandidateList > candidates
Set of candidate neighbors for each point.
Definition: neighbor_search_rules.hpp:187
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.
Definition: neighbor_search_rules_impl.hpp:495
TraversalInfoType & TraversalInfo()
Modify the traversal info.
Definition: neighbor_search_rules.hpp:158
The TraversalInfo class holds traversal information which is used in dual-tree (and single-tree) trav...
Definition: traversal_info.hpp:50
size_t lastQueryIndex
The last query point BaseCase() was called with.
Definition: neighbor_search_rules.hpp:202
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: cv.hpp:1
TraversalInfoType traversalInfo
Traversal info for the parent combination; this is updated by the traversal before each call to Score...
Definition: neighbor_search_rules.hpp:215
size_t BaseCases() const
Get the number of base cases that have been performed.
Definition: neighbor_search_rules.hpp:143
const TreeType::Mat & referenceSet
The reference set.
Definition: neighbor_search_rules.hpp:166
std::pair< double, size_t > Candidate
Candidate represents a possible candidate neighbor (distance, index).
Definition: neighbor_search_rules.hpp:172
const size_t k
Number of neighbors to search for.
Definition: neighbor_search_rules.hpp:190
const double epsilon
Relative error to be considered in approximate search.
Definition: neighbor_search_rules.hpp:199
double BaseCase(const size_t queryIndex, const size_t referenceIndex)
Get the distance from the query point to the reference point.
Definition: neighbor_search_rules_impl.hpp:85
void GetResults(arma::Mat< size_t > &neighbors, arma::mat &distances)
Store the list of candidates for each query point in the given matrices.
Definition: neighbor_search_rules_impl.hpp:63
size_t & Scores()
Modify the number of scores that have been performed.
Definition: neighbor_search_rules.hpp:150
tree::TraversalInfo< TreeType > TraversalInfoType
Convenience typedef.
Definition: neighbor_search_rules.hpp:153
double lastBaseCase
The last base case result.
Definition: neighbor_search_rules.hpp:206
size_t lastReferenceIndex
The last reference point BaseCase() was called with.
Definition: neighbor_search_rules.hpp:204
The NeighborSearchRules class is a template helper class used by NeighborSearch class when performing...
Definition: neighbor_search_rules.hpp:35
double Score(const size_t queryIndex, TreeType &referenceNode)
Get the score for recursion order.
Definition: neighbor_search_rules_impl.hpp:111
size_t Scores() const
Get the number of scores that have been performed.
Definition: neighbor_search_rules.hpp:148
const TraversalInfoType & TraversalInfo() const
Get the traversal info.
Definition: neighbor_search_rules.hpp:156
size_t & BaseCases()
Modify the number of base cases that have been performed.
Definition: neighbor_search_rules.hpp:145
double Rescore(const size_t queryIndex, TreeType &referenceNode, const double oldScore) const
Re-evaluate the score for recursion order.
Definition: neighbor_search_rules_impl.hpp:170
size_t MinimumBaseCases() const
Get the minimum number of base cases we need to perform to have acceptable results.
Definition: neighbor_search_rules.hpp:162
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.
Definition: neighbor_search_rules_impl.hpp:23
double CalculateBound(TreeType &queryNode) const
Recalculate the bound for a given query node.
Definition: neighbor_search_rules_impl.hpp:370
size_t GetBestChild(const size_t queryIndex, TreeType &referenceNode)
Get the child node with the best score.
Definition: neighbor_search_rules_impl.hpp:155
MetricType & metric
The instantiated metric.
Definition: neighbor_search_rules.hpp:193
size_t scores
The number of scores that have been performed.
Definition: neighbor_search_rules.hpp:211
size_t baseCases
The number of base cases that have been performed.
Definition: neighbor_search_rules.hpp:209
const TreeType::Mat & querySet
The query set.
Definition: neighbor_search_rules.hpp:169
Compare two candidates based on the distance.
Definition: neighbor_search_rules.hpp:175
bool sameSet
Denotes whether or not the reference and query sets are the same.
Definition: neighbor_search_rules.hpp:196