IGLib  1.5
The IGLib base library for development of numerical, technical and business applications.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events
IG.Num.DistanceComparer< PointContainerType, PointType > Class Template Referenceabstract

Class that is used to calculate and compare distances between point containers. More...

+ Inheritance diagram for IG.Num.DistanceComparer< PointContainerType, PointType >:
+ Collaboration diagram for IG.Num.DistanceComparer< PointContainerType, PointType >:

Classes

class  StoredDistanceComparerClass
 Compares two point containers according to their StoredDistance property. More...
 

Public Member Functions

 DistanceComparer (PointContainerType referencePoint, DistanceDelegate< PointType > distanceFunction)
 Constructs a new comparer according to input distance to a reference poiont (type IVector). More...
 
 DistanceComparer (PointContainerType referencePoint, DistanceDelegate< PointType > distanceFunction, IVector lengthScales)
 Constructs a new comparer according to input distance to a reference poiont (type IVector). More...
 
abstract void GetPointCoordinates (PointType pt, ref IVector coord)
 Gets vector of coordinates of the specified point and stores it in the specified variable. More...
 
void SetCoordinateScales (IVector min, IVector max, IVector lengthScales)
 Sets parameters that affect default calculation of distance and relative point coordinates. More...
 
void GetRelativeCoordinates (IVector coord, ref IVector relativeCoortinates)
 Converts the specified coordinates to relative coordinates where compponents run from 0 to 1 if original coordinates run from minimal to maximal value. More...
 
void SetOutputScales (IVector min, IVector max, IVector lengthScales)
 Sets parameters that affect default calculation of output distance and output relative coordinates. More...
 
void GetOutputRelativeCoordinates (IVector coord, ref IVector relativeCoortinates)
 Converts the specified OUTPUT coordinates to relative coordinates where compponents run from 0 to 1 if original coordinates run from minimal to maximal value. More...
 
virtual double OutputDistance (PointContainerType pt1, PointContainerType pt2)
 Returns output distance between two point containers. More...
 
virtual int Compare (PointContainerType pt1, PointContainerType pt2)
 Compares two points according to the current comparer definition. More...
 
virtual double Distance (PointType pt1, PointType pt2)
 Returns distance between the specified two points. More...
 
double Distance (PointContainerType boxedPt1, PointContainerType boxedPt2)
 Returns distance between the specified two points enclosed in PointContainer objects, as defined by the distance calculation delegate (property DistanceFunction) of the current object. More...
 
double Distance (PointContainerType boxedPt1, PointType pt2)
 Returns distance between the specified point encolosed in an PointContainer object and a non-enclosed point, as defined by the distance calculation delegate (property DistanceFunction) of the current object. More...
 
double Distance (PointType pt1, PointContainerType boxedPt2)
 Returns distance between the specified point and the second point encolosed in an PointContainer object, as defined by the distance calculation delegate (property DistanceFunction) of the current object. More...
 
double Distance (PointType pt)
 Returns distance between the specified point and the reference point (property ReferencePoint) of the current object (enclosed in PointContainer<PointType> object), as defined by the distance calculation delegate of the current comparer object (property DistanceFunction). More...
 
double Distance (PointContainerType boxedPt)
 Returns distance between the specified point (enclosed in PointContainer<PointType> pbject) and the reference point (property ReferencePoint) of the current object (property ReferencePoint), as defined by the distance calculation delegate of the current comparer object (property DistanceFunction). More...
 
void Sort (List< PointContainerType > list)
 Sorts a list of point containers with the current comparer. More...
 
void SortUsingStoredDistance (List< PointContainerType > list)
 Sorts a list of point containers with the current comparer. More...
 

Protected Member Functions

virtual double OutputDistance (IVector outVec1, IVector outVec2)
 Returns output distance between two output vectors. More...
 
virtual double DefaultDistanceFunction (PointType pt1, PointType pt2)
 Default distance funciton for the current class, used when distance calculation delegate is not specified. More...
 

Protected Attributes

PointContainerType _referencePoint
 
DistanceDelegate< PointType > _distanceFunction
 
IVector _lengthScales = null
 
IVector _min = null
 
IVector _max = null
 
IVector _outputLengthScales = null
 
IVector _outputMin = null
 
IVector _outputMax = null
 

Properties

object Lock [get]
 This object's central lock object to be used by other object. Do not use this object for locking in class' methods, for this you should use InternalLock. More...
 
