GClasses
GClasses::GNeighborFinderGeneralizing Class Referenceabstract

Finds the k-nearest neighbors (in a dataset) of an arbitrary vector (which may or may not be in the dataset). More...

#include <GNeighborFinder.h>

Inheritance diagram for GClasses::GNeighborFinderGeneralizing:
GClasses::GNeighborFinder GClasses::GBallTree GClasses::GBruteForceNeighborFinder GClasses::GKdTree

Public Member Functions

 GNeighborFinderGeneralizing (const GMatrix *pData, size_t neighborCount, 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 void neighbors (size_t *pOutNeighbors, double *pOutDistances, const double *pInputVector)=0
 pOutNeighbors and pOutDistances should both be arrays of size neighborCount. pInputVector is the vector whose neighbors will be found. 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. More...
 
virtual void reoptimize ()=0
 If you make major changes, you can call this to tell it to rebuild any optimization structures. More...
 
- Public Member Functions inherited from GClasses::GNeighborFinder
 GNeighborFinder (const GMatrix *pData, size_t neighborCount)
 
virtual ~GNeighborFinder ()
 
const GMatrixdata ()
 Returns the data passed to the constructor of this object. More...
 
virtual bool isCached ()
 Returns true iff the neighbors and distances are pre-computed. More...
 
size_t neighborCount ()
 Returns the number of neighbors to find. More...
 
virtual void neighbors (size_t *pOutNeighbors, size_t index)=0
 Returns the k-nearest neighbors of the point specified by index. The neighbors are not necessarily sorted, but you can call GNeighborFinder::sortNeighbors if you want them to be sorted. 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. More...
 
virtual void neighbors (size_t *pOutNeighbors, double *pOutDistances, size_t index)=0
 Returns the k-nearest neighbors of the point specified by index. The neighbors are not necessarily sorted, but you can call GNeighborFinder::sortNeighbors if you want them to be sorted. pOutNeighbors and pOutDistances should both be arrays of size neighborCount. index refers to the point/vector whose neighbors you want to obtain. 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. More...
 
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. (Note: This method is pointless, since the neighors are already guaranteed to come in sorted order. Todo: figure out why it is still here) More...
 

Protected Attributes

bool m_ownMetric
 
GDistanceMetricm_pMetric
 
- Protected Attributes inherited from GClasses::GNeighborFinder
size_t m_neighborCount
 
const GMatrixm_pData
 

Additional Inherited Members

- Static Public Member Functions inherited from GClasses::GNeighborFinder
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. (Note: This method is pointless, since the neighors are already guaranteed to come in sorted order. Todo: figure out why it is still here) More...
 

Detailed Description

Finds the k-nearest neighbors (in a dataset) of an arbitrary vector (which may or may not be in the dataset).

Constructor & Destructor Documentation

GClasses::GNeighborFinderGeneralizing::GNeighborFinderGeneralizing ( const GMatrix pData,
size_t  neighborCount,
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 GClasses::GNeighborFinderGeneralizing::~GNeighborFinderGeneralizing ( )
virtual

Member Function Documentation

virtual bool GClasses::GNeighborFinderGeneralizing::canGeneralize ( )
inlinevirtual

Returns true. See the comment for GNeighborFinder::canGeneralize.

Reimplemented from GClasses::GNeighborFinder.

virtual void GClasses::GNeighborFinderGeneralizing::neighbors ( size_t *  pOutNeighbors,
double *  pOutDistances,
const double *  pInputVector 
)
pure virtual

pOutNeighbors and pOutDistances should both be arrays of size neighborCount. pInputVector is the vector whose neighbors will be found. 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::GBallTree, GClasses::GKdTree, and GClasses::GBruteForceNeighborFinder.

virtual void GClasses::GNeighborFinderGeneralizing::reoptimize ( )
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, and GClasses::GBruteForceNeighborFinder.

Member Data Documentation

bool GClasses::GNeighborFinderGeneralizing::m_ownMetric
protected
GDistanceMetric* GClasses::GNeighborFinderGeneralizing::m_pMetric
protected