CWeightedCommWordStringKernel Class Reference

Inheritance diagram for CWeightedCommWordStringKernel:

Inheritance graph
[legend]

List of all members.


Detailed Description

kernel WeightedCommWordString

Definition at line 22 of file WeightedCommWordStringKernel.h.


Public Member Functions

 CWeightedCommWordStringKernel (INT size, bool use_sign, ENormalizationType normalization_=FULL_NORMALIZATION)
 CWeightedCommWordStringKernel (CStringFeatures< WORD > *l, CStringFeatures< WORD > *r, bool use_sign=false, ENormalizationType normalization_=FULL_NORMALIZATION, INT size=10)
virtual ~CWeightedCommWordStringKernel ()
virtual bool init (CFeatures *l, CFeatures *r)
virtual void cleanup ()
virtual DREAL compute_optimized (INT idx)
virtual void add_to_normal (INT idx, DREAL weight)
void merge_normal ()
bool set_wd_weights ()
bool set_weights (DREAL *w, INT d)
virtual EKernelType get_kernel_type ()
virtual const CHARget_name ()
virtual EFeatureType get_feature_type ()
virtual DREALcompute_scoring (INT max_degree, INT &num_feat, INT &num_sym, DREAL *target, INT num_suppvec, INT *IDX, DREAL *alphas, bool do_init=true)
bool load_init (FILE *src)
bool save_init (FILE *dest)
virtual bool init_dictionary (INT size)
virtual bool init_optimization (INT count, INT *IDX, DREAL *weights)
virtual bool delete_optimization ()
virtual void clear_normal ()
virtual void remove_lhs ()
virtual void remove_rhs ()
void get_dictionary (INT &dsize, DREAL *&dweights)
CHARcompute_consensus (INT &num_feat, INT num_suppvec, INT *IDX, DREAL *alphas)
void set_use_dict_diagonal_optimization (bool flag)
bool get_use_dict_diagonal_optimization ()
virtual EFeatureClass get_feature_class ()
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 ()
virtual void set_optimization_type (EOptimizationType t)
bool get_is_initialized ()
bool init_optimization_svm (CSVM *svm)
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_helper (INT idx_a, INT idx_b, bool do_sort)
virtual DREAL compute (INT idx_a, INT idx_b)
virtual DREAL compute_diag (INT idx_a)
DREAL normalize_weight (DREAL *weights, DREAL value, INT seq_num, INT seq_len, ENormalizationType p_normalization)
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

INT degree
DREALweights
DREALsqrtdiag_lhs
DREALsqrtdiag_rhs
bool initialized
INT dictionary_size
DREALdictionary_weights
bool use_sign
ENormalizationType normalization
bool use_dict_diagonal_optimization
INTdict_diagonal_optimization
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

CWeightedCommWordStringKernel::CWeightedCommWordStringKernel ( INT  size,
bool  use_sign,
ENormalizationType  normalization_ = FULL_NORMALIZATION 
)

constructor

Parameters:
size cache size
use_sign if sign shall be used
normalization_ type of normalization

Definition at line 16 of file WeightedCommWordStringKernel.cpp.

CWeightedCommWordStringKernel::CWeightedCommWordStringKernel ( CStringFeatures< WORD > *  l,
CStringFeatures< WORD > *  r,
bool  use_sign = false,
ENormalizationType  normalization_ = FULL_NORMALIZATION,
INT  size = 10 
)

constructor

Parameters:
l features of left-hand side
r features of right-hand side
use_sign if sign shall be used
normalization_ type of normalization
size cache size

Definition at line 24 of file WeightedCommWordStringKernel.cpp.

CWeightedCommWordStringKernel::~CWeightedCommWordStringKernel (  )  [virtual]

Definition at line 35 of file WeightedCommWordStringKernel.cpp.


Member Function Documentation

bool CWeightedCommWordStringKernel::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 CCommWordStringKernel.

Definition at line 40 of file WeightedCommWordStringKernel.cpp.

