69 using namespace shogun;
118 if (strcmp(name,
"LIBSVM_ONECLASS")==0)
122 SG_INFO(
"created SVMlibsvm object for oneclass\n");
124 else if (strcmp(name,
"LIBSVM_MULTICLASS")==0)
128 SG_INFO(
"created SVMlibsvm object for multiclass\n");
130 else if (strcmp(name,
"LIBSVM_NUMULTICLASS")==0)
134 SG_INFO(
"created SVMlibsvm object for multiclass\n") ;
137 else if (strcmp(name,
"SCATTERSVM_NO_BIAS_SVMLIGHT")==0)
141 SG_INFO(
"created ScatterSVM NO BIAS SVMLIGHT object\n") ;
143 #endif //USE_SVMLIGHT
144 else if (strcmp(name,
"SCATTERSVM_NO_BIAS_LIBSVM")==0)
148 SG_INFO(
"created ScatterSVM NO BIAS LIBSVM object\n") ;
150 else if (strcmp(name,
"SCATTERSVM_TESTRULE1")==0)
154 SG_INFO(
"created ScatterSVM TESTRULE1 object\n") ;
156 else if (strcmp(name,
"SCATTERSVM_TESTRULE2")==0)
160 SG_INFO(
"created ScatterSVM TESTRULE2 object\n") ;
162 else if (strcmp(name,
"LIBSVM_NU")==0)
166 SG_INFO(
"created SVMlibsvm object\n") ;
168 else if (strcmp(name,
"LIBSVM")==0)
172 SG_INFO(
"created SVMlibsvm object\n") ;
174 else if (strcmp(name,
"LARANK")==0)
178 SG_INFO(
"created LaRank object\n") ;
181 else if ((strcmp(name,
"LIGHT")==0) || (strcmp(name,
"SVMLIGHT")==0))
185 SG_INFO(
"created SVMLight object\n") ;
187 else if (strcmp(name,
"SVMLIGHT_ONECLASS")==0)
191 SG_INFO(
"created SVMLightOneClass object\n") ;
193 else if (strcmp(name,
"SVRLIGHT")==0)
197 SG_INFO(
"created SVRLight object\n") ;
199 #endif //USE_SVMLIGHT
200 else if (strcmp(name,
"GPBTSVM")==0)
204 SG_INFO(
"created GPBT-SVM object\n") ;
206 else if (strcmp(name,
"MPDSVM")==0)
210 SG_INFO(
"created MPD-SVM object\n") ;
212 else if (strcmp(name,
"GNPPSVM")==0)
216 SG_INFO(
"created GNPP-SVM object\n") ;
218 else if (strcmp(name,
"GMNPSVM")==0)
222 SG_INFO(
"created GMNP-SVM object\n") ;
224 else if (strcmp(name,
"LIBSVR")==0)
228 SG_INFO(
"created SVRlibsvm object\n") ;
231 else if (strcmp(name,
"KERNELRIDGEREGRESSION")==0)
235 ui->ui_labels->get_train_labels());
239 else if (strcmp(name,
"PERCEPTRON")==0)
243 SG_INFO(
"created Perceptron object\n") ;
246 else if (strncmp(name,
"LIBLINEAR",9)==0)
250 if (strcmp(name,
"LIBLINEAR_L2R_LR")==0)
253 SG_INFO(
"created LibLinear l2 regularized logistic regression object\n") ;
255 else if (strcmp(name,
"LIBLINEAR_L2R_L2LOSS_SVC_DUAL")==0)
258 SG_INFO(
"created LibLinear l2 regularized l2 loss SVM dual object\n") ;
260 else if (strcmp(name,
"LIBLINEAR_L2R_L2LOSS_SVC")==0)
263 SG_INFO(
"created LibLinear l2 regularized l2 loss SVM primal object\n") ;
265 else if (strcmp(name,
"LIBLINEAR_L1R_L2LOSS_SVC")==0)
268 SG_INFO(
"created LibLinear l1 regularized l2 loss SVM primal object\n") ;
270 else if (strcmp(name,
"LIBLINEAR_L2R_L1LOSS_SVC_DUAL")==0)
273 SG_INFO(
"created LibLinear l2 regularized l1 loss dual SVM object\n") ;
276 SG_ERROR(
"unknown liblinear type\n");
284 else if (strcmp(name,
"LDA")==0)
288 SG_INFO(
"created LDA object\n") ;
292 else if (strcmp(name,
"LPM")==0)
300 SG_INFO(
"created LPM object\n") ;
302 else if (strcmp(name,
"LPBOOST")==0)
310 SG_INFO(
"created LPBoost object\n") ;
312 else if (strcmp(name,
"SUBGRADIENTLPM")==0)
323 SG_INFO(
"created Subgradient LPM object\n") ;
326 else if (strncmp(name,
"KNN", strlen(
"KNN"))==0)
330 SG_INFO(
"created KNN object\n") ;
332 else if (strncmp(name,
"KMEANS", strlen(
"KMEANS"))==0)
336 SG_INFO(
"created KMeans object\n") ;
338 else if (strncmp(name,
"HIERARCHICAL", strlen(
"HIERARCHICAL"))==0)
342 SG_INFO(
"created Hierarchical clustering object\n") ;
344 else if (strcmp(name,
"SVMLIN")==0)
351 SG_INFO(
"created SVMLin object\n") ;
353 else if (strcmp(name,
"SUBGRADIENTSVM")==0)
364 SG_INFO(
"created Subgradient SVM object\n") ;
366 else if (strncmp(name,
"WDSVMOCAS", strlen(
"WDSVMOCAS"))==0)
376 SG_INFO(
"created Weighted Degree Kernel SVM Ocas(OCAS) object of order %d (from order:%d)\n", d, from_d) ;
378 else if (strcmp(name,
"SVMOCAS")==0)
387 SG_INFO(
"created SVM Ocas(OCAS) object\n") ;
389 else if (strcmp(name,
"SVMSGD")==0)
394 SG_INFO(
"created SVM SGD object\n") ;
396 else if (strcmp(name,
"SVMBMRM")==0 || (strcmp(name,
"SVMPERF")==0))
405 SG_INFO(
"created SVM Ocas(BMRM/PERF) object\n") ;
407 else if (strcmp(name,
"MKL_CLASSIFICATION")==0)
412 else if (strcmp(name,
"MKL_ONECLASS")==0)
417 else if (strcmp(name,
"MKL_MULTICLASS")==0)
422 else if (strcmp(name,
"MKL_REGRESSION")==0)
429 SG_ERROR(
"Unknown classifier %s.\n", name);
443 CLabels* trainlabels=
ui->ui_labels->get_train_labels();
445 SG_ERROR(
"No trainlabels available.\n");
447 CKernel* kernel=
ui->ui_kernel->get_kernel();
451 bool success=
ui->ui_kernel->init_kernel(
"TRAIN");
453 if (!success || !
ui->ui_kernel->is_initialized() || !kernel->
has_features())
454 SG_ERROR(
"Kernel not initialized / no train features available.\n");
458 SG_ERROR(
"Number of train labels (%d) and training vectors (%d) differs!\n", trainlabels->
get_num_labels(), num_vec);
492 trainlabels=
ui->ui_labels->get_train_labels();
494 SG_INFO(
"Training one class mkl.\n");
495 if (!trainlabels && !oneclass)
496 SG_ERROR(
"No trainlabels available.\n");
498 CKernel* kernel=
ui->ui_kernel->get_kernel();
502 bool success=
ui->ui_kernel->init_kernel(
"TRAIN");
503 if (!success || !
ui->ui_kernel->is_initialized() || !kernel->
has_features())
504 SG_ERROR(
"Kernel not initialized.\n");
508 SG_ERROR(
"Number of train labels (%d) and training vectors (%d) differs!\n", trainlabels->
get_num_labels(), num_vec);
547 bool result=mkl->
train();
562 trainlabels=
ui->ui_labels->get_train_labels();
564 SG_INFO(
"Training one class svm.\n");
565 if (!trainlabels && !oneclass)
566 SG_ERROR(
"No trainlabels available.\n");
568 CKernel* kernel=
ui->ui_kernel->get_kernel();
572 bool success=
ui->ui_kernel->init_kernel(
"TRAIN");
574 if (!success || !
ui->ui_kernel->is_initialized() || !kernel->
has_features())
575 SG_ERROR(
"Kernel not initialized / no train features available.\n");
579 SG_ERROR(
"Number of train labels (%d) and training vectors (%d) differs!\n", trainlabels->
get_num_labels(), num_vec);
654 SG_ERROR(
"No distance available\n");
656 if (!
ui->ui_distance->init_distance(
"TRAIN"))
657 SG_ERROR(
"Initializing distance with train features failed.\n");
667 ((
CKMeans*) classifier)->set_max_iter(max_iter);
668 result=((
CKMeans*) classifier)->train();
678 SG_ERROR(
"Unknown clustering type %d\n", type);
686 CLabels* trainlabels=
ui->ui_labels->get_train_labels();
695 if (!
ui->ui_distance->init_distance(
"TRAIN"))
696 SG_ERROR(
"Initializing distance with train features failed.\n");
703 SG_ERROR(
"No distance available.\n");
719 trainlabels=
ui->ui_labels->get_train_labels();
721 SG_ERROR(
"No trainlabels available.\n");
723 CKernel* kernel=
ui->ui_kernel->get_kernel();
727 bool success=
ui->ui_kernel->init_kernel(
"TRAIN");
729 if (!success || !
ui->ui_kernel->is_initialized() || !kernel->
has_features())
730 SG_ERROR(
"Kernel not initialized / no train features available.\n");
734 SG_ERROR(
"Number of train labels (%d) and training vectors (%d) differs!\n", trainlabels->
get_num_labels(), num_vec);
741 bool result=krr->
train();
752 CFeatures* trainfeatures=
ui->ui_features->get_train_features();
753 CLabels* trainlabels=
ui->ui_labels->get_train_labels();
757 SG_ERROR(
"No trainfeatures available.\n");
760 SG_ERROR(
"Trainfeatures not based on DotFeatures.\n");
776 SG_ERROR(
"LDA requires train features of class SIMPLE type REAL.\n");
798 SG_ERROR(
"LPM and LPBOOST require trainfeatures of class SPARSE type REAL.\n");
810 CFeatures* trainfeatures=
ui->ui_features->get_train_features();
811 CLabels* trainlabels=
ui->ui_labels->get_train_labels();
816 SG_ERROR(
"No trainfeatures available.\n");
820 SG_ERROR(
"Trainfeatures are not of class STRING type BYTE.\n");
838 FILE* model_file=fopen(filename,
"r");
845 SG_DEBUG(
"file successfully read.\n");
849 SG_ERROR(
"SVM/Classifier creation/loading failed on file %s.\n", filename);
854 SG_ERROR(
"Opening file %s failed.\n", filename);
859 SG_ERROR(
"Type %s of SVM/Classifier unknown.\n", type);
871 FILE* file=fopen(param,
"w");
875 printf(
"writing to file %s failed!\n", param);
878 printf(
"successfully written classifier into \"%s\" !\n", param);
886 SG_ERROR(
"create classifier first\n");
927 SG_INFO(
"Disabling max_train_time.\n");
935 SG_ERROR(
"No regression method allocated\n");
941 SG_ERROR(
"Underlying method not capable of SV-regression\n");
968 if (weight_epsilon<0)
988 if (lambda<0 || lambda>1)
998 SG_ERROR(
"1 <= mkl_block_norm <= inf\n");
1059 SG_INFO(
"Enabling shrinking optimization.\n");
1061 SG_INFO(
"Disabling shrinking optimization.\n");
1070 SG_INFO(
"Enabling batch computation.\n");
1072 SG_INFO(
"Disabling batch computation.\n");
1081 SG_INFO(
"Enabling LINADD optimization.\n");
1083 SG_INFO(
"Disabling LINADD optimization.\n");
1092 SG_INFO(
"Enabling svm bias.\n");
1094 SG_INFO(
"Disabling svm bias.\n");
1103 SG_INFO(
"Enabling mkl interleaved optimization.\n");
1105 SG_INFO(
"Disabling mkl interleaved optimization.\n");
1115 SG_INFO(
"Enabling AUC maximization.\n");
1117 SG_INFO(
"Disabling AUC maximization.\n");
1166 SG_ERROR(
"unknown classifier type\n");
1175 CFeatures* trainfeatures=
ui->ui_features->get_train_features();
1176 CFeatures* testfeatures=
ui->ui_features->get_test_features();
1179 SG_ERROR(
"No kernelmachine available.\n");
1183 if (
ui->ui_kernel->get_kernel()->get_kernel_type()!=
K_CUSTOM)
1185 if (
ui->ui_kernel->get_kernel()->get_kernel_type()==
K_COMBINED
1186 && ( !trainfeatures || !testfeatures ))
1188 SG_DEBUG(
"skipping initialisation of combined kernel "
1189 "as train/test features are unavailable\n");
1194 SG_ERROR(
"No training features available.\n");
1196 SG_ERROR(
"No test features available.\n");
1198 success=
ui->ui_kernel->init_kernel(
"TEST");
1202 if (!success || !
ui->ui_kernel->is_initialized())
1203 SG_ERROR(
"Kernel not initialized.\n");
1219 SG_INFO(
"Starting kernel machine testing.\n");
1225 int32_t& brows, int32_t& bcols,
1250 return get_svm(weights, rows, cols, bias, brows, bcols, idx);
1263 return get_linear(weights, rows, cols, bias, brows, bcols);
1273 SG_ERROR(
"unknown classifier type\n");
1288 int32_t& brows, int32_t& bcols, int32_t idx)
1306 for (int32_t i=0; i<rows; i++)
1320 int32_t& brows, int32_t& bcols)
1361 for (int32_t i=0; i<rows*cols; i++)
1368 SG_ERROR(
"internal error - unknown clustering type\n");
1376 int32_t& brows, int32_t& bcols)
1400 CFeatures* trainfeatures=
ui->ui_features->get_train_features();
1401 CFeatures* testfeatures=
ui->ui_features->get_test_features();
1405 SG_ERROR(
"no kernelmachine available\n") ;
1410 SG_ERROR(
"no training features available\n") ;
1416 SG_ERROR(
"no test features available\n") ;
1420 bool success=
ui->ui_distance->init_distance(
"TEST");
1422 if (!success || !
ui->ui_distance->is_initialized())
1424 SG_ERROR(
"distance not initialized\n") ;
1429 ui->ui_distance->get_distance());
1430 SG_INFO(
"starting distance machine testing\n") ;
1437 CFeatures* testfeatures=
ui->ui_features->get_test_features();
1441 SG_ERROR(
"no classifier available\n") ;
1446 SG_ERROR(
"no test features available\n") ;
1451 SG_ERROR(
"testfeatures not based on DotFeatures\n") ;
1456 SG_INFO(
"starting linear classifier testing\n") ;
1462 CFeatures* testfeatures=
ui->ui_features->get_test_features();
1471 SG_ERROR(
"no test features available\n") ;
1477 SG_ERROR(
"testfeatures not of class STRING type BYTE\n") ;
1482 SG_INFO(
"starting linear classifier testing\n") ;
1488 CFeatures* trainfeatures=
ui->ui_features->get_train_features();
1489 CFeatures* testfeatures=
ui->ui_features->get_test_features();
1497 if (!
ui->ui_kernel->is_initialized())
1499 SG_ERROR(
"kernel not initialized\n") ;
1503 if (!
ui->ui_kernel->get_kernel() ||
1504 !
ui->ui_kernel->get_kernel()->get_kernel_type()==
K_CUSTOM)
1508 SG_ERROR(
"no training features available\n") ;
1514 SG_ERROR(
"no test features available\n") ;
1520 ui->ui_kernel->get_kernel());
1544 if (strncmp(solver,
"NEWTON", 6)==0)
1546 SG_INFO(
"Using NEWTON solver.\n");
1549 else if (strncmp(solver,
"DIRECT", 6)==0)
1551 SG_INFO(
"Using DIRECT solver\n");
1554 else if (strncmp(solver,
"BLOCK_NORM", 9)==0)
1556 SG_INFO(
"Using BLOCK_NORM solver\n");
1559 else if (strncmp(solver,
"ELASTICNET", 10)==0)
1561 SG_INFO(
"Using ELASTICNET solver\n");
1564 else if (strncmp(solver,
"AUTO", 4)==0)
1566 SG_INFO(
"Automagically determining solver.\n");
1570 else if (strncmp(solver,
"CPLEX", 5)==0)
1572 SG_INFO(
"USING CPLEX METHOD selected\n");
1577 else if (strncmp(solver,
"GLPK", 4)==0)
1579 SG_INFO(
"Using GLPK solver\n");
1584 SG_ERROR(
"Unknown solver type, %s (not compiled in?)\n", solver);
1593 if (strcmp(name,
"LIBSVM_ONECLASS")==0)
1597 SG_INFO(
"created SVMlibsvm object for oneclass\n");
1599 else if (strcmp(name,
"LIBSVM_NU")==0)
1603 SG_INFO(
"created SVMlibsvm object\n") ;
1605 else if (strcmp(name,
"LIBSVM")==0)
1609 SG_INFO(
"created SVMlibsvm object\n") ;
1612 else if ((strcmp(name,
"LIGHT")==0) || (strcmp(name,
"SVMLIGHT")==0))
1616 SG_INFO(
"created SVMLight object\n") ;
1618 else if (strcmp(name,
"SVMLIGHT_ONECLASS")==0)
1622 SG_INFO(
"created SVMLightOneClass object\n") ;
1624 else if (strcmp(name,
"SVRLIGHT")==0)
1628 SG_INFO(
"created SVRLight object\n") ;
1630 #endif //USE_SVMLIGHT
1631 else if (strcmp(name,
"GPBTSVM")==0)
1635 SG_INFO(
"created GPBT-SVM object\n") ;
1637 else if (strcmp(name,
"MPDSVM")==0)
1641 SG_INFO(
"created MPD-SVM object\n") ;
1643 else if (strcmp(name,
"GNPPSVM")==0)
1647 SG_INFO(
"created GNPP-SVM object\n") ;
1649 else if (strcmp(name,
"LIBSVR")==0)
1653 SG_INFO(
"created SVRlibsvm object\n") ;
1657 SG_ERROR(
"Unknown SV-classifier %s.\n", name);