63 using namespace shogun;
112 if (strcmp(name,
"LIBSVM_ONECLASS")==0)
116 SG_INFO(
"created SVMlibsvm object for oneclass\n");
118 else if (strcmp(name,
"LIBSVM_MULTICLASS")==0)
122 SG_INFO(
"created SVMlibsvm object for multiclass\n");
124 else if (strcmp(name,
"LIBSVM_NUMULTICLASS")==0)
128 SG_INFO(
"created SVMlibsvm object for multiclass\n") ;
131 else if (strcmp(name,
"SCATTERSVM_NO_BIAS_LIBSVM")==0)
135 SG_INFO(
"created ScatterSVM NO BIAS LIBSVM object\n") ;
137 else if (strcmp(name,
"SCATTERSVM_TESTRULE1")==0)
141 SG_INFO(
"created ScatterSVM TESTRULE1 object\n") ;
143 else if (strcmp(name,
"SCATTERSVM_TESTRULE2")==0)
147 SG_INFO(
"created ScatterSVM TESTRULE2 object\n") ;
149 else if (strcmp(name,
"LIBSVM_NU")==0)
153 SG_INFO(
"created SVMlibsvm object\n") ;
155 else if (strcmp(name,
"LIBSVM")==0)
159 SG_INFO(
"created SVMlibsvm object\n") ;
161 else if (strcmp(name,
"LARANK")==0)
165 SG_INFO(
"created LaRank object\n") ;
168 else if (strcmp(name,
"GPBTSVM")==0)
172 SG_INFO(
"created GPBT-SVM object\n") ;
174 else if (strcmp(name,
"MPDSVM")==0)
178 SG_INFO(
"created MPD-SVM object\n") ;
180 else if (strcmp(name,
"GNPPSVM")==0)
184 SG_INFO(
"created GNPP-SVM object\n") ;
186 else if (strcmp(name,
"GMNPSVM")==0)
190 SG_INFO(
"created GMNP-SVM object\n") ;
192 else if (strcmp(name,
"LIBSVR")==0)
196 SG_INFO(
"created SVRlibsvm object\n") ;
199 else if (strcmp(name,
"KRR")==0)
203 ui->ui_labels->get_train_labels());
207 else if (strcmp(name,
"PERCEPTRON")==0)
211 SG_INFO(
"created Perceptron object\n") ;
214 else if (strncmp(name,
"LIBLINEAR",9)==0)
218 if (strcmp(name,
"LIBLINEAR_L2R_LR")==0)
221 SG_INFO(
"created LibLinear l2 regularized logistic regression object\n") ;
223 else if (strcmp(name,
"LIBLINEAR_L2R_L2LOSS_SVC_DUAL")==0)
226 SG_INFO(
"created LibLinear l2 regularized l2 loss SVM dual object\n") ;
228 else if (strcmp(name,
"LIBLINEAR_L2R_L2LOSS_SVC")==0)
231 SG_INFO(
"created LibLinear l2 regularized l2 loss SVM primal object\n") ;
233 else if (strcmp(name,
"LIBLINEAR_L1R_L2LOSS_SVC")==0)
236 SG_INFO(
"created LibLinear l1 regularized l2 loss SVM primal object\n") ;
238 else if (strcmp(name,
"LIBLINEAR_L2R_L1LOSS_SVC_DUAL")==0)
241 SG_INFO(
"created LibLinear l2 regularized l1 loss dual SVM object\n") ;
244 SG_ERROR(
"unknown liblinear type\n");
252 else if (strcmp(name,
"LDA")==0)
256 SG_INFO(
"created LDA object\n") ;
260 else if (strcmp(name,
"LPM")==0)
268 SG_INFO(
"created LPM object\n") ;
270 else if (strcmp(name,
"LPBOOST")==0)
278 SG_INFO(
"created LPBoost object\n") ;
280 else if (strcmp(name,
"SUBGRADIENTLPM")==0)
291 SG_INFO(
"created Subgradient LPM object\n") ;
294 else if (strncmp(name,
"KNN", strlen(
"KNN"))==0)
298 SG_INFO(
"created KNN object\n") ;
300 else if (strncmp(name,
"KMEANS", strlen(
"KMEANS"))==0)
304 SG_INFO(
"created KMeans object\n") ;
306 else if (strncmp(name,
"HIERARCHICAL", strlen(
"HIERARCHICAL"))==0)
310 SG_INFO(
"created Hierarchical clustering object\n") ;
312 else if (strcmp(name,
"SVMLIN")==0)
319 SG_INFO(
"created SVMLin object\n") ;
321 else if (strcmp(name,
"SUBGRADIENTSVM")==0)
332 SG_INFO(
"created Subgradient SVM object\n") ;
334 else if (strncmp(name,
"WDSVMOCAS", strlen(
"WDSVMOCAS"))==0)
344 SG_INFO(
"created Weighted Degree Kernel SVM Ocas(OCAS) object of order %d (from order:%d)\n", d, from_d) ;
346 else if (strcmp(name,
"SVMOCAS")==0)
355 SG_INFO(
"created SVM Ocas(OCAS) object\n") ;
357 else if (strcmp(name,
"SVMSGD")==0)
362 SG_INFO(
"created SVM SGD object\n") ;
364 else if (strcmp(name,
"SVMBMRM")==0 || (strcmp(name,
"SVMPERF")==0))
373 SG_INFO(
"created SVM Ocas(BMRM/PERF) object\n") ;
375 else if (strcmp(name,
"MKL_CLASSIFICATION")==0)
385 else if (strcmp(name,
"MKL_ONECLASS")==0)
390 else if (strcmp(name,
"MKL_MULTICLASS")==0)
395 else if (strcmp(name,
"MKL_REGRESSION")==0)
402 SG_ERROR(
"Unknown classifier %s.\n", name);
416 CLabels* trainlabels=
ui->ui_labels->get_train_labels();
418 SG_ERROR(
"No trainlabels available.\n");
420 CKernel* kernel=
ui->ui_kernel->get_kernel();
424 bool success=
ui->ui_kernel->init_kernel(
"TRAIN");
426 if (!success || !
ui->ui_kernel->is_initialized() || !kernel->
has_features())
427 SG_ERROR(
"Kernel not initialized / no train features available.\n");
431 SG_ERROR(
"Number of train labels (%d) and training vectors (%d) differs!\n", trainlabels->
get_num_labels(), num_vec);
465 trainlabels=
ui->ui_labels->get_train_labels();
467 SG_INFO(
"Training one class mkl.\n");
468 if (!trainlabels && !oneclass)
469 SG_ERROR(
"No trainlabels available.\n");
471 CKernel* kernel=
ui->ui_kernel->get_kernel();
475 bool success=
ui->ui_kernel->init_kernel(
"TRAIN");
476 if (!success || !
ui->ui_kernel->is_initialized() || !kernel->
has_features())
477 SG_ERROR(
"Kernel not initialized.\n");
481 SG_ERROR(
"Number of train labels (%d) and training vectors (%d) differs!\n", trainlabels->
get_num_labels(), num_vec);
520 bool result=mkl->
train();
534 trainlabels=
ui->ui_labels->get_train_labels();
536 SG_INFO(
"Training one class svm.\n");
537 if (!trainlabels && !oneclass)
538 SG_ERROR(
"No trainlabels available.\n");
540 CKernel* kernel=
ui->ui_kernel->get_kernel();
544 bool success=
ui->ui_kernel->init_kernel(
"TRAIN");
546 if (!success || !
ui->ui_kernel->is_initialized() || !kernel->
has_features())
547 SG_ERROR(
"Kernel not initialized / no train features available.\n");
551 SG_ERROR(
"Number of train labels (%d) and training vectors (%d) differs!\n", trainlabels->
get_num_labels(), num_vec);
587 bool result=svm->
train();
595 CDistance* distance=
ui->ui_distance->get_distance();
598 SG_ERROR(
"No distance available\n");
600 if (!
ui->ui_distance->init_distance(
"TRAIN"))
601 SG_ERROR(
"Initializing distance with train features failed.\n");
611 ((
CKMeans*) classifier)->set_max_iter(max_iter);
612 result=((
CKMeans*) classifier)->train();
622 SG_ERROR(
"Unknown clustering type %d\n", type);
630 CLabels* trainlabels=
ui->ui_labels->get_train_labels();
631 CDistance* distance=
ui->ui_distance->get_distance();
639 if (!
ui->ui_distance->init_distance(
"TRAIN"))
640 SG_ERROR(
"Initializing distance with train features failed.\n");
647 SG_ERROR(
"No distance available.\n");
663 trainlabels=
ui->ui_labels->get_train_labels();
665 SG_ERROR(
"No trainlabels available.\n");
667 CKernel* kernel=
ui->ui_kernel->get_kernel();
671 bool success=
ui->ui_kernel->init_kernel(
"TRAIN");
673 if (!success || !
ui->ui_kernel->is_initialized() || !kernel->
has_features())
674 SG_ERROR(
"Kernel not initialized / no train features available.\n");
678 SG_ERROR(
"Number of train labels (%d) and training vectors (%d) differs!\n", trainlabels->
get_num_labels(), num_vec);
685 bool result=krr->
train();
696 CFeatures* trainfeatures=
ui->ui_features->get_train_features();
697 CLabels* trainlabels=
ui->ui_labels->get_train_labels();
701 SG_ERROR(
"No trainfeatures available.\n");
704 SG_ERROR(
"Trainfeatures not based on DotFeatures.\n");
720 SG_ERROR(
"LDA requires train features of class SIMPLE type REAL.\n");
742 SG_ERROR(
"LPM and LPBOOST require trainfeatures of class SPARSE type REAL.\n");
754 CFeatures* trainfeatures=
ui->ui_features->get_train_features();
755 CLabels* trainlabels=
ui->ui_labels->get_train_labels();
760 SG_ERROR(
"No trainfeatures available.\n");
764 SG_ERROR(
"Trainfeatures are not of class STRING type BYTE.\n");
782 FILE* model_file=fopen(filename,
"r");
788 SG_DEBUG(
"file successfully read.\n");
792 SG_ERROR(
"SVM/Classifier creation/loading failed on file %s.\n", filename);
797 SG_ERROR(
"Opening file %s failed.\n", filename);
802 SG_ERROR(
"Type %s of SVM/Classifier unknown.\n", type);
814 FILE* file=fopen(param,
"w");
817 printf(
"writing to file %s failed!\n", param);
820 printf(
"successfully written classifier into \"%s\" !\n", param);
828 SG_ERROR(
"create classifier first\n");
869 SG_INFO(
"Disabling max_train_time.\n");
877 SG_ERROR(
"No regression method allocated\n");
883 SG_ERROR(
"Underlying method not capable of SV-regression\n");
910 if (weight_epsilon<0)
930 if (lambda<0 || lambda>1)
940 SG_ERROR(
"1 <= mkl_block_norm <= inf\n");
1001 SG_INFO(
"Enabling shrinking optimization.\n");
1003 SG_INFO(
"Disabling shrinking optimization.\n");
1012 SG_INFO(
"Enabling batch computation.\n");
1014 SG_INFO(
"Disabling batch computation.\n");
1023 SG_INFO(
"Enabling LINADD optimization.\n");
1025 SG_INFO(
"Disabling LINADD optimization.\n");
1034 SG_INFO(
"Enabling svm bias.\n");
1036 SG_INFO(
"Disabling svm bias.\n");
1045 SG_INFO(
"Enabling mkl interleaved optimization.\n");
1047 SG_INFO(
"Disabling mkl interleaved optimization.\n");
1057 SG_INFO(
"Enabling AUC maximization.\n");
1059 SG_INFO(
"Disabling AUC maximization.\n");
1108 SG_ERROR(
"unknown classifier type\n");
1117 CFeatures* trainfeatures=
ui->ui_features->get_train_features();
1118 CFeatures* testfeatures=
ui->ui_features->get_test_features();
1121 SG_ERROR(
"No kernelmachine available.\n");
1125 if (
ui->ui_kernel->get_kernel()->get_kernel_type()!=
K_CUSTOM)
1127 if (
ui->ui_kernel->get_kernel()->get_kernel_type()==
K_COMBINED
1128 && ( !trainfeatures || !testfeatures ))
1130 SG_DEBUG(
"skipping initialisation of combined kernel "
1131 "as train/test features are unavailable\n");
1136 SG_ERROR(
"No training features available.\n");
1138 SG_ERROR(
"No test features available.\n");
1140 success=
ui->ui_kernel->init_kernel(
"TEST");
1144 if (!success || !
ui->ui_kernel->is_initialized())
1145 SG_ERROR(
"Kernel not initialized.\n");
1151 SG_INFO(
"Starting kernel machine testing.\n");
1157 int32_t& brows, int32_t& bcols,
1182 return get_svm(weights, rows, cols, bias, brows, bcols, idx);
1195 return get_linear(weights, rows, cols, bias, brows, bcols);
1205 SG_ERROR(
"unknown classifier type\n");
1220 int32_t& brows, int32_t& bcols, int32_t idx)
1238 for (int32_t i=0; i<rows; i++)
1252 int32_t& brows, int32_t& bcols)
1293 for (int32_t i=0; i<rows*cols; i++)
1300 SG_ERROR(
"internal error - unknown clustering type\n");
1308 int32_t& brows, int32_t& bcols)
1322 linear->
get_w(w, rows);
1325 memcpy(weights, w,
sizeof(
float64_t)*rows);
1332 CFeatures* trainfeatures=
ui->ui_features->get_train_features();
1333 CFeatures* testfeatures=
ui->ui_features->get_test_features();
1337 SG_ERROR(
"no kernelmachine available\n") ;
1342 SG_ERROR(
"no training features available\n") ;
1348 SG_ERROR(
"no test features available\n") ;
1352 bool success=
ui->ui_distance->init_distance(
"TEST");
1354 if (!success || !
ui->ui_distance->is_initialized())
1356 SG_ERROR(
"distance not initialized\n") ;
1361 ui->ui_distance->get_distance());
1362 SG_INFO(
"starting distance machine testing\n") ;
1369 CFeatures* testfeatures=
ui->ui_features->get_test_features();
1373 SG_ERROR(
"no classifier available\n") ;
1378 SG_ERROR(
"no test features available\n") ;
1383 SG_ERROR(
"testfeatures not based on DotFeatures\n") ;
1388 SG_INFO(
"starting linear classifier testing\n") ;
1394 CFeatures* testfeatures=
ui->ui_features->get_test_features();
1403 SG_ERROR(
"no test features available\n") ;
1409 SG_ERROR(
"testfeatures not of class STRING type BYTE\n") ;
1414 SG_INFO(
"starting linear classifier testing\n") ;
1420 CFeatures* trainfeatures=
ui->ui_features->get_train_features();
1421 CFeatures* testfeatures=
ui->ui_features->get_test_features();
1429 if (!
ui->ui_kernel->is_initialized())
1431 SG_ERROR(
"kernel not initialized\n") ;
1435 if (!
ui->ui_kernel->get_kernel() ||
1436 !
ui->ui_kernel->get_kernel()->get_kernel_type()==
K_CUSTOM)
1440 SG_ERROR(
"no training features available\n") ;
1446 SG_ERROR(
"no test features available\n") ;
1452 ui->ui_kernel->get_kernel());
1476 if (strncmp(solver,
"NEWTON", 6)==0)
1478 SG_INFO(
"Using NEWTON solver.\n");
1481 else if (strncmp(solver,
"DIRECT", 6)==0)
1483 SG_INFO(
"Using DIRECT solver\n");
1486 else if (strncmp(solver,
"BLOCK_NORM", 9)==0)
1488 SG_INFO(
"Using BLOCK_NORM solver\n");
1491 else if (strncmp(solver,
"ELASTICNET", 10)==0)
1493 SG_INFO(
"Using ELASTICNET solver\n");
1496 else if (strncmp(solver,
"AUTO", 4)==0)
1498 SG_INFO(
"Automagically determining solver.\n");
1502 else if (strncmp(solver,
"CPLEX", 5)==0)
1504 SG_INFO(
"USING CPLEX METHOD selected\n");
1509 else if (strncmp(solver,
"GLPK", 4)==0)
1511 SG_INFO(
"Using GLPK solver\n");
1516 SG_ERROR(
"Unknown solver type, %s (not compiled in?)\n", solver);
1525 if (strcmp(name,
"LIBSVM_ONECLASS")==0)
1529 SG_INFO(
"created SVMlibsvm object for oneclass\n");
1531 else if (strcmp(name,
"LIBSVM_MULTICLASS")==0)
1535 SG_INFO(
"created SVMlibsvm object for multiclass\n");
1537 else if (strcmp(name,
"LIBSVM_NUMULTICLASS")==0)
1541 SG_INFO(
"created SVMlibsvm object for multiclass\n") ;
1543 else if (strcmp(name,
"SCATTERSVM_RULE1")==0)
1547 SG_INFO(
"created ScatterSVM RULE1 object\n") ;
1549 else if (strcmp(name,
"SCATTERSVM_RULE2")==0)
1553 SG_INFO(
"created ScatterSVM RULE2 object\n") ;
1555 else if (strcmp(name,
"LIBSVM_NU")==0)
1559 SG_INFO(
"created SVMlibsvm object\n") ;
1561 else if (strcmp(name,
"LIBSVM")==0)
1565 SG_INFO(
"created SVMlibsvm object\n") ;
1567 else if (strcmp(name,
"LARANK")==0)
1571 SG_INFO(
"created LaRank object\n") ;
1574 else if (strcmp(name,
"GPBTSVM")==0)
1578 SG_INFO(
"created GPBT-SVM object\n") ;
1580 else if (strcmp(name,
"MPDSVM")==0)
1584 SG_INFO(
"created MPD-SVM object\n") ;
1586 else if (strcmp(name,
"GNPPSVM")==0)
1590 SG_INFO(
"created GNPP-SVM object\n") ;
1592 else if (strcmp(name,
"GMNPSVM")==0)
1596 SG_INFO(
"created GMNP-SVM object\n") ;
1598 else if (strcmp(name,
"LIBSVR")==0)
1602 SG_INFO(
"created SVRlibsvm object\n") ;
1606 SG_ERROR(
"Unknown SV-classifier %s.\n", name);