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

Inheritance diagram for CWeightedDegreeStringKernel:
Inheritance graph
[legend]

List of all members.

Public Member Functions

 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 ()
bool load_init (FILE *src)
bool save_init (FILE *dest)
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)
void set_subkernel_weights (float64_t *weights2, int32_t num_weights2)
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 (float64_t *p_weights, int32_t d)
bool set_weights (float64_t *weights, int32_t d, int32_t len)
bool set_position_weights (float64_t *position_weights, int32_t len=0)
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 init_block_weights_external ()
bool delete_position_weights ()
bool set_max_mismatch (int32_t max)
int32_t get_max_mismatch ()
bool set_degree (int32_t deg)
int32_t get_degree ()
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 ()

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
float64_tposition_weights
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
int32_t num_block_weights_external
float64_tblock_weights_external
float64_tblock_weights
EWDKernType type
int32_t which_degree
CTrie< DNATrie > * tries
bool tree_initialized
CAlphabetalphabet

Constructor & Destructor Documentation

CWeightedDegreeStringKernel::CWeightedDegreeStringKernel ( int32_t  degree,
EWDKernType  type = E_WD 
)

constructor

Parameters:
degree degree
type weighted degree kernel type

Definition at line 44 of file WeightedDegreeStringKernel.cpp.

CWeightedDegreeStringKernel::CWeightedDegreeStringKernel ( float64_t weights,
int32_t  degree 
)

constructor

Parameters:
weights kernel's weights
degree degree

Definition at line 63 of file WeightedDegreeStringKernel.cpp.

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

constructor

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

Definition at line 82 of file WeightedDegreeStringKernel.cpp.

CWeightedDegreeStringKernel::~CWeightedDegreeStringKernel (  )  [virtual]

Definition at line 98 of file WeightedDegreeStringKernel.cpp.


Member Function Documentation

void CWeightedDegreeStringKernel::add_example_to_single_tree ( int32_t  idx,
float64_t  weight,
int32_t  tree_num 
) [protected]

add example to single tree

Parameters:
idx index
weight weight
tree_num which tree

Definition at line 439 of file WeightedDegreeStringKernel.cpp.

void CWeightedDegreeStringKernel::add_example_to_single_tree_mismatch ( int32_t  idx,
float64_t  weight,
int32_t  tree_num 
) [protected]

add example to single tree mismatch

Parameters:
idx index
weight weight
tree_num which tree

Definition at line 485 of file WeightedDegreeStringKernel.cpp.

void CWeightedDegreeStringKernel::add_example_to_tree ( int32_t  idx,
float64_t  weight 
) [protected]

add example to tree

Parameters:
idx index
weight weight

Definition at line 395 of file WeightedDegreeStringKernel.cpp.

void CWeightedDegreeStringKernel::add_example_to_tree_mismatch ( int32_t  idx,
float64_t  weight 
) [protected]

add example to tree mismatch

Parameters:
idx index
weight weight

Definition at line 461 of file WeightedDegreeStringKernel.cpp.

virtual void CWeightedDegreeStringKernel::add_to_normal ( int32_t  idx,
float64_t  weight 
) [virtual]

add to normal

Parameters:
idx where to add
weight what to add

Reimplemented from CKernel.

Definition at line 199 of file WeightedDegreeStringKernel.h.

void CWeightedDegreeStringKernel::cleanup (  )  [virtual]

clean up kernel

Reimplemented from CKernel.

Definition at line 180 of file WeightedDegreeStringKernel.cpp.

virtual void CWeightedDegreeStringKernel::clear_normal (  )  [virtual]

clear normal subkernel functionality

Reimplemented from CKernel.

Definition at line 185 of file WeightedDegreeStringKernel.h.

float64_t CWeightedDegreeStringKernel::compute ( int32_t  idx_a,
int32_t  idx_b 
) [protected, virtual]

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_a index a
idx_b index b
Returns:
computed kernel function at indices a,b

Implements CKernel.

Definition at line 372 of file WeightedDegreeStringKernel.cpp.

float64_t * CWeightedDegreeStringKernel::compute_abs_weights ( int32_t &  len  ) 

compute abs weights

Parameters:
len len
Returns:
computed abs weights

Definition at line 558 of file WeightedDegreeStringKernel.cpp.

void CWeightedDegreeStringKernel::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_vec number of vectors
vec_idx vector index
target target
num_suppvec number of support vectors
IDX IDX
alphas alphas
factor factor

Reimplemented from CKernel.

Definition at line 893 of file WeightedDegreeStringKernel.cpp.

