GClasses

GClasses::GNeighborFinder Class Reference

Finds the k-nearest neighbors of any vector in a dataset. More...

#include <GNeighborFinder.h>

Inheritance diagram for GClasses::GNeighborFinder:
GClasses::GNeighborFinderCacheWrapper GClasses::GNeighborFinderGeneralizing GClasses::GSaffron GClasses::GSequenceNeighborFinder GClasses::GTemporalNeighborFinder GClasses::GBruteForceNeighborFinder GClasses::GKdTree

List of all members.

Public Member Functions

 GNeighborFinder (GMatrix *pData, size_t neighborCount)
virtual ~GNeighborFinder ()
GMatrixdata ()
 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

GMatrixm_pData
size_t m_neighborCount

Detailed Description

Finds the k-nearest neighbors of any vector in a dataset.


Constructor & Destructor Documentation

GClasses::GNeighborFinder::GNeighborFinder ( GMatrix pData,
size_t  neighborCount 
) [inline]
virtual GClasses::GNeighborFinder::~GNeighborFinder ( ) [inline, virtual]

Member Function Documentation

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.


Member Data Documentation