GClasses
GClasses::GNeighborGraph Class Reference

Detailed Description

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

#include <GNeighborFinder.h>

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

Public Member Functions

 GNeighborGraph (GNeighborFinder *pNF, bool own, size_t neighbors)
 Makes a GNeighborGraph that has precomputed the k-nearest neighbors of each point in a dataset. If own is true, then this will take ownership of pNF. More...
 
 GNeighborGraph (double squaredRadius, GNeighborFinder *pNF, bool own)
 Makes a GNeighborGraph that has precomputed the neighbors of each point in a dataset within a specified radius. More...
 
 GNeighborGraph (bool own, GNeighborFinderGeneralizing *pNF)
 Makes a GNeighborGraph assuming the data represents a sequence of observations. First, it computes the distance between each point and its previous and next points. Then, it finds all neighbors within a radius of the maximum of those two distances. More...
 
virtual ~GNeighborGraph ()
 
size_t cutShortcuts (size_t cycleLen)
 Uses CycleCut to remove shortcut connections. (Assumes fillCache has already been called.) More...
 
virtual double distance (size_t i)
 See the comment for GNeighborFinder::distance. More...
 
void dropInvalidNeighbors ()
 Drops all neighbors that have been set to INVALID_INDEX. This method is used by CycleCut. It is probably not useful for any other purpose. More...
 
virtual size_t findNearest (size_t k, size_t pointIndex)
 See the comment for GNeighborFinder::findNearest. More...
 
virtual size_t findWithinRadius (double squaredRadius, size_t pointIndex)
 See the comment for GNeighborFinder::findWithinRadius. 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 size_t neighbor (size_t i)
 See the comment for GNeighborFinder::neighbor. More...
 
void recomputeDistances (GDistanceMetric *pMetric)
 recomputes all neighbor distances using the specified metric. More...
 
void set (size_t point, size_t neighbor_number, size_t neighbor)
 Sets the specified neighbor. (Does not change the distance.) This method is used by CycleCut. It is probably not useful for any other purpose. More...
 
void swapInData (const GMatrix *pNewData)
 Uses pNewData for subsequent calls to recomputeDistances. More...
 
GNeighborFinderwrappedNeighborFinder ()
 Returns a pointer to the neighbor finder that this wraps. More...
 
- Public Member Functions inherited from GClasses::GNeighborFinder
 GNeighborFinder (const GMatrix *pData)
 
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...
 

Protected Member Functions

void fillCacheNearest (size_t k)
 Fills the cache with the k-nearest neighbors of each point. More...
 
void fillCacheRadius (double squaredRadius)
 Fills the cache with the neighbors of each point within a specified radius. More...
 

Protected Attributes

std::vector< std::vector< double > > m_dists
 
size_t m_focus
 
std::vector< std::vector< size_t > > m_neighs
 
bool m_own
 
GNeighborFinderm_pNF
 
- Protected Attributes inherited from GClasses::GNeighborFinder
const GMatrixm_pData
 

Constructor & Destructor Documentation

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

Makes a GNeighborGraph that has precomputed the k-nearest neighbors of each point in a dataset. If own is true, then this will take ownership of pNF.

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

Makes a GNeighborGraph that has precomputed the neighbors of each point in a dataset within a specified radius.

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

Makes a GNeighborGraph assuming the data represents a sequence of observations. First, it computes the distance between each point and its previous and next points. Then, it finds all neighbors within a radius of the maximum of those two distances.

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

Member Function Documentation

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

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

virtual double GClasses::GNeighborGraph::distance ( size_t  i)
inlinevirtual

See the comment for GNeighborFinder::distance.

Implements GClasses::GNeighborFinder.

void GClasses::GNeighborGraph::dropInvalidNeighbors ( )

Drops all neighbors that have been set to INVALID_INDEX. This method is used by CycleCut. It is probably not useful for any other purpose.

void GClasses::GNeighborGraph::fillCacheNearest ( size_t  k)
protected

Fills the cache with the k-nearest neighbors of each point.

void GClasses::GNeighborGraph::fillCacheRadius ( double  squaredRadius)
protected

Fills the cache with the neighbors of each point within a specified radius.

virtual size_t GClasses::GNeighborGraph::findNearest ( size_t  k,
size_t  pointIndex 
)
inlinevirtual

See the comment for GNeighborFinder::findNearest.

Implements GClasses::GNeighborFinder.

virtual size_t GClasses::GNeighborGraph::findWithinRadius ( double  squaredRadius,
size_t  pointIndex 
)
inlinevirtual
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 size_t GClasses::GNeighborGraph::neighbor ( size_t  i)
inlinevirtual

See the comment for GNeighborFinder::neighbor.

Implements GClasses::GNeighborFinder.

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

recomputes all neighbor distances using the specified metric.

void GClasses::GNeighborGraph::set ( size_t  point,
size_t  neighbor_number,
size_t  neighbor 
)

Sets the specified neighbor. (Does not change the distance.) This method is used by CycleCut. It is probably not useful for any other purpose.

void GClasses::GNeighborGraph::swapInData ( const GMatrix pNewData)

Uses pNewData for subsequent calls to recomputeDistances.

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

Returns a pointer to the neighbor finder that this wraps.

Member Data Documentation

std::vector<std::vector<double> > GClasses::GNeighborGraph::m_dists
protected
size_t GClasses::GNeighborGraph::m_focus
protected
std::vector<std::vector<size_t> > GClasses::GNeighborGraph::m_neighs
protected
bool GClasses::GNeighborGraph::m_own
protected
GNeighborFinder* GClasses::GNeighborGraph::m_pNF
protected