void * CWeightedDegreeStringKernel::compute_batch_helper ( void *  p  )  [static]

helper for compute batch

Parameters:
p thread parameter

Definition at line 859 of file WeightedDegreeStringKernel.cpp.

void CWeightedDegreeStringKernel::compute_by_subkernel ( int32_t  idx,
float64_t subkernel_contrib 
) [virtual]

compute by subkernel

Parameters:
idx index
subkernel_contrib subkernel contribution

Reimplemented from CKernel.

Definition at line 227 of file WeightedDegreeStringKernel.h.

float64_t CWeightedDegreeStringKernel::compute_by_tree ( int32_t  idx  )  [protected]

compute by tree

Parameters:
idx index
Returns:
computed value

Definition at line 511 of file WeightedDegreeStringKernel.cpp.

void CWeightedDegreeStringKernel::compute_by_tree ( int32_t  idx,
float64_t LevelContrib 
)

compute by tree

Parameters:
idx index
LevelContrib level contribution
Returns:
computed value

Definition at line 533 of file WeightedDegreeStringKernel.cpp.

virtual float64_t CWeightedDegreeStringKernel::compute_optimized ( int32_t  idx  )  [virtual]

compute optimized

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

Reimplemented from CKernel.

Definition at line 152 of file WeightedDegreeStringKernel.h.

float64_t CWeightedDegreeStringKernel::compute_using_block ( char *  avec,
int32_t  alen,
char *  bvec,
int32_t  blen 
) [protected]

compute using block

Parameters:
avec vector a
alen length of vector a
bvec vector b
blen length of vector b
Returns:
computed value

Definition at line 299 of file WeightedDegreeStringKernel.cpp.

float64_t CWeightedDegreeStringKernel::compute_with_mismatch ( char *  avec,
int32_t  alen,
char *  bvec,
int32_t  blen 
) [protected]

compute with mismatch

Parameters:
avec vector a
alen length of vector a
bvec vector b
blen length of vector b
Returns:
computed value

Definition at line 271 of file WeightedDegreeStringKernel.cpp.

float64_t CWeightedDegreeStringKernel::compute_without_mismatch ( char *  avec,
int32_t  alen,
char *  bvec,
int32_t  blen 
) [protected]

compute without mismatch

Parameters:
avec vector a
alen length of vector a
bvec vector b
blen length of vector b
Returns:
computed value

Definition at line 325 of file WeightedDegreeStringKernel.cpp.

float64_t CWeightedDegreeStringKernel::compute_without_mismatch_matrix ( char *  avec,
int32_t  alen,
char *  bvec,
int32_t  blen 
) [protected]

compute without mismatch matrix

Parameters:
avec vector a
alen length of vector a
bvec vector b
blen length of vector b
Returns:
computed value

Definition at line 348 of file WeightedDegreeStringKernel.cpp.

void CWeightedDegreeStringKernel::create_empty_tries (  )  [protected]

create emtpy tries

Definition at line 127 of file WeightedDegreeStringKernel.cpp.

bool CWeightedDegreeStringKernel::delete_optimization (  )  [virtual]

delete optimization

Returns:
if deleting was successful

Reimplemented from CKernel.

Definition at line 257 of file WeightedDegreeStringKernel.cpp.

bool CWeightedDegreeStringKernel::delete_position_weights (  ) 

delete position weights

Returns:
if deleting was successful

Definition at line 470 of file WeightedDegreeStringKernel.h.

int32_t CWeightedDegreeStringKernel::get_degree (  ) 

get degree

Returns:
degree

Definition at line 501 of file WeightedDegreeStringKernel.h.

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

get degree weights

Parameters:
d degree weights will be stored here
len number of degree weights will be stored here

Definition at line 335 of file WeightedDegreeStringKernel.h.

virtual EKernelType CWeightedDegreeStringKernel::get_kernel_type (  )  [virtual]

return what type of kernel we are

Returns:
kernel type WEIGHTEDDEGREE

Implements CKernel.

Definition at line 107 of file WeightedDegreeStringKernel.h.

int32_t CWeightedDegreeStringKernel::get_max_mismatch (  ) 

get maximum mismatch

Returns:
maximum mismatch

Definition at line 488 of file WeightedDegreeStringKernel.h.

int32_t CWeightedDegreeStringKernel::get_mkl_stepsize (  ) 

get MKL step size

Returns:
MKL step size

Definition at line 535 of file WeightedDegreeStringKernel.h.

virtual const char* CWeightedDegreeStringKernel::get_name (  )  const [virtual]

