CKernel Class Reference

Inheritance diagram for CKernel:

Inheritance graph
[legend]

List of all members.


Detailed Description

class Kernel

Definition at line 22 of file Kernel.h.


Public Member Functions

 CKernel (INT size)
 CKernel (CFeatures *l, CFeatures *r, INT size)
virtual ~CKernel ()
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)
virtual bool init (CFeatures *lhs, CFeatures *rhs)
virtual void cleanup ()
bool load (CHAR *fname)
bool save (CHAR *fname)
virtual bool load_init (FILE *src)=0
virtual bool save_init (FILE *dest)=0
CFeaturesget_lhs ()
CFeaturesget_rhs ()
INT get_num_vec_lhs ()
INT get_num_vec_rhs ()
bool has_features ()
virtual void remove_lhs_and_rhs ()
virtual void remove_lhs ()
virtual void remove_rhs ()
 takes all necessary steps if the rhs is removed from kernel
virtual EKernelType get_kernel_type ()=0
virtual EFeatureType get_feature_type ()=0
virtual EFeatureClass get_feature_class ()=0
virtual const CHARget_name ()=0
void set_cache_size (INT size)
int get_cache_size ()
void list_kernel ()
bool has_property (EKernelProperty p)
virtual void clear_normal ()
virtual void add_to_normal (INT vector_idx, DREAL weight)
EOptimizationType get_optimization_type ()
virtual void set_optimization_type (EOptimizationType t)
bool get_is_initialized ()
virtual bool init_optimization (INT count, INT *IDX, DREAL *weights)
virtual bool delete_optimization ()
bool init_optimization_svm (CSVM *svm)
virtual DREAL compute_optimized (INT vector_idx)
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

void set_property (EKernelProperty p)
void unset_property (EKernelProperty p)
void set_is_initialized (bool p_init)
virtual DREAL compute (INT x, INT y)=0
void do_precompute_matrix ()
 matrix precomputation
void init_sqrt_diag (DREAL *v, INT num)

Protected Attributes

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

CKernel::CKernel ( INT  size  ) 

constructor

Parameters:
size cache size

Definition at line 33 of file Kernel.cpp.

CKernel::CKernel ( CFeatures l,
CFeatures r,
INT  size 
)

constructor

Parameters:
l features for left-hand side
r features for right-hand side
size cache size

Definition at line 49 of file Kernel.cpp.

CKernel::~CKernel (  )  [virtual]

Definition at line 66 of file Kernel.cpp.


Member Function Documentation

DREAL CKernel::kernel ( INT  idx_a,
INT  idx_b 
)

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 
)

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]

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]

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::init ( CFeatures lhs,
CFeatures rhs 
) [virtual]

void CKernel::cleanup (  )  [virtual]

bool CKernel::load ( CHAR fname  ) 

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  ) 

save kernel matrix

Parameters:
fname filename to save to
Returns:
if saving was successful

Definition at line 327 of file Kernel.cpp.

virtual bool CKernel::load_init ( FILE *  src  )  [pure virtual]

virtual bool CKernel::save_init ( FILE *  dest  )  [pure virtual]

CFeatures* CKernel::get_lhs (  ) 

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 (  ) 

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 (  ) 

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 (  ) 

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 (  ) 

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]

remove lhs and rhs from kernel

Definition at line 358 of file Kernel.cpp.

void CKernel::remove_lhs (  )  [virtual]

void CKernel::remove_rhs (  )  [virtual]

takes all necessary steps if the rhs is removed from kernel

remove rhs from kernel

Reimplemented in CCombinedKernel, CCommUlongStringKernel, and CCommWordStringKernel.

Definition at line 379 of file Kernel.cpp.

virtual EKernelType CKernel::get_kernel_type (  )  [pure virtual]

virtual EFeatureType CKernel::get_feature_type (  )  [pure virtual]

virtual EFeatureClass CKernel::get_feature_class (  )  [pure virtual]

virtual const CHAR* CKernel::get_name (  )  [pure virtual]

void CKernel::set_cache_size ( INT  size  ) 

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 (  ) 

return the size of the kernel cache

Returns:
size of kernel cache

Definition at line 259 of file Kernel.h.

void CKernel::list_kernel (  ) 

list kernel

Definition at line 389 of file Kernel.cpp.

bool CKernel::has_property ( EKernelProperty  p  ) 

check if kernel has given property