PointContainerType ReferencePoint [get, set]
 Reference point. More...
 
DistanceDelegate< PointType > DistanceFunction [get, set]
 Delegate that calculates distance between two vectors. More...
 
IVector LengthScales [protected get, set]
 Sets the vector of length scales that are used for calculation of distances. More...
 
IVector Min [protected get, set]
 Sets the vector of minimal values for point coordinates. Needed for calculation of relative coordinate vector. More...
 
IVector Max [protected get, set]
 Sets the vector of maximal values point coordinates. Needed for calculation of relative coordinate vector. More...
 
IVector OutputLengthScales [protected get, set]
 Sets the vector of OUTPUT vector's length scales that are used for calculation of distances and relative coordinates. More...
 
IVector OutputMin [protected get, set]
 Sets the vector of minimal values for point OUTPUT values. Needed for calculation of relative coordinate vector. More...
 
IVector OutputMax [protected get, set]
 Sets the vector of maximal values point OUTPUT values. Needed for calculation of relative coordinate vector. More...
 
IComparer< PointContainerType > StoredDistanceComparer [get]
 Gets comparer that compares two point containers of type PointContainerType by the stored distance stored on those points. More...
 
- Properties inherited from IG.Num.IDistanceComparer< PointContainerType, PointType >
PointContainerType ReferencePoint [get, set]
 Reference point. More...
 
IVector LengthScales [set]
 Sets the vector of length scales that are used for calculation of distances. More...
 
IVector Min [set]
 Sets the vector of minimal values for point coordinates. Needed for calculation of relative coordinate vector. More...
 
IVector Max [set]
 Sets the vector of maximal values point coordinates. Needed for calculation of relative coordinate vector. More...
 
IVector OutputLengthScales [set]
 Sets the vector of OUTPUT vector's length scales that are used for calculation of distances and relative coordinates. More...
 
IVector OutputMin [set]
 Sets the vector of minimal values for point OUTPUT values. Needed for calculation of relative coordinate vector. More...
 
IVector OutputMax [set]
 Sets the vector of maximal values point OUTPUT values. Needed for calculation of relative coordinate vector. More...
 
IComparer< PointContainerType > StoredDistanceComparer [get]
 Gets comparer that compares two point containers of type PointContainerType by the stored distance stored on those points. More...
 
- Properties inherited from IG.Lib.ILockable
object Lock [get]
 

Private Member Functions

 DistanceComparer ()
 

Private Attributes

object _mainLock = new object()
 
IComparer< PointContainerType > _storedDistanceComparer
 

Detailed Description

Class that is used to calculate and compare distances between point containers.

Template Parameters
PointTypeType of the point objects that have a point position in space, and whose containers of type PointContainer<PointType> are compared by the current class.
PointContainerTypeType of point container that is used to wrap points of the point type.

This class as a part of group of classes that have been created in 2008 in order to support different operations and algorithms on losely connected clouds of points that are embedded in space of arbitrary dimension. The primary intended application was in optimization algorithms based on successive approximations of response and on restricted step prototype algorithms, developed by the author. The scope is much broader, however, because these classes can support closest neighbors algorithms, various graph algorithms based on points in space, detection of clusters, etc.

In 2009, major refactoring has been performed where a more generic structure has been introduced, allowing implementation of generic algorithm methods that can be used with different representations of points.

In 2011, the classes weer migrated from sandbox environment to the prduction IGLib library and simplified a bit. The intention is to use the classes in the artificial neural network-based approximation modules developed for COBIK and the University of Nova Gorica. The intention is, however, that the eventual algorithms developed within this scope are implemented in a generic way, such that they can serve multiple purposes.

$A Igor Sep08 May09 Dec11;

Type Constraints
PointContainerType :IPointContainer<PointType> 

Constructor & Destructor Documentation

IG.Num.DistanceComparer< PointContainerType, PointType >.DistanceComparer ( )
inlineprivate
IG.Num.DistanceComparer< PointContainerType, PointType >.DistanceComparer ( PointContainerType  referencePoint,
DistanceDelegate< PointType >  distanceFunction 
)
inline

Constructs a new comparer according to input distance to a reference poiont (type IVector).

Parameters
referencePointReference point. Training elements are compared by their distance to this point.
distanceFunctionDelegate used for calculation of distance between two points.
immutableIf true then a copy of the reference point is stored internally rather than just its reference, so it can not be changed.
IG.Num.DistanceComparer< PointContainerType, PointType >.DistanceComparer ( PointContainerType  referencePoint,
DistanceDelegate< PointType >  distanceFunction,
IVector  lengthScales 
)
inline

