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

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 and requires CCombinedFeatures to be used.

It is defined as:

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

Definition at line 46 of file CombinedKernel.h.

Inheritance diagram for CCombinedKernel:
Inheritance graph
[legend]

Public Member Functions

 CCombinedKernel (int32_t size=10, bool append_subkernel_weights=false)
virtual ~CCombinedKernel ()
virtual bool init (CFeatures *lhs, CFeatures *rhs)
virtual void cleanup ()
virtual EKernelType get_kernel_type ()
virtual EFeatureType get_feature_type ()
virtual EFeatureClass get_feature_class ()
virtual const char * get_name () const
void list_kernels ()
CKernelget_first_kernel ()
CKernelget_first_kernel (CListElement *&current)
CKernelget_kernel (int32_t idx)
CKernelget_last_kernel ()
CKernelget_next_kernel ()
CKernelget_next_kernel (CListElement *&current)
bool insert_kernel (CKernel *k)
bool append_kernel (CKernel *k)
bool delete_kernel ()
bool get_append_subkernel_weights ()
int32_t get_num_subkernels ()
virtual bool has_features ()
virtual void remove_lhs ()
virtual void remove_rhs ()
virtual void remove_lhs_and_rhs ()
virtual bool init_optimization (int32_t count, int32_t *IDX, float64_t *weights)
virtual bool delete_optimization ()
virtual float64_t compute_optimized (int32_t idx)
virtual void compute_batch (int32_t num_vec, int32_t *vec_idx, float64_t *target, int32_t num_suppvec, int32_t *IDX, float64_t *alphas, float64_t factor=1.0)
void emulate_compute_batch (CKernel *k, int32_t num_vec, int32_t *vec_idx, float64_t *target, int32_t num_suppvec, int32_t *IDX, float64_t *weights)
virtual void add_to_normal (int32_t idx, float64_t weight)
virtual void clear_normal ()
virtual void compute_by_subkernel (int32_t idx, float64_t *subkernel_contrib)
virtual const float64_tget_subkernel_weights (int32_t &num_weights)
virtual SGVector< float64_tget_subkernel_weights ()
virtual void set_subkernel_weights (SGVector< float64_t > weights)
virtual void set_optimization_type (EOptimizationType t)
bool precompute_subkernels ()
CCombinedKernelKernelToCombinedKernel (shogun::CKernel *n)
- Public Member Functions inherited from CKernel
 CKernel ()
 CKernel (int32_t size)
 CKernel (CFeatures *l, CFeatures *r, int32_t size)
virtual ~CKernel ()
float64_t kernel (int32_t idx_a, int32_t idx_b)
SGMatrix< float64_tget_kernel_matrix ()
virtual SGVector< float64_tget_kernel_col (int32_t j)
virtual SGVector< float64_tget_kernel_row (int32_t i)
template<class T >
SGMatrix< T > get_kernel_matrix ()
virtual bool set_normalizer (CKernelNormalizer *normalizer)
virtual CKernelNormalizerget_normalizer ()
virtual bool init_normalizer ()
void load (CFile *loader)
void save (CFile *writer)
CFeaturesget_lhs ()
CFeaturesget_rhs ()
virtual int32_t get_num_vec_lhs ()
virtual int32_t get_num_vec_rhs ()
bool get_lhs_equals_rhs ()
void set_cache_size (int32_t size)
int32_t 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)
float64_t get_combined_kernel_weight ()
void set_combined_kernel_weight (float64_t nw)
- 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)

Static Public Member Functions

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

Protected Member Functions

virtual float64_t compute (int32_t x, int32_t y)
void adjust_num_lhs_rhs_initialized (CKernel *k)
- Protected Member Functions inherited from CKernel
void set_property (EKernelProperty p)
void unset_property (EKernelProperty p)
void set_is_initialized (bool p_init)
int32_t compute_row_start (int64_t offs, int32_t n, bool symmetric)
virtual void load_serializable_post () throw (ShogunException)
virtual void save_serializable_pre () throw (ShogunException)
virtual void save_serializable_post () throw (ShogunException)
virtual void register_params ()
- Protected Member Functions inherited from CSGObject
virtual void load_serializable_pre () throw (ShogunException)

Protected Attributes

CListkernel_list
int32_t sv_count
int32_t * sv_idx
float64_tsv_weight
float64_tsubkernel_weights_buffer
bool append_subkernel_weights
bool initialized
- Protected Attributes inherited from CKernel
int32_t cache_size
 cache_size in MB
KERNELCACHE_ELEMkernel_matrix
CFeatureslhs
 feature vectors to occur on left hand side
CFeaturesrhs
 feature vectors to occur on right hand side
bool lhs_equals_rhs
 lhs
int32_t num_lhs
 number of feature vectors on left hand side
int32_t num_rhs
 number of feature vectors on right hand side
float64_t combined_kernel_weight
bool optimization_initialized
EOptimizationType opt_type
uint64_t properties
CKernelNormalizernormalizer

Additional Inherited Members

- Public Attributes inherited from CSGObject
SGIOio
Parallelparallel
Versionversion
Parameterm_parameters
Parameterm_model_selection_parameters
- Static Protected Member Functions inherited from CKernel
template<class T >
static void * get_kernel_matrix_helper (void *p)

Constructor & Destructor Documentation

CCombinedKernel ( int32_t  size = 10,
bool  append_subkernel_weights = false 
)

constructor

Parameters
sizecache size
append_subkernel_weightsif subkernel weights shall be appended

Definition at line 45 of file CombinedKernel.cpp.

~CCombinedKernel ( )
virtual

Definition at line 56 of file CombinedKernel.cpp.

Member Function Documentation

void add_to_normal ( int32_t  idx,
float64_t  weight 
)
virtual

add to normal vector

Parameters
idxwhere to add
weightwhat to add

Reimplemented from CKernel.

Definition at line 579 of file CombinedKernel.cpp.

void adjust_num_lhs_rhs_initialized ( CKernel k)
protected

adjust the variables num_lhs, num_rhs and initialized based on the kernel to be appended/inserted

Parameters
kkernel

Definition at line 399 of file CombinedKernel.h.

bool append_kernel ( CKernel k)

append kernel

Parameters
kkernel
Returns
if appending was successful

Definition at line 190 of file CombinedKernel.h.

void cleanup ( )
virtual

clean up kernel

Reimplemented from CKernel.

Definition at line 205 of file CombinedKernel.cpp.

void clear_normal ( )
virtual

clear normal vector

Reimplemented from CKernel.

Definition at line 593 of file CombinedKernel.cpp.

float64_t compute ( int32_t  x,
int32_t  y 
)
protectedvirtual

compute kernel function

Parameters
xx
yy
Returns
computed kernel function

Implements CKernel.

Definition at line 243 of file CombinedKernel.cpp.

