SHOGUN v0.9.0
公有成员 | 保护成员 | 静态保护成员 | 保护属性 | 友元
CKernel类参考

详细描述

The Kernel base class.

Non-mathematically spoken, a kernel is a function that given two input objects ${\bf x}$ and ${\bf x'}$ returns a score describing the similarity of the vectors. The score should be larger when the objects are more similar.

It can be defined as

\[ k({\bf x},{\bf x'})= \Phi_k({\bf x})\cdot \Phi_k({\bf x'}) \]

where $\Phi$ maps the objects into some potentially high dimensional feature space.

Apart from the input features, the base kernel takes only one argument (the size of the kernel cache) that is used to efficiently train kernel-machines like e.g. SVMs.

In case you would like to define your own kernel, you only have to define a new compute() function (and the kernel name via get_name() and the kernel type get_kernel_type()). A good example to look at is the GaussianKernel.

在文件Kernel.h第150行定义。

继承图,类CKernel
Inheritance graph
[图例]

所有成员的列表。

公有成员

 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)
void get_kernel_matrix (float64_t **dst, int32_t *m, int32_t *n)
virtual std::vector< float64_t > get_kernel_col (int32_t j)
virtual std::vector< float64_t > get_kernel_row (int32_t i)
template<class T >
T * get_kernel_matrix (int32_t &m, int32_t &n, T *target)
virtual bool init (CFeatures *lhs, CFeatures *rhs)
virtual bool set_normalizer (CKernelNormalizer *normalizer)
virtual CKernelNormalizer * get_normalizer ()
virtual bool init_normalizer ()
virtual void cleanup ()
void load (CFile *loader)
void save (CFile *writer)
CFeatures * get_lhs ()
CFeatures * get_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_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
void set_cache_size (int32_t size)
int32_t get_cache_size ()
void list_kernel ()
bool has_property (EKernelProperty p)
virtual void clear_normal ()
virtual void add_to_normal (int32_t vector_idx, float64_t weight)
EOptimizationType get_optimization_type ()
virtual void set_optimization_type (EOptimizationType t)
bool get_is_initialized ()
virtual bool init_optimization (int32_t count, int32_t *IDX, float64_t *weights)
virtual bool delete_optimization ()
bool init_optimization_svm (CSVM *svm)
virtual float64_t compute_optimized (int32_t vector_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)
float64_t get_combined_kernel_weight ()
void set_combined_kernel_weight (float64_t nw)
virtual int32_t get_num_subkernels ()
virtual void compute_by_subkernel (int32_t vector_idx, float64_t *subkernel_contrib)
virtual const float64_t * get_subkernel_weights (int32_t &num_weights)
virtual void set_subkernel_weights (float64_t *weights, int32_t num_weights)

保护成员

void set_property (EKernelProperty p)
void unset_property (EKernelProperty p)
void set_is_initialized (bool p_init)
virtual float64_t compute (int32_t x, int32_t y)=0
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)

静态保护成员

template<class T >
static void * get_kernel_matrix_helper (void *p)

保护属性

int32_t cache_size
 cache_size in MB
KERNELCACHE_ELEM * kernel_matrix
CFeatures * lhs
 feature vectors to occur on left hand side
CFeatures * rhs
 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
CKernelNormalizer * normalizer

友元

class CVarianceKernelNormalizer
class CSqrtDiagKernelNormalizer
class CAvgDiagKernelNormalizer
class CRidgeKernelNormalizer
class CFirstElementKernelNormalizer
class CMultitaskKernelNormalizer
class CMultitaskKernelMklNormalizer
class CMultitaskKernelMaskNormalizer
class CMultitaskKernelMaskPairNormalizer
class CTanimotoKernelNormalizer
class CDiceKernelNormalizer
class CZeroMeanCenterKernelNormalizer

构造及析构函数文档

CKernel ( )

default constructor

在文件Kernel.cpp第38行定义。

CKernel ( int32_t  size)

constructor

参数:
sizecache size

在文件Kernel.cpp第43行定义。

CKernel ( CFeatures *  l,
CFeatures *  r,
int32_t  size 
)

constructor

参数:
lfeatures for left-hand side
rfeatures for right-hand side
sizecache size

在文件Kernel.cpp第54行定义。

~CKernel ( ) [virtual]

在文件Kernel.cpp第67行定义。


成员函数文档

void add_to_normal ( int32_t  vector_idx,
float64_t  weight 
) [virtual]

add vector*factor to 'virtual' normal vector

参数:
vector_idxindex
weightweight