Constructs a new comparer according to input distance to a reference poiont (type IVector).

Parameters
referencePointReference point. Training elements are compared by their distance to this point.
distanceFunctionDelegate used for calculation of distance between two points.
immutableIf true then a copy of the reference point is stored internally rather than just its reference, so it can not be changed.

Member Function Documentation

abstract void IG.Num.DistanceComparer< PointContainerType, PointType >.GetPointCoordinates ( PointType  pt,
ref IVector  coord 
)
pure virtual

Gets vector of coordinates of the specified point and stores it in the specified variable.

Where the type of point object itself contains vector of coordinates, only reference is stored. The obtained vector should therefore not be modified in any way.

Parameters
ptPoint for which vector of coordinates is obtained.
coordVector variable where extracted vector of coordinates is stored.

Implements IG.Num.IDistanceComparer< PointContainerType, PointType >.

void IG.Num.DistanceComparer< PointContainerType, PointType >.SetCoordinateScales ( IVector  min,
IVector  max,
IVector  lengthScales 
)
inline

Sets parameters that affect default calculation of distance and relative point coordinates.

Parameters
minVector of minimal coordinates.
maxVector of maximal coordinates.
lengthScalesVector of length scales.

Implements IG.Num.IDistanceComparer< PointContainerType, PointType >.

void IG.Num.DistanceComparer< PointContainerType, PointType >.GetRelativeCoordinates ( IVector  coord,
ref IVector  relativeCoortinates 
)
inline

Converts the specified coordinates to relative coordinates where compponents run from 0 to 1 if original coordinates run from minimal to maximal value.

Minimal coordinate values are stored in Min and maximal values are stored in Max.

Parameters
coordVector of original coordinates.
relativeCoortinatesVector where converted relative coordinates are stored.

Calculation of relative coordinates does not rely on the vector of length scales, but only on vectors of minimal and maximal coordinates.

Implements IG.Num.IDistanceComparer< PointContainerType, PointType >.

void IG.Num.DistanceComparer< PointContainerType, PointType >.SetOutputScales ( IVector  min,
IVector  max,
IVector  lengthScales 
)
inline

Sets parameters that affect default calculation of output distance and output relative coordinates.

Parameters
minVector of minimal output coordinates.
maxVector of maximal output coordinates.
lengthScalesVector of output length scales.

Implements IG.Num.IDistanceComparer< PointContainerType, PointType >.

void IG.Num.DistanceComparer< PointContainerType, PointType >.GetOutputRelativeCoordinates ( IVector  coord,
ref IVector  relativeCoortinates 
)
inline

Converts the specified OUTPUT coordinates to relative coordinates where compponents run from 0 to 1 if original coordinates run from minimal to maximal value.

Minimal OUTPUT coordinate values are stored in OutputMin and maximal values are stored in OutputMax.

Parameters
coordVector of original coordinates.
relativeCoortinatesVector where converted relative OUTPUT coordinates are stored.

Calculation of relative coordinates does not rely on the vector of length scales, but only on vectors of minimal and maximal coordinates.

This functionality is used only in those types of points that have input parameters and output values, such as approximation data points.

Implements IG.Num.IDistanceComparer< PointContainerType, PointType >.

virtual double IG.Num.DistanceComparer< PointContainerType, PointType >.OutputDistance ( PointContainerType  pt1,
PointContainerType  pt2 
)
inlinevirtual

Returns output distance between two point containers.

If vector of output scales (property OutputLengthScales) is specified then weighted Euclidean distance between output vectors of the specified containers is returned (differences in components are divided by components of vector output scaling lengths before being squared).

If vector of output length scales is not specified then usual Euclidean distance between coordinates of the two specified points is returned.

Parameters
pt1The first poiint container for distance calculation.
pt2The second point container for distance calculation.

This functionality is used only in those types of points that have input parameters and output values, such as approximation data points.

While definition of input distance (between point co-ordinates) can be defined by a delegate, definition of output distance is currenyly fixed, can not be modified (except by setting the vector of output length scales that affects the definition).

Implements IG.Num.IDistanceComparer< PointContainerType, PointType >.

virtual double IG.Num.DistanceComparer< PointContainerType, PointType >.OutputDistance ( IVector  outVec1,
IVector  outVec2 
)
inlineprotectedvirtual

