63 using namespace shogun;
84 SG_DEBUG(
"created OligoStringKernel (%p) with size %d, k %d, width %f.\n", kern, size, k, width);
93 SG_ERROR(
"Couldn't create DiagKernel with size %d, diag %f.\n", size, diag);
95 SG_DEBUG(
"created DiagKernel (%p) with size %d, diag %f.\n", kern, size, diag);
104 SG_ERROR(
"Couldn't create ConstKernel with c %f.\n", c);
106 SG_DEBUG(
"created ConstKernel (%p) with c %f.\n", kern, c);
116 SG_DEBUG(
"created CustomKernel (%p).\n", kern);
120 if (source_is_diag && dest_is_diag && num_feat==1)
125 else if (!source_is_diag && dest_is_diag && num_vec==num_feat)
136 int32_t size,
float64_t width, int32_t max_shift, int32_t shift_step)
140 SG_ERROR(
"Couldn't create GaussianShiftKernel with size %d, width %f, max_shift %d, shift_step %d.\n", size, width, max_shift, shift_step);
142 SG_DEBUG(
"created GaussianShiftKernel (%p) with size %d, width %f, max_shift %d, shift_step %d.\n", kern, size, width, max_shift, shift_step);
151 SG_ERROR(
"Couldn't create GaussianKernel with size %d, width %f.\n", size, width);
153 SG_DEBUG(
"created GaussianKernel (%p) with size %d, width %f.\n", kern, size, width);
162 SG_ERROR(
"Couldn't create GaussianKernel with size %d, width %f.\n", size, width);
164 SG_DEBUG(
"created GaussianKernel (%p) with size %d, width %f.\n", kern, size, width);
174 SG_ERROR(
"Couldn't create SigmoidKernel with size %d, gamma %f, coef0 %f.\n", size, gamma, coef0);
176 SG_DEBUG(
"created SigmoidKernel (%p) with size %d, gamma %f, coef0 %f.\n", kern, size, gamma, coef0);
185 SG_ERROR(
"Couldn't create WaveletKernel with size %d, Wdilation %f, Wtranslation %f.\n", size, Wdilation, Wtranslation);
187 SG_DEBUG(
"created WaveletKernel (%p) with size %d, Wdilation %f, Wtranslation %f.\n", kern, size, Wdilation, Wtranslation);
192 int32_t size, int32_t degree,
bool inhomogene,
bool normalize)
197 SG_DEBUG(
"created PolyKernel with size %d, degree %d, inhomogene %d normalize %d.\n", kern, size, degree, inhomogene, normalize);
203 int32_t size, int32_t degree,
bool inhomogene,
bool normalize)
208 SG_DEBUG(
"created PolyKernel (%p) with size %d, degree %d, inhomogene %d, normalize %d.\n", kern, size, degree, inhomogene, normalize);
214 int32_t size, int32_t length, int32_t inner_degree, int32_t outer_degree,
222 size, length, inner_degree, outer_degree);
227 size, length, inner_degree, outer_degree);
231 SG_ERROR(
"Couldn't create (Simple)LocalityImprovedStringKernel with size %d, length %d, inner_degree %d, outer_degree %d.\n", size, length, inner_degree, outer_degree);
233 SG_DEBUG(
"created (Simple)LocalityImprovedStringKernel with size %d, length %d, inner_degree %d, outer_degree %d.\n", kern, size, length, inner_degree, outer_degree);
239 int32_t size, int32_t order, int32_t max_mismatch,
bool use_normalization,
240 int32_t mkl_stepsize,
bool block_computation, int32_t single_degree)
242 float64_t* weights=get_weights(order, max_mismatch);
245 if (single_degree>=0)
247 ASSERT(single_degree<order);
248 for (i=0; i<order; i++)
250 if (i!=single_degree)
259 SG_DEBUG(
"created WeightedDegreeStringKernel (%p) with size %d, order %d, "
260 "max_mismatch %d, use_normalization %d, mkl_stepsize %d, "
261 "block_computation %d, single_degree %d.\n",
262 kern, size, order, max_mismatch, (
int) use_normalization, mkl_stepsize,
263 block_computation, single_degree);
265 if (!use_normalization)
269 set_use_block_computation(block_computation);
279 int32_t size, int32_t order, int32_t max_mismatch, int32_t length,
283 int32_t* shifts=
SG_MALLOC(int32_t, length);
285 for (i=center; i<length; i++)
286 shifts[i]=(int32_t) floor(((
float64_t) (i-center))/step);
288 for (i=center-1; i>=0; i--)
289 shifts[i]=(int32_t) floor(((
float64_t) (center-i))/step);
291 for (i=0; i<length; i++)
293 if (shifts[i]>length)
297 for (i=0; i<length; i++)
298 SG_INFO(
"shift[%i]=%i\n", i, shifts[i]);
300 float64_t* weights=get_weights(order, max_mismatch);
304 SG_ERROR(
"Couldn't create WeightedDegreePositionStringKernel with size %d, order %d, max_mismatch %d, length %d, center %d, step %f.\n", size, order, max_mismatch, length, center, step);
306 SG_DEBUG(
"created WeightedDegreePositionStringKernel with size %d, order %d, max_mismatch %d, length %d, center %d, step %f.\n", kern, size, order, max_mismatch, length, center, step);
314 int32_t size, int32_t order, int32_t max_mismatch, int32_t* shifts,
315 int32_t length, int32_t mkl_stepsize,
float64_t* position_weights)
317 float64_t* weights=get_weights(order, max_mismatch);
322 SG_DEBUG(
"created WeightedDegreePositionStringKernel (%p) with size %d, order %d, max_mismatch %d, length %d and position_weights (MKL stepsize: %d).\n", kern, size, order, max_mismatch, length, mkl_stepsize);
324 if (!position_weights)
327 for (int32_t i=0; i<length; i++)
328 position_weights[i]=1.0/length;
338 int32_t size, int32_t order, int32_t max_mismatch, int32_t* shifts,
339 int32_t length,
bool use_normalization)
341 float64_t* weights=get_weights(order, max_mismatch);
344 if (!use_normalization)
348 SG_DEBUG(
"created WeightedDegreePositionStringKernel (%p) with size %d, order %d, max_mismatch %d, length %d, use_normalization %d.\n", kern, size, order, max_mismatch, length, use_normalization);
354 float64_t* CGUIKernel::get_weights(int32_t order, int32_t max_mismatch)
360 for (i=0; i<order; i++)
365 for (i=0; i<order; i++)
368 for (i=0; i<order; i++)
370 for (int32_t j=1; j<=max_mismatch; j++)
375 weights[i+j*order]=weights[i]/(nk*
CMath::pow(3, j));
378 weights[i+j*order]=0;
389 SG_ERROR(
"Couldn't create WeightedDegreeRBFKernel with size %d, width %f, degree %d, nof_properties %d.\n", size, width, degree, nof_properties);
391 SG_DEBUG(
"created WeightedDegreeRBFKernel (%p) with size %d, width %f, degree %d, nof_properties %d.\n", kern, size, width, degree, nof_properties);
401 SG_ERROR(
"Couldn't create SpectrumMismatchRBFKernel with size %d, width %f, degree %d, max_mismatch %d.\n", size, width, degree, max_mismatch);
403 SG_DEBUG(
"created SpectrumMismatchRBFKernel (%p) with size %d, width %f, degree %d, max_mismatch %d.\n", kern, size, width, degree, max_mismatch);
414 SG_ERROR(
"Couldn't create LocalAlignmentStringKernel with size %d.\n", size);
416 SG_DEBUG(
"created LocalAlignmentStringKernel (%p) with size %d.\n", kern, size);
425 SG_ERROR(
"Couldn't create FixedDegreeStringKernel with size %d and d %d.\n", size, d);
427 SG_DEBUG(
"created FixedDegreeStringKernel (%p) with size %d and d %d.\n", kern, size, d);
436 SG_ERROR(
"Couldn't create Chi2Kernel with size %d and width %f.\n", size, width);
438 SG_DEBUG(
"created Chi2Kernel (%p) with size %d and width %f.\n", kern, size, width);
444 int32_t size,
bool use_sign,
char* norm_str,
EKernelType ktype)
449 norm_str= (
char*)
"FULL";
458 SG_DEBUG(
"created WeightedCommWord/CommWord/CommUlongStringKernel (%p) with size %d, use_sign %d norm_str %s.\n", kern, size, use_sign, norm_str);
461 if (strncmp(norm_str,
"NO", 2)==0)
465 else if (strncmp(norm_str,
"FULL", 4)==0)
470 SG_ERROR(
"Unsupported Normalizer requested, supports only FULL and NO\n");
476 int32_t size, int32_t d,
bool normalize)
479 SG_DEBUG(
"created MatchWordStringKernel (%p) with size %d and d %d.\n", kern, size, d);
487 int32_t size, int32_t degree,
bool inhomogene,
bool normalize)
490 SG_DEBUG(
"created PolyMatchStringKernel (%p) with size %d, degree %d, inhomogene %d normalize %d.\n", kern, size, degree, inhomogene, normalize);
498 int32_t size, int32_t degree,
bool inhomogene,
bool normalize)
501 SG_DEBUG(
"created PolyMatchWordStringKernel (%p) with size %d, degree %d, inhomogene %d, normalize %d.\n", kern, size, degree, inhomogene, normalize);
510 SG_INFO(
"Getting estimator.\n");
517 SG_ERROR(
"Couldn't create SalzbergWordString with size %d.\n", size);
519 SG_DEBUG(
"created SalzbergWordString (%p) with size %d.\n", kern, size);
538 SG_INFO(
"Getting estimator.\n");
545 SG_ERROR(
"Couldn't create HistogramWordString with size %d.\n", size);
547 SG_DEBUG(
"created HistogramWordString (%p) with size %d.\n", kern, size);
557 SG_DEBUG(
"created LinearByteKernel (%p) with size %d and scale %f.\n", kern, size, scale);
567 SG_DEBUG(
"created LinearWordKernel (%p) with size %d and scale %f.\n", kern, size, scale);
579 SG_DEBUG(
"created LinearStringKernel (%p) with size %d and scale %f.\n", kern, size, scale);
590 SG_DEBUG(
"created LinearKernel (%p) with size %d and scale %f.\n", kern, size, scale);
601 SG_DEBUG(
"created LinearKernel (%p) with size %d and scale %f.\n", kern, size, scale);
613 SG_DEBUG(
"created TPPK (%p) with size %d and km %p, rows %d, cols %d.\n", kern, size, km, rows, cols);
622 SG_ERROR(
"No distance set for DistanceKernel.\n");
626 SG_ERROR(
"Couldn't create DistanceKernel with size %d and width %f.\n", size, width);
628 SG_DEBUG(
"created DistanceKernel (%p) with size %d and width %f.\n", kern, size, width);
634 int32_t size,
bool append_subkernel_weights)
638 SG_ERROR(
"Couldn't create CombinedKernel with size %d and append_subkernel_weights %d.\n", size, append_subkernel_weights);
640 SG_DEBUG(
"created CombinedKernel (%p) with size %d and append_subkernel_weights %d.\n", kern, size, append_subkernel_weights);
655 if (strncmp(normalization,
"IDENTITY", 8)==0)
657 SG_INFO(
"Identity Normalization (==NO NORMALIZATION) selected\n");
660 else if (strncmp(normalization,
"AVGDIAG", 7)==0)
662 SG_INFO(
"Average Kernel Diagonal Normalization selected\n");
665 else if (strncmp(normalization,
"RIDGE", 5)==0)
667 SG_INFO(
"Ridge Kernel Normalization selected\n");
670 else if (strncmp(normalization,
"SQRTDIAG", 8)==0)
672 SG_INFO(
"Sqrt Diagonal Normalization selected\n");
675 else if (strncmp(normalization,
"FIRSTELEMENT", 12)==0)
677 SG_INFO(
"First Element Normalization selected\n");
680 else if (strncmp(normalization,
"VARIANCE", 8)==0)
682 SG_INFO(
"Variance Normalization selected\n");
685 else if (strncmp(normalization,
"SCATTER", 7)==0)
687 SG_INFO(
"Scatter Normalization selected\n");
688 CLabels* train_labels=
ui->ui_labels->get_train_labels();
692 else if (strncmp(normalization,
"ZEROMEANCENTER", 13)==0)
694 SG_INFO(
"Zero Mean Center Normalization selected\n");
698 SG_ERROR(
"Wrong kernel normalizer name.\n");
713 SG_DEBUG(
"set new kernel (%p).\n", kern);
723 CSVM* svm=(
CSVM*)
ui->ui_classifier->get_classifier();
729 int32_t* sv_idx=
SG_MALLOC(int32_t, num_sv);
732 for (int32_t i=0; i<num_sv; i++)
744 SG_ERROR(
"Initialization of kernel optimization failed\n");
778 if (!strncmp(target,
"TRAIN", 5))
780 CFeatures* train=
ui->ui_features->get_train_features();
786 if ((k_fclass==fclass || k_fclass==
C_ANY || fclass==
C_ANY) &&
787 (k_ftype==ftype || k_ftype==
F_ANY || ftype==
F_ANY))
790 SG_INFO(
"Initialising kernel with TRAIN DATA, train: %p\n", train);
795 SG_ERROR(
"Kernel can not process this train feature type: %d %d.\n", fclass, ftype);
798 SG_DEBUG(
"Not initing kernel - no train features assigned.\n");
800 else if (!strncmp(target,
"TEST", 4))
802 CFeatures* train=
ui->ui_features->get_train_features();
803 CFeatures* test=
ui->ui_features->get_test_features();
808 if ((k_fclass==fclass || k_fclass==
C_ANY || fclass==
C_ANY) &&
809 (k_ftype==ftype || k_ftype==
F_ANY || ftype==
F_ANY))
816 if ((k_fclass==tr_fclass || k_fclass==
C_ANY || tr_fclass==
C_ANY) &&
817 (k_ftype==tr_ftype || k_ftype==
F_ANY || tr_ftype==
F_ANY))
819 SG_INFO(
"Initialising kernel with TRAIN DATA, train: %p\n", train);
824 SG_ERROR(
"Kernel can not process this train feature type: %d %d.\n", fclass, ftype);
827 SG_INFO(
"Initialising kernel with TEST DATA, train: %p test %p\n", train, test);
832 SG_ERROR(
"Kernel can not process this test feature type: %d %d.\n", fclass, ftype);
835 SG_DEBUG(
"Not initing kernel - no train and test features assigned.\n");
838 SG_ERROR(
"Unknown target %s.\n", target);
854 SG_ERROR(
"Writing to file %s failed!\n", filename);
858 SG_INFO(
"Successfully written kernel to \"%s\" !\n", filename);
862 SG_ERROR(
"No kernel set / kernel not initialized!\n");
870 SG_ERROR(
"Given kernel to add is invalid.\n");
887 SG_ERROR(
"Combined kernel object could not be created.\n");
897 SG_ERROR(
"Adding of kernel failed.\n");
909 SG_ERROR(
"Need a combined kernel for deleting the last kernel in it.\n");
915 SG_ERROR(
"No kernel available to delete.\n");
935 if (strncmp(opt_type,
"FASTBUTMEMHUNGRY", 16)==0)
937 SG_INFO(
"FAST METHOD selected\n");
943 else if (strncmp(opt_type,
"SLOWBUTMEMEFFICIENT", 19)==0)
945 SG_INFO(
"MEMORY EFFICIENT METHOD selected\n");
952 SG_ERROR(
"Wrong kernel optimization type.\n");
963 SG_ERROR(
"Not a combined kernel.\n");
CKernel * create_spectrummismatchrbf(int32_t size=10, float64_t *AA_matrix=NULL, int32_t nr=128, int32_t nc=128, int32_t max_mismatch=1, int32_t degree=1, float64_t width=1)
CKernel * create_linear(int32_t size=10, float64_t scale=-1)
CKernel * create_weighteddegreepositionstring(int32_t size=10, int32_t order=3, int32_t max_mismatch=1, int32_t length=0, int32_t center=0, float64_t step=1)
virtual bool init(CFeatures *lhs, CFeatures *rhs)
int32_t get_num_support_vectors()
CKernel * create_sparsepoly(int32_t size=10, int32_t degree=2, bool inhomogene=false, bool normalize=true)
Computes the standard linear kernel on CDotFeatures.
The standard Sigmoid kernel computed on dense real valued features.
Computes the standard polynomial kernel on CDotFeatures.
CKernel * create_histogramword(int32_t size=10)
spectrum mismatch rbf kernel
The Diagonal Kernel returns a constant for the diagonal and zero otherwise.
Class Distance, a base class for all the distances used in the Shogun toolbox.
virtual EFeatureType get_feature_type()=0
CKernel * create_commstring(int32_t size=10, bool use_sign=false, char *norm_str=NULL, EKernelType ktype=K_WEIGHTEDCOMMWORDSTRING)
CKernel * create_polymatchwordstring(int32_t size=10, int32_t degree=2, bool inhomogene=false, bool normalize=true)
This class offers access to the Oligo Kernel introduced by Meinicke et al. in 2004.
CKernel * create_sparselinear(int32_t size=10, float64_t scale=-1)
The CommUlongString kernel may be used to compute the spectrum kernel from strings that have been map...
The class Labels models labels, i.e. class assignments of objects.
CKernel * create_fixeddegreestring(int32_t size=10, int32_t d=3)
The Custom Kernel allows for custom user provided kernel matrices.
CKernel * create_linearstring(int32_t size=10, float64_t scale=-1)
CKernel * create_localityimprovedstring(int32_t size=10, int32_t length=3, int32_t inner_degree=3, int32_t outer_degree=1, EKernelType ktype=K_LOCALITYIMPROVED)
virtual bool set_normalizer(CKernelNormalizer *normalizer)
CKernel * create_linearword(int32_t size=10, float64_t scale=-1)
CKernel * create_weighteddegreepositionstring2(int32_t size=10, int32_t order=3, int32_t max_mismatch=1, int32_t *shifts=NULL, int32_t length=0, bool use_normalization=true)
CKernel * create_gaussianshift(int32_t size=10, float64_t width=1, int32_t max_shift=0, int32_t shift_step=1)
The FixedDegree String kernel takes as input two strings of same size and counts the number of matche...
virtual bool delete_optimization()
void set_cache_size(int32_t size)
bool init_kernel(const char *target)
virtual void set_optimization_type(EOptimizationType t)
The SalzbergWordString kernel implements the Salzberg kernel.
CKernel * create_linearbyte(int32_t size=10, float64_t scale=-1)
CKernel * create_combined(int32_t size=10, bool append_subkernel_weights=false)
CKernel * create_custom(float64_t *kmatrix, int32_t num_feat, int32_t num_vec, bool source_is_diag, bool dest_is_diag)
A Ascii File access class.
The WeightedCommWordString kernel may be used to compute the weighted spectrum kernel (i...
Computes the Tensor Product Pair Kernel (TPPK).
EFeatureClass
shogun feature class
bool get_is_initialized()
The Constant Kernel returns a constant for all elements.
The Chi2 kernel operating on realvalued vectors computes the chi-squared distance between sets of his...
bool set_triangle_kernel_matrix_from_triangle(SGVector< float64_t > tri_kernel_matrix)
The class PolyMatchWordStringKernel computes a variant of the polynomial kernel on word-features...
bool has_property(EKernelProperty p)
bool save_kernel(char *filename)
The HistogramWordString computes the TOP kernel on inhomogeneous Markov Chains.
CKernel * create_localalignmentstring(int32_t size=10)
CKernel * create_salzbergword(int32_t size=10)
bool set_optimization_type(char *opt_type)
CKernel * create_weighteddegreepositionstring3(int32_t size=10, int32_t order=3, int32_t max_mismatch=1, int32_t *shifts=NULL, int32_t length=0, int32_t mkl_stepsize=1, float64_t *position_weights=NULL)
CKernel * create_weighteddegreerbf(int32_t size=10, int32_t degree=1, int32_t nof_properties=1, float64_t width=1)
CKernel * create_const(int32_t size=10, float64_t c=1)
Class SGObject is the base class of all shogun objects.
virtual EFeatureClass get_feature_class()=0
CKernel * create_weighteddegreestring(int32_t size=10, int32_t order=3, int32_t max_mismatch=1, bool use_normalization=true, int32_t mkl_stepsize=1, bool block_computation=true, int32_t single_degree=-1)
CKernel * create_sigmoid(int32_t size=10, float64_t gamma=0.01, float64_t coef0=0)
Computes the standard linear kernel on dense char valued features.
An experimental kernel inspired by the WeightedDegreePositionStringKernel and the Gaussian kernel...
The CommWordString kernel may be used to compute the spectrum kernel from strings that have been mapp...
static int32_t pow(int32_t x, int32_t n)
virtual EFeatureType get_feature_type()=0
CKernel * create_poly(int32_t size=10, int32_t degree=2, bool inhomogene=false, bool normalize=true)
The class PolyMatchStringKernel computes a variant of the polynomial kernel on strings of same length...
void set_combined_kernel_weight(float64_t nw)
float64_t get_alpha(int32_t idx)
The Weighted Degree String kernel.
The Combined kernel is used to combine a number of kernels into a single CombinedKernel object by lin...
the scatter kernel normalizer
Normalize the kernel by a constant obtained from the first element of the kernel matrix, i.e. .
Identity Kernel Normalization, i.e. no normalization is applied.
The class MatchWordStringKernel computes a variant of the polynomial kernel on strings of same length...
Normalize the kernel by adding a constant term to its diagonal. This aids kernels to become positive ...
SimpleLocalityImprovedString kernel, is a ``simplified'' and better performing version of the Localit...
CKernel * create_diag(int32_t size=10, float64_t diag=1)
int32_t get_support_vector(int32_t idx)
ZeroMeanCenterKernelNormalizer centers the kernel in feature space.
The well known Gaussian kernel (swiss army knife for SVMs) computed on CDotFeatures.
The Distance kernel takes a distance as input.
CKernel * create_chi2(int32_t size=10, float64_t width=1)
EFeatureType
shogun feature type
bool delete_kernel_optimization()
static int64_t nchoosek(int32_t n, int32_t k)
weighted degree RBF kernel
SqrtDiagKernelNormalizer divides by the Square Root of the product of the diagonal elements...
CKernel * create_matchwordstring(int32_t size=10, int32_t d=3, bool normalize=true)
Normalize the kernel by either a constant or the average value of the diagonal elements (depending on...
virtual EKernelType get_kernel_type()=0
virtual bool init_optimization(int32_t count, int32_t *IDX, float64_t *weights)
bool set_full_kernel_matrix_from_full(SGMatrix< float32_t > full_kernel_matrix)
The class Features is the base class of all feature objects.
CKernel * create_wavelet(int32_t size=10, float64_t Wdilation=5.0, float64_t Wtranslation=2.0)
A generic Support Vector Machine Interface.
bool set_triangle_kernel_matrix_from_full(SGMatrix< float64_t > full_kernel_matrix)
bool precompute_subkernels()
CKernel * create_gaussian(int32_t size=10, float64_t width=1)
CKernel * create_oligo(int32_t size, int32_t k, float64_t width)
CKernel * create_tppk(int32_t size, float64_t *km, int32_t rows, int32_t cols)
bool init_kernel_optimization()
The Weighted Degree Position String kernel (Weighted Degree kernel with shifts).
bool set_kernel(CKernel *kern)
The LocalAlignmentString kernel compares two sequences through all possible local alignments between ...
CKernel * create_distance(int32_t size=10, float64_t width=1)
#define SG_MALLOC(type, len)
CKernel * create_polymatchstring(int32_t size=10, int32_t degree=2, bool inhomogene=false, bool normalize=true)
VarianceKernelNormalizer divides by the ``variance''.
bool add_kernel(CKernel *kern, float64_t weight=1)
The LocalityImprovedString kernel is inspired by the polynomial kernel. Comparing neighboring charact...
virtual EFeatureClass get_feature_class()=0
CKernel * create_sparsegaussian(int32_t size=10, float64_t width=1)
bool set_normalization(char *normalization, float64_t c=0.0, float64_t r=0.0)