The Kernel base class.
Non-mathematically spoken, a kernel is a function that given two input objects and
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
where 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.
公有成员 | |
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) |
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 | 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) |
静态保护成员 | |
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 | |
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 |
CKernel | ( | ) |
default constructor
在文件Kernel.cpp第44行定义。
CKernel | ( | int32_t | size ) |
constructor
l | features for left-hand side |
r | features for right-hand side |
size | cache size |
在文件Kernel.cpp第74行定义。
~CKernel | ( | ) | [virtual] |
在文件Kernel.cpp第91行定义。
void add_to_normal | ( | int32_t | vector_idx, |
float64_t | weight | ||
) | [virtual] |
add vector*factor to 'virtual' normal vector
vector_idx | index |
weight | weight |
被CCombinedKernel、CCommUlongStringKernel、CCommWordStringKernel、CLinearByteKernel、CLinearKernel、CLinearStringKernel、CLinearWordKernel、CSparseLinearKernel、CWeightedCommWordStringKernel、CWeightedDegreePositionStringKernel及CWeightedDegreeStringKernel重载。
在文件Kernel.cpp第433行定义。
void cleanup | ( | ) | [virtual] |
clean up your kernel
base method only removes lhs and rhs overload to add further cleanup but make sure CKernel::cleanup() is called
被CCombinedKernel、CCommUlongStringKernel、CCommWordStringKernel、CCustomKernel、CFixedDegreeStringKernel、CGaussianMatchStringKernel、CHistogramWordStringKernel、CLinearByteKernel、CLinearKernel、CLinearStringKernel、CLinearWordKernel、CLocalAlignmentStringKernel、COligoStringKernel、CPolyKernel、CPolyMatchStringKernel、CPolyMatchWordStringKernel、CPyramidChi2、CSalzbergWordStringKernel、CSigmoidKernel、CSimpleLocalityImprovedStringKernel、CSNPStringKernel、CSparseGaussianKernel、CSparseLinearKernel、CSparsePolyKernel、CSpectrumMismatchRBFKernel、CSpectrumRBFKernel、CWeightedCommWordStringKernel、CWeightedDegreePositionStringKernel及CWeightedDegreeStringKernel重载。
在文件Kernel.cpp第184行定义。
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、CLinearByteKernel、CLinearKernel、CLinearStringKernel、CLinearWordKernel、CSparseLinearKernel、CWeightedDegreePositionStringKernel及CWeightedDegreeStringKernel重载。
在文件Kernel.cpp第438行定义。
virtual float64_t compute | ( | int32_t | x, |
int32_t | y | ||
) | [protected, pure virtual] |
compute kernel function for features a and b idx_{a,b} denote the index of the feature vectors in the corresponding feature object
abstract base method
x | index a |
y | index b |
在CAUCKernel、CChi2Kernel、CCombinedKernel、CCommUlongStringKernel、CCommWordStringKernel、CConstKernel、CCustomKernel、CDiagKernel、CDistanceKernel、CFixedDegreeStringKernel、CGaussianKernel、CGaussianMatchStringKernel、CGaussianShiftKernel、CGaussianShortRealKernel、CHistogramWordStringKernel、CLinearByteKernel、CLinearKernel、CLinearStringKernel、CLinearWordKernel、CLocalAlignmentStringKernel、CLocalityImprovedStringKernel、CMatchWordStringKernel、COligoStringKernel、CPolyKernel、CPolyMatchStringKernel、CPolyMatchWordStringKernel、CPyramidChi2、CRegulatoryModulesStringKernel、CSalzbergWordStringKernel、CSigmoidKernel、CSimpleLocalityImprovedStringKernel、CSNPStringKernel、CSparseGaussianKernel、CSparseLinearKernel、CSparsePolyKernel、CSpectrumMismatchRBFKernel、CSpectrumRBFKernel、CTensorProductPairKernel、CWeightedDegreePositionStringKernel、CWeightedDegreeRBFKernel及CWeightedDegreeStringKernel内被实现。
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第426行定义。
void compute_by_subkernel | ( | int32_t | vector_idx, |
float64_t * | subkernel_contrib | ||
) | [virtual] |
compute by subkernel
vector_idx | index |
subkernel_contrib | subkernel contribution |
被CCombinedKernel、CWeightedDegreePositionStringKernel及CWeightedDegreeStringKernel重载。
在文件Kernel.cpp第448行定义。
float64_t compute_optimized | ( | int32_t | vector_idx ) | [virtual] |
compute optimized
vector_idx | index to compute |
被CCombinedKernel、CCommUlongStringKernel、CCommWordStringKernel、CLinearByteKernel、CLinearKernel、CLinearStringKernel、CLinearWordKernel、CSparseLinearKernel、CWeightedCommWordStringKernel、CWeightedDegreePositionStringKernel及CWeightedDegreeStringKernel重载。
在文件Kernel.cpp第420行定义。
int32_t compute_row_start | ( | int64_t | offs, |
int32_t | n, | ||
bool | symmetric | ||
) | [protected] |
bool delete_optimization | ( | ) | [virtual] |
delete optimization
被CCombinedKernel、CCommUlongStringKernel、CCommWordStringKernel、CLinearByteKernel、CLinearKernel、CLinearStringKernel、CLinearWordKernel、CSparseLinearKernel、CWeightedDegreePositionStringKernel及CWeightedDegreeStringKernel重载。
在文件Kernel.cpp第414行定义。
int32_t get_cache_size | ( | ) |
float64_t get_combined_kernel_weight | ( | ) |
virtual EFeatureClass get_feature_class | ( | ) | [pure virtual] |
return feature class the kernel can deal with
abstract base method
在CCombinedKernel、CConstKernel、CCustomKernel、CDiagKernel、CDistanceKernel、CSimpleKernel< ST >、CSparseKernel< ST >、CStringKernel< ST >、CSimpleKernel< float64_t >、CSimpleKernel< float32_t >、CSimpleKernel< int32_t >、CSimpleKernel< uint8_t >、CSimpleKernel< uint16_t >、CSparseKernel< float64_t >、CStringKernel< char >、CStringKernel< uint16_t >及CStringKernel< uint64_t >内被实现。
virtual EFeatureType get_feature_type | ( | ) | [pure virtual] |
return feature type the kernel can deal with
abstract base method
在CCombinedKernel、CCommUlongStringKernel、CCommWordStringKernel、CConstKernel、CCustomKernel、CDiagKernel、CDistanceKernel、CSimpleKernel< ST >、CSparseGaussianKernel、CSparseKernel< ST >、CSparsePolyKernel、CStringKernel< ST >、CWeightedCommWordStringKernel、CSimpleKernel< float64_t >、CSimpleKernel< float32_t >、CSimpleKernel< int32_t >、CSimpleKernel< uint8_t >、CSimpleKernel< uint16_t >、CSparseKernel< float64_t >、CStringKernel< char >、CStringKernel< uint16_t >、CStringKernel< uint64_t >、CSimpleKernel< ST >、CSimpleKernel< ST >、CSimpleKernel< ST >、CSimpleKernel< ST >、CSimpleKernel< ST >、CSimpleKernel< ST >、CSimpleKernel< ST >、CSimpleKernel< ST >、CSparseKernel< ST >、CSparseKernel< ST >、CSparseKernel< ST >、CSparseKernel< ST >、CSparseKernel< ST >、CSparseKernel< ST >、CSparseKernel< ST >、CStringKernel< ST >、CStringKernel< ST >、CStringKernel< ST >、CStringKernel< ST >、CStringKernel< ST >、CStringKernel< ST >及CStringKernel< ST >内被实现。
bool get_is_initialized | ( | ) |
void get_kernel_matrix | ( | float64_t ** | dst, |
int32_t * | m, | ||
int32_t * | n | ||
) |
get kernel matrix
dst | destination where matrix will be stored |
m | dimension m of matrix |
n | dimension n of matrix |
在文件Kernel.cpp第102行定义。
T* get_kernel_matrix | ( | int32_t & | m, |
int32_t & | n, | ||
T * | target | ||
) |
static void* get_kernel_matrix_helper | ( | void * | p ) | [static, protected] |
virtual EKernelType get_kernel_type | ( | ) | [pure virtual] |
return what type of kernel we are, e.g. Linear,Polynomial, Gaussian,...
abstract base method
在CAUCKernel、CChi2Kernel、CCombinedKernel、CCommUlongStringKernel、CCommWordStringKernel、CConstKernel、CCustomKernel、CDiagKernel、CDistanceKernel、CFixedDegreeStringKernel、CGaussianKernel、CGaussianMatchStringKernel、CGaussianShiftKernel、CGaussianShortRealKernel、CHistogramWordStringKernel、CLinearByteKernel、CLinearKernel、CLinearStringKernel、CLinearWordKernel、CLocalAlignmentStringKernel、CLocalityImprovedStringKernel、CMatchWordStringKernel、COligoStringKernel、CPolyKernel、CPolyMatchStringKernel、CPolyMatchWordStringKernel、CPyramidChi2、CRegulatoryModulesStringKernel、CSalzbergWordStringKernel、CSigmoidKernel、CSimpleLocalityImprovedStringKernel、CSNPStringKernel、CSparseGaussianKernel、CSparseLinearKernel、CSparsePolyKernel、CSpectrumMismatchRBFKernel、CSpectrumRBFKernel、CTensorProductPairKernel、CWeightedCommWordStringKernel、CWeightedDegreePositionStringKernel、CWeightedDegreeRBFKernel及CWeightedDegreeStringKernel内被实现。
CFeatures* get_lhs | ( | ) |
CKernelNormalizer * get_normalizer | ( | ) | [virtual] |
int32_t get_num_subkernels | ( | ) | [virtual] |
get number of subkernels
被CCombinedKernel、CWeightedDegreePositionStringKernel及CWeightedDegreeStringKernel重载。
在文件Kernel.cpp第443行定义。
virtual int32_t get_num_vec_lhs | ( | ) | [virtual] |
virtual int32_t get_num_vec_rhs | ( | ) | [virtual] |
EOptimizationType get_optimization_type | ( | ) |
CFeatures* get_rhs | ( | ) |
const float64_t * get_subkernel_weights | ( | int32_t & | num_weights ) | [virtual] |
get subkernel weights
num_weights | number of weights will be stored here |
被CCombinedKernel、CWeightedDegreePositionStringKernel及CWeightedDegreeStringKernel重载。
在文件Kernel.cpp第454行定义。
virtual bool has_features | ( | ) | [virtual] |
test whether features have been assigned to lhs and rhs
bool has_property | ( | EKernelProperty | p ) |
initialize kernel e.g. setup lhs/rhs of kernel, precompute normalization constants etc. make sure to check that your kernel can deal with the supplied features (!)
lhs | features for left-hand side |
rhs | features for right-hand side |
被CAUCKernel、CChi2Kernel、CCombinedKernel、CCommUlongStringKernel、CCommWordStringKernel、CConstKernel、CCustomKernel、CDistanceKernel、CFixedDegreeStringKernel、CGaussianKernel、CGaussianMatchStringKernel、CGaussianShortRealKernel、CHistogramWordStringKernel、CLinearByteKernel、CLinearKernel、CLinearStringKernel、CLinearWordKernel、CLocalAlignmentStringKernel、CLocalityImprovedStringKernel、CMatchWordStringKernel、COligoStringKernel、CPolyKernel、CPolyMatchStringKernel、CPolyMatchWordStringKernel、CPyramidChi2、CRegulatoryModulesStringKernel、CSalzbergWordStringKernel、CSigmoidKernel、CSimpleKernel< ST >、CSimpleLocalityImprovedStringKernel、CSNPStringKernel、CSparseGaussianKernel、CSparseKernel< ST >、CSparseLinearKernel、CSparsePolyKernel、CSpectrumMismatchRBFKernel、CSpectrumRBFKernel、CStringKernel< ST >、CTensorProductPairKernel、CWeightedCommWordStringKernel、CWeightedDegreePositionStringKernel、CWeightedDegreeRBFKernel、CWeightedDegreeStringKernel、CSimpleKernel< float64_t >、CSimpleKernel< float32_t >、CSimpleKernel< int32_t >、CSimpleKernel< uint8_t >、CSimpleKernel< uint16_t >、CSparseKernel< float64_t >、CStringKernel< char >、CStringKernel< uint16_t >及CStringKernel< uint64_t >重载。
在文件Kernel.cpp第131行定义。
bool init_normalizer | ( | ) | [virtual] |
bool init_optimization | ( | int32_t | count, |
int32_t * | IDX, | ||
float64_t * | weights | ||
) | [virtual] |
initialize optimization
count | count |
IDX | index |
weights | weights |
被CCombinedKernel、CCommUlongStringKernel、CCommWordStringKernel、CLinearByteKernel、CLinearKernel、CLinearStringKernel、CLinearWordKernel、CSparseLinearKernel、CWeightedDegreePositionStringKernel及CWeightedDegreeStringKernel重载。
在文件Kernel.cpp第407行定义。
bool init_optimization_svm | ( | CSVM * | svm ) |
float64_t kernel | ( | int32_t | idx_a, |
int32_t | idx_b | ||
) |
bool lhs_equals_rhs | ( | ) |
void list_kernel | ( | ) |
list kernel
在文件Kernel.cpp第240行定义。
void load | ( | CFile * | loader ) |
void remove_lhs | ( | ) | [virtual] |
remove lhs from kernel
被CCombinedKernel、CCommUlongStringKernel、CSpectrumMismatchRBFKernel、CSpectrumRBFKernel、CWeightedDegreePositionStringKernel及CWeightedDegreeStringKernel重载。
在文件Kernel.cpp第217行定义。
void remove_lhs_and_rhs | ( | ) | [virtual] |
void remove_rhs | ( | ) | [virtual] |
takes all necessary steps if the rhs is removed from kernel
remove rhs from kernel
被CCombinedKernel及CCommUlongStringKernel重载。
在文件Kernel.cpp第229行定义。
void save | ( | CFile * | writer ) |
void set_cache_size | ( | int32_t | size ) |
void set_combined_kernel_weight | ( | float64_t | nw ) |
void set_is_initialized | ( | bool | p_init ) | [protected] |
bool set_normalizer | ( | CKernelNormalizer * | normalizer ) | [virtual] |
set the current kernel normalizer
被CWeightedDegreeStringKernel重载。
在文件Kernel.cpp第161行定义。
virtual void set_optimization_type | ( | EOptimizationType | t ) | [virtual] |
void set_property | ( | EKernelProperty | p ) | [protected] |
void set_subkernel_weights | ( | float64_t * | weights, |
int32_t | num_weights | ||
) | [virtual] |
set subkernel weights
weights | subkernel weights |
num_weights | number of weights |
被CCombinedKernel、CWeightedDegreePositionStringKernel及CWeightedDegreeStringKernel重载。
在文件Kernel.cpp第460行定义。
void unset_property | ( | EKernelProperty | p ) | [protected] |
friend class CAvgDiagKernelNormalizer [friend] |
friend class CDiceKernelNormalizer [friend] |
friend class CFirstElementKernelNormalizer [friend] |
friend class CMultitaskKernelMaskNormalizer [friend] |
friend class CMultitaskKernelMaskPairNormalizer [friend] |
friend class CMultitaskKernelMklNormalizer [friend] |
friend class CMultitaskKernelNormalizer [friend] |
friend class CRidgeKernelNormalizer [friend] |
friend class CSqrtDiagKernelNormalizer [friend] |
friend class CTanimotoKernelNormalizer [friend] |
friend class CVarianceKernelNormalizer [friend] |
int32_t cache_size [protected] |
float64_t combined_kernel_weight [protected] |
KERNELCACHE_ELEM* kernel_matrix [protected] |
this *COULD* store the whole kernel matrix usually not applicable / necessary to compute the whole matrix
CKernelNormalizer* normalizer [protected] |
EOptimizationType opt_type [protected] |
bool optimization_initialized [protected] |
uint64_t properties [protected] |