latest version v1.9 - last update 10 Apr 2010 |
Policy class used by several classifiers/trees to measure the square of the euclidian distance between two points of type T. More...
#include <ltiL2Distance.h>
Public Types | |
typedef D | distance_type |
Public Member Functions | |
distance_type | operator() (const T &a, const T &b) const |
Special methods for Minkowski distances | |
void | accumulate (const distance_type element, distance_type &accumulator) const |
void | accumulate (const typename T::value_type element1, const typename T::value_type element2, distance_type &accumulator) const |
distance_type | computeDistance (const distance_type &accumulator) const |
distance_type | component (const typename T::value_type element1, const typename T::value_type element2) const |
bool | accLessThan (const distance_type acc, const distance_type dist) const |
bool | accGreaterThan (const distance_type acc, const distance_type dist) const |
Policy class used by several classifiers/trees to measure the square of the euclidian distance between two points of type T.
The type T MUST define the value_type type, which exist for example for vectors, (t)points and (t)rgbPixels.
If you really want, you can use this class directly through the operator().
l2SquareDistantor< vector<double> > myDist; dvector a,b; ... // fill vectors with data double dist = myDist(a,b);
But remember that there is also a global template function distanceSqr() which is easier to use:
dvector a,b; ... // fill vectors with data double dist = distanceSqr(a,b);
You can of course also use the lti::l2Distance functor, as usual with its apply() methods.
typedef D lti::l2SquareDistantor< T, D >::distance_type |
type returned by the distantor
bool lti::l2SquareDistantor< T, D >::accGreaterThan | ( | const distance_type | acc, | |
const distance_type | dist | |||
) | const [inline] |
Return true if the given partial computed from accumulator is greater than the given distance.
Assume you have accumulated acc until now, and you want to check if the partial distance derived from this accumulator is greater than the given distance. So you check accLessThan(accumulator,distance)
For this norm it computes acc > dist
bool lti::l2SquareDistantor< T, D >::accLessThan | ( | const distance_type | acc, | |
const distance_type | dist | |||
) | const [inline] |
Return true if the given partial computed from accumulator is less than the given distance.
Assume you have accumulated acc until now, and you want to check if the partial distance derived from this accumulator is less than the given distance. So you check accLessThan(accumulator,distance)
For this norm it computes acc < dist
void lti::l2SquareDistantor< T, D >::accumulate | ( | const typename T::value_type | element1, | |
const typename T::value_type | element2, | |||
distance_type & | accumulator | |||
) | const [inline] |
This member accumulates in the given accumulator, the difference of the given elements.
It can be used when the distance need to be computed manually, but using a distantor to still allow the flexibility of changing distances.
For the l2SquareDistantor this is just acc+=((elem1-elem2)^2).
element1 | component of the first point | |
element2 | component of the second point | |
accumulator | variable where the elements will be accumulated. |
void lti::l2SquareDistantor< T, D >::accumulate | ( | const distance_type | element, | |
distance_type & | accumulator | |||
) | const [inline] |
This member accumulates in the given accumulator, the given element.
It can be used when the distance need to be computed manually, but using a distantor to still allow the flexibility of changing distances.
For the l2SquareDistantor this is just acc+=(elem*elem).
element | component of the difference between two points. | |
accumulator | variable where the elements will be accumulated. |
distance_type lti::l2SquareDistantor< T, D >::component | ( | const typename T::value_type | element1, | |
const typename T::value_type | element2 | |||
) | const [inline] |
return the distance between two components, which is in some way a component of the total distance (that is the reason for the name).
For this distantor it return (element2-element1)^2
distance_type lti::l2SquareDistantor< T, D >::computeDistance | ( | const distance_type & | accumulator | ) | const [inline] |
Compute from the given accumulator the desired distance.
distance_type lti::l2SquareDistantor< T, D >::operator() | ( | const T & | a, | |
const T & | b | |||
) | const [inline] |
compute the distance between a and b