void CWeightedCommWordStringKernel::cleanup (  )  [virtual]

clean up kernel

Reimplemented from CCommWordStringKernel.

Definition at line 50 of file WeightedCommWordStringKernel.cpp.

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

compute optimized

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

Reimplemented from CCommWordStringKernel.

Definition at line 256 of file WeightedCommWordStringKernel.cpp.

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

add to normal

Parameters:
idx where to add
weight what to add

Reimplemented from CCommWordStringKernel.

Definition at line 198 of file WeightedCommWordStringKernel.cpp.

void CWeightedCommWordStringKernel::merge_normal (  ) 

merge normal

Definition at line 224 of file WeightedCommWordStringKernel.cpp.

bool CWeightedCommWordStringKernel::set_wd_weights (  ) 

set weighted degree weights

Returns:
if setting was successful

Definition at line 57 of file WeightedCommWordStringKernel.cpp.

bool CWeightedCommWordStringKernel::set_weights ( DREAL w,
INT  d 
)

set custom weights (swig compatible)

Parameters:
w weights
d degree (must match number of weights)
Returns:
if setting was successful

Definition at line 76 of file WeightedCommWordStringKernel.cpp.

virtual EKernelType CWeightedCommWordStringKernel::get_kernel_type (  )  [virtual]

return what type of kernel we are

Returns:
kernel type WEIGHTEDCOMMWORDSTRING

Reimplemented from CCommWordStringKernel.

Definition at line 96 of file WeightedCommWordStringKernel.h.

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

return the kernel's name

Returns:
name WeightedCommWordString

Reimplemented from CCommWordStringKernel.

Definition at line 102 of file WeightedCommWordStringKernel.h.

virtual EFeatureType CWeightedCommWordStringKernel::get_feature_type (  )  [virtual]

return feature type the kernel can deal with

Returns:
feature type WORD

Reimplemented from CCommWordStringKernel.

Definition at line 108 of file WeightedCommWordStringKernel.h.

DREAL * CWeightedCommWordStringKernel::compute_scoring ( INT  max_degree,
INT num_feat,
INT num_sym,
DREAL target,
INT  num_suppvec,
INT IDX,
DREAL alphas,
bool  do_init = true 
) [virtual]

compute scoring

Parameters:
max_degree maximum degree
num_feat number of features
num_sym number of symbols
target target
num_suppvec number of support vectors
IDX IDX
alphas alphas
do_init if initialization shall be performed
Returns:
computed score

Reimplemented from CCommWordStringKernel.

Definition at line 289 of file WeightedCommWordStringKernel.cpp.

DREAL CWeightedCommWordStringKernel::compute_helper ( INT  idx_a,
INT  idx_b,
bool  do_sort 
) [protected, virtual]

helper for compute

Parameters:
idx_a index a
idx_b index b
do_sort if sorting shall be performed

Reimplemented from CCommWordStringKernel.

Definition at line 87 of file WeightedCommWordStringKernel.cpp.

bool CCommWordStringKernel::load_init ( FILE *  src  )  [virtual, inherited]

load kernel init_data

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

Implements CKernel.

Definition at line 187 of file CommWordStringKernel.cpp.

bool CCommWordStringKernel::save_init ( FILE *  dest  )  [virtual, inherited]

save kernel init_data

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

Implements CKernel.

Definition at line 192 of file CommWordStringKernel.cpp.

bool CCommWordStringKernel::init_dictionary ( INT  size  )  [virtual, inherited]

initialize dictionary

Parameters:
size size

Definition at line 40 of file CommWordStringKernel.cpp.

bool CCommWordStringKernel::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 from CKernel.

Definition at line 409 of file CommWordStringKernel.cpp.

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

delete optimization

Returns:
if deleting was successful

Reimplemented from CKernel.

Definition at line 436 of file CommWordStringKernel.cpp.

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

clear normal

Reimplemented from CKernel.

Definition at line 403 of file CommWordStringKernel.cpp.

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

remove lhs from kernel