return the kernel's name

Returns:
name WeightedDegree

Implements CSGObject.

Definition at line 113 of file WeightedDegreeStringKernel.h.

virtual int32_t CWeightedDegreeStringKernel::get_num_subkernels (  )  [virtual]

get number of subkernels

Returns:
number of subkernels

Reimplemented from CKernel.

Definition at line 213 of file WeightedDegreeStringKernel.h.

float64_t* CWeightedDegreeStringKernel::get_position_weights ( int32_t &  len  ) 

get position weights

Parameters:
len number of position weights will be stored here
Returns:
position weights

Definition at line 366 of file WeightedDegreeStringKernel.h.

const float64_t* CWeightedDegreeStringKernel::get_subkernel_weights ( int32_t &  num_weights  )  [virtual]

get subkernel weights

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

Reimplemented from CKernel.

Definition at line 244 of file WeightedDegreeStringKernel.h.

bool CWeightedDegreeStringKernel::get_use_block_computation (  ) 

check if block computation is performed

Returns:
if block computation is performed

Definition at line 518 of file WeightedDegreeStringKernel.h.

float64_t* CWeightedDegreeStringKernel::get_weights ( int32_t &  num_weights  ) 

get weights

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

Definition at line 347 of file WeightedDegreeStringKernel.h.

int32_t CWeightedDegreeStringKernel::get_which_degree (  ) 

get which degree

Returns:
which degree

Definition at line 552 of file WeightedDegreeStringKernel.h.

bool CWeightedDegreeStringKernel::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 CStringKernel< char >.

Definition at line 138 of file WeightedDegreeStringKernel.cpp.

bool CWeightedDegreeStringKernel::init_block_weights (  ) 

initialize block weights

Returns:
if initialization was successful

Definition at line 831 of file WeightedDegreeStringKernel.cpp.

bool CWeightedDegreeStringKernel::init_block_weights_const (  ) 

initialize block weights constant

Returns:
if initialization was successful

Definition at line 716 of file WeightedDegreeStringKernel.cpp.

bool CWeightedDegreeStringKernel::init_block_weights_cubicpoly (  ) 

initialize block weights cubic polynomial

Returns:
if initialization was successful

Definition at line 761 of file WeightedDegreeStringKernel.cpp.

bool CWeightedDegreeStringKernel::init_block_weights_exp (  ) 

initialize block weights exponential

Returns:
if initialization was successful

Definition at line 778 of file WeightedDegreeStringKernel.cpp.

bool CWeightedDegreeStringKernel::init_block_weights_external (  ) 

initialize block weights external

Returns:
if initialization was successful

Definition at line 812 of file WeightedDegreeStringKernel.cpp.

bool CWeightedDegreeStringKernel::init_block_weights_from_wd (  ) 

initialize block weights from weighted degree

Returns:
if initialization was successful

Definition at line 668 of file WeightedDegreeStringKernel.cpp.

bool CWeightedDegreeStringKernel::init_block_weights_from_wd_external (  ) 

initialize block weights from external weighted degree

Returns:
if initialization was successful

Definition at line 688 of file WeightedDegreeStringKernel.cpp.

bool CWeightedDegreeStringKernel::init_block_weights_linear (  ) 

initialize block weights linear

Returns:
if initialization was successful

Definition at line 730 of file WeightedDegreeStringKernel.cpp.

bool CWeightedDegreeStringKernel::init_block_weights_log (  ) 

initialize block weights logarithmic

Returns:
if initialization was successful

Definition at line 795 of file WeightedDegreeStringKernel.cpp.

bool CWeightedDegreeStringKernel::init_block_weights_sqpoly (  ) 

initialize block weights squared polynomial

Returns:
if initialization was successful

Definition at line 744 of file WeightedDegreeStringKernel.cpp.

bool CWeightedDegreeStringKernel::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:
count count
IDX IDX
alphas alphas
tree_num which tree
Returns:
if initializing was successful

Definition at line 215 of file WeightedDegreeStringKernel.cpp.

virtual bool CWeightedDegreeStringKernel::init_optimization ( int32_t  count,
int32_t *  IDX,
float64_t alphas 
) [virtual]

initialize optimization

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

Reimplemented from CKernel.

Definition at line 122 of file WeightedDegreeStringKernel.h.

bool CWeightedDegreeStringKernel::is_tree_initialized (  ) 

check if tree is initialized

Returns:
if tree is initialized

Definition at line 328 of file WeightedDegreeStringKernel.h.

bool CWeightedDegreeStringKernel::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 204 of file WeightedDegreeStringKernel.cpp.

