GClasses
GClasses::GDistanceMetric Class Referenceabstract

This class enables you to define a distance (or dissimilarity) metric between two vectors. pScaleFactors is an optional parameter (it can be NULL) that lets the calling class scale the significance of each dimension. Distance metrics that do not mix with this concept may simply ignore any scale factors. Typically, classes that use this should be able to assume that the triangle inequality will hold, but do not necessarily enforce the parallelogram law. More...

#include <GDistance.h>

Inheritance diagram for GClasses::GDistanceMetric:
GClasses::GLNormDistance GClasses::GRowDistance GClasses::GRowDistanceScaled

Public Member Functions

 GDistanceMetric ()
 
 GDistanceMetric (GDomNode *pNode)
 
virtual ~GDistanceMetric ()
 
virtual void init (const GRelation *pRelation, bool own)=0
 This must be called before squaredDistance can be called. Takes ownership of pRelation iff own is true. More...
 
double operator() (const std::vector< double > &a, const std::vector< double > &b) const
 Return squaredDistance(a,b). Allows dissimilarity metrics to be used as function objects. Do not override. Override squaredDistance(a,b) instead. See GDistanceMetric::squaredDistance(const std::vector<double>&, const std::vector<double>&) More...
 
double operator() (const double *pA, const double *pB) const
 Return squaredDistance(pA, pB). Allows dissimilarity metrics to be used as function objects. Do not override. Override squaredDistance(pA,pB) instead. See GDistanceMetric::squaredDistance(const double*, const double*) More...
 
const GRelationrelation () const
 Returns the relation that specifies the meaning of the vector elements. More...
 
virtual double * scaleFactors ()
 Returns a pointer to the vector of scale factors. This may be NULL if the metric does not use scale factors. More...
 
virtual GDomNodeserialize (GDom *pDoc) const =0
 Marshal this object into a DOM, which can then be converted to a variety of serial formats. More...
 
virtual double squaredDistance (const std::vector< double > &a, const std::vector< double > &b) const
 Return the squared distance (or squared dissimilarity) between the two specified vectors. More...
 
virtual double squaredDistance (const double *pA, const double *pB) const =0
 Computes the squared distance (or squared dissimilarity) between the two specified vectors. More...
 

Static Public Member Functions

static GDistanceMetricdeserialize (GDomNode *pNode)
 Deserializes a distance metric. More...
 

Protected Member Functions

GDomNodebaseDomNode (GDom *pDoc, const char *szClassName) const
 
void setRelation (const GRelation *pRelation, bool own)
 Sets the relation to use with this metric. Takes ownership of the relation iff own is true. More...
 

Protected Attributes

bool m_ownRelation
 
const GRelationm_pRelation
 

Detailed Description

This class enables you to define a distance (or dissimilarity) metric between two vectors. pScaleFactors is an optional parameter (it can be NULL) that lets the calling class scale the significance of each dimension. Distance metrics that do not mix with this concept may simply ignore any scale factors. Typically, classes that use this should be able to assume that the triangle inequality will hold, but do not necessarily enforce the parallelogram law.

Constructor & Destructor Documentation

GClasses::GDistanceMetric::GDistanceMetric ( )
inline
GClasses::GDistanceMetric::GDistanceMetric ( GDomNode pNode)
virtual GClasses::GDistanceMetric::~GDistanceMetric ( )
virtual

Member Function Documentation

GDomNode* GClasses::GDistanceMetric::baseDomNode ( GDom pDoc,
const char *  szClassName 
) const
protected
static GDistanceMetric* GClasses::GDistanceMetric::deserialize ( GDomNode pNode)
static

Deserializes a distance metric.

virtual void GClasses::GDistanceMetric::init ( const GRelation pRelation,
bool  own 
)
pure virtual

This must be called before squaredDistance can be called. Takes ownership of pRelation iff own is true.

Implemented in GClasses::GLNormDistance, GClasses::GRowDistanceScaled, and GClasses::GRowDistance.

double GClasses::GDistanceMetric::operator() ( const std::vector< double > &  a,
const std::vector< double > &  b 
) const
inline

Return squaredDistance(a,b). Allows dissimilarity metrics to be used as function objects. Do not override. Override squaredDistance(a,b) instead. See GDistanceMetric::squaredDistance(const std::vector<double>&, const std::vector<double>&)

double GClasses::GDistanceMetric::operator() ( const double *  pA,
const double *  pB 
) const
inline

Return squaredDistance(pA, pB). Allows dissimilarity metrics to be used as function objects. Do not override. Override squaredDistance(pA,pB) instead. See GDistanceMetric::squaredDistance(const double*, const double*)

const GRelation* GClasses::GDistanceMetric::relation ( ) const
inline

Returns the relation that specifies the meaning of the vector elements.

virtual double* GClasses::GDistanceMetric::scaleFactors ( )
inlinevirtual

Returns a pointer to the vector of scale factors. This may be NULL if the metric does not use scale factors.

Reimplemented in GClasses::GRowDistanceScaled.

virtual GDomNode* GClasses::GDistanceMetric::serialize ( GDom pDoc) const
pure virtual

Marshal this object into a DOM, which can then be converted to a variety of serial formats.

Implemented in GClasses::GLNormDistance, GClasses::GRowDistanceScaled, and GClasses::GRowDistance.

void GClasses::GDistanceMetric::setRelation ( const GRelation pRelation,
bool  own 
)
protected

Sets the relation to use with this metric. Takes ownership of the relation iff own is true.

virtual double GClasses::GDistanceMetric::squaredDistance ( const std::vector< double > &  a,
const std::vector< double > &  b 
) const
virtual

Return the squared distance (or squared dissimilarity) between the two specified vectors.

It is assumed that a and b are vectors of the same dimension - and that that dimension is compatible with the relation given in init. By default uses squaredDistance(const double*, const double*) const so subclassers only need to change that method.

virtual double GClasses::GDistanceMetric::squaredDistance ( const double *  pA,
const double *  pB 
) const
pure virtual

Computes the squared distance (or squared dissimilarity) between the two specified vectors.

Implemented in GClasses::GLNormDistance, GClasses::GRowDistanceScaled, and GClasses::GRowDistance.

Member Data Documentation

bool GClasses::GDistanceMetric::m_ownRelation
protected
const GRelation* GClasses::GDistanceMetric::m_pRelation
protected