Class Distance, a base class for all the distances used in the Shogun toolbox.
The distance (or metric) is a function satisfying (for all
) conditions below:
Currently distance inherited from the CDistance class should be symmetric.
The simpliest example of a distance function is the euclidian distance:
In the means of Shogun toolbox the distance function is defined on the 'space' of CFeatures.
Definition at line 79 of file Distance.h.
Public Member Functions | |
CDistance () | |
CDistance (CFeatures *lhs, CFeatures *rhs) | |
virtual | ~CDistance () |
float64_t | distance (int32_t idx_a, int32_t idx_b) |
SGMatrix< float64_t > | get_distance_matrix () |
virtual float64_t * | get_distance_matrix_real (int32_t &m, int32_t &n, float64_t *target) |
virtual float32_t * | get_distance_matrix_shortreal (int32_t &m, int32_t &n, float32_t *target) |
virtual bool | init (CFeatures *lhs, CFeatures *rhs) |
virtual void | cleanup ()=0 |
void | load (CFile *loader) |
void | save (CFile *writer) |
CFeatures * | get_lhs () |
CFeatures * | get_rhs () |
CFeatures * | replace_rhs (CFeatures *rhs) |
virtual void | remove_lhs_and_rhs () |
virtual void | remove_lhs () |
takes all necessary steps if the lhs is removed from distance matrix | |
virtual void | remove_rhs () |
takes all necessary steps if the rhs is removed from distance matrix | |
virtual EDistanceType | get_distance_type ()=0 |
virtual EFeatureType | get_feature_type ()=0 |
virtual EFeatureClass | get_feature_class ()=0 |
bool | get_precompute_matrix () |
virtual void | set_precompute_matrix (bool flag) |
int32_t | get_num_vec_lhs () |
int32_t | get_num_vec_rhs () |
bool | has_features () |
bool | lhs_equals_rhs () |
Protected Member Functions | |
virtual float64_t | compute (int32_t x, int32_t y)=0 |
void | do_precompute_matrix () |
matrix precomputation | |
Static Protected Member Functions | |
static void * | run_distance_thread (void *p) |
run distance thread | |
Protected Attributes | |
float32_t * | precomputed_matrix |
bool | precompute_matrix |
CFeatures * | lhs |
feature vectors to occur on left hand side | |
CFeatures * | rhs |
feature vectors to occur on right hand side |
CDistance | ( | ) |
default constructor
Definition at line 56 of file Distance.cpp.
init distance
lhs | features of left-hand side | |
rhs | features of right-hand side |
Definition at line 62 of file Distance.cpp.
~CDistance | ( | ) | [virtual] |
Definition at line 68 of file Distance.cpp.
virtual void cleanup | ( | ) | [pure virtual] |
cleanup distance
abstract base method
Implemented in CAttenuatedEuclidianDistance, CBrayCurtisDistance, CCanberraMetric, CCanberraWordDistance, CChebyshewMetric, CChiSquareDistance, CCosineDistance, CCustomDistance, CEuclidianDistance, CGeodesicMetric, CHammingWordDistance, CJensenMetric, CKernelDistance, CManhattanMetric, CManhattanWordDistance, CMinkowskiMetric, CRealDistance, CSimpleDistance< ST >, CSparseDistance< ST >, CSparseEuclidianDistance, CStringDistance< ST >, CTanimotoDistance, CSimpleDistance< float64_t >, CSparseDistance< float64_t >, and CStringDistance< uint16_t >.
virtual float64_t compute | ( | int32_t | x, | |
int32_t | y | |||
) | [protected, pure virtual] |
compute distance function for features a and b idx_{a,b} denote the index of the feature vectors in the corresponding feature object
Implemented in CAttenuatedEuclidianDistance, CBrayCurtisDistance, CCanberraMetric, CCanberraWordDistance, CChebyshewMetric, CChiSquareDistance, CCosineDistance, CCustomDistance, CEuclidianDistance, CGeodesicMetric, CHammingWordDistance, CJensenMetric, CKernelDistance, CManhattanMetric, CManhattanWordDistance, CMinkowskiMetric, CRealDistance, CSparseEuclidianDistance, and CTanimotoDistance.
float64_t distance | ( | int32_t | idx_a, | |
int32_t | idx_b | |||
) |
get distance function for lhs feature vector a and rhs feature vector b
idx_a | feature vector a at idx_a | |
idx_b | feature vector b at idx_b |
Definition at line 101 of file Distance.h.
void do_precompute_matrix | ( | ) | [protected] |
matrix precomputation
Definition at line 157 of file Distance.cpp.
get distance matrix
Definition at line 181 of file Distance.cpp.
get distance matrix real
m | dimension m | |
n | dimension n | |
target | target matrix |
Definition at line 257 of file Distance.cpp.
float32_t * get_distance_matrix_shortreal | ( | int32_t & | m, | |
int32_t & | n, | |||
float32_t * | target | |||
) | [virtual] |
get distance matrix short real
m | dimension m | |
n | dimension n | |
target | target matrix |
Definition at line 188 of file Distance.cpp.
virtual EDistanceType get_distance_type | ( | ) | [pure virtual] |
get distance type we are
abstrace base method
Implemented in CAttenuatedEuclidianDistance, CBrayCurtisDistance, CCanberraMetric, CCanberraWordDistance, CChebyshewMetric, CChiSquareDistance, CCosineDistance, CCustomDistance, CEuclidianDistance, CGeodesicMetric, CHammingWordDistance, CJensenMetric, CKernelDistance, CManhattanMetric, CManhattanWordDistance, CMinkowskiMetric, CRealDistance, CSimpleDistance< ST >, CSparseDistance< ST >, CSparseEuclidianDistance, CStringDistance< ST >, CTanimotoDistance, CSimpleDistance< float64_t >, CSparseDistance< float64_t >, and CStringDistance< uint16_t >.
virtual EFeatureClass get_feature_class | ( | ) | [pure virtual] |
get feature class the distance can deal with
abstract base method
Implemented in CCustomDistance, CKernelDistance, CSimpleDistance< ST >, CSparseDistance< ST >, CStringDistance< ST >, CSimpleDistance< float64_t >, CSparseDistance< float64_t >, and CStringDistance< uint16_t >.
virtual EFeatureType get_feature_type | ( | ) | [pure virtual] |
get feature type the distance can deal with
abstrace base method
Implemented in CAttenuatedEuclidianDistance, CCustomDistance, CEuclidianDistance, CKernelDistance, CRealDistance, CSimpleDistance< ST >, CSparseDistance< ST >, CSparseEuclidianDistance, CStringDistance< ST >, CSimpleDistance< float64_t >, CSparseDistance< float64_t >, CStringDistance< uint16_t >, CSimpleDistance< ST >, CSimpleDistance< ST >, CSimpleDistance< ST >, CSimpleDistance< ST >, CSimpleDistance< ST >, CSimpleDistance< ST >, CSimpleDistance< ST >, CSparseDistance< ST >, CSparseDistance< ST >, CSparseDistance< ST >, CSparseDistance< ST >, CSparseDistance< ST >, CSparseDistance< ST >, CSparseDistance< ST >, CStringDistance< ST >, CStringDistance< ST >, CStringDistance< ST >, CStringDistance< ST >, CStringDistance< ST >, CStringDistance< ST >, and CStringDistance< ST >.
CFeatures* get_lhs | ( | ) |
get left-hand side features used in distance matrix
Definition at line 196 of file Distance.h.
int32_t get_num_vec_lhs | ( | ) |
get number of vectors of lhs features
Reimplemented in CCustomDistance.
Definition at line 274 of file Distance.h.
int32_t get_num_vec_rhs | ( | ) |
get number of vectors of rhs features
Reimplemented in CCustomDistance.
Definition at line 286 of file Distance.h.
bool get_precompute_matrix | ( | ) |
FIXME: precompute matrix should be dropped, handling should be via customdistance
Definition at line 252 of file Distance.h.
CFeatures* get_rhs | ( | ) |
get right-hand side features used in distance matrix
Definition at line 202 of file Distance.h.
bool has_features | ( | ) |
test whether features have been assigned to lhs and rhs
Reimplemented in CCustomDistance.
Definition at line 298 of file Distance.h.
init distance
make sure to check that your distance can deal with the supplied features (!)
lhs | features of left-hand side | |
rhs | features of right-hand side |
Reimplemented in CAttenuatedEuclidianDistance, CBrayCurtisDistance, CCanberraMetric, CCanberraWordDistance, CChebyshewMetric, CChiSquareDistance, CCosineDistance, CCustomDistance, CEuclidianDistance, CGeodesicMetric, CHammingWordDistance, CJensenMetric, CKernelDistance, CManhattanMetric, CManhattanWordDistance, CMinkowskiMetric, CRealDistance, CSimpleDistance< ST >, CSparseDistance< ST >, CSparseEuclidianDistance, CStringDistance< ST >, CTanimotoDistance, CSimpleDistance< float64_t >, CSparseDistance< float64_t >, and CStringDistance< uint16_t >.
Definition at line 76 of file Distance.cpp.
bool lhs_equals_rhs | ( | ) |
test whether features on lhs and rhs are the same
Definition at line 307 of file Distance.h.
void load | ( | CFile * | loader | ) |
load the kernel matrix
loader | File object via which to load data |
Definition at line 102 of file Distance.cpp.
void remove_lhs | ( | ) | [virtual] |
takes all necessary steps if the lhs is removed from distance matrix
Definition at line 123 of file Distance.cpp.
void remove_lhs_and_rhs | ( | ) | [virtual] |
remove lhs and rhs from distance
Definition at line 114 of file Distance.cpp.
void remove_rhs | ( | ) | [virtual] |
takes all necessary steps if the rhs is removed from distance matrix
takes all necessary steps if the rhs is removed from kernel
Definition at line 130 of file Distance.cpp.
replace right-hand side features used in distance matrix
make sure to check that your distance can deal with the supplied features (!)
rhs | features of right-hand side |
Definition at line 136 of file Distance.cpp.
void * run_distance_thread | ( | void * | p | ) | [static, protected] |
run distance thread
Definition at line 355 of file Distance.cpp.
void save | ( | CFile * | writer | ) |
save kernel matrix
writer | File object via which to save data |
Definition at line 108 of file Distance.cpp.
virtual void set_precompute_matrix | ( | bool | flag | ) | [virtual] |
FIXME: precompute matrix should be dropped, handling should be via customdistance
flag | if precompute_matrix |
Definition at line 259 of file Distance.h.
feature vectors to occur on left hand side
Definition at line 340 of file Distance.h.
bool precompute_matrix [protected] |
FIXME: precompute matrix should be dropped, handling should be via customdistance
Definition at line 337 of file Distance.h.
float32_t* precomputed_matrix [protected] |
FIXME: precompute matrix should be dropped, handling should be via customdistance
Definition at line 332 of file Distance.h.
feature vectors to occur on right hand side
Definition at line 342 of file Distance.h.