void CWeightedDegreeStringKernel::remove_lhs (  )  [protected, virtual]

remove lhs from kernel

Reimplemented from CKernel.

Definition at line 116 of file WeightedDegreeStringKernel.cpp.

bool CWeightedDegreeStringKernel::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 209 of file WeightedDegreeStringKernel.cpp.

bool CWeightedDegreeStringKernel::set_degree ( int32_t  deg  ) 

set degree

Parameters:
deg new degree
Returns:
if setting was successful

Definition at line 495 of file WeightedDegreeStringKernel.h.

bool CWeightedDegreeStringKernel::set_max_mismatch ( int32_t  max  ) 

set maximum mismatch

Parameters:
max new maximum mismatch
Returns:
if setting was succesful

Definition at line 997 of file WeightedDegreeStringKernel.cpp.

bool CWeightedDegreeStringKernel::set_mkl_stepsize ( int32_t  step  ) 

set MKL steps ize

Parameters:
step new step size
Returns:
if setting was successful

Definition at line 525 of file WeightedDegreeStringKernel.h.

bool CWeightedDegreeStringKernel::set_position_weights ( float64_t position_weights,
int32_t  len = 0 
)

set position weights

Parameters:
position_weights new position weights
len number of position weights
Returns:
if setting was successful

Definition at line 639 of file WeightedDegreeStringKernel.cpp.

void CWeightedDegreeStringKernel::set_subkernel_weights ( float64_t weights2,
int32_t  num_weights2 
) [virtual]

set subkernel weights

Parameters:
weights2 weights
num_weights2 number of weights

Reimplemented from CKernel.

Definition at line 266 of file WeightedDegreeStringKernel.h.

bool CWeightedDegreeStringKernel::set_use_block_computation ( bool  block  ) 

set if block computation shall be performed

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

Definition at line 508 of file WeightedDegreeStringKernel.h.

void CWeightedDegreeStringKernel::set_wd_weights ( float64_t p_weights,
int32_t  d 
)

set wd weights

Parameters:
p_weights new eights
d degree
Returns:
if setting was successful

Definition at line 385 of file WeightedDegreeStringKernel.h.

bool CWeightedDegreeStringKernel::set_wd_weights_by_type ( EWDKernType  type  ) 

set wd weights

Parameters:
type weighted degree kernel type
Returns:
if setting was successful

if we know a better weighting later on do a switch

Definition at line 564 of file WeightedDegreeStringKernel.cpp.

bool CWeightedDegreeStringKernel::set_weights ( float64_t weights,
int32_t  d,
int32_t  len 
)

set weights

Parameters:
weights new weights
d degree
len number of weights

Definition at line 614 of file WeightedDegreeStringKernel.cpp.

bool CWeightedDegreeStringKernel::set_which_degree ( int32_t  which  ) 

set which degree

Parameters:
which which degree
Returns:
if setting was successful

Definition at line 542 of file WeightedDegreeStringKernel.h.


Member Data Documentation

alphabet of features

Definition at line 700 of file WeightedDegreeStringKernel.h.

if block computation is used

Definition at line 679 of file WeightedDegreeStringKernel.h.

(internal) block weights

Definition at line 687 of file WeightedDegreeStringKernel.h.

external block weights

Definition at line 684 of file WeightedDegreeStringKernel.h.

degree

Definition at line 666 of file WeightedDegreeStringKernel.h.

if kernel is initialized

Definition at line 676 of file WeightedDegreeStringKernel.h.

length

Definition at line 668 of file WeightedDegreeStringKernel.h.

maximum mismatch

Definition at line 671 of file WeightedDegreeStringKernel.h.

MKL step size

Definition at line 664 of file WeightedDegreeStringKernel.h.

number of external block weights

Definition at line 682 of file WeightedDegreeStringKernel.h.

position weights

Definition at line 660 of file WeightedDegreeStringKernel.h.

sequence length

Definition at line 673 of file WeightedDegreeStringKernel.h.

if tree is initialized

Definition at line 697 of file WeightedDegreeStringKernel.h.

tries

Definition at line 694 of file WeightedDegreeStringKernel.h.

WeightedDegree kernel type

Definition at line 689 of file WeightedDegreeStringKernel.h.

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

Definition at line 658 of file WeightedDegreeStringKernel.h.

weights buffer

Definition at line 662 of file WeightedDegreeStringKernel.h.

which degree

Definition at line 691 of file WeightedDegreeStringKernel.h.


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

SHOGUN Machine Learning Toolbox - Documentation