Reimplemented from CKernel.

Definition at line 59 of file CommWordStringKernel.cpp.

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

remove rhs from kernel

Reimplemented from CKernel.

Definition at line 79 of file CommWordStringKernel.cpp.

void CCommWordStringKernel::get_dictionary ( INT dsize,
DREAL *&  dweights 
) [inherited]

get dictionary

Parameters:
dsize dictionary size will be stored in here
dweights dictionary weights will be stored in here

Definition at line 164 of file CommWordStringKernel.h.

CHAR * CCommWordStringKernel::compute_consensus ( INT num_feat,
INT  num_suppvec,
INT IDX,
DREAL alphas 
) [inherited]

compute consensus

Parameters:
num_feat number of features
num_suppvec number of support vectors
IDX IDX
alphas alphas
Returns:
computed consensus

Definition at line 612 of file CommWordStringKernel.cpp.

void CCommWordStringKernel::set_use_dict_diagonal_optimization ( bool  flag  )  [inherited]

set_use_dict_diagonal_optimization

Parameters:
flag enable diagonal optimization

Definition at line 202 of file CommWordStringKernel.h.

bool CCommWordStringKernel::get_use_dict_diagonal_optimization (  )  [inherited]

get.use.dict.diagonal.optimization

Returns:
true if diagonal optimization is on

Definition at line 211 of file CommWordStringKernel.h.

virtual DREAL CCommWordStringKernel::compute ( INT  idx_a,
INT  idx_b 
) [protected, virtual, inherited]

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 225 of file CommWordStringKernel.h.

DREAL CCommWordStringKernel::compute_diag ( INT  idx_a  )  [protected, virtual, inherited]

helper to compute only diagonal normalization for training

Parameters:
idx_a index a
Returns:
unnormalized diagonal value

Definition at line 197 of file CommWordStringKernel.cpp.

DREAL CCommWordStringKernel::normalize_weight ( DREAL weights,
DREAL  value,
INT  seq_num,
INT  seq_len,
ENormalizationType  p_normalization 
) [protected, inherited]

normalize weight

Parameters:
weights weights
value value
seq_num sequence number
seq_len length of sequence
p_normalization type of normalization

Definition at line 254 of file CommWordStringKernel.h.

template<class ST>
virtual EFeatureClass CStringKernel< ST >::get_feature_class (  )  [virtual, inherited]

return feature class the kernel can deal with

Returns:
feature class STRING

Implements CKernel.

Definition at line 63 of file StringKernel.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.

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.

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_svm ( CSVM svm  )  [inherited]

initialize optimization

Parameters:
svm svm model
Returns:
if initializing was successful

Definition at line 644 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

degree

Definition at line 136 of file WeightedCommWordStringKernel.h.

weights for each of the subkernels of degree 1...d

Definition at line 139 of file WeightedCommWordStringKernel.h.

DREAL* CCommWordStringKernel::sqrtdiag_lhs [protected, inherited]

sqrt diagonal of left-hand side

Definition at line 287 of file CommWordStringKernel.h.

DREAL* CCommWordStringKernel::sqrtdiag_rhs [protected, inherited]

sqrt diagonal of right-hand side

Definition at line 289 of file CommWordStringKernel.h.

bool CCommWordStringKernel::initialized [protected, inherited]

if kernel is initialized

Definition at line 291 of file CommWordStringKernel.h.

size of dictionary (number of possible strings)

Definition at line 294 of file CommWordStringKernel.h.

dictionary weights - array to hold counters for all possible strings

Definition at line 297 of file CommWordStringKernel.h.

bool CCommWordStringKernel::use_sign [protected, inherited]

if sign shall be used

Definition at line 300 of file CommWordStringKernel.h.

type of normalization

Definition at line 302 of file CommWordStringKernel.h.

whether diagonal optimization shall be used

Definition at line 305 of file CommWordStringKernel.h.

array to hold counters for all strings

Definition at line 307 of file CommWordStringKernel.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