This class offers access to the Oligo Kernel introduced by Meinicke et al. in 2004.
The class has functions to preprocess the data such that the kernel computation can be pursued faster. The kernel function is then kernelOligoFast or kernelOligo.
Requires significant speedup, should be working but as is might be applicable only to academic small scale problems:
- the kernel should only ever see encoded sequences, which however requires another OligoFeatures object (using CDenseFeatures of pairs)
Uses CSqrtDiagKernelNormalizer, as the vanilla kernel seems to be very diagonally dominant.
在文件 OligoStringKernel.h 第 44 行定义.
|
| | COligoStringKernel () |
| |
| | COligoStringKernel (int32_t cache_size, int32_t k, float64_t width) |
| |
| | COligoStringKernel (CStringFeatures< char > *l, CStringFeatures< char > *r, int32_t k, float64_t width) |
| |
| virtual | ~COligoStringKernel () |
| |
| virtual bool | init (CFeatures *l, CFeatures *r) |
| |
| virtual EKernelType | get_kernel_type () |
| |
| virtual const char * | get_name () const |
| |
| virtual float64_t | compute (int32_t x, int32_t y) |
| |
| virtual void | cleanup () |
| |
| virtual EFeatureClass | get_feature_class () |
| |
| virtual EFeatureType | get_feature_type () |
| |
| float64_t | kernel (int32_t idx_a, int32_t idx_b) |
| |
| SGMatrix< float64_t > | get_kernel_matrix () |
| |
| template<class T > |
| SGMatrix< T > | get_kernel_matrix () |
| |
| SGVector< float64_t > | get_kernel_diagonal (SGVector< float64_t > preallocated=SGVector< float64_t >()) |
| |
| virtual SGVector< float64_t > | get_kernel_col (int32_t j) |
| |
| virtual SGVector< float64_t > | get_kernel_row (int32_t i) |
| |
| virtual float64_t | sum_symmetric_block (index_t block_begin, index_t block_size, bool no_diag=true) |
| |
| virtual float64_t | sum_block (index_t block_begin_row, index_t block_begin_col, index_t block_size_row, index_t block_size_col, bool no_diag=false) |
| |
| virtual SGVector< float64_t > | row_wise_sum_symmetric_block (index_t block_begin, index_t block_size, bool no_diag=true) |
| |
| virtual SGMatrix< float64_t > | row_wise_sum_squared_sum_symmetric_block (index_t block_begin, index_t block_size, bool no_diag=true) |
| |
| virtual SGVector< float64_t > | row_col_wise_sum_block (index_t block_begin_row, index_t block_begin_col, index_t block_size_row, index_t block_size_col, bool no_diag=false) |
| |
| virtual bool | set_normalizer (CKernelNormalizer *normalizer) |
| |
| virtual CKernelNormalizer * | get_normalizer () |
| |
| virtual bool | init_normalizer () |
| |
| 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 更多...
|
| |
| 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 SGVector< float64_t > | get_subkernel_weights () |
| |
| virtual void | set_subkernel_weights (SGVector< float64_t > weights) |
| |
| virtual SGMatrix< float64_t > | get_parameter_gradient (const TParameter *param, index_t index=-1) |
| |
| virtual CSGObject * | shallow_copy () const |
| |
| virtual CSGObject * | deep_copy () const |
| |
| virtual bool | is_generic (EPrimitiveType *generic) const |
| |
| template<class T > |
| void | set_generic () |
| |
| template<> |
| void | set_generic () |
| |
| template<> |
| void | set_generic () |
| |
| template<> |
| void | set_generic () |
| |
| template<> |
| void | set_generic () |
| |
| template<> |
| void | set_generic () |
| |
| template<> |
| void | set_generic () |
| |
| template<> |
| void | set_generic () |
| |
| template<> |
| void | set_generic () |
| |
| template<> |
| void | set_generic () |
| |
| template<> |
| void | set_generic () |
| |
| template<> |
| void | set_generic () |
| |
| template<> |
| void | set_generic () |
| |
| template<> |
| void | set_generic () |
| |
| template<> |
| void | set_generic () |
| |
| template<> |
| void | set_generic () |
| |
| void | unset_generic () |
| |
| virtual void | print_serializable (const char *prefix="") |
| |
| virtual bool | save_serializable (CSerializableFile *file, const char *prefix="", int32_t param_version=Version::get_version_parameter()) |
| |
| virtual bool | load_serializable (CSerializableFile *file, const char *prefix="", int32_t param_version=Version::get_version_parameter()) |
| |
| DynArray< TParameter * > * | load_file_parameters (const SGParamInfo *param_info, int32_t file_version, CSerializableFile *file, const char *prefix="") |
| |
| DynArray< TParameter * > * | load_all_file_parameters (int32_t file_version, int32_t current_version, CSerializableFile *file, const char *prefix="") |
| |
| void | map_parameters (DynArray< TParameter * > *param_base, int32_t &base_version, DynArray< const SGParamInfo * > *target_param_infos) |
| |
| void | set_global_io (SGIO *io) |
| |
| SGIO * | get_global_io () |
| |
| void | set_global_parallel (Parallel *parallel) |
| |
| Parallel * | get_global_parallel () |
| |
| void | set_global_version (Version *version) |
| |
| Version * | get_global_version () |
| |
| SGStringList< char > | get_modelsel_names () |
| |
| void | print_modsel_params () |
| |
| char * | get_modsel_param_descr (const char *param_name) |
| |
| index_t | get_modsel_param_index (const char *param_name) |
| |
| void | build_gradient_parameter_dictionary (CMap< TParameter *, CSGObject * > *dict) |
| |
| virtual void | update_parameter_hash () |
| |
| virtual bool | parameter_hash_changed () |
| |
| virtual bool | equals (CSGObject *other, float64_t accuracy=0.0, bool tolerant=false) |
| |
| virtual CSGObject * | clone () |
| |
|
| float64_t | kernelOligoFast (const std::vector< std::pair< int32_t, float64_t > > &x, const std::vector< std::pair< int32_t, float64_t > > &y, int32_t max_distance=-1) |
| | returns the value of the oligo kernel for sequences 'x' and 'y' 更多...
|
| |
| float64_t | kernelOligo (const std::vector< std::pair< int32_t, float64_t > > &x, const std::vector< std::pair< int32_t, float64_t > > &y) |
| | returns the value of the oligo kernel for sequences 'x' and 'y' 更多...
|
| |
| void | set_property (EKernelProperty p) |
| |
| void | unset_property (EKernelProperty p) |
| |
| void | set_is_initialized (bool p_init) |
| |
| 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) |
| |
| virtual void | register_params () |
| |
| virtual TParameter * | migrate (DynArray< TParameter * > *param_base, const SGParamInfo *target) |
| |
| virtual void | one_to_one_migration_prepare (DynArray< TParameter * > *param_base, const SGParamInfo *target, TParameter *&replacement, TParameter *&to_migrate, char *old_name=NULL) |
| |
| virtual void | load_serializable_pre () throw (ShogunException) |
| |
|
| static void | encodeOligo (const std::string &sequence, uint32_t k_mer_length, const std::string &allowed_characters, std::vector< std::pair< int32_t, float64_t > > &values) |
| | encodes the signals of the sequence 更多...
|
| |
| static void | getSequences (const std::vector< std::string > &sequences, uint32_t k_mer_length, const std::string &allowed_characters, std::vector< std::vector< std::pair< int32_t, float64_t > > > &encoded_sequences) |
| | encodes all sequences with the encodeOligo function and stores them in 'encoded_sequences' 更多...
|
| |
| template<class T > |
| static void * | get_kernel_matrix_helper (void *p) |
| |
| 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 |
|
) |
| |
|
virtualinherited |
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, CWeightedDegreeStringKernel , 以及 CWeightedDegreePositionStringKernel 重载.
在文件 Kernel.cpp 第 345 行定义.
| void encodeOligo |
( |
const std::string & |
sequence, |
|
|
uint32_t |
k_mer_length, |
|
|
const std::string & |
allowed_characters, |
|
|
std::vector< std::pair< int32_t, float64_t > > & |
values |
|
) |
| |
|
staticprotected |
encodes the signals of the sequence
This function stores the oligo function signals in 'values'.
The 'k_mer_length' and the 'allowed_characters' determine, which signals are used. Every pair contains the position of the signal and a numerical value reflecting the signal. The numerical value represents the k_mer to a base n = |allowed_characters|. Example: The value of k_mer CG for the allowed characters ACGT would be 1 * n^1 + 2 * n^0 = 6.
在文件 OligoStringKernel.cpp 第 81 行定义.
| float64_t kernelOligoFast |
( |
const std::vector< std::pair< int32_t, float64_t > > & |
x, |
|
|
const std::vector< std::pair< int32_t, float64_t > > & |
y, |
|
|
int32_t |
max_distance = -1 |
|
) |
| |
|
protected |
returns the value of the oligo kernel for sequences 'x' and 'y'
This function computes the kernel value of the oligo kernel, which was introduced by Meinicke et al. in 2004. 'x' and 'y' are encoded by encodeOligo and 'exp_cache' has to be constructed by getExpFunctionCache.
'max_distance' can be used to speed up the computation even further by restricting the maximum distance between a k_mer at position i in sequence 'x' and a k_mer at position j in sequence 'y'. If i - j > 'max_distance' the value is not added to the kernel value. This approximation is switched off by default (max_distance < 0).
在文件 OligoStringKernel.cpp 第 164 行定义.
|
|
protectedvirtualinherited |
creates a new TParameter instance, which contains migrated data from the version that is provided. The provided parameter data base is used for migration, this base is a collection of all parameter data of the previous version. Migration is done FROM the data in param_base TO the provided param info Migration is always one version step. Method has to be implemented in subclasses, if no match is found, base method has to be called.
If there is an element in the param_base which equals the target, a copy of the element is returned. This represents the case when nothing has changed and therefore, the migrate method is not overloaded in a subclass
- 参数
-
| param_base | set of TParameter instances to use for migration |
| target | parameter info for the resulting TParameter |
- 返回
- a new TParameter instance with migrated data from the base of the type which is specified by the target parameter
在文件 SGObject.cpp 第 893 行定义.
Computes row-wise/col-wise sum of kernel values. This method is useful while computing statistical estimation of mean/variance over kernel values but the kernel matrix is too huge to be fit inside memory.
- 参数
-
| block_begin_row | the row index at which the block starts |
| block_begin_col | the col index at which the block starts |
| block_size_row | the number of rows in the block |
| block_size_col | the number of cols in the block |
For Example, block_begin_row 0, block_begin_col 4 and block_size_row 5, block_size_col 6 represents the block that starts at index (0,4) in the kernel matrix and goes upto (0+5-1,4+6-1) i.e. (4,9) both inclusive
- 参数
-
| no_diag | if true (default is false), the diagonal elements are excluded from the row/col-wise sum, provided that block_size_row and block_size_col are same (i.e. the block is square). Otherwise, these are always added |
- 返回
- a vector whose first block_size_row entries contain row-wise sum of kernel values computed as
\[ v[i]=\sum_{j}k(i+\text{block-begin-row}, j+\text{block-begin-col}) \]
and rest block_size_col entries col-wise sum of kernel values computed as
\[ v[\text{block-size-row}+j]=\sum_{i}k(i+\text{block-begin-row}, j+\text{block-begin-col}) \]
where \(i\in[0,\text{block-size-row}-1]\) and \(j\in[0,\text{block-size-col}-1]\)
被 CCustomKernel 重载.
在文件 Kernel.cpp 第 735 行定义.
Computes row-wise/col-wise sum and squared sum of kernel values from a symmetric part of the kernel matrix that always is supposed to contain the main upper diagonal. This method is useful while computing statistical estimation of mean/variance over kernel values but the kernel matrix is too huge to be fit inside memory.
- 参数
-
| block_begin | the row and col index at which the block starts |
| block_size | the number of rows and cols in the block |
For Example, block_begin 4 and block_size 5 represents the block that starts at index (4,4) in the kernel matrix and goes upto (4+5-1,4+5-1) i.e. (8,8) both inclusive
- 参数
-
| no_diag | if true (default), the diagonal elements are excluded from the row/col-wise sum |
- 返回
- a matrix whose first column contains the row-wise sum of kernel values computed as
\[ v_0[i]=\sum_{j}k(i+\text{block-begin}, j+\text{block-begin}) \]
and second column contains the row-wise sum of squared kernel values
\[ v_1[i]=\sum_{j}^k^2(i+\text{block-begin}, j+\text{block-begin}) \]
where \(i,j\in[0,\text{block-size}-1]\)
被 CCustomKernel 重载.
在文件 Kernel.cpp 第 676 行定义.
Computes row-wise/col-wise sum from a symmetric part of the kernel matrix that always is supposed to contain the main upper diagonal. This method is useful while computing statistical estimation of mean/variance over kernel values but the kernel matrix is too huge to be fit inside memory.
- 参数
-
| block_begin | the row and col index at which the block starts |
| block_size | the number of rows and cols in the block |
For Example, block_begin 4 and block_size 5 represents the block that starts at index (4,4) in the kernel matrix and goes upto (4+5-1,4+5-1) i.e. (8,8) both inclusive
- 参数
-
| no_diag | if true (default), the diagonal elements are excluded from the row/col-wise sum |
- 返回
- vector containing row-wise sum computed as
\[ v[i]=\sum_{j}k(i+\text{block-begin}, j+\text{block-begin}) \]
where \(i,j\in[0,\text{block-size}-1]\)
被 CCustomKernel 重载.
在文件 Kernel.cpp 第 622 行定义.
Computes sum of kernel values from a specified block. This method is useful while computing statistical estimation of mean/variance over kernel values but the kernel matrix is too huge to be fit inside memory.
- 参数
-
| block_begin_row | the row index at which the block starts |
| block_begin_col | the col index at which the block starts |
| block_size_row | the number of rows in the block |
| block_size_col | the number of cols in the block |
For example, block_begin_row 0, block_begin_col 4 and block_size_row 5, block_size_col 6 represents the block that starts at index (0,4) in the kernel matrix and goes upto (0+5-1,4+6-1) i.e. (4,9) both inclusive
- 参数
-
| no_diag | if true (default is false), the diagonal elements are excluded from the sum, provided that block_size_row and block_size_col are same (i.e. the block is square). Otherwise, these are always added |
- 返回
- sum of kernel values within the block computed as
\[ \sum_{i}\sum_{j}k(i+\text{block-begin-row}, j+\text{block-begin-col}) \]
where \(i\in[0,\text{block-size-row}-1]\) and \(j\in[0,\text{block-size-col}-1]\)
被 CCustomKernel 重载.
在文件 Kernel.cpp 第 576 行定义.
Computes sum from a symmetric part of the kernel matrix that always is supposed to contain the main upper diagonal. This method is useful while computing statistical estimation of mean/variance over kernel values but the kernel matrix is too huge to be fit inside memory.
- 参数
-
| block_begin | the row and col index at which the block starts |
| block_size | the number of rows and cols in the block |
For example, block_begin 4 and block_size 5 represents the block that starts at index (4,4) in the kernel matrix and goes upto (4+5-1,4+5-1) i.e. (8,8) both inclusive
- 参数
-
| no_diag | if true (default), the diagonal elements are excluded from the sum |
- 返回
- sum of kernel values within the block computed as
\[ \sum_{i}\sum_{j}k(i+\text{block-begin}, j+\text{block-begin}) \]
where \(i,j\in[0,\text{block-size}-1]\)
被 CCustomKernel 重载.
在文件 Kernel.cpp 第 523 行定义.