被CCombinedKernel、CCommUlongStringKernel、CCommWordStringKernel、CLinearKernel、CLinearStringKernel、CWeightedCommWordStringKernel、CWeightedDegreePositionStringKernel及CWeightedDegreeStringKernel重载。

在文件Kernel.cpp第334行定义。

void cleanup ( ) [virtual]
void clear_normal ( ) [virtual]

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

被CCombinedKernel、CCommUlongStringKernel、CCommWordStringKernel、CLinearKernel、CLinearStringKernel、CWeightedDegreePositionStringKernel及CWeightedDegreeStringKernel重载。

在文件Kernel.cpp第339行定义。

virtual float64_t compute ( int32_t  x,
int32_t  y 
) [protected, pure 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]

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

被CCombinedKernel、CWeightedDegreePositionStringKernel及CWeightedDegreeStringKernel重载。

在文件Kernel.cpp第327行定义。

void compute_by_subkernel ( int32_t  vector_idx,
float64_t *  subkernel_contrib 
) [virtual]

compute by subkernel

参数:
vector_idxindex
subkernel_contribsubkernel contribution

被CCombinedKernel、CWeightedDegreePositionStringKernel及CWeightedDegreeStringKernel重载。

在文件Kernel.cpp第349行定义。

float64_t compute_optimized ( int32_t  vector_idx) [virtual]

compute optimized

参数:
vector_idxindex to compute
返回:
optimized value at given index

被CCombinedKernel、CCommUlongStringKernel、CCommWordStringKernel、CLinearKernel、CLinearStringKernel、CWeightedCommWordStringKernel、CWeightedDegreePositionStringKernel及CWeightedDegreeStringKernel重载。

在文件Kernel.cpp第321行定义。

int32_t compute_row_start ( int64_t  offs,
int32_t  n,
bool  symmetric 
) [protected]

compute row start offset for parallel kernel matrix computation

参数:
offsoffset
nnumber of columns
symmetricwhether matrix is symmetric

在文件Kernel.h第673行定义。

bool delete_optimization ( ) [virtual]

delete optimization

返回:
if deleting was successful

被CCombinedKernel、CCommUlongStringKernel、CCommWordStringKernel、CLinearKernel、CLinearStringKernel、CWeightedDegreePositionStringKernel及CWeightedDegreeStringKernel重载。

在文件Kernel.cpp第315行定义。

int32_t get_cache_size ( )

return the size of the kernel cache

返回:
size of kernel cache

在文件Kernel.h第502行定义。

float64_t get_combined_kernel_weight ( )

get combined kernel weight

返回:
combined kernel weight

在文件Kernel.h第593行定义。

virtual EFeatureClass get_feature_class ( ) [pure virtual]
virtual EFeatureType get_feature_type ( ) [pure virtual]
bool get_is_initialized ( )

check if optimization is initialized

返回:
if optimization is initialized

在文件Kernel.h第544行定义。

virtual std::vector<float64_t> get_kernel_col ( int32_t  j) [virtual]

get column j

返回:
the jth column of the kernel matrix

在文件Kernel.h第221行定义。

T* get_kernel_matrix ( int32_t &  m,
int32_t &  n,
T *  target 
)

get kernel matrix real

参数:
mdimension m of matrix
ndimension n of matrix
targetthe kernel matrix
返回:
the kernel matrix

在文件Kernel.h第264行定义。

void get_kernel_matrix ( float64_t **  dst,
int32_t *  m,
int32_t *  n 
)

get kernel matrix

参数:
dstdestination where matrix will be stored
mdimension m of matrix
ndimension n of matrix

在文件Kernel.cpp第78行定义。

static void* get_kernel_matrix_helper ( void *  p) [static, protected]

helper for computing the kernel matrix in a parallel way

参数:
pthread parameters

在文件Kernel.h第690行定义。

virtual std::vector<float64_t> get_kernel_row ( int32_t  i) [virtual]

get row i

返回:
the ith row of the kernel matrix

在文件Kernel.h第241行定义。

virtual EKernelType get_kernel_type ( ) [pure virtual]
CFeatures* get_lhs ( )

get left-hand side of features used in kernel

返回:
features of left-hand side

在文件Kernel.h第410行定义。

bool get_lhs_equals_rhs ( )

test whether features on lhs and rhs are the same

返回:
true if features are the same

在文件Kernel.h第449行定义。

CKernelNormalizer * get_normalizer ( ) [virtual]

obtain the current kernel normalizer

返回:
the kernel normalizer

在文件Kernel.cpp第151行定义。

int32_t get_num_subkernels ( ) [virtual]