Returns output distance between two output vectors.

If vector of output scales (property OutputLengthScales) is specified then weighted Euclidean distance between coordinates of the specified point is returned (differences in coordinates are divided by components of vector of scales before being squared).

If vector of output length scales is not specified then usual Euclidean distance between coordinates of the two specified points is returned.

Parameters
outVec1The first output vector for output distance calculation.
outVec2The second output vector for output distance calculation.

This functionality is used only in those types of points that have input parameters and output values, such as approximation data points.

While definition of input distance (between point co-ordinates) can be defined by a delegate, definition of output distance is currenyly fixed, can not be modified (except by setting the vector of output length scales that affects the definition).

References IG.Num.VectorBase.DistancePlain(), and IG.Num.VectorBase.DistanceWeightedPlain().

virtual double IG.Num.DistanceComparer< PointContainerType, PointType >.DefaultDistanceFunction ( PointType  pt1,
PointType  pt2 
)
inlineprotectedvirtual

Default distance funciton for the current class, used when distance calculation delegate is not specified.

If vector of length scales (property LengthScales) is specified then weighted Euclidean distance between coordinates of the specified point is returned (differences in coordinates are divided by components of this vector before being squared).

Iv vector of length scales is not specified then Euclidean distance between coordinates of the two specified points is returned.

Parameters
pt1The first poiint for distance calculation.
pt2The second point for distance calculation.

References IG.Num.VectorBase.DistancePlain(), and IG.Num.VectorBase.DistanceWeightedPlain().

virtual int IG.Num.DistanceComparer< PointContainerType, PointType >.Compare ( PointContainerType  pt1,
PointContainerType  pt2 
)
inlinevirtual

Compares two points according to the current comparer definition.

Parameters
pt1the first point to be compared.
pt2The second point to be compared.
Returns
A negative value if the first point is smaller, positive value if it is greater, and 0 if it is equal to the second point according to comparison criterion implemented by the current comparer object.

Reimplemented in IG.Num.DistanceComparer< PointContainerType, PointType >.StoredDistanceComparerClass.

virtual double IG.Num.DistanceComparer< PointContainerType, PointType >.Distance ( PointType  pt1,
PointType  pt2 
)
inlinevirtual

Returns distance between the specified two points.

Parameters
pt1The first point.
pt2The second point.

Distance is defined by the DistanceFunction property, which is a delegate of type DistanceDelegate<PointType>.

Implements IG.Num.IDistanceComparer< PointContainerType, PointType >.

double IG.Num.DistanceComparer< PointContainerType, PointType >.Distance ( PointContainerType  boxedPt1,
PointContainerType  boxedPt2 
)
inline

Returns distance between the specified two points enclosed in PointContainer objects, as defined by the distance calculation delegate (property DistanceFunction) of the current object.

Parameters
boxedPt1The first point.
boxedPt2The second point.

Implements IG.Num.IDistanceComparer< PointContainerType, PointType >.

double IG.Num.DistanceComparer< PointContainerType, PointType >.Distance ( PointContainerType  boxedPt1,
PointType  pt2 
)
inline

Returns distance between the specified point encolosed in an PointContainer object and a non-enclosed point, as defined by the distance calculation delegate (property DistanceFunction) of the current object.

Parameters
boxedPt1The first training element.
pt2The second training element.

Implements IG.Num.IDistanceComparer< PointContainerType, PointType >.

double IG.Num.DistanceComparer< PointContainerType, PointType >.Distance ( PointType  pt1,
PointContainerType  boxedPt2 
)
inline

Returns distance between the specified point and the second point encolosed in an PointContainer object, as defined by the distance calculation delegate (property DistanceFunction) of the current object.

Parameters
pt1The first point.
boxedPt2The second point enclosed in PointContainer<PointType> object.

Implements IG.Num.IDistanceComparer< PointContainerType, PointType >.

double IG.Num.DistanceComparer< PointContainerType, PointType >.Distance ( PointType  pt)
inline

Returns distance between the specified point and the reference point (property ReferencePoint) of the current object (enclosed in PointContainer<PointType> object), as defined by the distance calculation delegate of the current comparer object (property DistanceFunction).

Parameters
ptVector whose distance to the reference point is returned.

Implements IG.Num.IDistanceComparer< PointContainerType, PointType >.

double IG.Num.DistanceComparer< PointContainerType, PointType >.Distance ( PointContainerType  boxedPt)
inline

Returns distance between the specified point (enclosed in PointContainer<PointType> pbject) and the reference point (property ReferencePoint) of the current object (property ReferencePoint), as defined by the distance calculation delegate of the current comparer object (property DistanceFunction).

Parameters
ptPont enclosed in an PointContainer object whose distance to the reference point is returned.

Implements IG.Num.IDistanceComparer< PointContainerType, PointType >.

void IG.Num.DistanceComparer< PointContainerType, PointType >.Sort ( List< PointContainerType >  list)
inline

Sorts a list of point containers with the current comparer.

Parameters
listList of point containers to be sorted.

Implements IG.Num.IDistanceComparer< PointContainerType, PointType >.

void IG.Num.DistanceComparer< PointContainerType, PointType >.SortUsingStoredDistance ( List< PointContainerType >  list)
inline

Sorts a list of point containers with the current comparer.

Parameters
listList of point containers to be sorted.

Implements IG.Num.IDistanceComparer< PointContainerType, PointType >.

Member Data Documentation

object IG.Num.DistanceComparer< PointContainerType, PointType >._mainLock = new object()
private
PointContainerType IG.Num.DistanceComparer< PointContainerType, PointType >._referencePoint
protected
DistanceDelegate<PointType> IG.Num.DistanceComparer< PointContainerType, PointType >._distanceFunction
protected
IVector IG.Num.DistanceComparer< PointContainerType, PointType >._lengthScales = null
protected
IVector IG.Num.DistanceComparer< PointContainerType, PointType >._min = null
protected
IVector IG.Num.DistanceComparer< PointContainerType, PointType >._max = null
protected
IVector IG.Num.DistanceComparer< PointContainerType, PointType >._outputLengthScales = null
protected
IVector IG.Num.DistanceComparer< PointContainerType, PointType >._outputMin = null
protected
IVector IG.Num.DistanceComparer< PointContainerType, PointType >._outputMax = null
protected
IComparer<PointContainerType> IG.Num.DistanceComparer< PointContainerType, PointType >._storedDistanceComparer
private

Property Documentation

object IG.Num.DistanceComparer< PointContainerType, PointType >.Lock
get

This object's central lock object to be used by other object. Do not use this object for locking in class' methods, for this you should use InternalLock.

PointContainerType IG.Num.DistanceComparer< PointContainerType, PointType >.ReferencePoint
getset

Reference point.

Points are compared with respect to the distance to this point.

DistanceDelegate<PointType> IG.Num.DistanceComparer< PointContainerType, PointType >.DistanceFunction
getsetprotected

Delegate that calculates distance between two vectors.

If set to nul then default distance function (DefaultDistanceFunction) is used for distance calculation.

IVector IG.Num.DistanceComparer< PointContainerType, PointType >.LengthScales
protected getset

Sets the vector of length scales that are used for calculation of distances.

Property has protected setter.

IVector IG.Num.DistanceComparer< PointContainerType, PointType >.Min
protected getset

Sets the vector of minimal values for point coordinates. Needed for calculation of relative coordinate vector.

Property has protected setter.

IVector IG.Num.DistanceComparer< PointContainerType, PointType >.Max
protected getset

Sets the vector of maximal values point coordinates. Needed for calculation of relative coordinate vector.

Property has protected setter.

IVector IG.Num.DistanceComparer< PointContainerType, PointType >.OutputLengthScales
protected getset

Sets the vector of OUTPUT vector's length scales that are used for calculation of distances and relative coordinates.

Property has protected setter.

This functionality is used only in those types of points that have input parameters and output values, such as approximation data points.

IVector IG.Num.DistanceComparer< PointContainerType, PointType >.OutputMin
protected getset

Sets the vector of minimal values for point OUTPUT values. Needed for calculation of relative coordinate vector.

Property has protected setter.

This functionality is used only in those types of points that have input parameters and output values, such as approximation data points.

IVector IG.Num.DistanceComparer< PointContainerType, PointType >.OutputMax
protected getset

Sets the vector of maximal values point OUTPUT values. Needed for calculation of relative coordinate vector.

Property has protected setter.

This functionality is used only in those types of points that have input parameters and output values, such as approximation data points.

IComparer<PointContainerType> IG.Num.DistanceComparer< PointContainerType, PointType >.StoredDistanceComparer
get

Gets comparer that compares two point containers of type PointContainerType by the stored distance stored on those points.


The documentation for this class was generated from the following file: