GClasses
GClasses::GNeighborGraph Class Reference

This wraps a neighbor finding algorithm. It caches the queries for neighbors for the purpose of improving runtime performance. More...

#include <GNeighborFinder.h>

Inheritance diagram for GClasses::GNeighborGraph:
GClasses::GNeighborFinder

Public Member Functions

 GNeighborGraph (GNeighborFinder *pNF, bool own)
 If own is true, then this will take ownership of pNF. More...
 
virtual ~GNeighborGraph ()
 
size_t * cache ()
 Returns the cache of neighbors. (You should probably call fillCache before calling this.) More...
 
size_t cutShortcuts (size_t cycleLen)
 Uses CycleCut to remove shortcut connections. (Assumes fillCache has already been called.) More...
 
void fillCache ()
 Ensures that the cache is populated with data for every index in the dataset. More...
 
void fillDistances (GDistanceMetric *pMetric)
 (Re)computes all neighbor distances using the specified metric. More...
 
virtual bool isCached ()
 See the comment for GNeighborFinder::isCached. More...
 
bool isConnected ()
 Returns true iff the neighbors form a connected graph when each neighbor is evaluated as a bi-directional edge. (Assumes that fillCache has already been called.) More...
 
virtual void neighbors (size_t *pOutNeighbors, size_t index)
 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)
 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 normalizeDistances ()
 Normalizes all the neighborhoods so that all neighbor distances are approximately 1. More...
 
void patchMissingSpots (GRand *pRand)
 Patches any missing neighbors by randomly selecting another of its neighbors to fill both spots. More...
 
GRandomIndexIteratorrandomEdgeIterator (GRand &rand)
 Returns an iterator that can visit each edge in random order. More...
 
double * squaredDistanceTable ()
 Returns the table of squared dissimilarities. More...
 
GNeighborFinderwrappedNeighborFinder ()
 Returns a pointer to the neighbor finder that this wraps. More...
 
- Public Member Functions inherited from GClasses::GNeighborFinder
 GNeighborFinder (const GMatrix *pData, size_t neighborCount)
 
virtual ~GNeighborFinder ()
 
virtual bool canGeneralize ()
 Returns true if this neighbor finder can operate on points that are not in the dataset passed to the constructor. More...
 
const GMatrixdata ()
 Returns the data passed to the constructor of this object. More...
 
size_t neighborCount ()
 Returns the number of neighbors to find. 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_own
 
size_t * m_pCache
 
double * m_pDissims
 
GNeighborFinderm_pNF
 
GRandomIndexIteratorm_pRandomEdgeIterator
 
- 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

This wraps a neighbor finding algorithm. It caches the queries for neighbors for the purpose of improving runtime performance.

Constructor & Destructor Documentation

GClasses::GNeighborGraph::GNeighborGraph ( GNeighborFinder pNF,
bool  own 
)

If own is true, then this will take ownership of pNF.

virtual GClasses::GNeighborGraph::~GNeighborGraph ( )
virtual

Member Function Documentation

size_t* GClasses::GNeighborGraph::cache ( )
inline

Returns the cache of neighbors. (You should probably call fillCache before calling this.)

size_t GClasses::GNeighborGraph::cutShortcuts ( size_t  cycleLen)

Uses CycleCut to remove shortcut connections. (Assumes fillCache has already been called.)

void GClasses::GNeighborGraph::fillCache ( )

Ensures that the cache is populated with data for every index in the dataset.

void GClasses::GNeighborGraph::fillDistances ( GDistanceMetric pMetric)

(Re)computes all neighbor distances using the specified metric.

virtual bool GClasses::GNeighborGraph::isCached ( )
inlinevirtual

See the comment for GNeighborFinder::isCached.

Reimplemented from GClasses::GNeighborFinder.

bool GClasses::GNeighborGraph::isConnected ( )

Returns true iff the neighbors form a connected graph when each neighbor is evaluated as a bi-directional edge. (Assumes that fillCache has already been called.)

virtual void GClasses::GNeighborGraph::neighbors ( size_t *  pOutNeighbors,
size_t  index 
)
virtual

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.

Implements GClasses::GNeighborFinder.

virtual void GClasses::GNeighborGraph::neighbors ( size_t *  pOutNeighbors,
double *  pOutDistances,
size_t  index 
)
virtual

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.

Implements GClasses::GNeighborFinder.

void GClasses::GNeighborGraph::normalizeDistances ( )

Normalizes all the neighborhoods so that all neighbor distances are approximately 1.

void GClasses::GNeighborGraph::patchMissingSpots ( GRand pRand)

Patches any missing neighbors by randomly selecting another of its neighbors to fill both spots.

GRandomIndexIterator& GClasses::GNeighborGraph::randomEdgeIterator ( GRand rand)

Returns an iterator that can visit each edge in random order.

double* GClasses::GNeighborGraph::squaredDistanceTable ( )
inline

Returns the table of squared dissimilarities.

GNeighborFinder* GClasses::GNeighborGraph::wrappedNeighborFinder ( )
inline

Returns a pointer to the neighbor finder that this wraps.

Member Data Documentation

bool GClasses::GNeighborGraph::m_own
protected
size_t* GClasses::GNeighborGraph::m_pCache
protected
double* GClasses::GNeighborGraph::m_pDissims
protected
GNeighborFinder* GClasses::GNeighborGraph::m_pNF
protected
GRandomIndexIterator* GClasses::GNeighborGraph::m_pRandomEdgeIterator
protected