get number of subkernels

返回:
number of subkernels

被CCombinedKernel、CWeightedDegreePositionStringKernel及CWeightedDegreeStringKernel重载。

在文件Kernel.cpp第344行定义。

virtual int32_t get_num_vec_lhs ( ) [virtual]

get number of vectors of lhs features

返回:
number of vectors of left-hand side

被CCustomKernel重载。

在文件Kernel.h第422行定义。

virtual int32_t get_num_vec_rhs ( ) [virtual]

get number of vectors of rhs features

返回:
number of vectors of right-hand side

被CCustomKernel重载。

在文件Kernel.h第431行定义。

EOptimizationType get_optimization_type ( )

get optimization type

返回:
optimization type

在文件Kernel.h第532行定义。

CFeatures* get_rhs ( )

get right-hand side of features used in kernel

返回:
features of right-hand side

在文件Kernel.h第416行定义。

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

get subkernel weights

参数:
num_weightsnumber of weights will be stored here
返回:
subkernel weights

被CCombinedKernel、CWeightedDegreePositionStringKernel及CWeightedDegreeStringKernel重载。

在文件Kernel.cpp第355行定义。

virtual bool has_features ( ) [virtual]

test whether features have been assigned to lhs and rhs

返回:
true if features are assigned

被CCombinedKernel及CCustomKernel重载。

在文件Kernel.h第440行定义。

bool has_property ( EKernelProperty  p)

check if kernel has given property

参数:
pkernel property
返回:
if kernel has given property

在文件Kernel.h第514行定义。

bool init ( CFeatures *  lhs,
CFeatures *  rhs 
) [virtual]
bool init_normalizer ( ) [virtual]

initialize the current kernel normalizer

返回:
if init was successful

在文件Kernel.cpp第157行定义。

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

initialize optimization

参数:
countcount
IDXindex
weightsweights
返回:
if initializing was successful

被CCombinedKernel、CCommUlongStringKernel、CCommWordStringKernel、CLinearKernel、CLinearStringKernel、CWeightedDegreePositionStringKernel及CWeightedDegreeStringKernel重载。

在文件Kernel.cpp第308行定义。

bool init_optimization_svm ( CSVM *  svm)

initialize optimization

参数:
svmsvm model
返回:
if initializing was successful

在文件Kernel.cpp第368行定义。

float64_t kernel ( int32_t  idx_a,
int32_t  idx_b 
)

get kernel function for lhs feature vector a and rhs feature vector b

参数:
idx_aindex of feature vector a
idx_bindex of feature vector b
返回:
computed kernel function

在文件Kernel.h第196行定义。

void list_kernel ( )

list kernel

在文件Kernel.cpp第225行定义。

void load ( CFile *  loader)

load the kernel matrix

参数:
loaderFile object via which to load data

在文件Kernel.cpp第169行定义。

void load_serializable_post ( void  ) throw (ShogunException) [protected, virtual]

Can (optionally) be overridden to post-initialize some member variables which are not PARAMETER::ADD'ed. Make sure that at first the overridden method BASE_CLASS::LOAD_SERIALIZABLE_POST is called.

异常:
ShogunExceptionWill be thrown if an error occurres.

重载CSGObject。

被CGaussianKernel及CWeightedDegreePositionStringKernel重载。

在文件Kernel.cpp第386行定义。

void remove_lhs ( ) [virtual]
void remove_lhs_and_rhs ( ) [virtual]

remove lhs and rhs from kernel

被CCombinedKernel重载。

在文件Kernel.cpp第185行定义。

void remove_rhs ( ) [virtual]

takes all necessary steps if the rhs is removed from kernel

remove rhs from kernel

被CCombinedKernel及CCommUlongStringKernel重载。

在文件Kernel.cpp第212行定义。

void save ( CFile *  writer)

save kernel matrix

参数:
writerFile object via which to save data

在文件Kernel.cpp第175行定义。

void save_serializable_post ( ) throw (ShogunException) [protected, virtual]

Can (optionally) be overridden to post-initialize some member variables which are not PARAMETER::ADD'ed. Make sure that at first the overridden method BASE_CLASS::SAVE_SERIALIZABLE_POST is called.

异常:
ShogunExceptionWill be thrown if an error occurres.

重载CSGObject。

在文件Kernel.cpp第401行定义。

void save_serializable_pre ( ) throw (ShogunException) [protected, virtual]

Can (optionally) be overridden to pre-initialize some member variables which are not PARAMETER::ADD'ed. Make sure that at first the overridden method BASE_CLASS::SAVE_SERIALIZABLE_PRE is called.

