GClasses
GClasses::GNeighborFinderGeneralizing Class Referenceabstract

Detailed Description

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

#include <GNeighborFinder.h>

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

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...
 
GDistanceMetricmetric ()
 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 GMatrixdata ()
 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
 
GDistanceMetricm_pMetric
 
- Protected Attributes inherited from GClasses::GNeighborFinder
const GMatrixm_pData
 

Constructor & Destructor Documentation

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 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 double GClasses::GNeighborFinderGeneralizing::distance ( size_t  i)
inlinevirtual

See the comment for GNeighborFinder::distance.

Implements GClasses::GNeighborFinder.

virtual size_t GClasses::GNeighborFinderGeneralizing::findNearest ( size_t  k,
const GVec vector 
)
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.

virtual size_t GClasses::GNeighborFinderGeneralizing::findWithinRadius ( double  squaredRadius,
const GVec vector 
)
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.

void GClasses::GNeighborFinderGeneralizing::insertionSortNeighbors ( size_t  start,
size_t  end 
)
protected

A helper method used by sortNeighbors when the remaining portion to sort is small.

GDistanceMetric* GClasses::GNeighborFinderGeneralizing::metric ( )
inline

Returns the metric.

virtual size_t GClasses::GNeighborFinderGeneralizing::neighbor ( size_t  i)
inlinevirtual

See the comment for GNeighborFinder::neighbor.

Implements GClasses::GNeighborFinder.

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, 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.

Member Data Documentation

std::vector<double> GClasses::GNeighborFinderGeneralizing::m_dists
protected
std::vector<size_t> GClasses::GNeighborFinderGeneralizing::m_neighs
protected
bool GClasses::GNeighborFinderGeneralizing::m_ownMetric
protected
GDistanceMetric* GClasses::GNeighborFinderGeneralizing::m_pMetric
protected