GClasses
|
Finds the k-nearest neighbors (in a dataset) of an arbitrary vector (which may or may not be in the dataset).
#include <GNeighborFinder.h>
Public Member Functions | |
GNeighborFinderGeneralizing (const GMatrix *pData, GDistanceMetric *pMetric=NULL, bool ownMetric=false) | |
Create a neighborfinder for finding the neighborCount nearest neighbors under the given metric. If ownMetric is true, then the neighborFinder takes responsibility for deleting the metric, otherwise it is the caller's responsibility. More... | |
virtual | ~GNeighborFinderGeneralizing () |
virtual bool | canGeneralize () |
Returns true. See the comment for GNeighborFinder::canGeneralize. More... | |
virtual double | distance (size_t i) |
See the comment for GNeighborFinder::distance. More... | |
virtual size_t | findNearest (size_t k, const GVec &vector)=0 |
Finds the nearest neighbors of the specified vector. Returns the number of neighbors found. Call "neighbor" or "distance" to obtain the neighbors and distances that were found. More... | |
virtual size_t | findWithinRadius (double squaredRadius, const GVec &vector)=0 |
Finds all neighbors of the specified vector within a specified radius. Returns the number of neighbors found. Call "neighbor" or "distance" to obtain the neighbors and distances that were found. More... | |
GDistanceMetric * | metric () |
Returns the metric. More... | |
virtual size_t | neighbor (size_t i) |
See the comment for GNeighborFinder::neighbor. More... | |
virtual void | reoptimize ()=0 |
If you make major changes, you can call this to tell it to rebuild any optimization structures. More... | |
void | sortNeighbors (size_t start=0, size_t end=INVALID_INDEX) |
Uses Quick Sort to sort the neighbors from least to most distant. More... | |
Public Member Functions inherited from GClasses::GNeighborFinder | |
GNeighborFinder (const GMatrix *pData) | |
virtual | ~GNeighborFinder () |
const GMatrix * | data () |
Returns the data passed to the constructor of this object. More... | |
virtual size_t | findNearest (size_t k, size_t pointIndex)=0 |
Finds the k-nearest neighbors of the specified point index. Returns the number of neighbors found. Call "neighbor" or "distance" to obtain the neighbors and distances that were found. More... | |
virtual size_t | findWithinRadius (double squaredRadius, size_t pointIndex)=0 |
Finds all neighbors of the specified point index within a specified radius. Returns the number of neighbors found. Call "neighbor" or "distance" to obtain the neighbors and distances that were found. More... | |
virtual bool | isCached () |
Returns true iff the neighbors and distances are pre-computed. More... | |
Protected Member Functions | |
void | insertionSortNeighbors (size_t start, size_t end) |
A helper method used by sortNeighbors when the remaining portion to sort is small. More... | |
Protected Attributes | |
std::vector< double > | m_dists |
std::vector< size_t > | m_neighs |
bool | m_ownMetric |
GDistanceMetric * | m_pMetric |
Protected Attributes inherited from GClasses::GNeighborFinder | |
const GMatrix * | m_pData |
GClasses::GNeighborFinderGeneralizing::GNeighborFinderGeneralizing | ( | const GMatrix * | pData, |
GDistanceMetric * | pMetric = NULL , |
||
bool | ownMetric = false |
||
) |
Create a neighborfinder for finding the neighborCount nearest neighbors under the given metric. If ownMetric is true, then the neighborFinder takes responsibility for deleting the metric, otherwise it is the caller's responsibility.
|
virtual |
|
inlinevirtual |
Returns true. See the comment for GNeighborFinder::canGeneralize.
Reimplemented from GClasses::GNeighborFinder.
|
inlinevirtual |
See the comment for GNeighborFinder::distance.
Implements GClasses::GNeighborFinder.
|
pure virtual |
Finds the nearest neighbors of the specified vector. Returns the number of neighbors found. Call "neighbor" or "distance" to obtain the neighbors and distances that were found.
Implemented in GClasses::GBallTree, GClasses::GKdTree, GClasses::GSparseNeighborFinder, and GClasses::GBruteForceNeighborFinder.
|
pure virtual |
Finds all neighbors of the specified vector within a specified radius. Returns the number of neighbors found. Call "neighbor" or "distance" to obtain the neighbors and distances that were found.
Implemented in GClasses::GBallTree, GClasses::GKdTree, GClasses::GSparseNeighborFinder, and GClasses::GBruteForceNeighborFinder.
|
protected |
A helper method used by sortNeighbors when the remaining portion to sort is small.
|
inline |
Returns the metric.
|
inlinevirtual |
See the comment for GNeighborFinder::neighbor.
Implements GClasses::GNeighborFinder.
|
pure virtual |
If you make major changes, you can call this to tell it to rebuild any optimization structures.
Implemented in GClasses::GBallTree, GClasses::GKdTree, GClasses::GSparseNeighborFinder, and GClasses::GBruteForceNeighborFinder.
void GClasses::GNeighborFinderGeneralizing::sortNeighbors | ( | size_t | start = 0 , |
size_t | end = INVALID_INDEX |
||
) |
Uses Quick Sort to sort the neighbors from least to most distant.
|
protected |
|
protected |
|
protected |
|
protected |