GClasses
|
Finds the k-nearest neighbors of any vector in a dataset. More...
#include <GNeighborFinder.h>
Public Member Functions | |
GNeighborFinder (GMatrix *pData, size_t neighborCount) | |
virtual | ~GNeighborFinder () |
GMatrix * | data () |
Returns the data passed to the constructor of this object. | |
size_t | neighborCount () |
Returns the number of neighbors to find. | |
virtual bool | canGeneralize () |
Returns true if this neighbor finder can operate on points that are not in the dataset passed to the constructor. | |
virtual bool | isCached () |
Returns true iff the neighbors and distances are pre-computed. | |
virtual void | neighbors (size_t *pOutNeighbors, size_t index)=0 |
pOutNeighbors should be an array of size neighborCount. index refers to the point/vector whose neighbors you want to obtain. The value INVALID_INDEX may be used to fill slots with no point if necessary. | |
virtual void | neighbors (size_t *pOutNeighbors, double *pOutDistances, size_t index)=0 |
pOutNeighbors and pOutDistances should both be arrays of size neighborCount. index refers to the point/vector whose neighbors you want to obtain. The neighbors are not necessarily sorted, but you can call GNeighborFinder::sortNeighbors if you want them to be sorted. If there are not enough points in the data set to fill the neighbor array, the empty ones will have an index of INVALID_INDEX. | |
void | sortNeighbors (size_t *pNeighbors, double *pDistances) |
Uses Quick Sort to sort the neighbors from least to most dissimilar, followed by any slots for with INVALID_INDEX for the index. | |
Static Public Member Functions | |
static void | sortNeighbors (size_t neighborCount, size_t *pNeighbors, double *pDistances) |
Uses Quick Sort to sort the neighbors from least to most dissimilar, followed by any slots for with INVALID_INDEX for the index. | |
Protected Attributes | |
GMatrix * | m_pData |
size_t | m_neighborCount |
Finds the k-nearest neighbors of any vector in a dataset.
GClasses::GNeighborFinder::GNeighborFinder | ( | GMatrix * | pData, |
size_t | neighborCount | ||
) | [inline] |
virtual GClasses::GNeighborFinder::~GNeighborFinder | ( | ) | [inline, virtual] |
virtual bool GClasses::GNeighborFinder::canGeneralize | ( | ) | [inline, virtual] |
Returns true if this neighbor finder can operate on points that are not in the dataset passed to the constructor.
Reimplemented in GClasses::GNeighborFinderGeneralizing.
GMatrix* GClasses::GNeighborFinder::data | ( | ) | [inline] |
Returns the data passed to the constructor of this object.
virtual bool GClasses::GNeighborFinder::isCached | ( | ) | [inline, virtual] |
Returns true iff the neighbors and distances are pre-computed.
Reimplemented in GClasses::GNeighborFinderCacheWrapper.
size_t GClasses::GNeighborFinder::neighborCount | ( | ) | [inline] |
Returns the number of neighbors to find.
virtual void GClasses::GNeighborFinder::neighbors | ( | size_t * | pOutNeighbors, |
size_t | index | ||
) | [pure virtual] |
pOutNeighbors should be an array of size neighborCount. index refers to the point/vector whose neighbors you want to obtain. The value INVALID_INDEX may be used to fill slots with no point if necessary.
Implemented in GClasses::GNeighborFinderCacheWrapper, GClasses::GBruteForceNeighborFinder, GClasses::GKdTree, GClasses::GSaffron, GClasses::GTemporalNeighborFinder, and GClasses::GSequenceNeighborFinder.
virtual void GClasses::GNeighborFinder::neighbors | ( | size_t * | pOutNeighbors, |
double * | pOutDistances, | ||
size_t | index | ||
) | [pure virtual] |
pOutNeighbors and pOutDistances should both be arrays of size neighborCount. index refers to the point/vector whose neighbors you want to obtain. The neighbors are not necessarily sorted, but you can call GNeighborFinder::sortNeighbors if you want them to be sorted. If there are not enough points in the data set to fill the neighbor array, the empty ones will have an index of INVALID_INDEX.
Implemented in GClasses::GNeighborFinderCacheWrapper, GClasses::GBruteForceNeighborFinder, GClasses::GKdTree, GClasses::GSaffron, GClasses::GTemporalNeighborFinder, and GClasses::GSequenceNeighborFinder.
static void GClasses::GNeighborFinder::sortNeighbors | ( | size_t | neighborCount, |
size_t * | pNeighbors, | ||
double * | pDistances | ||
) | [static] |
Uses Quick Sort to sort the neighbors from least to most dissimilar, followed by any slots for with INVALID_INDEX for the index.
void GClasses::GNeighborFinder::sortNeighbors | ( | size_t * | pNeighbors, |
double * | pDistances | ||
) |
Uses Quick Sort to sort the neighbors from least to most dissimilar, followed by any slots for with INVALID_INDEX for the index.
size_t GClasses::GNeighborFinder::m_neighborCount [protected] |
GMatrix* GClasses::GNeighborFinder::m_pData [protected] |