void compute_batch ( int32_t  num_vec,
int32_t *  vec_idx,
float64_t target,
int32_t  num_suppvec,
int32_t *  IDX,
float64_t alphas,
float64_t  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 336 of file CombinedKernel.cpp.

void compute_by_subkernel ( int32_t  idx,
float64_t subkernel_contrib 
)
virtual

compute by subkernel

Parameters
idxindex
subkernel_contribsubkernel contribution

Reimplemented from CKernel.

Definition at line 607 of file CombinedKernel.cpp.

void * compute_kernel_helper ( void *  p)
static

helper for compute kernel

Parameters
pthread parameter

Definition at line 383 of file CombinedKernel.cpp.

float64_t compute_optimized ( int32_t  idx)
virtual

compute optimized

Parameters
idxindex to compute
Returns
optimized value at given index

Reimplemented from CKernel.

Definition at line 534 of file CombinedKernel.cpp.

void * compute_optimized_kernel_helper ( void *  p)
static

helper for compute optimized kernel

Parameters
pthread parameter

Definition at line 370 of file CombinedKernel.cpp.

bool delete_kernel ( )

delete kernel

Returns
if deleting was successful

Definition at line 206 of file CombinedKernel.h.

bool delete_optimization ( )
virtual

delete optimization

Returns
if deleting was successful

Reimplemented from CKernel.

Definition at line 310 of file CombinedKernel.cpp.

void emulate_compute_batch ( CKernel k,
int32_t  num_vec,
int32_t *  vec_idx,
float64_t target,
int32_t  num_suppvec,
int32_t *  IDX,
float64_t weights 
)

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

Parameters
kkernel
num_vecnumber of vectors
vec_idxvector index
targettarget
num_suppvecnumber of support vectors
IDXIDX
weightsweights

Definition at line 405 of file CombinedKernel.cpp.

bool get_append_subkernel_weights ( )

check if subkernel weights are appended

Returns
if subkernel weigths are appended

Definition at line 224 of file CombinedKernel.h.

virtual EFeatureClass get_feature_class ( )
virtual

return feature class the kernel can deal with

Returns
feature class COMBINED

Implements CKernel.

Definition at line 92 of file CombinedKernel.h.

virtual EFeatureType get_feature_type ( )
virtual

return feature type the kernel can deal with

Returns
feature type UNKNOWN

Implements CKernel.

Definition at line 83 of file CombinedKernel.h.

CKernel* get_first_kernel ( )

get first kernel

Returns
first kernel

Definition at line 110 of file CombinedKernel.h.

CKernel* get_first_kernel ( CListElement *&  current)

get first kernel

Parameters
current
Returns
first kernel

Definition at line 120 of file CombinedKernel.h.

CKernel* get_kernel ( int32_t  idx)

get kernel

Parameters
idxindex of kernel
Returns
kernel at index idx

Definition at line 130 of file CombinedKernel.h.

virtual EKernelType get_kernel_type ( )
virtual

return what type of kernel we are

Returns
kernel type COMBINED

Implements CKernel.

Definition at line 74 of file CombinedKernel.h.

CKernel* get_last_kernel ( )

get last kernel

Returns
last kernel

Definition at line 145 of file CombinedKernel.h.

virtual const char* get_name ( ) const
virtual

return the kernel's name

Returns
name Combined

Implements CSGObject.

Definition at line 101 of file CombinedKernel.h.

CKernel* get_next_kernel ( )

get next kernel

Returns
next kernel

Definition at line 154 of file CombinedKernel.h.

CKernel* get_next_kernel ( CListElement *&  current)

get next kernel multi-thread safe

Parameters
current
Returns
next kernel

Definition at line 164 of file CombinedKernel.h.

int32_t get_num_subkernels ( )
virtual

get number of subkernels

Returns
number of subkernels

Reimplemented from CKernel.

Definition at line 233 of file CombinedKernel.h.

const float64_t * get_subkernel_weights ( int32_t &  num_weights)
virtual

get subkernel weights

Parameters
num_weightswhere number of weights is stored
Returns
subkernel weights

Reimplemented from CKernel.

Definition at line 646 of file CombinedKernel.cpp.

SGVector< float64_t > get_subkernel_weights ( )
virtual

get subkernel weights (swig compatible)

Returns
subkernel weights

Definition at line 688 of file CombinedKernel.cpp.

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 257 of file CombinedKernel.h.

bool init ( CFeatures lhs,
CFeatures rhs 
)
virtual

initialize kernel

Parameters
lhsfeatures of left-hand side
rhsfeatures of right-hand side
Returns
if initializing was successful

Reimplemented from CKernel.

Definition at line 67 of file CombinedKernel.cpp.

bool init_optimization ( int32_t  count,
int32_t *  IDX,
float64_t weights 
)
virtual

initialize optimization

Parameters
countcount
IDXindex
weightsweights
Returns
if initializing was successful

Reimplemented from CKernel.

Definition at line 259 of file CombinedKernel.cpp.

bool insert_kernel ( CKernel k)

insert kernel

Parameters
kkernel
Returns
if inserting was successful

Definition at line 174 of file CombinedKernel.h.

CCombinedKernel* KernelToCombinedKernel ( shogun::CKernel n)

casts kernel to combined kernel

Parameters
nkernel to cast

Definition at line 380 of file CombinedKernel.h.

void list_kernels ( )

list kernels

Definition at line 225 of file CombinedKernel.cpp.

bool precompute_subkernels ( )

precompute all sub-kernels

Definition at line 746 of file CombinedKernel.cpp.

void remove_lhs ( )
virtual

remove lhs from kernel

Reimplemented from CKernel.

Definition at line 147 of file CombinedKernel.cpp.

void remove_lhs_and_rhs ( )
virtual

remove lhs and rhs from kernel

Reimplemented from CKernel.

Definition at line 184 of file CombinedKernel.cpp.

void remove_rhs ( )
virtual

remove rhs from kernel

Reimplemented from CKernel.

Definition at line 167 of file CombinedKernel.cpp.

void set_optimization_type ( EOptimizationType  t)
virtual

set optimization type

Parameters
toptimization type

Reimplemented from CKernel.

Definition at line 731 of file CombinedKernel.cpp.

void set_subkernel_weights ( SGVector< float64_t weights)
virtual

set subkernel weights

Parameters
weightsnew subkernel weights

Reimplemented from CKernel.

Definition at line 696 of file CombinedKernel.cpp.

Member Data Documentation

bool append_subkernel_weights
protected

if subkernel weights are appended

Definition at line 449 of file CombinedKernel.h.

bool initialized
protected

whether kernel is ready to be used

Definition at line 451 of file CombinedKernel.h.

CList* kernel_list
protected

list of kernels

Definition at line 439 of file CombinedKernel.h.

float64_t* subkernel_weights_buffer
protected

subkernel weights buffers

Definition at line 447 of file CombinedKernel.h.

int32_t sv_count
protected

support vector count

Definition at line 441 of file CombinedKernel.h.

int32_t* sv_idx
protected

support vector index

Definition at line 443 of file CombinedKernel.h.

float64_t* sv_weight
protected

support vector weights

Definition at line 445 of file CombinedKernel.h.


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

SHOGUN Machine Learning Toolbox - Documentation