CCustomKernel Class Reference

Inheritance diagram for CCustomKernel:

Inheritance graph
[legend]

List of all members.


Detailed Description

Custom Kernel

This 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. Also note that values are stored as 32bit floats.

Definition at line 26 of file CustomKernel.h.


Public Member Functions

 CCustomKernel ()
 CCustomKernel (CFeatures *l, CFeatures *r)
virtual ~CCustomKernel ()
virtual SHORTREALget_kernel_matrix_shortreal (INT &m, INT &n, SHORTREAL *target=NULL)
virtual bool init (CFeatures *l, CFeatures *r)
virtual void cleanup ()
virtual bool load_init (FILE *src)
virtual bool save_init (FILE *dest)
virtual EKernelType get_kernel_type ()
virtual EFeatureType get_feature_type ()
virtual EFeatureClass get_feature_class ()
virtual const CHARget_name ()
bool set_triangle_kernel_matrix_from_triangle (const DREAL *km, INT len)
bool set_triangle_kernel_matrix_from_full (const DREAL *km, INT rows, INT cols)
bool set_full_kernel_matrix_from_full (const DREAL *km, INT rows, INT cols)
DREAL kernel (INT idx_a, INT idx_b)
void get_kernel_matrix (DREAL **dst, INT *m, INT *n)
virtual DREALget_kernel_matrix_real (int &m, int &n, DREAL *target)
bool load (CHAR *fname)
bool save (CHAR *fname)
CFeaturesget_lhs ()
CFeaturesget_rhs ()
INT get_num_vec_lhs ()
INT get_num_vec_rhs ()
bool has_features ()
virtual void remove_lhs_and_rhs ()
virtual void remove_lhs ()
virtual void remove_rhs ()
 takes all necessary steps if the rhs is removed from kernel
void set_cache_size (INT size)
int get_cache_size ()
void list_kernel ()
bool has_property (EKernelProperty p)
virtual void clear_normal ()
virtual void add_to_normal (INT vector_idx, DREAL weight)
EOptimizationType get_optimization_type ()
virtual void set_optimization_type (EOptimizationType t)
bool get_is_initialized ()
virtual bool init_optimization (INT count, INT *IDX, DREAL *weights)
virtual bool delete_optimization ()
bool init_optimization_svm (CSVM *svm)
virtual DREAL compute_optimized (INT vector_idx)
virtual void compute_batch (INT num_vec, INT *vec_idx, DREAL *target, INT num_suppvec, INT *IDX, DREAL *alphas, DREAL factor=1.0)
DREAL get_combined_kernel_weight ()
void set_combined_kernel_weight (double nw)
virtual INT get_num_subkernels ()
virtual void compute_by_subkernel (INT vector_idx, DREAL *subkernel_contrib)
virtual const DREALget_subkernel_weights (INT &num_weights)
virtual void set_subkernel_weights (DREAL *weights, INT num_weights)
bool get_precompute_matrix ()
bool get_precompute_subkernel_matrix ()
virtual void set_precompute_matrix (bool flag, bool subkernel_flag)

Static Public Attributes

static CParallel parallel
static CIO io
static CVersion version

Protected Member Functions

virtual DREAL compute (INT row, INT col)
void set_property (EKernelProperty p)
void unset_property (EKernelProperty p)
void set_is_initialized (bool p_init)
void do_precompute_matrix ()
 matrix precomputation
void init_sqrt_diag (DREAL *v, INT num)

Protected Attributes

SHORTREALkmatrix
INT num_rows
INT num_cols
bool upper_diagonal
INT cache_size
 cache_size in MB
KERNELCACHE_ELEMkernel_matrix
SHORTREALprecomputed_matrix
bool precompute_subkernel_matrix
bool precompute_matrix
CFeatureslhs
 feature vectors to occur on left hand side
CFeaturesrhs
 feature vectors to occur on right hand side
DREAL combined_kernel_weight
bool optimization_initialized
EOptimizationType opt_type
ULONG properties

Constructor & Destructor Documentation

CCustomKernel::CCustomKernel (  ) 

default constructor

Definition at line 16 of file CustomKernel.cpp.

CCustomKernel::CCustomKernel ( CFeatures l,
CFeatures r 
)

constructor

Parameters:
l features of left-hand side
r features of right-hand side

Definition at line 21 of file CustomKernel.cpp.

CCustomKernel::~CCustomKernel (  )  [virtual]

Definition at line 29 of file CustomKernel.cpp.


Member Function Documentation

SHORTREAL * CCustomKernel::get_kernel_matrix_shortreal ( INT m,
INT n,
SHORTREAL target = NULL 
) [virtual]

get kernel matrix shortreal

Parameters:
m dimension m of matrix
n dimension n of matrix
target target for kernel matrix
Returns:
the kernel matrix

Reimplemented from CKernel.

Definition at line 34 of file CustomKernel.cpp.

bool CCustomKernel::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 56 of file CustomKernel.cpp.

void CCustomKernel::cleanup (  )  [virtual]

clean up kernel

Reimplemented from CKernel.

Definition at line 76 of file CustomKernel.cpp.

bool CCustomKernel::load_init ( FILE *  src  )  [virtual]

load kernel init_data

Parameters:
src file to load from
Returns:
if loading was successful

Implements CKernel.

Definition at line 82 of file CustomKernel.cpp.

bool CCustomKernel::save_init ( FILE *  dest  )  [virtual]

save kernel init_data

Parameters:
dest file to save to
Returns:
if saving was successful

Implements CKernel.

Definition at line 87 of file CustomKernel.cpp.

virtual EKernelType CCustomKernel::get_kernel_type (  )  [virtual]

return what type of kernel we are

Returns:
kernel type CUSTOM

Implements CKernel.

Definition at line 79 of file CustomKernel.h.

virtual EFeatureType CCustomKernel::get_feature_type (  )  [virtual]

return feature type the kernel can deal with

Returns:
feature type ANY

Implements CKernel.

Definition at line 85 of file CustomKernel.h.

virtual EFeatureClass CCustomKernel::get_feature_class (  )  [virtual]

return feature class the kernel can deal with

Returns:
feature class ANY

Implements CKernel.

Definition at line 91 of file CustomKernel.h.

virtual const CHAR* CCustomKernel::get_name (  )  [virtual]

return the kernel's name

Returns:
name Custom

Implements CKernel.

Definition at line 97 of file CustomKernel.h.

bool CCustomKernel::set_triangle_kernel_matrix_from_triangle ( const DREAL km,
INT  len 
)

set kernel matrix (only elements from upper triangle) from elements of upper triangle (concat'd), including the main diagonal

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 93 of file CustomKernel.cpp.

bool CCustomKernel::set_triangle_kernel_matrix_from_full ( const DREAL km,
INT  rows,
INT  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 126 of file CustomKernel.cpp.

bool CCustomKernel::set_full_kernel_matrix_from_full ( const DREAL km,
INT  rows,
INT  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 154 of file CustomKernel.cpp.

virtual DREAL CCustomKernel::compute ( INT  row,
INT  col 
) [protected, virtual]

compute kernel function

Parameters:
row row
col col
Returns:
computed kernel function

Implements CKernel.

Definition at line 135 of file CustomKernel.h.

DREAL CKernel::kernel ( INT  idx_a,
INT  idx_b 
) [inherited]

get kernel function for lhs feature vector a and rhs feature vector b

Parameters:
idx_a index of feature vector a
idx_b index of feature vector b
Returns:
computed kernel function

Definition at line 48 of file Kernel.h.

void CKernel::get_kernel_matrix ( DREAL **  dst,
INT m,
INT n 
) [inherited]

get kernel matrix

Parameters:
dst destination where matrix will be stored
m dimension m of matrix
n dimension n of matrix

Definition at line 79 of file Kernel.cpp.

DREAL * CKernel::get_kernel_matrix_real ( int &  m,
int &  n,
DREAL target 
) [virtual, inherited]

get kernel matrix real

Parameters:
m dimension m of matrix
n dimension n of matrix
target the kernel matrix
Returns:
the kernel matrix

Definition at line 216 of file Kernel.cpp.

bool CKernel::load ( CHAR fname  )  [inherited]

load the kernel matrix

Parameters:
fname filename to load from
Returns:
if loading was succesful

Definition at line 322 of file Kernel.cpp.

bool CKernel::save ( CHAR fname  )  [inherited]

save kernel matrix

Parameters:
fname filename to save to
Returns:
if saving was successful

Definition at line 327 of file Kernel.cpp.

CFeatures* CKernel::get_lhs (  )  [inherited]

get left-hand side of features used in kernel

Returns:
features of left-hand side

Definition at line 164 of file Kernel.h.

CFeatures* CKernel::get_rhs (  )  [inherited]

get right-hand side of features used in kernel

Returns:
features of right-hand side

Definition at line 170 of file Kernel.h.

INT CKernel::get_num_vec_lhs (  )  [inherited]

get number of vectors of lhs features

Returns:
number of vectors of left-hand side

Definition at line 176 of file Kernel.h.

INT CKernel::get_num_vec_rhs (  )  [inherited]

get number of vectors of rhs features

Returns:
number of vectors of right-hand side

Definition at line 188 of file Kernel.h.

bool CKernel::has_features (  )  [inherited]

test whether features have been assigned to lhs and rhs

Returns:
true if features are assigned

Definition at line 200 of file Kernel.h.

void CKernel::remove_lhs_and_rhs (  )  [virtual, inherited]

remove lhs and rhs from kernel

Definition at line 358 of file Kernel.cpp.

void CKernel::remove_lhs (  )  [virtual, inherited]

void CKernel::remove_rhs (  )  [virtual, inherited]

takes all necessary steps if the rhs is removed from kernel

remove rhs from kernel

Reimplemented in CCombinedKernel, CCommUlongStringKernel, and CCommWordStringKernel.

Definition at line 379 of file Kernel.cpp.

void CKernel::set_cache_size ( INT  size  )  [inherited]

set the size of the kernel cache

Parameters:
size of kernel cache

Definition at line 249 of file Kernel.h.

int CKernel::get_cache_size (  )  [inherited]

return the size of the kernel cache

Returns:
size of kernel cache

Definition at line 259 of file Kernel.h.

void CKernel::list_kernel (  )  [inherited]

list kernel

Definition at line 389 of file Kernel.cpp.

bool CKernel::has_property ( EKernelProperty  p  )  [inherited]

check if kernel has given property

Parameters:
p kernel property
Returns:
if kernel has given property

Definition at line 271 of file Kernel.h.

void CKernel::clear_normal (  )  [virtual, inherited]

for optimizable kernels, i.e. kernels where the weight vector can be computed explicitely (if it fits into memory)

Reimplemented in CCombinedKernel, CCommUlongStringKernel, CCommWordStringKernel, CLinearByteKernel, CLinearKernel, CLinearStringKernel, CLinearWordKernel, CSparseLinearKernel, CWeightedDegreePositionStringKernel, and CWeightedDegreeStringKernel.

Definition at line 578 of file Kernel.cpp.

void CKernel::add_to_normal ( INT  vector_idx,
DREAL  weight 
) [virtual, inherited]

EOptimizationType CKernel::get_optimization_type (  )  [inherited]

get optimization type

Returns:
optimization type

Definition at line 289 of file Kernel.h.

virtual void CKernel::set_optimization_type ( EOptimizationType  t  )  [virtual, inherited]

set optimization type

Parameters:
t optimization type to set

Reimplemented in CCombinedKernel.

Definition at line 295 of file Kernel.h.

bool CKernel::get_is_initialized (  )  [inherited]

check if optimization is initialized

Returns:
if optimization is initialized

Definition at line 301 of file Kernel.h.

bool CKernel::init_optimization ( INT  count,
INT IDX,
DREAL weights 
) [virtual, inherited]

initialize optimization

Parameters:
count count
IDX index
weights weights
Returns:
if initializing was successful

Reimplemented in CCombinedKernel, CCommUlongStringKernel, CCommWordStringKernel, CLinearByteKernel, CLinearKernel, CLinearStringKernel, CLinearWordKernel, CSparseLinearKernel, CWeightedDegreePositionStringKernel, and CWeightedDegreeStringKernel.

Definition at line 550 of file Kernel.cpp.

bool CKernel::delete_optimization (  )  [virtual, inherited]

bool CKernel::init_optimization_svm ( CSVM svm  )  [inherited]

initialize optimization

Parameters:
svm svm model
Returns:
if initializing was successful

Definition at line 644 of file Kernel.cpp.

DREAL CKernel::compute_optimized ( INT  vector_idx  )  [virtual, inherited]

compute optimized

Parameters:
vector_idx index to compute
Returns:
optimized value at given index

Reimplemented in CCombinedKernel, CCommUlongStringKernel, CCommWordStringKernel, CLinearByteKernel, CLinearKernel, CLinearStringKernel, CLinearWordKernel, CSparseLinearKernel, CWeightedCommWordStringKernel, CWeightedDegreePositionStringKernel, and CWeightedDegreeStringKernel.

Definition at line 562 of file Kernel.cpp.

void CKernel::compute_batch ( INT  num_vec,
INT vec_idx,
DREAL target,
INT  num_suppvec,
INT IDX,
DREAL alphas,
DREAL  factor = 1.0 
) [virtual, inherited]

computes output for a batch of examples in an optimized fashion (favorable if kernel supports it, i.e. has KP_BATCHEVALUATION. to the outputvector target (of length num_vec elements) the output for the examples enumerated in vec_idx are added. therefore make sure that it is initialized with ZERO. the following num_suppvec, IDX, alphas arguments are the number of support vectors, their indices and weights

Reimplemented in CCombinedKernel, CWeightedDegreePositionStringKernel, and CWeightedDegreeStringKernel.

Definition at line 568 of file Kernel.cpp.

DREAL CKernel::get_combined_kernel_weight (  )  [inherited]

get combined kernel weight

Returns:
combined kernel weight

Definition at line 346 of file Kernel.h.

void CKernel::set_combined_kernel_weight ( double  nw  )  [inherited]

set combined kernel weight

Parameters:
nw nw

Definition at line 352 of file Kernel.h.

INT CKernel::get_num_subkernels (  )  [virtual, inherited]

get number of subkernels

Returns:
number of subkernels

Reimplemented in CCombinedKernel, CWeightedDegreePositionStringKernel, and CWeightedDegreeStringKernel.

Definition at line 583 of file Kernel.cpp.

void CKernel::compute_by_subkernel ( INT  vector_idx,
DREAL subkernel_contrib 
) [virtual, inherited]

compute by subkernel

Parameters:
vector_idx index
subkernel_contrib subkernel contribution

Reimplemented in CCombinedKernel, CWeightedDegreePositionStringKernel, and CWeightedDegreeStringKernel.

Definition at line 588 of file Kernel.cpp.

const DREAL * CKernel::get_subkernel_weights ( INT num_weights  )  [virtual, inherited]

get subkernel weights

Parameters:
num_weights number of weights will be stored here
Returns:
subkernel weights

Reimplemented in CCombinedKernel, CWeightedDegreePositionStringKernel, and CWeightedDegreeStringKernel.

Definition at line 593 of file Kernel.cpp.

void CKernel::set_subkernel_weights ( DREAL weights,
INT  num_weights 
) [virtual, inherited]

set subkernel weights

Parameters:
weights subkernel weights
num_weights number of weights

Reimplemented in CCombinedKernel, CWeightedDegreePositionStringKernel, and CWeightedDegreeStringKernel.

Definition at line 599 of file Kernel.cpp.

bool CKernel::get_precompute_matrix (  )  [inherited]

get precompute matrix

Returns:
if matrix shall be precomputed

Definition at line 386 of file Kernel.h.

bool CKernel::get_precompute_subkernel_matrix (  )  [inherited]

get precompute subkernel matrix

Returns:
if subkernel matrix shall be precomputed

Definition at line 392 of file Kernel.h.

virtual void CKernel::set_precompute_matrix ( bool  flag,
bool  subkernel_flag 
) [virtual, inherited]

set precompute matrix

Parameters:
flag flag
subkernel_flag subkernel flag

Reimplemented in CCombinedKernel.

Definition at line 399 of file Kernel.h.

void CKernel::set_property ( EKernelProperty  p  )  [protected, inherited]

set property

Parameters:
p kernel property to set

Definition at line 416 of file Kernel.h.

void CKernel::unset_property ( EKernelProperty  p  )  [protected, inherited]

unset property

Parameters:
p kernel property to unset

Definition at line 425 of file Kernel.h.

void CKernel::set_is_initialized ( bool  p_init  )  [protected, inherited]

set is initialized

Parameters:
p_init if optimization shall be set to initialized

Definition at line 434 of file Kernel.h.

void CKernel::do_precompute_matrix (  )  [protected, inherited]

matrix precomputation

Definition at line 606 of file Kernel.cpp.

void CKernel::init_sqrt_diag ( DREAL v,
INT  num 
) [protected, inherited]

initialize sqrt diagonal

Parameters:
v v
num num

Definition at line 634 of file Kernel.cpp.


Member Data Documentation

kernel matrix

Definition at line 158 of file CustomKernel.h.

number of rows

Definition at line 160 of file CustomKernel.h.

number of columns

Definition at line 162 of file CustomKernel.h.

upper diagonal

Definition at line 164 of file CustomKernel.h.

INT CKernel::cache_size [protected, inherited]

cache_size in MB

Definition at line 464 of file Kernel.h.

KERNELCACHE_ELEM* CKernel::kernel_matrix [protected, inherited]

this *COULD* store the whole kernel matrix usually not applicable / faster

Definition at line 470 of file Kernel.h.

SHORTREAL* CKernel::precomputed_matrix [protected, inherited]

precomputed matrix

Definition at line 473 of file Kernel.h.

bool CKernel::precompute_subkernel_matrix [protected, inherited]

if subkernel matrix shall be precomputed

Definition at line 475 of file Kernel.h.

bool CKernel::precompute_matrix [protected, inherited]

if matrix shall be precomputed

Definition at line 477 of file Kernel.h.

CFeatures* CKernel::lhs [protected, inherited]

feature vectors to occur on left hand side

Definition at line 480 of file Kernel.h.

CFeatures* CKernel::rhs [protected, inherited]

feature vectors to occur on right hand side

Definition at line 482 of file Kernel.h.

DREAL CKernel::combined_kernel_weight [protected, inherited]

combined kernel weight

Definition at line 485 of file Kernel.h.

bool CKernel::optimization_initialized [protected, inherited]

if optimization is initialized

Definition at line 488 of file Kernel.h.

EOptimizationType CKernel::opt_type [protected, inherited]

optimization type (currently FASTBUTMEMHUNGRY and SLOWBUTMEMEFFICIENT)

Definition at line 492 of file Kernel.h.

ULONG CKernel::properties [protected, inherited]

properties

Definition at line 495 of file Kernel.h.

CParallel CSGObject::parallel [static, inherited]

Definition at line 105 of file SGObject.h.

CIO CSGObject::io [static, inherited]

Definition at line 106 of file SGObject.h.

CVersion CSGObject::version [static, inherited]

Definition at line 107 of file SGObject.h.


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

SHOGUN Machine Learning Toolbox - Documentation