SHOGUN  v1.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
List of all members | Public Member Functions | Protected Member Functions | Protected Attributes
CCustomDistance Class Reference

Detailed Description

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.

Inheritance diagram for CCustomDistance:
Inheritance graph
[legend]

Public Member Functions

 CCustomDistance ()
 CCustomDistance (CDistance *d)
 CCustomDistance (const SGMatrix< float64_t > distance_matrix)
 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 ()
- Public Member Functions inherited from CDistance
 CDistance ()
 CDistance (CFeatures *lhs, CFeatures *rhs)
virtual ~CDistance ()
float64_t distance (int32_t idx_a, int32_t idx_b)
SGMatrix< float64_tget_distance_matrix ()
virtual float64_tget_distance_matrix_real (int32_t &m, int32_t &n, float64_t *target)
virtual float32_tget_distance_matrix_shortreal (int32_t &m, int32_t &n, float32_t *target)
void load (CFile *loader)
void save (CFile *writer)
CFeaturesget_lhs ()
CFeaturesget_rhs ()
CFeaturesreplace_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
bool get_precompute_matrix ()
virtual void set_precompute_matrix (bool flag)
bool lhs_equals_rhs ()
- Public Member Functions inherited from CSGObject
 CSGObject ()
 CSGObject (const CSGObject &orig)
virtual ~CSGObject ()
virtual bool is_generic (EPrimitiveType *generic) const
template<class T >
void set_generic ()
void unset_generic ()
virtual void print_serializable (const char *prefix="")
virtual bool save_serializable (CSerializableFile *file, const char *prefix="")
virtual bool load_serializable (CSerializableFile *file, const char *prefix="")
void set_global_io (SGIO *io)
SGIOget_global_io ()
void set_global_parallel (Parallel *parallel)
Parallelget_global_parallel ()
void set_global_version (Version *version)
Versionget_global_version ()
SGVector< char * > get_modelsel_names ()
char * get_modsel_param_descr (const char *param_name)
index_t get_modsel_param_index (const char *param_name)

Protected Member Functions

virtual float64_t compute (int32_t row, int32_t col)
- Protected Member Functions inherited from CDistance
void do_precompute_matrix ()
 matrix precomputation
- Protected Member Functions inherited from CSGObject
virtual void load_serializable_pre () throw (ShogunException)
virtual void load_serializable_post () throw (ShogunException)
virtual void save_serializable_pre () throw (ShogunException)
virtual void save_serializable_post () throw (ShogunException)

Protected Attributes

float32_tdmatrix
int32_t num_rows
int32_t num_cols
bool upper_diagonal
- Protected Attributes inherited from CDistance
float32_tprecomputed_matrix
bool precompute_matrix
CFeatureslhs
 feature vectors to occur on left hand side
CFeaturesrhs
 feature vectors to occur on right hand side

Additional Inherited Members

- Public Attributes inherited from CSGObject
SGIOio
Parallelparallel
Versionversion
Parameterm_parameters
Parameterm_model_selection_parameters
- Static Protected Member Functions inherited from CDistance
static void * run_distance_thread (void *p)
 run distance thread

Constructor & Destructor Documentation

default constructor

Definition at line 20 of file CustomDistance.cpp.

constructor

compute custom distance from given distance matrix

Parameters
ddistance matrix

Definition at line 25 of file CustomDistance.cpp.

CCustomDistance ( const SGMatrix< float64_t distance_matrix)

constructor

Parameters
distance_matrixdistance matrix

Definition at line 66 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)

Parameters
dmdistance matrix
rowsnumber of rows in matrix
colsnumber of cols in matrix
Returns
if setting was successful

Definition at line 75 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)

Parameters
dmdistance matrix
rowsnumber of rows in matrix
colsnumber of cols in matrix
Returns
if setting was successful

Definition at line 82 of file CustomDistance.cpp.

~CCustomDistance ( )
virtual

Definition at line 89 of file CustomDistance.cpp.

Member Function Documentation

void cleanup ( )
virtual

clean up distance

Implements CDistance.

Definition at line 131 of file CustomDistance.cpp.

virtual float64_t compute ( int32_t  row,
int32_t  col 
)
protectedvirtual

compute distance function

Parameters
rowrow
colcol
Returns
computed distance function

Implements CDistance.

Definition at line 363 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

Parameters
rowsfeatures of left-hand side
colsfeatures of right-hand side
Returns
if initializing was successful

Definition at line 94 of file CustomDistance.cpp.

virtual EDistanceType get_distance_type ( )
virtual

return what type of distance we are

Returns
distance type CUSTOM

Implements CDistance.

Definition at line 102 of file CustomDistance.h.

virtual EFeatureClass get_feature_class ( )
virtual

return feature class the distance can deal with

Returns
feature class ANY

Implements CDistance.

Definition at line 114 of file CustomDistance.h.

virtual EFeatureType get_feature_type ( )
virtual

return feature type the distance can deal with

Returns
feature type ANY

Implements CDistance.

Definition at line 108 of file CustomDistance.h.

virtual const char* get_name ( ) const
virtual

return the distance's name

Returns
name Custom

Implements CSGObject.

Definition at line 120 of file CustomDistance.h.

virtual int32_t get_num_vec_lhs ( )
virtual

get number of vectors of lhs features

Returns
number of vectors of left-hand side

Reimplemented from CDistance.

Definition at line 333 of file CustomDistance.h.

virtual int32_t get_num_vec_rhs ( )
virtual

get number of vectors of rhs features

Returns
number of vectors of right-hand side

Reimplemented from CDistance.

Definition at line 342 of file CustomDistance.h.

virtual bool has_features ( )
virtual

test whether features have been assigned to lhs and rhs

Returns
true if features are assigned

Reimplemented from CDistance.

Definition at line 351 of file CustomDistance.h.

bool init ( CFeatures l,
CFeatures r 
)
virtual

initialize distance

Parameters
lfeatures of left-hand side
rfeatures of right-hand side
Returns
if initializing was successful

Reimplemented from CDistance.

Definition at line 99 of file CustomDistance.cpp.

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

Parameters
dmdistance matrix
rowsnumber of rows in matrix
colsnumber of cols in matrix
Returns
if setting was successful

Definition at line 276 of file CustomDistance.h.

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

Parameters
dmdistance matrix
rowsnumber of rows in matrix
colsnumber of cols in matrix
Returns
if setting was successful

Definition at line 291 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

Parameters
dmdistance matrix
rowsnumber of rows in matrix
colsnumber of cols in matrix
Returns
if setting was successful

Definition at line 305 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

Parameters
dmdistance matrix
rowsnumber of rows in matrix
colsnumber of cols in matrix
Returns
if setting was successful

Definition at line 210 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

Parameters
dmdistance matrix
rowsnumber of rows in matrix
colsnumber of cols in matrix
Returns
if setting was successful

Definition at line 226 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

Parameters
dmdistance matrix
rowsnumber of rows in matrix
colsnumber of cols in matrix
Returns
if setting was successful

Definition at line 241 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

Parameters
dmdistance matrix
lendenotes the size of the array and should match len=cols*(cols+1)/2
Returns
if setting was successful

Definition at line 132 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

Parameters
dmdistance matrix
lendenotes the size of the array and should match len=cols*(cols+1)/2
Returns
if setting was successful

Definition at line 148 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

Parameters
dmdistance matrix
lendenotes the size of the array and should match len=cols*(cols+1)/2
Returns
if setting was successful

Definition at line 165 of file CustomDistance.h.

Member Data Documentation

float32_t* dmatrix
protected

distance matrix

Definition at line 395 of file CustomDistance.h.

int32_t num_cols
protected

number of columns

Definition at line 399 of file CustomDistance.h.

int32_t num_rows
protected

number of rows

Definition at line 397 of file CustomDistance.h.

bool upper_diagonal
protected

upper diagonal

Definition at line 401 of file CustomDistance.h.


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

SHOGUN Machine Learning Toolbox - Documentation