SHOGUN v0.9.0
|
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) |
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
l | features for left-hand side |
r | features for right-hand side |
size | cache 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_idx | index |
weight | weight |
被CCombinedKernel、CCommUlongStringKernel、CCommWordStringKernel、CLinearKernel、CLinearStringKernel、CWeightedCommWordStringKernel、CWeightedDegreePositionStringKernel及CWeightedDegreeStringKernel重载。
在文件Kernel.cpp第334行定义。
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、CGaussianKernel、CGaussianMatchStringKernel、CHistogramWordStringKernel、CLinearKernel、CLinearStringKernel、CLocalAlignmentStringKernel、COligoStringKernel、CPolyKernel、CPolyMatchStringKernel、CPolyMatchWordStringKernel、CPyramidChi2、CSalzbergWordStringKernel、CSigmoidKernel、CSimpleLocalityImprovedStringKernel、CSNPStringKernel、CSparseSpatialSampleStringKernel、CSpectrumMismatchRBFKernel、CSpectrumRBFKernel、CWeightedCommWordStringKernel、CWeightedDegreePositionStringKernel及CWeightedDegreeStringKernel重载。
在文件Kernel.cpp第162行定义。
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] |
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、CDotKernel、CFixedDegreeStringKernel、CGaussianKernel、CGaussianMatchStringKernel、CGaussianShiftKernel、CGaussianShortRealKernel、CHistogramIntersectionKernel、CHistogramWordStringKernel、CLinearStringKernel、CLocalAlignmentStringKernel、CLocalityImprovedStringKernel、CMatchWordStringKernel、COligoStringKernel、CPolyKernel、CPolyMatchStringKernel、CPolyMatchWordStringKernel、CPyramidChi2、CRegulatoryModulesStringKernel、CSalzbergWordStringKernel、CSigmoidKernel、CSimpleLocalityImprovedStringKernel、CSNPStringKernel、CSparseSpatialSampleStringKernel、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第327行定义。
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第349行定义。
float64_t compute_optimized | ( | int32_t | vector_idx | ) | [virtual] |
compute optimized
vector_idx | index to compute |
被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] |
bool delete_optimization | ( | ) | [virtual] |
delete optimization
被CCombinedKernel、CCommUlongStringKernel、CCommWordStringKernel、CLinearKernel、CLinearStringKernel、CWeightedDegreePositionStringKernel及CWeightedDegreeStringKernel重载。
在文件Kernel.cpp第315行定义。
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
在CAUCKernel、CChi2Kernel、CCombinedKernel、CConstKernel、CCustomKernel、CDiagKernel、CDistanceKernel、CDotKernel、CSparseKernel< ST >、CStringKernel< ST >、CTensorProductPairKernel、CWeightedDegreeRBFKernel、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
在CAUCKernel、CChi2Kernel、CCombinedKernel、CCommUlongStringKernel、CCommWordStringKernel、CConstKernel、CCustomKernel、CDiagKernel、CDistanceKernel、CDotKernel、CSparseKernel< ST >、CStringKernel< ST >、CTensorProductPairKernel、CWeightedCommWordStringKernel、CWeightedDegreeRBFKernel、CStringKernel< char >、CStringKernel< uint16_t >、CStringKernel< uint64_t >、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 | ( | ) |
virtual std::vector<float64_t> get_kernel_col | ( | int32_t | j | ) | [virtual] |
T* get_kernel_matrix | ( | int32_t & | m, |
int32_t & | n, | ||
T * | target | ||
) |
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第78行定义。
static void* get_kernel_matrix_helper | ( | void * | p | ) | [static, protected] |
virtual std::vector<float64_t> get_kernel_row | ( | int32_t | i | ) | [virtual] |
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、CDotKernel、CFixedDegreeStringKernel、CGaussianKernel、CGaussianMatchStringKernel、CGaussianShiftKernel、CGaussianShortRealKernel、CHistogramIntersectionKernel、CHistogramWordStringKernel、CLinearKernel、CLinearStringKernel、CLocalAlignmentStringKernel、CLocalityImprovedStringKernel、CMatchWordStringKernel、COligoStringKernel、CPolyKernel、CPolyMatchStringKernel、CPolyMatchWordStringKernel、CPyramidChi2、CRegulatoryModulesStringKernel、CSalzbergWordStringKernel、CSigmoidKernel、CSimpleLocalityImprovedStringKernel、CSNPStringKernel、CSparseKernel< ST >、CSparseSpatialSampleStringKernel、CSpectrumMismatchRBFKernel、CSpectrumRBFKernel、CStringKernel< ST >、CTensorProductPairKernel、CWeightedCommWordStringKernel、CWeightedDegreePositionStringKernel、CWeightedDegreeRBFKernel、CWeightedDegreeStringKernel、CStringKernel< char >、CStringKernel< uint16_t >及CStringKernel< uint64_t >内被实现。
CFeatures* get_lhs | ( | ) |
bool get_lhs_equals_rhs | ( | ) |
CKernelNormalizer * get_normalizer | ( | ) | [virtual] |
int32_t get_num_subkernels | ( | ) | [virtual] |
get number of subkernels
被CCombinedKernel、CWeightedDegreePositionStringKernel及CWeightedDegreeStringKernel重载。
在文件Kernel.cpp第344行定义。
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第355行定义。
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、CDiagKernel、CDistanceKernel、CDotKernel、CFixedDegreeStringKernel、CGaussianKernel、CGaussianMatchStringKernel、CGaussianShortRealKernel、CHistogramIntersectionKernel、CHistogramWordStringKernel、CLinearKernel、CLinearStringKernel、CLocalAlignmentStringKernel、CLocalityImprovedStringKernel、CMatchWordStringKernel、COligoStringKernel、CPolyKernel、CPolyMatchStringKernel、CPolyMatchWordStringKernel、CPyramidChi2、CRegulatoryModulesStringKernel、CSalzbergWordStringKernel、CSigmoidKernel、CSimpleLocalityImprovedStringKernel、CSNPStringKernel、CSparseKernel< ST >、CSparseSpatialSampleStringKernel、CSpectrumMismatchRBFKernel、CSpectrumRBFKernel、CStringKernel< ST >、CTensorProductPairKernel、CWeightedCommWordStringKernel、CWeightedDegreePositionStringKernel、CWeightedDegreeRBFKernel、CWeightedDegreeStringKernel、CStringKernel< char >、CStringKernel< uint16_t >及CStringKernel< uint64_t >重载。
在文件Kernel.cpp第107行定义。
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、CLinearKernel、CLinearStringKernel、CWeightedDegreePositionStringKernel及CWeightedDegreeStringKernel重载。
在文件Kernel.cpp第308行定义。
bool init_optimization_svm | ( | CSVM * | svm | ) |
float64_t kernel | ( | int32_t | idx_a, |
int32_t | idx_b | ||
) |
void list_kernel | ( | ) |
list kernel
在文件Kernel.cpp第225行定义。
void load | ( | CFile * | loader | ) |
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.
ShogunException | Will be thrown if an error occurres. |
重载CSGObject。
被CGaussianKernel及CWeightedDegreePositionStringKernel重载。
在文件Kernel.cpp第386行定义。
void remove_lhs | ( | ) | [virtual] |
remove lhs from kernel
被CCombinedKernel、CCommUlongStringKernel、CSpectrumMismatchRBFKernel、CSpectrumRBFKernel、CWeightedDegreePositionStringKernel及CWeightedDegreeStringKernel重载。
在文件Kernel.cpp第200行定义。
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第212行定义。
void save | ( | CFile * | writer | ) |
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.
ShogunException | Will 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.
ShogunException | Will be thrown if an error occurres. |
重载CSGObject。
在文件Kernel.cpp第393行定义。
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第139行定义。
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第361行定义。
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] |
friend class CZeroMeanCenterKernelNormalizer [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
bool lhs_equals_rhs [protected] |
CKernelNormalizer* normalizer [protected] |
EOptimizationType opt_type [protected] |
bool optimization_initialized [protected] |
uint64_t properties [protected] |