异常:
ShogunExceptionWill be thrown if an error occurres.

重载CSGObject。

在文件Kernel.cpp第393行定义。

void set_cache_size ( int32_t  size)

set the size of the kernel cache

参数:
sizeof kernel cache

在文件Kernel.h第492行定义。

void set_combined_kernel_weight ( float64_t  nw)

set combined kernel weight

参数:
nwnew combined kernel weight

在文件Kernel.h第599行定义。

void set_is_initialized ( bool  p_init) [protected]

set is initialized

参数:
p_initif optimization shall be set to initialized

在文件Kernel.h第653行定义。

bool set_normalizer ( CKernelNormalizer *  normalizer) [virtual]

set the current kernel normalizer

返回:
if successful

被CWeightedDegreeStringKernel重载。

在文件Kernel.cpp第139行定义。

virtual void set_optimization_type ( EOptimizationType  t) [virtual]

set optimization type

参数:
toptimization type to set

被CCombinedKernel重载。

在文件Kernel.h第538行定义。

void set_property ( EKernelProperty  p) [protected]

set property

参数:
pkernel property to set

在文件Kernel.h第635行定义。

void set_subkernel_weights ( float64_t *  weights,
int32_t  num_weights 
) [virtual]

set subkernel weights

参数:
weightssubkernel weights
num_weightsnumber of weights

被CCombinedKernel、CWeightedDegreePositionStringKernel及CWeightedDegreeStringKernel重载。

在文件Kernel.cpp第361行定义。

void unset_property ( EKernelProperty  p) [protected]

unset property

参数:
pkernel property to unset

在文件Kernel.h第644行定义。


友元及相关函数文档

friend class CAvgDiagKernelNormalizer [friend]

被CCommWordStringKernel重载。

在文件Kernel.h第154行定义。

friend class CDiceKernelNormalizer [friend]

被CCommWordStringKernel重载。

在文件Kernel.h第162行定义。

friend class CFirstElementKernelNormalizer [friend]

被CCommWordStringKernel重载。

在文件Kernel.h第156行定义。

friend class CMultitaskKernelMaskNormalizer [friend]

在文件Kernel.h第159行定义。

friend class CMultitaskKernelMaskPairNormalizer [friend]

在文件Kernel.h第160行定义。

friend class CMultitaskKernelMklNormalizer [friend]

在文件Kernel.h第158行定义。

friend class CMultitaskKernelNormalizer [friend]

在文件Kernel.h第157行定义。

friend class CRidgeKernelNormalizer [friend]

被CCommWordStringKernel重载。

在文件Kernel.h第155行定义。

friend class CSqrtDiagKernelNormalizer [friend]

被CCommWordStringKernel重载。

在文件Kernel.h第153行定义。

friend class CTanimotoKernelNormalizer [friend]

被CCommWordStringKernel重载。

在文件Kernel.h第161行定义。

friend class CVarianceKernelNormalizer [friend]

被CCommWordStringKernel重载。

在文件Kernel.h第152行定义。

friend class CZeroMeanCenterKernelNormalizer [friend]

在文件Kernel.h第163行定义。


成员数据文档

int32_t cache_size [protected]

cache_size in MB

在文件Kernel.h第781行定义。

combined kernel weight

在文件Kernel.h第803行定义。

this *COULD* store the whole kernel matrix usually not applicable / necessary to compute the whole matrix

被CSpectrumMismatchRBFKernel及CSpectrumRBFKernel重载。

在文件Kernel.h第787行定义。

CFeatures* lhs [protected]

feature vectors to occur on left hand side

在文件Kernel.h第790行定义。

bool lhs_equals_rhs [protected]

lhs

在文件Kernel.h第795行定义。

normalize the kernel(i,j) function based on this normalization function

在文件Kernel.h第817行定义。

int32_t num_lhs [protected]

number of feature vectors on left hand side

在文件Kernel.h第798行定义。

int32_t num_rhs [protected]

number of feature vectors on right hand side

在文件Kernel.h第800行定义。

optimization type (currently FASTBUTMEMHUNGRY and SLOWBUTMEMEFFICIENT)

在文件Kernel.h第810行定义。

bool optimization_initialized [protected]

if optimization is initialized

在文件Kernel.h第806行定义。

uint64_t properties [protected]

kernel properties

在文件Kernel.h第813行定义。

CFeatures* rhs [protected]

feature vectors to occur on right hand side

在文件Kernel.h第792行定义。


该类的文档由以下文件生成:

SHOGUN Machine Learning Toolbox - Documentation