mlpack
Static Public Member Functions | List of all members
mlpack::neighbor::NearestNS Class Reference

This class implements the necessary methods for the SortPolicy template parameter of the NeighborSearch class. More...

#include <nearest_neighbor_sort.hpp>

Static Public Member Functions

static bool IsBetter (const double value, const double ref)
 Return whether or not value is "better" than ref. More...
 
template<typename TreeType >
static double BestNodeToNodeDistance (const TreeType *queryNode, const TreeType *referenceNode)
 Return the best possible distance between two nodes. More...
 
template<typename TreeType >
static double BestNodeToNodeDistance (const TreeType *queryNode, const TreeType *referenceNode, const double centerToCenterDistance)
 Return the best possible distance between two nodes, given that the distance between the centers of the two nodes has already been calculated. More...
 
template<typename TreeType >
static double BestNodeToNodeDistance (const TreeType *queryNode, const TreeType *referenceNode, const TreeType *referenceChildNode, const double centerToCenterDistance)
 Return the best possible distance between the query node and the reference child node given the base case distance between the query node and the reference node. More...
 
template<typename VecType , typename TreeType >
static double BestPointToNodeDistance (const VecType &queryPoint, const TreeType *referenceNode)
 Return the best possible distance between a node and a point. More...
 
template<typename VecType , typename TreeType >
static double BestPointToNodeDistance (const VecType &queryPoint, const TreeType *referenceNode, const double pointToCenterDistance)
 Return the best possible distance between a point and a node, given that the distance between the point and the center of the node has already been calculated. More...
 
template<typename VecType , typename TreeType >
static size_t GetBestChild (const VecType &queryPoint, TreeType &referenceNode)
 Return the best child according to this sort policy. More...
 
template<typename TreeType >
static size_t GetBestChild (const TreeType &queryNode, TreeType &referenceNode)
 Return the best child according to this sort policy. More...
 
static double WorstDistance ()
 Return what should represent the worst possible distance with this particular sort policy. More...
 
static double BestDistance ()
 Return what should represent the best possible distance with this particular sort policy. More...
 
static double CombineBest (const double a, const double b)
 Return the best combination of the two distances.
 
static double CombineWorst (const double a, const double b)
 Return the worst combination of the two distances.
 
static double Relax (const double value, const double epsilon)
 Return the given value relaxed. More...
 
static double ConvertToScore (const double distance)
 Convert the given distance into a score. More...
 
static double ConvertToDistance (const double score)
 Convert the given score to a distance. More...
 

Detailed Description

This class implements the necessary methods for the SortPolicy template parameter of the NeighborSearch class.

The sorting policy here is that the minimum distance is the best (so, when used with NeighborSearch, the output is nearest neighbors).

This class is also meant to serve as a guide to implement a custom SortPolicy. All of the methods implemented here must be implemented by any other SortPolicy classes.

Member Function Documentation

◆ BestDistance()

static double mlpack::neighbor::NearestNS::BestDistance ( )
inlinestatic

Return what should represent the best possible distance with this particular sort policy.

In our case, this should be the minimum possible distance, 0.0.

Returns
0.0

◆ BestNodeToNodeDistance() [1/3]

template<typename TreeType >
double mlpack::neighbor::NearestNS::BestNodeToNodeDistance ( const TreeType *  queryNode,
const TreeType *  referenceNode 
)
inlinestatic

Return the best possible distance between two nodes.

In our case, this is the minimum distance between the two tree nodes using the given distance function.

◆ BestNodeToNodeDistance() [2/3]

template<typename TreeType >
double mlpack::neighbor::NearestNS::BestNodeToNodeDistance ( const TreeType *  queryNode,
const TreeType *  referenceNode,
const double  centerToCenterDistance 
)
inlinestatic

Return the best possible distance between two nodes, given that the distance between the centers of the two nodes has already been calculated.

This is used in conjunction with trees that have self-children (like cover trees).

◆ BestNodeToNodeDistance() [3/3]

template<typename TreeType >
double mlpack::neighbor::NearestNS::BestNodeToNodeDistance ( const TreeType *  queryNode,
const TreeType *  referenceNode,
const TreeType *  referenceChildNode,
const double  centerToCenterDistance 
)
inlinestatic

Return the best possible distance between the query node and the reference child node given the base case distance between the query node and the reference node.

TreeType::ParentDistance() must be implemented to use this.

Parameters
queryNodeQuery node.
referenceNodeReference node.
referenceChildNodeChild of reference node which is being inspected.
centerToCenterDistanceDistance between centers of query node and reference node.

◆ BestPointToNodeDistance() [1/2]

template<typename VecType , typename TreeType >
double mlpack::neighbor::NearestNS::BestPointToNodeDistance ( const VecType &  queryPoint,
const TreeType *  referenceNode 
)
inlinestatic

Return the best possible distance between a node and a point.

In our case, this is the minimum distance between the tree node and the point using the given distance function.

◆ BestPointToNodeDistance() [2/2]

template<typename VecType , typename TreeType >
double mlpack::neighbor::NearestNS::BestPointToNodeDistance ( const VecType &  queryPoint,
const TreeType *  referenceNode,
const double  pointToCenterDistance 
)
inlinestatic

Return the best possible distance between a point and a node, given that the distance between the point and the center of the node has already been calculated.

This is used in conjunction with trees that have self-children (like cover trees).

◆ ConvertToDistance()

static double mlpack::neighbor::NearestNS::ConvertToDistance ( const double  score)
inlinestatic

Convert the given score to a distance.

This is the inverse of the operation provided by ConvertToScore(). For nearest neighbor search, there is no need for any change.

◆ ConvertToScore()

static double mlpack::neighbor::NearestNS::ConvertToScore ( const double  distance)
inlinestatic

Convert the given distance into a score.

Lower scores are better, so in the case of nearest neighbor sort where lower distances are better, we just return the distance.

◆ GetBestChild() [1/2]

template<typename VecType , typename TreeType >
static size_t mlpack::neighbor::NearestNS::GetBestChild ( const VecType &  queryPoint,
TreeType &  referenceNode 
)
inlinestatic

Return the best child according to this sort policy.

In this case it will return the one with the minimum distance.

◆ GetBestChild() [2/2]

template<typename TreeType >
static size_t mlpack::neighbor::NearestNS::GetBestChild ( const TreeType &  queryNode,
TreeType &  referenceNode 
)
inlinestatic

Return the best child according to this sort policy.

In this case it will return the one with the minimum distance.

◆ IsBetter()

static bool mlpack::neighbor::NearestNS::IsBetter ( const double  value,
const double  ref 
)
inlinestatic

Return whether or not value is "better" than ref.

In this case, that means that the value is less than or equal to the reference.

Parameters
valueValue to compare
refValue to compare with
Returns
bool indicating whether or not (value <= ref).

◆ Relax()

static double mlpack::neighbor::NearestNS::Relax ( const double  value,
const double  epsilon 
)
inlinestatic

Return the given value relaxed.

Parameters
valueValue to relax.
epsilonRelative error (non-negative).
Returns
double Value relaxed.

◆ WorstDistance()

static double mlpack::neighbor::NearestNS::WorstDistance ( )
inlinestatic

Return what should represent the worst possible distance with this particular sort policy.

In our case, this should be the maximum possible distance, DBL_MAX.

Returns
DBL_MAX

The documentation for this class was generated from the following files: