CCombinedKernel Class Reference

Inheritance diagram for CCombinedKernel:

Inheritance graph
[legend]

List of all members.


Detailed Description

The Combined kernel is used to combine a number of kernels into a single CombinedKernel object by linear combination. It keeps pointers to the added sub-kernels $k_m({\bf x}, {\bf x'})$ and for each sub-kernel - a kernel specific weight $\beta_m$.

It is especially useful to combine kernels working on different domains and to combine kernels looking at independent features.

It is defined as:

\[ k_{combined}({\bf x}, {\bf x'}) = \sum_{m=0}^M \beta_m k_m({\bf x}, {\bf x'}) \]

Definition at line 37 of file CombinedKernel.h.


Public Member Functions

 CCombinedKernel (INT size=10, bool append_subkernel_weights=false)
 CCombinedKernel (CCombinedFeatures *l, CCombinedFeatures *r, bool append_subkernel_weights=false)
virtual ~CCombinedKernel ()
virtual bool init (CFeatures *lhs, CFeatures *rhs)
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 ()
void list_kernels ()
CKernelget_first_kernel ()
CKernelget_first_kernel (CListElement< CKernel * > *&current)
CKernelget_kernel (INT idx)
CKernelget_last_kernel ()
CKernelget_next_kernel (const CKernel *current)
CKernelget_next_kernel (CListElement< CKernel * > *&current)
bool insert_kernel (CKernel *k)
bool append_kernel (CKernel *k)
bool delete_kernel ()
bool get_append_subkernel_weights ()
int get_num_subkernels ()
virtual void remove_lhs ()
virtual void remove_rhs ()
virtual bool init_optimization (INT count, INT *IDX, DREAL *weights)
virtual bool delete_optimization ()
virtual DREAL compute_optimized (INT idx)
virtual void compute_batch (INT num_vec, INT *vec_idx, DREAL *target, INT num_suppvec, INT *IDX, DREAL *alphas, DREAL factor=1.0)
void emulate_compute_batch (CKernel *k, INT num_vec, INT *vec_idx, DREAL *target, INT num_suppvec, INT *IDX, DREAL *weights)
virtual void add_to_normal (INT idx, DREAL weight)
virtual void clear_normal ()
virtual void compute_by_subkernel (INT idx, DREAL *subkernel_contrib)
virtual const DREALget_subkernel_weights (INT &num_weights)
virtual void set_subkernel_weights (DREAL *weights, INT num_weights)
virtual void set_optimization_type (EOptimizationType t)
virtual void set_precompute_matrix (bool flag, bool subkernel_flag)
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)
virtual SHORTREALget_kernel_matrix_shortreal (int &m, int &n, SHORTREAL *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 ()
void set_cache_size (INT size)
int get_cache_size ()
void list_kernel ()
bool has_property (EKernelProperty p)
EOptimizationType get_optimization_type ()
bool get_is_initialized ()
bool init_optimization_svm (CSVM *svm)
DREAL get_combined_kernel_weight ()
void set_combined_kernel_weight (double nw)
bool get_precompute_matrix ()
bool get_precompute_subkernel_matrix ()

Static Public Member Functions

static void * compute_optimized_kernel_helper (void *p)
static void * compute_kernel_helper (void *p)

Static Public Attributes

static CParallel parallel
static CIO io
static CVersion version

Protected Member Functions

virtual DREAL compute (INT x, INT y)
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

CList< CKernel * > * kernel_list
INT sv_count
INTsv_idx
DREALsv_weight
DREALsubkernel_weights_buffer
bool append_subkernel_weights
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

CCombinedKernel::CCombinedKernel ( INT  size = 10,
bool  append_subkernel_weights = false 
)

constructor

Parameters:
size cache size
append_subkernel_weights if subkernel weights shall be appended

Definition at line 40 of file CombinedKernel.cpp.

CCombinedKernel::CCombinedKernel ( CCombinedFeatures l,
CCombinedFeatures r,
bool  append_subkernel_weights = false 
)

constructor

Parameters:
l features for left-hand side
r features for right-hand side
append_subkernel_weights if subkernel weights shall be appended

Definition at line 51 of file CombinedKernel.cpp.

CCombinedKernel::~CCombinedKernel (  )  [virtual]

Definition at line 65 of file CombinedKernel.cpp.


Member Function Documentation

bool CCombinedKernel::init ( CFeatures lhs,
CFeatures rhs 
) [virtual]

initialize kernel

Parameters:
lhs features of left-hand side
rhs features of right-hand side
Returns:
if initializing was successful

Reimplemented from CKernel.

Definition at line 76 of file CombinedKernel.cpp.

void CCombinedKernel::cleanup (  )  [virtual]

clean up kernel

Reimplemented from CKernel.

Definition at line 183 of file CombinedKernel.cpp.

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

load kernel init_data

NOT IMPLEMENTED!

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

Implements CKernel.

Definition at line 78 of file CombinedKernel.h.

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

save kernel init_data

NOT IMPLEMENTED!

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

Implements CKernel.

Definition at line 87 of file CombinedKernel.h.

virtual EKernelType CCombinedKernel::get_kernel_type (  )  [virtual]

return what type of kernel we are

Returns:
kernel type COMBINED

Implements CKernel.

Definition at line 93 of file CombinedKernel.h.

virtual EFeatureType CCombinedKernel::get_feature_type (  )  [virtual]

return feature type the kernel can deal with

Returns:
feature type UNKNOWN

Implements CKernel.

Definition at line 102 of file CombinedKernel.h.

virtual EFeatureClass CCombinedKernel::get_feature_class (  )  [virtual]

return feature class the kernel can deal with

Returns:
feature class COMBINED

Implements CKernel.

Definition at line 111 of file CombinedKernel.h.

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

return the kernel's name

Returns:
name Combined

Implements CKernel.

Definition at line 120 of file CombinedKernel.h.

void CCombinedKernel::list_kernels (  ) 

list kernels

Definition at line 199 of file CombinedKernel.cpp.

CKernel* CCombinedKernel::get_first_kernel (  ) 

get first kernel

Returns:
first kernel

Definition at line 129 of file CombinedKernel.h.

CKernel* CCombinedKernel::get_first_kernel ( CListElement< CKernel * > *&  current  ) 

get first kernel

Parameters:
current 
Returns:
first kernel

Definition at line 139 of file CombinedKernel.h.

CKernel* CCombinedKernel::get_kernel ( INT  idx  ) 

get kernel

Parameters:
idx index of kernel
Returns:
kernel at index idx

Definition at line 149 of file CombinedKernel.h.

CKernel* CCombinedKernel::get_last_kernel (  ) 

get last kernel

Returns:
last kernel

Definition at line 161 of file CombinedKernel.h.

CKernel* CCombinedKernel::get_next_kernel ( const CKernel current  ) 

get next kernel

Parameters:
current 
Returns:
next kernel

Definition at line 171 of file CombinedKernel.h.

CKernel* CCombinedKernel::get_next_kernel ( CListElement< CKernel * > *&  current  ) 

get next kernel multi-thread safe

Parameters:
current 
Returns:
next kernel

Definition at line 182 of file CombinedKernel.h.

bool CCombinedKernel::insert_kernel ( CKernel k  ) 

insert kernel

Parameters:
k kernel
Returns:
if inserting was successful

Definition at line 192 of file CombinedKernel.h.

bool CCombinedKernel::append_kernel ( CKernel k  ) 

append kernel

Parameters:
k kernel
Returns:
if appending was successful

Definition at line 208 of file CombinedKernel.h.

bool CCombinedKernel::delete_kernel (  ) 

delete kernel

Returns:
if deleting was successful

Definition at line 223 of file CombinedKernel.h.

bool CCombinedKernel::get_append_subkernel_weights (  ) 

check if subkernel weights are appended

Returns:
if subkernel weigths are appended

Definition at line 235 of file CombinedKernel.h.

int CCombinedKernel::get_num_subkernels (  )  [virtual]

get number of subkernels

Returns:
number of subkernels

Reimplemented from CKernel.

Definition at line 244 of file CombinedKernel.h.

void CCombinedKernel::remove_lhs (  )  [virtual]

remove lhs from kernel

Reimplemented from CKernel.

Definition at line 145 of file CombinedKernel.cpp.

void CCombinedKernel::remove_rhs (  )  [virtual]

remove rhs from kernel

Reimplemented from CKernel.

Definition at line 165 of file CombinedKernel.cpp.

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

initialize optimization

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

Reimplemented from CKernel.

Definition at line 231 of file CombinedKernel.cpp.

bool CCombinedKernel::delete_optimization (  )  [virtual]

delete optimization

Returns:
if deleting was successful

Reimplemented from CKernel.

Definition at line 281 of file CombinedKernel.cpp.

DREAL CCombinedKernel::compute_optimized ( INT  idx  )  [virtual]

compute optimized

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

Reimplemented from CKernel.

Definition at line 497 of file CombinedKernel.cpp.

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

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 from CKernel.

Definition at line 306 of file CombinedKernel.cpp.

void * CCombinedKernel::compute_optimized_kernel_helper ( void *  p  )  [static]

helper for compute optimized kernel

Parameters:
p thread parameter

Definition at line 338 of file CombinedKernel.cpp.

void * CCombinedKernel::compute_kernel_helper ( void *  p  )  [static]

helper for compute kernel

Parameters:
p thread parameter

Definition at line 351 of file CombinedKernel.cpp.

void CCombinedKernel::emulate_compute_batch ( CKernel k,
INT  num_vec,
INT vec_idx,
DREAL target,
INT  num_suppvec,
INT IDX,
DREAL weights 
)

emulates batch computation, via linadd optimization w^t x or even down to sum_i alpha_i K(x_i,x)

Parameters:
k kernel
num_vec number of vectors
vec_idx vector index
target target
num_suppvec number of support vectors
IDX IDX
weights weights

Definition at line 374 of file CombinedKernel.cpp.

void CCombinedKernel::add_to_normal ( INT  idx,
DREAL  weight 
) [virtual]

add to normal vector

Parameters:
idx where to add
weight what to add

Reimplemented from CKernel.

Definition at line 540 of file CombinedKernel.cpp.

void CCombinedKernel::clear_normal (  )  [virtual]

clear normal vector

Reimplemented from CKernel.

Definition at line 553 of file CombinedKernel.cpp.

void CCombinedKernel::compute_by_subkernel ( INT  idx,
DREAL subkernel_contrib 
) [virtual]

compute by subkernel

Parameters:
idx index
subkernel_contrib subkernel contribution

Reimplemented from CKernel.

Definition at line 566 of file CombinedKernel.cpp.

const DREAL * CCombinedKernel::get_subkernel_weights ( INT num_weights  )  [virtual]

get subkernel weights

Parameters:
num_weights where number of weights is stored
Returns:
subkernel weights

Reimplemented from CKernel.

Definition at line 601 of file CombinedKernel.cpp.

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

set subkernel weights

Parameters:
weights new subkernel weights
num_weights number of subkernel weights

Reimplemented from CKernel.

Definition at line 639 of file CombinedKernel.cpp.

void CCombinedKernel::set_optimization_type ( EOptimizationType  t  )  [virtual]

set optimization type

Parameters:
t optimization type

Reimplemented from CKernel.

Definition at line 668 of file CombinedKernel.cpp.

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

set precompute matrix

Parameters:
flag flag
subkernel_flag subkernel flag

Reimplemented from CKernel.

Definition at line 364 of file CombinedKernel.h.

DREAL CCombinedKernel::compute ( INT  x,
INT  y 
) [protected, virtual]

compute kernel function

Parameters:
x x
y y
Returns:
computed kernel function

Implements CKernel.

Definition at line 216 of file CombinedKernel.cpp.

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.

SHORTREAL * CKernel::get_kernel_matrix_shortreal ( int &  m,
int &  n,
SHORTREAL target 
) [virtual, inherited]

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 in CCustomKernel.

Definition at line 146 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::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.

EOptimizationType CKernel::get_optimization_type (  )  [inherited]

get optimization type

Returns:
optimization type

Definition at line 289 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_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::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.

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.

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

list of kernels

Definition at line 394 of file CombinedKernel.h.

support vector count

Definition at line 396 of file CombinedKernel.h.

support vector index

Definition at line 398 of file CombinedKernel.h.

support vector weights

Definition at line 400 of file CombinedKernel.h.

subkernel weights buffers

Definition at line 402 of file CombinedKernel.h.

if subkernel weights are appended

Definition at line 404 of file CombinedKernel.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