Parameters:
p kernel property
Returns:
if kernel has given property

Definition at line 271 of file Kernel.h.

void CKernel::clear_normal (  )  [virtual]

for optimizable kernels, i.e. kernels where the weight vector can be computed explicitely (if it fits into memory)

Reimplemented in CCombinedKernel, CCommUlongStringKernel, CCommWordStringKernel, CLinearByteKernel, CLinearKernel, CLinearStringKernel, CLinearWordKernel, CSparseLinearKernel, CWeightedDegreePositionStringKernel, and CWeightedDegreeStringKernel.

Definition at line 578 of file Kernel.cpp.

void CKernel::add_to_normal ( INT  vector_idx,
DREAL  weight 
) [virtual]

EOptimizationType CKernel::get_optimization_type (  ) 

get optimization type

Returns:
optimization type

Definition at line 289 of file Kernel.h.

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

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 (  ) 

check if optimization is initialized

Returns:
if optimization is initialized

Definition at line 301 of file Kernel.h.

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

initialize optimization

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

Reimplemented in CCombinedKernel, CCommUlongStringKernel, CCommWordStringKernel, CLinearByteKernel, CLinearKernel, CLinearStringKernel, CLinearWordKernel, CSparseLinearKernel, CWeightedDegreePositionStringKernel, and CWeightedDegreeStringKernel.

Definition at line 550 of file Kernel.cpp.

bool CKernel::delete_optimization (  )  [virtual]

bool CKernel::init_optimization_svm ( CSVM svm  ) 

initialize optimization

Parameters:
svm svm model
Returns:
if initializing was successful

Definition at line 644 of file Kernel.cpp.

DREAL CKernel::compute_optimized ( INT  vector_idx  )  [virtual]

compute optimized

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

Reimplemented in CCombinedKernel, CCommUlongStringKernel, CCommWordStringKernel, CLinearByteKernel, CLinearKernel, CLinearStringKernel, CLinearWordKernel, CSparseLinearKernel, CWeightedCommWordStringKernel, CWeightedDegreePositionStringKernel, and CWeightedDegreeStringKernel.

Definition at line 562 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]

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 (  ) 

get combined kernel weight

Returns:
combined kernel weight

Definition at line 346 of file Kernel.h.

void CKernel::set_combined_kernel_weight ( double  nw  ) 

set combined kernel weight

Parameters:
nw nw

Definition at line 352 of file Kernel.h.

INT CKernel::get_num_subkernels (  )  [virtual]

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]

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]

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]

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 (  ) 

get precompute matrix

Returns:
if matrix shall be precomputed

Definition at line 386 of file Kernel.h.

bool CKernel::get_precompute_subkernel_matrix (  ) 

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]

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]

set property

Parameters:
p kernel property to set

Definition at line 416 of file Kernel.h.

void CKernel::unset_property ( EKernelProperty  p  )  [protected]

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]

set is initialized

Parameters:
p_init if optimization shall be set to initialized

Definition at line 434 of file Kernel.h.

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

void CKernel::do_precompute_matrix (  )  [protected]

matrix precomputation

Definition at line 606 of file Kernel.cpp.

void CKernel::init_sqrt_diag ( DREAL v,
INT  num 
) [protected]

initialize sqrt diagonal

Parameters:
v v
num num

Definition at line 634 of file Kernel.cpp.


Member Data Documentation

INT CKernel::cache_size [protected]

cache_size in MB

Definition at line 464 of file Kernel.h.

this *COULD* store the whole kernel matrix usually not applicable / faster

Definition at line 470 of file Kernel.h.

precomputed matrix

Definition at line 473 of file Kernel.h.

if subkernel matrix shall be precomputed

Definition at line 475 of file Kernel.h.

bool CKernel::precompute_matrix [protected]

if matrix shall be precomputed

Definition at line 477 of file Kernel.h.

CFeatures* CKernel::lhs [protected]

feature vectors to occur on left hand side

Definition at line 480 of file Kernel.h.

CFeatures* CKernel::rhs [protected]

feature vectors to occur on right hand side

Definition at line 482 of file Kernel.h.

combined kernel weight

Definition at line 485 of file Kernel.h.

if optimization is initialized

Definition at line 488 of file Kernel.h.

optimization type (currently FASTBUTMEMHUNGRY and SLOWBUTMEMEFFICIENT)

Definition at line 492 of file Kernel.h.

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