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)
135 int32_t size,
float64_t width, int32_t max_shift, int32_t shift_step)
139 SG_ERROR(
"Couldn't create GaussianShiftKernel with size %d, width %f, max_shift %d, shift_step %d.\n", size, width, max_shift, shift_step);
141 SG_DEBUG(
"created GaussianShiftKernel (%p) with size %d, width %f, max_shift %d, shift_step %d.\n", kern, size, width, max_shift, shift_step);
150 SG_ERROR(
"Couldn't create GaussianKernel with size %d, width %f.\n", size, width);
152 SG_DEBUG(
"created GaussianKernel (%p) with size %d, width %f.\n", kern, size, width);
161 SG_ERROR(
"Couldn't create GaussianKernel with size %d, width %f.\n", size, width);
163 SG_DEBUG(
"created GaussianKernel (%p) with size %d, width %f.\n", kern, size, width);
173 SG_ERROR(
"Couldn't create SigmoidKernel with size %d, gamma %f, coef0 %f.\n", size, gamma, coef0);
175 SG_DEBUG(
"created SigmoidKernel (%p) with size %d, gamma %f, coef0 %f.\n", kern, size, gamma, coef0);
184 SG_ERROR(
"Couldn't create WaveletKernel with size %d, Wdilation %f, Wtranslation %f.\n", size, Wdilation, Wtranslation);
186 SG_DEBUG(
"created WaveletKernel (%p) with size %d, Wdilation %f, Wtranslation %f.\n", kern, size, Wdilation, Wtranslation);
191 int32_t size, int32_t degree,
bool inhomogene,
bool normalize)
196 SG_DEBUG(
"created PolyKernel with size %d, degree %d, inhomogene %d normalize %d.\n", kern, size, degree, inhomogene, normalize);
202 int32_t size, int32_t degree,
bool inhomogene,
bool normalize)
207 SG_DEBUG(
"created PolyKernel (%p) with size %d, degree %d, inhomogene %d, normalize %d.\n", kern, size, degree, inhomogene, normalize);
213 int32_t size, int32_t length, int32_t inner_degree, int32_t outer_degree,
221 size, length, inner_degree, outer_degree);
226 size, length, inner_degree, outer_degree);
230 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);
232 SG_DEBUG(
"created (Simple)LocalityImprovedStringKernel with size %d, length %d, inner_degree %d, outer_degree %d.\n", kern, size, length, inner_degree, outer_degree);
238 int32_t size, int32_t order, int32_t max_mismatch,
bool use_normalization,
239 int32_t mkl_stepsize,
bool block_computation, int32_t single_degree)
241 float64_t* weights=get_weights(order, max_mismatch);
244 if (single_degree>=0)
246 ASSERT(single_degree<order);
247 for (i=0; i<order; i++)
249 if (i!=single_degree)
258 SG_DEBUG(
"created WeightedDegreeStringKernel (%p) with size %d, order %d, "
259 "max_mismatch %d, use_normalization %d, mkl_stepsize %d, "
260 "block_computation %d, single_degree %d.\n",
261 kern, size, order, max_mismatch, (
int) use_normalization, mkl_stepsize,
262 block_computation, single_degree);
264 if (!use_normalization)
268 set_use_block_computation(block_computation);
277 int32_t size, int32_t order, int32_t max_mismatch, int32_t length,
281 int32_t* shifts=
SG_MALLOC(int32_t, length);
283 for (i=center; i<length; i++)
284 shifts[i]=(int32_t) floor(((
float64_t) (i-center))/step);
286 for (i=center-1; i>=0; i--)
287 shifts[i]=(int32_t) floor(((
float64_t) (center-i))/step);
289 for (i=0; i<length; i++)
291 if (shifts[i]>length)
295 for (i=0; i<length; i++)
296 SG_INFO(
"shift[%i]=%i\n", i, shifts[i]);
298 float64_t* weights=get_weights(order, max_mismatch);
302 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);
304 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);
312 int32_t size, int32_t order, int32_t max_mismatch, int32_t* shifts,
313 int32_t length, int32_t mkl_stepsize,
float64_t* position_weights)
315 float64_t* weights=get_weights(order, max_mismatch);
320 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);
322 if (!position_weights)
325 for (int32_t i=0; i<length; i++)
326 position_weights[i]=1.0/length;
336 int32_t size, int32_t order, int32_t max_mismatch, int32_t* shifts,
337 int32_t length,
bool use_normalization)
339 float64_t* weights=get_weights(order, max_mismatch);
342 if (!use_normalization)
346 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);
352 float64_t* CGUIKernel::get_weights(int32_t order, int32_t max_mismatch)
358 for (i=0; i<order; i++)
363 for (i=0; i<order; i++)
366 for (i=0; i<order; i++)
368 for (int32_t j=1; j<=max_mismatch; j++)
373 weights[i+j*order]=weights[i]/(nk*
CMath::pow(3, j));
376 weights[i+j*order]=0;
387 SG_ERROR(
"Couldn't create WeightedDegreeRBFKernel with size %d, width %f, degree %d, nof_properties %d.\n", size, width, degree, nof_properties);
389 SG_DEBUG(
"created WeightedDegreeRBFKernel (%p) with size %d, width %f, degree %d, nof_properties %d.\n", kern, size, width, degree, nof_properties);
399 SG_ERROR(
"Couldn't create SpectrumMismatchRBFKernel with size %d, width %f, degree %d, max_mismatch %d.\n", size, width, degree, max_mismatch);
401 SG_DEBUG(
"created SpectrumMismatchRBFKernel (%p) with size %d, width %f, degree %d, max_mismatch %d.\n", kern, size, width, degree, max_mismatch);
412 SG_ERROR(
"Couldn't create LocalAlignmentStringKernel with size %d.\n", size);
414 SG_DEBUG(
"created LocalAlignmentStringKernel (%p) with size %d.\n", kern, size);
423 SG_ERROR(
"Couldn't create FixedDegreeStringKernel with size %d and d %d.\n", size, d);
425 SG_DEBUG(
"created FixedDegreeStringKernel (%p) with size %d and d %d.\n", kern, size, d);
434 SG_ERROR(
"Couldn't create Chi2Kernel with size %d and width %f.\n", size, width);
436 SG_DEBUG(
"created Chi2Kernel (%p) with size %d and width %f.\n", kern, size, width);
442 int32_t size,
bool use_sign,
char* norm_str,
EKernelType ktype)
447 norm_str= (
char*)
"FULL";
456 SG_DEBUG(
"created WeightedCommWord/CommWord/CommUlongStringKernel (%p) with size %d, use_sign %d norm_str %s.\n", kern, size, use_sign, norm_str);
459 if (strncmp(norm_str,
"NO", 2)==0)
463 else if (strncmp(norm_str,
"FULL", 4)==0)
468 SG_ERROR(
"Unsupported Normalizer requested, supports only FULL and NO\n");
474 int32_t size, int32_t d,
bool normalize)
477 SG_DEBUG(
"created MatchWordStringKernel (%p) with size %d and d %d.\n", kern, size, d);
485 int32_t size, int32_t degree,
bool inhomogene,
bool normalize)
488 SG_DEBUG(
"created PolyMatchStringKernel (%p) with size %d, degree %d, inhomogene %d normalize %d.\n", kern, size, degree, inhomogene, normalize);
496 int32_t size, int32_t degree,
bool inhomogene,
bool normalize)
499 SG_DEBUG(
"created PolyMatchWordStringKernel (%p) with size %d, degree %d, inhomogene %d, normalize %d.\n", kern, size, degree, inhomogene, normalize);
508 SG_INFO(
"Getting estimator.\n");
515 SG_ERROR(
"Couldn't create SalzbergWordString with size %d.\n", size);
517 SG_DEBUG(
"created SalzbergWordString (%p) with size %d.\n", kern, size);
536 SG_INFO(
"Getting estimator.\n");
543 SG_ERROR(
"Couldn't create HistogramWordString with size %d.\n", size);
545 SG_DEBUG(
"created HistogramWordString (%p) with size %d.\n", kern, size);
555 SG_DEBUG(
"created LinearByteKernel (%p) with size %d and scale %f.\n", kern, size, scale);
565 SG_DEBUG(
"created LinearWordKernel (%p) with size %d and scale %f.\n", kern, size, scale);
577 SG_DEBUG(
"created LinearStringKernel (%p) with size %d and scale %f.\n", kern, size, scale);
588 SG_DEBUG(
"created LinearKernel (%p) with size %d and scale %f.\n", kern, size, scale);
599 SG_DEBUG(
"created LinearKernel (%p) with size %d and scale %f.\n", kern, size, scale);
611 SG_DEBUG(
"created TPPK (%p) with size %d and km %p, rows %d, cols %d.\n", kern, size, km, rows, cols);
620 SG_ERROR(
"No distance set for DistanceKernel.\n");
624 SG_ERROR(
"Couldn't create DistanceKernel with size %d and width %f.\n", size, width);
626 SG_DEBUG(
"created DistanceKernel (%p) with size %d and width %f.\n", kern, size, width);
632 int32_t size,
bool append_subkernel_weights)
636 SG_ERROR(
"Couldn't create CombinedKernel with size %d and append_subkernel_weights %d.\n", size, append_subkernel_weights);
638 SG_DEBUG(
"created CombinedKernel (%p) with size %d and append_subkernel_weights %d.\n", kern, size, append_subkernel_weights);
653 if (strncmp(normalization,
"IDENTITY", 8)==0)
655 SG_INFO(
"Identity Normalization (==NO NORMALIZATION) selected\n");
658 else if (strncmp(normalization,
"AVGDIAG", 7)==0)
660 SG_INFO(
"Average Kernel Diagonal Normalization selected\n");
663 else if (strncmp(normalization,
"RIDGE", 5)==0)
665 SG_INFO(
"Ridge Kernel Normalization selected\n");
668 else if (strncmp(normalization,
"SQRTDIAG", 8)==0)
670 SG_INFO(
"Sqrt Diagonal Normalization selected\n");
673 else if (strncmp(normalization,
"FIRSTELEMENT", 12)==0)
675 SG_INFO(
"First Element Normalization selected\n");
678 else if (strncmp(normalization,
"VARIANCE", 8)==0)
680 SG_INFO(
"Variance Normalization selected\n");
683 else if (strncmp(normalization,
"SCATTER", 7)==0)
685 SG_INFO(
"Scatter Normalization selected\n");
686 CLabels* train_labels=
ui->ui_labels->get_train_labels();
690 else if (strncmp(normalization,
"ZEROMEANCENTER", 13)==0)
692 SG_INFO(
"Zero Mean Center Normalization selected\n");
696 SG_ERROR(
"Wrong kernel normalizer name.\n");
711 SG_DEBUG(
"set new kernel (%p).\n", kern);
721 CSVM* svm=(
CSVM*)
ui->ui_classifier->get_classifier();
727 int32_t* sv_idx=
SG_MALLOC(int32_t, num_sv);
730 for (int32_t i=0; i<num_sv; i++)
742 SG_ERROR(
"Initialization of kernel optimization failed\n");
776 if (!strncmp(target,
"TRAIN", 5))
778 CFeatures* train=
ui->ui_features->get_train_features();
784 if ((k_fclass==fclass || k_fclass==
C_ANY || fclass==
C_ANY) &&
785 (k_ftype==ftype || k_ftype==
F_ANY || ftype==
F_ANY))
788 SG_INFO(
"Initialising kernel with TRAIN DATA, train: %p\n", train);
793 SG_ERROR(
"Kernel can not process this train feature type: %d %d.\n", fclass, ftype);
796 SG_DEBUG(
"Not initing kernel - no train features assigned.\n");
798 else if (!strncmp(target,
"TEST", 4))
800 CFeatures* train=
ui->ui_features->get_train_features();
801 CFeatures* test=
ui->ui_features->get_test_features();
806 if ((k_fclass==fclass || k_fclass==
C_ANY || fclass==
C_ANY) &&
807 (k_ftype==ftype || k_ftype==
F_ANY || ftype==
F_ANY))
814 if ((k_fclass==tr_fclass || k_fclass==
C_ANY || tr_fclass==
C_ANY) &&
815 (k_ftype==tr_ftype || k_ftype==
F_ANY || tr_ftype==
F_ANY))
817 SG_INFO(
"Initialising kernel with TRAIN DATA, train: %p\n", train);
822 SG_ERROR(
"Kernel can not process this train feature type: %d %d.\n", fclass, ftype);
825 SG_INFO(
"Initialising kernel with TEST DATA, train: %p test %p\n", train, test);
830 SG_ERROR(
"Kernel can not process this test feature type: %d %d.\n", fclass, ftype);
833 SG_DEBUG(
"Not initing kernel - no train and test features assigned.\n");
836 SG_ERROR(
"Unknown target %s.\n", target);
852 SG_ERROR(
"Writing to file %s failed!\n", filename);
856 SG_INFO(
"Successfully written kernel to \"%s\" !\n", filename);
860 SG_ERROR(
"No kernel set / kernel not initialized!\n");
868 SG_ERROR(
"Given kernel to add is invalid.\n");
885 SG_ERROR(
"Combined kernel object could not be created.\n");
895 SG_ERROR(
"Adding of kernel failed.\n");
907 SG_ERROR(
"Need a combined kernel for deleting the last kernel in it.\n");
913 SG_ERROR(
"No kernel available to delete.\n");
934 #endif //USE_SVMLIGHT
942 if (strncmp(opt_type,
"FASTBUTMEMHUNGRY", 16)==0)
944 SG_INFO(
"FAST METHOD selected\n");
950 else if (strncmp(opt_type,
"SLOWBUTMEMEFFICIENT", 19)==0)
952 SG_INFO(
"MEMORY EFFICIENT METHOD selected\n");
959 SG_ERROR(
"Wrong kernel optimization type.\n");
970 SG_ERROR(
"Not a combined kernel.\n");