The Custom Distance allows for custom user provided distance matrices.
For squared training matrices it allows to store only the upper triangle of the distance to save memory: Full symmetric distance matrices can be stored as is or can be internally converted into (or directly given in) upper triangle representation. Also note that values are stored as 32bit floats.
Definition at line 29 of file CustomDistance.h.
Public Member Functions | |
CCustomDistance () | |
CCustomDistance (CDistance *d) | |
CCustomDistance (const float64_t *dm, int32_t rows, int32_t cols) | |
CCustomDistance (const float32_t *dm, int32_t rows, int32_t cols) | |
virtual | ~CCustomDistance () |
virtual bool | dummy_init (int32_t rows, int32_t cols) |
virtual bool | init (CFeatures *l, CFeatures *r) |
virtual void | cleanup () |
virtual EDistanceType | get_distance_type () |
virtual EFeatureType | get_feature_type () |
virtual EFeatureClass | get_feature_class () |
virtual const char * | get_name () const |
bool | set_triangle_distance_matrix_from_triangle (const float64_t *dm, int32_t len) |
bool | set_triangle_distance_matrix_from_triangle (const float32_t *dm, int32_t len) |
template<class T > | |
bool | set_triangle_distance_matrix_from_triangle_generic (const T *dm, int64_t len) |
bool | set_triangle_distance_matrix_from_full (const float64_t *dm, int32_t rows, int32_t cols) |
bool | set_triangle_distance_matrix_from_full (const float32_t *dm, int32_t rows, int32_t cols) |
template<class T > | |
bool | set_triangle_distance_matrix_from_full_generic (const T *dm, int32_t rows, int32_t cols) |
bool | set_full_distance_matrix_from_full (const float64_t *dm, int32_t rows, int32_t cols) |
bool | set_full_distance_matrix_from_full (const float32_t *dm, int32_t rows, int32_t cols) |
template<class T > | |
bool | set_full_distance_matrix_from_full_generic (const T *dm, int32_t rows, int32_t cols) |
virtual int32_t | get_num_vec_lhs () |
virtual int32_t | get_num_vec_rhs () |
virtual bool | has_features () |
Protected Member Functions | |
virtual float64_t | compute (int32_t row, int32_t col) |
Protected Attributes | |
float32_t * | dmatrix |
int32_t | num_rows |
int32_t | num_cols |
bool | upper_diagonal |
CCustomDistance | ( | ) |
default constructor
Definition at line 19 of file CustomDistance.cpp.
CCustomDistance | ( | CDistance * | d | ) |
constructor
compute custom distance from given distance matrix
d | distance matrix |
Definition at line 24 of file CustomDistance.cpp.
CCustomDistance | ( | const float64_t * | dm, | |
int32_t | rows, | |||
int32_t | cols | |||
) |
constructor
sets full distance matrix from full distance matrix (from double precision floats)
dm | distance matrix | |
rows | number of rows in matrix | |
cols | number of cols in matrix |
Definition at line 65 of file CustomDistance.cpp.
CCustomDistance | ( | const float32_t * | dm, | |
int32_t | rows, | |||
int32_t | cols | |||
) |
constructor
sets full distance matrix from full distance matrix (from single precision floats)
dm | distance matrix | |
rows | number of rows in matrix | |
cols | number of cols in matrix |
Definition at line 72 of file CustomDistance.cpp.
~CCustomDistance | ( | ) | [virtual] |
Definition at line 79 of file CustomDistance.cpp.
void cleanup | ( | ) | [virtual] |
virtual float64_t compute | ( | int32_t | row, | |
int32_t | col | |||
) | [protected, virtual] |
compute distance function
row | row | |
col | col |
Implements CDistance.
Definition at line 358 of file CustomDistance.h.
bool dummy_init | ( | int32_t | rows, | |
int32_t | cols | |||
) | [virtual] |
initialize distance with dummy features
Distances always need feature objects assigned. As the custom distance does not really require this it creates some magic dummy features that only know about the number of vectors
rows | features of left-hand side | |
cols | features of right-hand side |
Definition at line 84 of file CustomDistance.cpp.
virtual EDistanceType get_distance_type | ( | ) | [virtual] |
return what type of distance we are
Implements CDistance.
Definition at line 97 of file CustomDistance.h.
virtual EFeatureClass get_feature_class | ( | ) | [virtual] |
return feature class the distance can deal with
Implements CDistance.
Definition at line 109 of file CustomDistance.h.
virtual EFeatureType get_feature_type | ( | ) | [virtual] |
return feature type the distance can deal with
Implements CDistance.
Definition at line 103 of file CustomDistance.h.
virtual const char* get_name | ( | void | ) | const [virtual] |
return the distance's name
Implements CSGObject.
Definition at line 115 of file CustomDistance.h.
virtual int32_t get_num_vec_lhs | ( | ) | [virtual] |
get number of vectors of lhs features
Reimplemented from CDistance.
Definition at line 328 of file CustomDistance.h.
virtual int32_t get_num_vec_rhs | ( | ) | [virtual] |
get number of vectors of rhs features
Reimplemented from CDistance.
Definition at line 337 of file CustomDistance.h.
virtual bool has_features | ( | ) | [virtual] |
test whether features have been assigned to lhs and rhs
Reimplemented from CDistance.
Definition at line 346 of file CustomDistance.h.
initialize distance
l | features of left-hand side | |
r | features of right-hand side |
Reimplemented from CDistance.
Definition at line 89 of file CustomDistance.cpp.
bool set_full_distance_matrix_from_full | ( | const float32_t * | dm, | |
int32_t | rows, | |||
int32_t | cols | |||
) |
set full distance matrix from full distance matrix
for float32's
dm | distance matrix | |
rows | number of rows in matrix | |
cols | number of cols in matrix |
Definition at line 286 of file CustomDistance.h.
bool set_full_distance_matrix_from_full | ( | const float64_t * | dm, | |
int32_t | rows, | |||
int32_t | cols | |||
) |
set full distance matrix from full distance matrix
for float64's
dm | distance matrix | |
rows | number of rows in matrix | |
cols | number of cols in matrix |
Definition at line 271 of file CustomDistance.h.
bool set_full_distance_matrix_from_full_generic | ( | const T * | dm, | |
int32_t | rows, | |||
int32_t | cols | |||
) |
set full distance matrix from full distance matrix
dm | distance matrix | |
rows | number of rows in matrix | |
cols | number of cols in matrix |
Definition at line 300 of file CustomDistance.h.
bool set_triangle_distance_matrix_from_full | ( | const float64_t * | dm, | |
int32_t | rows, | |||
int32_t | cols | |||
) |
set distance matrix (only elements from upper triangle) from squared matrix
for float64's
dm | distance matrix | |
rows | number of rows in matrix | |
cols | number of cols in matrix |
Definition at line 205 of file CustomDistance.h.
bool set_triangle_distance_matrix_from_full | ( | const float32_t * | dm, | |
int32_t | rows, | |||
int32_t | cols | |||
) |
set distance matrix (only elements from upper triangle) from squared matrix
for float32's
dm | distance matrix | |
rows | number of rows in matrix | |
cols | number of cols in matrix |
Definition at line 221 of file CustomDistance.h.
bool set_triangle_distance_matrix_from_full_generic | ( | const T * | dm, | |
int32_t | rows, | |||
int32_t | cols | |||
) |
set distance matrix (only elements from upper triangle) from squared matrix
dm | distance matrix | |
rows | number of rows in matrix | |
cols | number of cols in matrix |
Definition at line 236 of file CustomDistance.h.
bool set_triangle_distance_matrix_from_triangle | ( | const float32_t * | dm, | |
int32_t | len | |||
) |
set distance matrix (only elements from upper triangle) from elements of upper triangle (concat'd), including the main diagonal
small variant for floats32's, triangle needs to have less than 2**32 elements
dm | distance matrix | |
len | denotes the size of the array and should match len=cols*(cols+1)/2 |
Definition at line 143 of file CustomDistance.h.
bool set_triangle_distance_matrix_from_triangle | ( | const float64_t * | dm, | |
int32_t | len | |||
) |
set distance matrix (only elements from upper triangle) from elements of upper triangle (concat'd), including the main diagonal
small variant for floats64's, triangle needs to have less than 2**32 elements
dm | distance matrix | |
len | denotes the size of the array and should match len=cols*(cols+1)/2 |
Definition at line 127 of file CustomDistance.h.
bool set_triangle_distance_matrix_from_triangle_generic | ( | const T * | dm, | |
int64_t | len | |||
) |
set distance matrix (only elements from upper triangle) from elements of upper triangle (concat'd), including the main diagonal
big variant, allowing the triangle to have more than 2**31-1 elements
dm | distance matrix | |
len | denotes the size of the array and should match len=cols*(cols+1)/2 |
Definition at line 160 of file CustomDistance.h.
distance matrix
Definition at line 390 of file CustomDistance.h.
int32_t num_cols [protected] |
number of columns
Definition at line 394 of file CustomDistance.h.
int32_t num_rows [protected] |
number of rows
Definition at line 392 of file CustomDistance.h.
bool upper_diagonal [protected] |
upper diagonal
Definition at line 396 of file CustomDistance.h.