The NeighborSearchRules class is a template helper class used by NeighborSearch class when performing distance-based neighbor searches.
More...
#include <neighbor_search_rules.hpp>
|
| 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. More...
|
|
void | GetResults (arma::Mat< size_t > &neighbors, arma::mat &distances) |
| Store the list of candidates for each query point in the given matrices. More...
|
|
double | BaseCase (const size_t queryIndex, const size_t referenceIndex) |
| Get the distance from the query point to the reference point. More...
|
|
double | Score (const size_t queryIndex, TreeType &referenceNode) |
| Get the score for recursion order. More...
|
|
size_t | GetBestChild (const size_t queryIndex, TreeType &referenceNode) |
| Get the child node with the best score. More...
|
|
size_t | GetBestChild (const TreeType &queryNode, TreeType &referenceNode) |
| Get the child node with the best score. More...
|
|
double | Rescore (const size_t queryIndex, TreeType &referenceNode, const double oldScore) const |
| Re-evaluate the score for recursion order. More...
|
|
double | Score (TreeType &queryNode, TreeType &referenceNode) |
| Get the score for recursion order. More...
|
|
double | Rescore (TreeType &queryNode, TreeType &referenceNode, const double oldScore) const |
| Re-evaluate the score for recursion order. More...
|
|
size_t | BaseCases () const |
| Get the number of base cases that have been performed.
|
|
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.
|
|
size_t & | Scores () |
| Modify the number of scores that have been performed.
|
|
const TraversalInfoType & | TraversalInfo () const |
| Get the traversal info.
|
|
TraversalInfoType & | TraversalInfo () |
| Modify the traversal info.
|
|
size_t | MinimumBaseCases () const |
| Get the minimum number of base cases we need to perform to have acceptable results. More...
|
|
|
typedef std::pair< double, size_t > | Candidate |
| Candidate represents a possible candidate neighbor (distance, index).
|
|
typedef std::priority_queue< Candidate, std::vector< Candidate >, CandidateCmp > | CandidateList |
| Use a priority queue to represent the list of candidate neighbors.
|
|
|
double | CalculateBound (TreeType &queryNode) const |
| Recalculate the bound for a given query node.
|
|
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. More...
|
|
template<typename SortPolicy, typename MetricType, typename TreeType>
class mlpack::neighbor::NeighborSearchRules< SortPolicy, MetricType, TreeType >
The NeighborSearchRules class is a template helper class used by NeighborSearch class when performing distance-based neighbor searches.
For each point in the query dataset, it keeps track of the k neighbors in the reference dataset which have the 'best' distance according to a given sorting policy.
- Template Parameters
-
SortPolicy | The sort policy for distances. |
MetricType | The metric to use for computation. |
TreeType | The tree type to use; must adhere to the TreeType API. |
◆ NeighborSearchRules()
template<typename SortPolicy , typename MetricType , typename TreeType >
Construct the NeighborSearchRules object.
This is usually done from within the NeighborSearch class at search time.
- Parameters
-
referenceSet | Set of reference data. |
querySet | Set of query data. |
k | Number of neighbors to search for. |
metric | Instantiated metric. |
epsilon | Relative approximate error. |
sameSet | If true, the query and reference set are taken to be the same, and a query point will not return itself in the results. |
◆ BaseCase()
template<typename SortPolicy , typename MetricType , typename TreeType >
Get the distance from the query point to the reference point.
This will update the list of candidates with the new point if appropriate and will track the number of base cases (number of points evaluated).
- Parameters
-
queryIndex | Index of query point. |
referenceIndex | Index of reference point. |
◆ GetBestChild() [1/2]
template<typename SortPolicy , typename MetricType , typename TreeType >
Get the child node with the best score.
- Parameters
-
queryIndex | Index of query point. |
referenceNode | Candidate node to be recursed into. |
◆ GetBestChild() [2/2]
template<typename SortPolicy , typename MetricType , typename TreeType >
Get the child node with the best score.
- Parameters
-
queryNode | Node to be considered. |
referenceNode | Candidate node to be recursed into. |
◆ GetResults()
template<typename SortPolicy , typename MetricType , typename TreeType >
Store the list of candidates for each query point in the given matrices.
- Parameters
-
neighbors | Matrix storing lists of neighbors for each query point. |
distances | Matrix storing distances of neighbors for each query point. |
◆ InsertNeighbor()
template<typename SortPolicy , typename MetricType , typename TreeType >
Helper function to insert a point into the list of candidate points.
- Parameters
-
queryIndex | Index of point whose neighbors we are inserting into. |
neighbor | Index of reference point which is being inserted. |
distance | Distance from query point to reference point. |
◆ MinimumBaseCases()
template<typename SortPolicy , typename MetricType , typename TreeType >
Get the minimum number of base cases we need to perform to have acceptable results.
This is only needed in defeatist search mode.
◆ Rescore() [1/2]
template<typename SortPolicy , typename MetricType , typename TreeType >
Re-evaluate the score for recursion order.
A low score indicates priority for recursion, while DBL_MAX indicates that the node should not be recursed into at all (it should be pruned). This is used when the score has already been calculated, but another recursion may have modified the bounds for pruning. So the old score is checked against the new pruning bound.
- Parameters
-
queryIndex | Index of query point. |
referenceNode | Candidate node to be recursed into. |
oldScore | Old score produced by Score() (or Rescore()). |
◆ Rescore() [2/2]
template<typename SortPolicy , typename MetricType , typename TreeType >
Re-evaluate the score for recursion order.
A low score indicates priority for recursion, while DBL_MAX indicates that the node should not be recursed into at all (it should be pruned). This is used when the score has already been calculated, but another recursion may have modified the bounds for pruning. So the old score is checked against the new pruning bound.
- Parameters
-
queryNode | Candidate query node to recurse into. |
referenceNode | Candidate reference node to recurse into. |
oldScore | Old score produced by Socre() (or Rescore()). |
◆ Score() [1/2]
template<typename SortPolicy , typename MetricType , typename TreeType >
Get the score for recursion order.
A low score indicates priority for recursion, while DBL_MAX indicates that the node should not be recursed into at all (it should be pruned).
- Parameters
-
queryIndex | Index of query point. |
referenceNode | Candidate node to be recursed into. |
◆ Score() [2/2]
template<typename SortPolicy , typename MetricType , typename TreeType >
Get the score for recursion order.
A low score indicates priority for recursionm while DBL_MAX indicates that the node should not be recursed into at all (it should be pruned).
- Parameters
-
queryNode | Candidate query node to recurse into. |
referenceNode | Candidate reference node to recurse into. |
◆ traversalInfo
template<typename SortPolicy , typename MetricType , typename TreeType >
Traversal info for the parent combination; this is updated by the traversal before each call to Score().
The documentation for this class was generated from the following files: