Public Member Functions | Protected Member Functions | Protected Attributes

CCustomKernel Class Reference


Detailed Description

The Custom Kernel allows for custom user provided kernel matrices.

For squared training matrices it allows to store only the upper triangle of the kernel to save memory: Full symmetric kernel 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 CustomKernel.h.

Inheritance diagram for CCustomKernel:
Inheritance graph
[legend]

List of all members.

Public Member Functions

 CCustomKernel ()
 CCustomKernel (CKernel *k)
 CCustomKernel (const float64_t *km, int32_t rows, int32_t cols)
 CCustomKernel (const float32_t *km, int32_t rows, int32_t cols)
virtual ~CCustomKernel ()
virtual bool dummy_init (int32_t rows, int32_t cols)
virtual bool init (CFeatures *l, CFeatures *r)
virtual void cleanup ()
virtual EKernelType get_kernel_type ()
virtual EFeatureType get_feature_type ()
virtual EFeatureClass get_feature_class ()
virtual const char * get_name () const
bool set_triangle_kernel_matrix_from_triangle (const float64_t *km, int32_t len)
bool set_triangle_kernel_matrix_from_triangle (const float32_t *km, int32_t len)
template<class T >
bool set_triangle_kernel_matrix_from_triangle_generic (const T *km, int64_t len)
bool set_triangle_kernel_matrix_from_full (const float64_t *km, int32_t rows, int32_t cols)
bool set_triangle_kernel_matrix_from_full (const float32_t *km, int32_t rows, int32_t cols)
template<class T >
bool set_triangle_kernel_matrix_from_full_generic (const T *km, int32_t rows, int32_t cols)
bool set_full_kernel_matrix_from_full (const float64_t *km, int32_t rows, int32_t cols)
bool set_full_kernel_matrix_from_full (const float32_t *km, int32_t rows, int32_t cols)
template<class T >
bool set_full_kernel_matrix_from_full_generic (const T *km, 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_tkmatrix
int32_t num_rows
int32_t num_cols
bool upper_diagonal

Constructor & Destructor Documentation

CCustomKernel (  ) 

default constructor

Definition at line 27 of file CustomKernel.cpp.

CCustomKernel ( CKernel k  ) 

constructor

compute custom kernel from given kernel matrix

Parameters:
k kernel matrix

Definition at line 33 of file CustomKernel.cpp.

CCustomKernel ( const float64_t km,
int32_t  rows,
int32_t  cols 
)

constructor

sets full kernel matrix from full kernel matrix (from double precision floats)

Parameters:
km kernel matrix
rows number of rows in matrix
cols number of cols in matrix
Returns:
if setting was successful

Definition at line 76 of file CustomKernel.cpp.

CCustomKernel ( const float32_t km,
int32_t  rows,
int32_t  cols 
)

constructor

sets full kernel matrix from full kernel matrix (from single precision floats)

Parameters:
km kernel matrix
rows number of rows in matrix
cols number of cols in matrix
Returns:
if setting was successful

Definition at line 84 of file CustomKernel.cpp.

~CCustomKernel (  )  [virtual]

Definition at line 92 of file CustomKernel.cpp.


Member Function Documentation

void cleanup (  )  [virtual]

clean up kernel

Reimplemented from CKernel.

Definition at line 123 of file CustomKernel.cpp.

virtual float64_t compute ( int32_t  row,
int32_t  col 
) [protected, virtual]

compute kernel function

Parameters:
row row
col col
Returns:
computed kernel function

Implements CKernel.

Definition at line 360 of file CustomKernel.h.

bool dummy_init ( int32_t  rows,
int32_t  cols 
) [virtual]

initialize kernel with dummy features

Kernels always need feature objects assigned. As the custom kernel does not really require this it creates some magic dummy features that only know about the number of vectors

Parameters:
rows features of left-hand side
cols features of right-hand side
Returns:
if initializing was successful

Definition at line 97 of file CustomKernel.cpp.

virtual EFeatureClass get_feature_class (  )  [virtual]

return feature class the kernel can deal with

Returns:
feature class ANY

Implements CKernel.

Definition at line 111 of file CustomKernel.h.

virtual EFeatureType get_feature_type (  )  [virtual]

return feature type the kernel can deal with

Returns:
feature type ANY

Implements CKernel.

Definition at line 105 of file CustomKernel.h.

virtual EKernelType get_kernel_type (  )  [virtual]

return what type of kernel we are

Returns:
kernel type CUSTOM

Implements CKernel.

Definition at line 99 of file CustomKernel.h.

virtual const char* get_name ( void   )  const [virtual]

return the kernel's name

Returns:
name Custom

Implements CSGObject.

Definition at line 117 of file CustomKernel.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 CKernel.

Definition at line 330 of file CustomKernel.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 CKernel.

Definition at line 339 of file CustomKernel.h.

virtual bool has_features (  )  [virtual]

test whether features have been assigned to lhs and rhs

Returns:
true if features are assigned

Reimplemented from CKernel.

Definition at line 348 of file CustomKernel.h.

bool init ( CFeatures l,
CFeatures r 
) [virtual]

initialize kernel

Parameters:
l features of left-hand side
r features of right-hand side
Returns:
if initializing was successful

Reimplemented from CKernel.

Definition at line 102 of file CustomKernel.cpp.

bool set_full_kernel_matrix_from_full ( const float32_t km,
int32_t  rows,
int32_t  cols 
)

set full kernel matrix from full kernel matrix

for float32's

Parameters:
km kernel matrix
rows number of rows in matrix
cols number of cols in matrix
Returns:
if setting was successful

Definition at line 288 of file CustomKernel.h.

bool set_full_kernel_matrix_from_full ( const float64_t km,
int32_t  rows,
int32_t  cols 
)

set full kernel matrix from full kernel matrix

for float64's

Parameters:
km kernel matrix
rows number of rows in matrix
cols number of cols in matrix
Returns:
if setting was successful

Definition at line 273 of file CustomKernel.h.

bool set_full_kernel_matrix_from_full_generic ( const T *  km,
int32_t  rows,
int32_t  cols 
)

set full kernel matrix from full kernel matrix

Parameters:
km kernel matrix
rows number of rows in matrix
cols number of cols in matrix
Returns:
if setting was successful

Definition at line 302 of file CustomKernel.h.

bool set_triangle_kernel_matrix_from_full ( const float64_t km,
int32_t  rows,
int32_t  cols 
)

set kernel matrix (only elements from upper triangle) from squared matrix

for float64's

Parameters:
km kernel matrix
rows number of rows in matrix
cols number of cols in matrix
Returns:
if setting was successful

Definition at line 207 of file CustomKernel.h.

bool set_triangle_kernel_matrix_from_full ( const float32_t km,
int32_t  rows,
int32_t  cols 
)

set kernel matrix (only elements from upper triangle) from squared matrix

for float32's

Parameters:
km kernel matrix
rows number of rows in matrix
cols number of cols in matrix
Returns:
if setting was successful

Definition at line 223 of file CustomKernel.h.

bool set_triangle_kernel_matrix_from_full_generic ( const T *  km,
int32_t  rows,
int32_t  cols 
)

set kernel matrix (only elements from upper triangle) from squared matrix

Parameters:
km kernel matrix
rows number of rows in matrix
cols number of cols in matrix
Returns:
if setting was successful

Definition at line 238 of file CustomKernel.h.

bool set_triangle_kernel_matrix_from_triangle ( const float32_t km,
int32_t  len 
)

set kernel 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:
km kernel matrix
len denotes the size of the array and should match len=cols*(cols+1)/2
Returns:
if setting was successful

Definition at line 145 of file CustomKernel.h.

bool set_triangle_kernel_matrix_from_triangle ( const float64_t km,
int32_t  len 
)

set kernel 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:
km kernel matrix
len denotes the size of the array and should match len=cols*(cols+1)/2
Returns:
if setting was successful

Definition at line 129 of file CustomKernel.h.

bool set_triangle_kernel_matrix_from_triangle_generic ( const T *  km,
int64_t  len 
)

set kernel 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:
km kernel matrix
len denotes the size of the array and should match len=cols*(cols+1)/2
Returns:
if setting was successful

Definition at line 162 of file CustomKernel.h.


Member Data Documentation

float32_t* kmatrix [protected]

kernel matrix

Definition at line 390 of file CustomKernel.h.

int32_t num_cols [protected]

number of columns

Definition at line 394 of file CustomKernel.h.

int32_t num_rows [protected]

number of rows

Definition at line 392 of file CustomKernel.h.

bool upper_diagonal [protected]

upper diagonal

Definition at line 396 of file CustomKernel.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation