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
CWeightedDegreeStringKernel Class Reference

Detailed Description

The Weighted Degree String kernel.

The WD kernel of order d compares two sequences ${\bf x}$ and ${\bf x'}$ of length L by summing all contributions of k-mer matches of lengths $k\in\{1,\dots,d\}$, weighted by coefficients $\beta_k$. It is defined as

\[ k({\bf x},{\bf x'})=\sum_{k=1}^d\beta_k\sum_{l=1}^{L-k+1}I({\bf u}_{k,l}({\bf x})={\bf u}_{k,l}({\bf x'})). \]

Here, ${\bf u}_{k,l}({\bf x})$ is the string of length k starting at position l of the sequence ${\bf x}$ and $I(\cdot)$ is the indicator function which evaluates to 1 when its argument is true and to 0 otherwise.

Definition at line 53 of file WeightedDegreeStringKernel.h.

Inheritance diagram for CWeightedDegreeStringKernel:
Inheritance graph
[legend]

Public Member Functions

 CWeightedDegreeStringKernel ()
 CWeightedDegreeStringKernel (int32_t degree, EWDKernType type=E_WD)
 CWeightedDegreeStringKernel (float64_t *weights, int32_t degree)
 CWeightedDegreeStringKernel (CStringFeatures< char > *l, CStringFeatures< char > *r, int32_t degree)
virtual ~CWeightedDegreeStringKernel ()
virtual bool init (CFeatures *l, CFeatures *r)
virtual void cleanup ()
EWDKernType get_type () const
virtual EKernelType get_kernel_type ()
virtual const char * get_name () const
virtual bool init_optimization (int32_t count, int32_t *IDX, float64_t *alphas)
virtual bool init_optimization (int32_t count, int32_t *IDX, float64_t *alphas, int32_t tree_num)
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)
virtual void clear_normal ()
virtual void add_to_normal (int32_t idx, float64_t weight)
virtual int32_t get_num_subkernels ()
void compute_by_subkernel (int32_t idx, float64_t *subkernel_contrib)
const float64_tget_subkernel_weights (int32_t &num_weights)
virtual void set_subkernel_weights (SGVector< float64_t > w)
virtual bool set_normalizer (CKernelNormalizer *normalizer_)
float64_tcompute_abs_weights (int32_t &len)
void compute_by_tree (int32_t idx, float64_t *LevelContrib)
bool is_tree_initialized ()
float64_tget_degree_weights (int32_t &d, int32_t &len)
float64_tget_weights (int32_t &num_weights)
float64_tget_position_weights (int32_t &len)
bool set_wd_weights_by_type (EWDKernType type)
void set_wd_weights (SGVector< float64_t > new_weights)
bool set_weights (SGMatrix< float64_t > new_weights)
bool set_position_weights (float64_t *pws, int32_t len)
bool init_block_weights ()
bool init_block_weights_from_wd ()
bool init_block_weights_from_wd_external ()
bool init_block_weights_const ()
bool init_block_weights_linear ()
bool init_block_weights_sqpoly ()
bool init_block_weights_cubicpoly ()
bool init_block_weights_exp ()
bool init_block_weights_log ()
bool delete_position_weights ()
bool set_max_mismatch (int32_t max)
int32_t get_max_mismatch () const
bool set_degree (int32_t deg)
int32_t get_degree () const
bool set_use_block_computation (bool block)
bool get_use_block_computation ()
bool set_mkl_stepsize (int32_t step)
int32_t get_mkl_stepsize ()
bool set_which_degree (int32_t which)
int32_t get_which_degree ()
- Public Member Functions inherited from CStringKernel< char >
 CStringKernel (int32_t cachesize=0)
 CStringKernel (CFeatures *l, CFeatures *r)
virtual EFeatureClass get_feature_class ()
virtual EFeatureType get_feature_type ()
- 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 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 ()
virtual bool has_features ()
bool get_lhs_equals_rhs ()
virtual void remove_lhs_and_rhs ()
virtual void remove_rhs ()
 takes all necessary steps if the rhs is removed from kernel
void set_cache_size (int32_t size)
int32_t get_cache_size ()
void list_kernel ()
bool has_property (EKernelProperty p)
EOptimizationType get_optimization_type ()
virtual void set_optimization_type (EOptimizationType t)
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_batch_helper (void *p)

Protected Member Functions

void create_empty_tries ()
void add_example_to_tree (int32_t idx, float64_t weight)
void add_example_to_single_tree (int32_t idx, float64_t weight, int32_t tree_num)
void add_example_to_tree_mismatch (int32_t idx, float64_t weight)
void add_example_to_single_tree_mismatch (int32_t idx, float64_t weight, int32_t tree_num)
float64_t compute_by_tree (int32_t idx)
float64_t compute (int32_t idx_a, int32_t idx_b)
float64_t compute_with_mismatch (char *avec, int32_t alen, char *bvec, int32_t blen)
float64_t compute_without_mismatch (char *avec, int32_t alen, char *bvec, int32_t blen)
float64_t compute_without_mismatch_matrix (char *avec, int32_t alen, char *bvec, int32_t blen)
float64_t compute_using_block (char *avec, int32_t alen, char *bvec, int32_t blen)
virtual void remove_lhs ()

Protected Attributes

float64_tweights
int32_t weights_degree
int32_t weights_length
float64_tposition_weights
int32_t position_weights_len
float64_tweights_buffer
int32_t mkl_stepsize
int32_t degree
int32_t length
int32_t max_mismatch
int32_t seq_length
bool initialized
bool block_computation
float64_tblock_weights
EWDKernType type
int32_t which_degree
CTrie< DNATrie > * tries
bool tree_initialized
CAlphabetalphabet

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

default constructor

Definition at line 48 of file WeightedDegreeStringKernel.cpp.

CWeightedDegreeStringKernel ( int32_t  degree,
EWDKernType  type = E_WD 
)

constructor

Parameters
degreedegree
typeweighted degree kernel type

Definition at line 55 of file WeightedDegreeStringKernel.cpp.

CWeightedDegreeStringKernel ( float64_t weights,
int32_t  degree 
)

constructor

Parameters
weightskernel's weights
degreedegree

Definition at line 68 of file WeightedDegreeStringKernel.cpp.

CWeightedDegreeStringKernel ( CStringFeatures< char > *  l,
CStringFeatures< char > *  r,
int32_t  degree 
)

constructor

Parameters
lfeatures of left-hand side
rfeatures of right-hand side
degreedegree

Definition at line 85 of file WeightedDegreeStringKernel.cpp.

Definition at line 97 of file WeightedDegreeStringKernel.cpp.

Member Function Documentation

void add_example_to_single_tree ( int32_t  idx,
float64_t  weight,
int32_t  tree_num 
)
protected

add example to single tree

Parameters
idxindex
weightweight
tree_numwhich tree

Definition at line 436 of file WeightedDegreeStringKernel.cpp.

void add_example_to_single_tree_mismatch ( int32_t  idx,
float64_t  weight,
int32_t  tree_num 
)
protected

add example to single tree mismatch

Parameters
idxindex
weightweight
tree_numwhich tree

Definition at line 487 of file WeightedDegreeStringKernel.cpp.

void add_example_to_tree ( int32_t  idx,
float64_t  weight 
)
protected

add example to tree

Parameters
idxindex
weightweight

Definition at line 390 of file WeightedDegreeStringKernel.cpp.

void add_example_to_tree_mismatch ( int32_t  idx,
float64_t  weight 
)
protected

add example to tree mismatch

Parameters
idxindex
weightweight

Definition at line 461 of file WeightedDegreeStringKernel.cpp.

virtual void add_to_normal ( int32_t  idx,
float64_t  weight 
)
virtual

add to normal

Parameters
idxwhere to add
weightwhat to add

Reimplemented from CKernel.

Definition at line 213 of file WeightedDegreeStringKernel.h.

void cleanup ( )
virtual

clean up kernel

Reimplemented from CKernel.

Definition at line 183 of file WeightedDegreeStringKernel.cpp.

virtual void clear_normal ( )
virtual

clear normal subkernel functionality

Reimplemented from CKernel.

Definition at line 195 of file WeightedDegreeStringKernel.h.

float64_t compute ( int32_t  idx_a,
int32_t  idx_b 
)
protectedvirtual

compute kernel function for features a and b idx_{a,b} denote the index of the feature vectors in the corresponding feature object

Parameters
idx_aindex a
idx_bindex b
Returns
computed kernel function at indices a,b

Implements CKernel.

Definition at line 364 of file WeightedDegreeStringKernel.cpp.

float64_t * compute_abs_weights ( int32_t &  len)

compute abs weights

Parameters
lenlen
Returns
computed abs weights

Definition at line 566 of file WeightedDegreeStringKernel.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

compute batch

Parameters
num_vecnumber of vectors
vec_idxvector index
targettarget
num_suppvecnumber of support vectors
IDXIDX
alphasalphas
factorfactor

Reimplemented from CKernel.

Definition at line 863 of file WeightedDegreeStringKernel.cpp.

void * compute_batch_helper ( void *  p)
static

helper for compute batch

Parameters
pthread parameter

Definition at line 827 of file WeightedDegreeStringKernel.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 247 of file WeightedDegreeStringKernel.h.

void compute_by_tree ( int32_t  idx,
float64_t LevelContrib 
)

compute by tree

Parameters
idxindex
LevelContriblevel contribution
Returns
computed value

Definition at line 539 of file WeightedDegreeStringKernel.cpp.

float64_t compute_by_tree ( int32_t  idx)
protected

compute by tree

Parameters
idxindex
Returns
computed value

Definition at line 515 of file WeightedDegreeStringKernel.cpp.

virtual 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 162 of file WeightedDegreeStringKernel.h.

float64_t compute_using_block ( char *  avec,
int32_t  alen,
char *  bvec,
int32_t  blen 
)
protected

compute using block

Parameters
avecvector a
alenlength of vector a
bvecvector b
blenlength of vector b
Returns
computed value

Definition at line 291 of file WeightedDegreeStringKernel.cpp.

float64_t compute_with_mismatch ( char *  avec,
int32_t  alen,
char *  bvec,
int32_t  blen 
)
protected

compute with mismatch

Parameters
avecvector a
alenlength of vector a
bvecvector b
blenlength of vector b
Returns
computed value

Definition at line 263 of file WeightedDegreeStringKernel.cpp.

float64_t compute_without_mismatch ( char *  avec,
int32_t  alen,
char *  bvec,
int32_t  blen 
)
protected

compute without mismatch

Parameters
avecvector a
alenlength of vector a
bvecvector b
blenlength of vector b
Returns
computed value

Definition at line 317 of file WeightedDegreeStringKernel.cpp.

float64_t compute_without_mismatch_matrix ( char *  avec,
int32_t  alen,
char *  bvec,
int32_t  blen 
)
protected

compute without mismatch matrix

Parameters
avecvector a
alenlength of vector a
bvecvector b
blenlength of vector b
Returns
computed value

Definition at line 340 of file WeightedDegreeStringKernel.cpp.

void create_empty_tries ( )
protected

create emtpy tries

Definition at line 128 of file WeightedDegreeStringKernel.cpp.

bool delete_optimization ( )
virtual

delete optimization

Returns
if deleting was successful

Reimplemented from CKernel.

Definition at line 249 of file WeightedDegreeStringKernel.cpp.

bool delete_position_weights ( )

delete position weights

Returns
if deleting was successful

Definition at line 518 of file WeightedDegreeStringKernel.h.

int32_t get_degree ( ) const

get degree

Returns
degree

Definition at line 549 of file WeightedDegreeStringKernel.h.

float64_t* get_degree_weights ( int32_t &  d,
int32_t &  len 
)

get degree weights

Parameters
ddegree weights will be stored here
lennumber of degree weights will be stored here

Definition at line 389 of file WeightedDegreeStringKernel.h.

virtual EKernelType get_kernel_type ( )
virtual

return what type of kernel we are

Returns
kernel type WEIGHTEDDEGREE

Implements CStringKernel< char >.

Definition at line 115 of file WeightedDegreeStringKernel.h.

int32_t get_max_mismatch ( ) const

get maximum mismatch

Returns
maximum mismatch

Definition at line 536 of file WeightedDegreeStringKernel.h.

int32_t get_mkl_stepsize ( )

get MKL step size

Returns
MKL step size

Definition at line 585 of file WeightedDegreeStringKernel.h.

virtual const char* get_name ( ) const
virtual

return the kernel's name

Returns
name WeightedDegree

Reimplemented from CStringKernel< char >.

Definition at line 121 of file WeightedDegreeStringKernel.h.

virtual int32_t get_num_subkernels ( )
virtual

get number of subkernels

Returns
number of subkernels

Reimplemented from CKernel.

Definition at line 231 of file WeightedDegreeStringKernel.h.

float64_t* get_position_weights ( int32_t &  len)

get position weights

Parameters
lennumber of position weights will be stored here
Returns
position weights

Definition at line 424 of file WeightedDegreeStringKernel.h.

const float64_t* get_subkernel_weights ( int32_t &  num_weights)
virtual

get subkernel weights

Parameters
num_weightsnumber of weights will be stored here
Returns
subkernel weights

Reimplemented from CKernel.

Definition at line 269 of file WeightedDegreeStringKernel.h.

EWDKernType get_type ( ) const

get WD kernel weighting type

Returns
weighting type
See Also
EWDKernType

Definition at line 106 of file WeightedDegreeStringKernel.h.

bool get_use_block_computation ( )

check if block computation is performed

Returns
if block computation is performed

Definition at line 566 of file WeightedDegreeStringKernel.h.

float64_t* get_weights ( int32_t &  num_weights)

get weights

Parameters
num_weightsnumber of weights will be stored here
Returns
weights

Definition at line 401 of file WeightedDegreeStringKernel.h.

int32_t get_which_degree ( )

get which degree

Returns
which degree

Definition at line 602 of file WeightedDegreeStringKernel.h.

bool init ( CFeatures l,
CFeatures r 
)
virtual

initialize kernel

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

Reimplemented from CStringKernel< char >.

Definition at line 141 of file WeightedDegreeStringKernel.cpp.

bool init_block_weights ( )

initialize block weights

Returns
if initialization was successful

Definition at line 802 of file WeightedDegreeStringKernel.cpp.

bool init_block_weights_const ( )

initialize block weights constant

Returns
if initialization was successful

Definition at line 726 of file WeightedDegreeStringKernel.cpp.

bool init_block_weights_cubicpoly ( )

initialize block weights cubic polynomial

Returns
if initialization was successful

Definition at line 761 of file WeightedDegreeStringKernel.cpp.

bool init_block_weights_exp ( )

initialize block weights exponential

Returns
if initialization was successful

Definition at line 774 of file WeightedDegreeStringKernel.cpp.

bool init_block_weights_from_wd ( )

initialize block weights from weighted degree

Returns
if initialization was successful

Definition at line 685 of file WeightedDegreeStringKernel.cpp.

bool init_block_weights_from_wd_external ( )

initialize block weights from external weighted degree

Returns
if initialization was successful

Definition at line 702 of file WeightedDegreeStringKernel.cpp.

bool init_block_weights_linear ( )

initialize block weights linear

Returns
if initialization was successful

Definition at line 736 of file WeightedDegreeStringKernel.cpp.

bool init_block_weights_log ( )

initialize block weights logarithmic

Returns
if initialization was successful

Definition at line 788 of file WeightedDegreeStringKernel.cpp.

bool init_block_weights_sqpoly ( )

initialize block weights squared polynomial

Returns
if initialization was successful

Definition at line 747 of file WeightedDegreeStringKernel.cpp.

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

initialize optimization

Parameters
countcount
IDXindex
alphasalphas
Returns
if initializing was successful

Reimplemented from CKernel.

Definition at line 132 of file WeightedDegreeStringKernel.h.

bool init_optimization ( int32_t  count,
int32_t *  IDX,
float64_t alphas,
int32_t  tree_num 
)
virtual

initialize optimization do initialization for tree_num up to upto_tree, use tree_num=-1 to construct all trees

Parameters
countcount
IDXIDX
alphasalphas
tree_numwhich tree
Returns
if initializing was successful

Definition at line 207 of file WeightedDegreeStringKernel.cpp.

bool is_tree_initialized ( )

check if tree is initialized

Returns
if tree is initialized

Definition at line 382 of file WeightedDegreeStringKernel.h.

void remove_lhs ( )
protectedvirtual

remove lhs from kernel

Reimplemented from CKernel.

Definition at line 117 of file WeightedDegreeStringKernel.cpp.

bool set_degree ( int32_t  deg)

set degree

Parameters
degnew degree
Returns
if setting was successful

Definition at line 543 of file WeightedDegreeStringKernel.h.

bool set_max_mismatch ( int32_t  max)

set maximum mismatch

Parameters
maxnew maximum mismatch
Returns
if setting was successful

Definition at line 967 of file WeightedDegreeStringKernel.cpp.

bool set_mkl_stepsize ( int32_t  step)

set MKL steps ize

Parameters
stepnew step size
Returns
if setting was successful

Definition at line 573 of file WeightedDegreeStringKernel.h.

virtual bool set_normalizer ( CKernelNormalizer normalizer_)
virtual

set the current kernel normalizer

Returns
if successful

Reimplemented from CKernel.

Definition at line 345 of file WeightedDegreeStringKernel.h.

bool set_position_weights ( float64_t pws,
int32_t  len 
)

set position weights

Parameters
pwsnew position weights
lennumber of position weights
Returns
if setting was successful

Definition at line 655 of file WeightedDegreeStringKernel.cpp.

virtual void set_subkernel_weights ( SGVector< float64_t w)
virtual

set subkernel weights

Parameters
wweights

Reimplemented from CKernel.

Definition at line 294 of file WeightedDegreeStringKernel.h.

bool set_use_block_computation ( bool  block)

set if block computation shall be performed

Parameters
blockif block computation shall be performed
Returns
if setting was successful

Definition at line 556 of file WeightedDegreeStringKernel.h.

void set_wd_weights ( SGVector< float64_t new_weights)

set wd weights

Parameters
new_weightsnew weights

Definition at line 441 of file WeightedDegreeStringKernel.h.

bool set_wd_weights_by_type ( EWDKernType  type)

set wd weights

Parameters
typeweighted degree kernel type
Returns
if setting was successful

if we know a better weighting later on do a switch

Definition at line 572 of file WeightedDegreeStringKernel.cpp.

bool set_weights ( SGMatrix< float64_t new_weights)

set weights

Parameters
new_weightsnew weights

Definition at line 625 of file WeightedDegreeStringKernel.cpp.

bool set_which_degree ( int32_t  which)

set which degree

Parameters
whichwhich degree
Returns
if setting was successful

Definition at line 592 of file WeightedDegreeStringKernel.h.

Member Data Documentation

CAlphabet* alphabet
protected

alphabet of features

Definition at line 758 of file WeightedDegreeStringKernel.h.

bool block_computation
protected

if block computation is used

Definition at line 742 of file WeightedDegreeStringKernel.h.

float64_t* block_weights
protected

(internal) block weights

Definition at line 745 of file WeightedDegreeStringKernel.h.

int32_t degree
protected

degree

Definition at line 729 of file WeightedDegreeStringKernel.h.

bool initialized
protected

if kernel is initialized

Definition at line 739 of file WeightedDegreeStringKernel.h.

int32_t length
protected

length

Definition at line 731 of file WeightedDegreeStringKernel.h.

int32_t max_mismatch
protected

maximum mismatch

Definition at line 734 of file WeightedDegreeStringKernel.h.

int32_t mkl_stepsize
protected

MKL step size

Definition at line 727 of file WeightedDegreeStringKernel.h.

float64_t* position_weights
protected

position weights

Definition at line 721 of file WeightedDegreeStringKernel.h.

int32_t position_weights_len
protected

position weights

Definition at line 723 of file WeightedDegreeStringKernel.h.

int32_t seq_length
protected

sequence length

Definition at line 736 of file WeightedDegreeStringKernel.h.

bool tree_initialized
protected

if tree is initialized

Definition at line 755 of file WeightedDegreeStringKernel.h.

CTrie<DNATrie>* tries
protected

tries

Definition at line 752 of file WeightedDegreeStringKernel.h.

EWDKernType type
protected

WeightedDegree kernel type

Definition at line 747 of file WeightedDegreeStringKernel.h.

float64_t* weights
protected

degree*length weights *length must match seq_length if != 0

Definition at line 713 of file WeightedDegreeStringKernel.h.

float64_t* weights_buffer
protected

weights buffer

Definition at line 725 of file WeightedDegreeStringKernel.h.

int32_t weights_degree
protected

degree

Definition at line 715 of file WeightedDegreeStringKernel.h.

int32_t weights_length
protected

length

Definition at line 717 of file WeightedDegreeStringKernel.h.

int32_t which_degree
protected

which degree

Definition at line 749 of file WeightedDegreeStringKernel.h.


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

SHOGUN Machine Learning Toolbox - Documentation