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,
"KERNELRIDGEREGRESSION")==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")
281 else if (strncmp(name,
"KNN", strlen(
"KNN"))==0)
285 SG_INFO(
"created KNN object\n")
287 else if (strncmp(name,
"KMEANS", strlen(
"KMEANS"))==0)
291 SG_INFO(
"created KMeans object\n")
293 else if (strncmp(name,
"HIERARCHICAL", strlen(
"HIERARCHICAL"))==0)
297 SG_INFO(
"created Hierarchical clustering object\n")
299 else if (strcmp(name,
"SVMLIN")==0)
306 SG_INFO(
"created SVMLin object\n")
308 else if (strncmp(name,
"WDSVMOCAS", strlen(
"WDSVMOCAS"))==0)
318 SG_INFO(
"created Weighted Degree Kernel SVM Ocas(OCAS) object of order %d (from order:%d)\n", d, from_d)
320 else if (strcmp(name,
"SVMOCAS")==0)
329 SG_INFO(
"created SVM Ocas(OCAS) object\n")
331 else if (strcmp(name,
"SVMSGD")==0)
336 SG_INFO(
"created SVM SGD object\n")
338 else if (strcmp(name,
"SVMBMRM")==0 || (strcmp(name,
"SVMPERF")==0))
347 SG_INFO(
"created SVM Ocas(BMRM/PERF) object\n")
349 else if (strcmp(name,
"MKL_CLASSIFICATION")==0)
354 else if (strcmp(name,
"MKL_ONECLASS")==0)
359 else if (strcmp(name,
"MKL_MULTICLASS")==0)
364 else if (strcmp(name,
"MKL_REGRESSION")==0)
371 SG_ERROR(
"Unknown classifier %s.\n", name)
385 CLabels* trainlabels=
ui->ui_labels->get_train_labels();
387 SG_ERROR(
"No trainlabels available.\n")
389 CKernel* kernel=
ui->ui_kernel->get_kernel();
393 bool success=
ui->ui_kernel->init_kernel(
"TRAIN");
395 if (!success || !
ui->ui_kernel->is_initialized() || !kernel->
has_features())
396 SG_ERROR(
"Kernel not initialized / no train features available.\n")
400 SG_ERROR(
"Number of train labels (%d) and training vectors (%d) differs!\n", trainlabels->
get_num_labels(), num_vec)
434 trainlabels=
ui->ui_labels->get_train_labels();
436 SG_INFO(
"Training one class mkl.\n")
437 if (!trainlabels && !oneclass)
438 SG_ERROR(
"No trainlabels available.\n")
440 CKernel* kernel=
ui->ui_kernel->get_kernel();
444 bool success=
ui->ui_kernel->init_kernel(
"TRAIN");
445 if (!success || !
ui->ui_kernel->is_initialized() || !kernel->
has_features())
446 SG_ERROR(
"Kernel not initialized.\n")
450 SG_ERROR(
"Number of train labels (%d) and training vectors (%d) differs!\n", trainlabels->
get_num_labels(), num_vec)
489 bool result=mkl->
train();
504 trainlabels=
ui->ui_labels->get_train_labels();
506 SG_INFO(
"Training one class svm.\n")
507 if (!trainlabels && !oneclass)
508 SG_ERROR(
"No trainlabels available.\n")
510 CKernel* kernel=
ui->ui_kernel->get_kernel();
514 bool success=
ui->ui_kernel->init_kernel(
"TRAIN");
516 if (!success || !
ui->ui_kernel->is_initialized() || !kernel->
has_features())
517 SG_ERROR(
"Kernel not initialized / no train features available.\n")
521 SG_ERROR(
"Number of train labels (%d) and training vectors (%d) differs!\n", trainlabels->
get_num_labels(), num_vec)
598 if (!
ui->ui_distance->init_distance(
"TRAIN"))
599 SG_ERROR(
"Initializing distance with train features failed.\n")
609 ((
CKMeans*) classifier)->set_max_iter(max_iter);
610 result=((
CKMeans*) classifier)->train();
620 SG_ERROR(
"Unknown clustering type %d\n", type)
628 CLabels* trainlabels=
ui->ui_labels->get_train_labels();
637 if (!
ui->ui_distance->init_distance(
"TRAIN"))
638 SG_ERROR(
"Initializing distance with train features failed.\n")
645 SG_ERROR(
"No distance available.\n")
661 trainlabels=
ui->ui_labels->get_train_labels();
663 SG_ERROR(
"No trainlabels available.\n")
665 CKernel* kernel=
ui->ui_kernel->get_kernel();
669 bool success=
ui->ui_kernel->init_kernel(
"TRAIN");
671 if (!success || !
ui->ui_kernel->is_initialized() || !kernel->
has_features())
672 SG_ERROR(
"Kernel not initialized / no train features available.\n")
676 SG_ERROR(
"Number of train labels (%d) and training vectors (%d) differs!\n", trainlabels->
get_num_labels(), num_vec)
683 bool result=krr->
train();
694 CFeatures* trainfeatures=
ui->ui_features->get_train_features();
695 CLabels* trainlabels=
ui->ui_labels->get_train_labels();
699 SG_ERROR(
"No trainfeatures available.\n")
702 SG_ERROR(
"Trainfeatures not based on DotFeatures.\n")
718 SG_ERROR(
"LDA requires train features of class SIMPLE type REAL.\n")
737 SG_ERROR(
"LPM and LPBOOST require trainfeatures of class SPARSE type REAL.\n")
749 CFeatures* trainfeatures=
ui->ui_features->get_train_features();
750 CLabels* trainlabels=
ui->ui_labels->get_train_labels();
755 SG_ERROR(
"No trainfeatures available.\n")
759 SG_ERROR(
"Trainfeatures are not of class STRING type BYTE.\n")
777 FILE* model_file=fopen(filename,
"r");
784 SG_DEBUG(
"file successfully read.\n")
788 SG_ERROR(
"SVM/Classifier creation/loading failed on file %s.\n", filename)
793 SG_ERROR(
"Opening file %s failed.\n", filename)
798 SG_ERROR(
"Type %s of SVM/Classifier unknown.\n", type)
810 FILE* file=fopen(param,
"w");
814 printf(
"writing to file %s failed!\n", param);
817 printf(
"successfully written classifier into \"%s\" !\n", param);
825 SG_ERROR(
"create classifier first\n")
866 SG_INFO(
"Disabling max_train_time.\n")
874 SG_ERROR(
"No regression method allocated\n")
880 SG_ERROR(
"Underlying method not capable of SV-regression\n")
907 if (weight_epsilon<0)
927 if (lambda<0 || lambda>1)
937 SG_ERROR(
"1 <= mkl_block_norm <= inf\n")
998 SG_INFO(
"Enabling shrinking optimization.\n")
1000 SG_INFO(
"Disabling shrinking optimization.\n")
1009 SG_INFO(
"Enabling batch computation.\n")
1011 SG_INFO(
"Disabling batch computation.\n")
1020 SG_INFO(
"Enabling LINADD optimization.\n")
1022 SG_INFO(
"Disabling LINADD optimization.\n")
1031 SG_INFO(
"Enabling svm bias.\n")
1033 SG_INFO(
"Disabling svm bias.\n")
1042 SG_INFO(
"Enabling mkl interleaved optimization.\n")
1044 SG_INFO(
"Disabling mkl interleaved optimization.\n")
1054 SG_INFO(
"Enabling AUC maximization.\n")
1056 SG_INFO(
"Disabling AUC maximization.\n")
1103 SG_ERROR(
"unknown classifier type\n")
1112 CFeatures* trainfeatures=
ui->ui_features->get_train_features();
1113 CFeatures* testfeatures=
ui->ui_features->get_test_features();
1116 SG_ERROR(
"No kernelmachine available.\n")
1120 REQUIRE(
ui->ui_kernel->get_kernel(),
"No kernel set");
1121 if (
ui->ui_kernel->get_kernel()->get_kernel_type()!=
K_CUSTOM)
1123 if (
ui->ui_kernel->get_kernel()->get_kernel_type()==
K_COMBINED
1124 && ( !trainfeatures || !testfeatures ))
1126 SG_DEBUG(
"skipping initialisation of combined kernel "
1127 "as train/test features are unavailable\n")
1132 SG_ERROR(
"No training features available.\n")
1134 SG_ERROR(
"No test features available.\n")
1136 success=
ui->ui_kernel->init_kernel(
"TEST");
1140 if (!success || !
ui->ui_kernel->is_initialized())
1141 SG_ERROR(
"Kernel not initialized.\n")
1157 SG_INFO(
"Starting kernel machine testing.\n")
1163 int32_t& brows, int32_t& bcols,
1188 return get_svm(weights, rows, cols, bias, brows, bcols, idx);
1199 return get_linear(weights, rows, cols, bias, brows, bcols);
1209 SG_ERROR(
"unknown classifier type\n")
1224 int32_t& brows, int32_t& bcols, int32_t idx)
1240 weights=SG_MALLOC(
float64_t, rows*cols);
1242 for (int32_t i=0; i<rows; i++)
1256 int32_t& brows, int32_t& bcols)
1277 centers=SG_MALLOC(
float64_t, rows*cols);
1296 centers=SG_MALLOC(
float64_t, rows*cols);
1297 for (int32_t i=0; i<rows*cols; i++)
1304 SG_ERROR(
"internal error - unknown clustering type\n")
1312 int32_t& brows, int32_t& bcols)
1336 CFeatures* trainfeatures=
ui->ui_features->get_train_features();
1337 CFeatures* testfeatures=
ui->ui_features->get_test_features();
1341 SG_ERROR(
"no kernelmachine available\n")
1346 SG_ERROR(
"no training features available\n")
1352 SG_ERROR(
"no test features available\n")
1356 bool success=
ui->ui_distance->init_distance(
"TEST");
1358 if (!success || !
ui->ui_distance->is_initialized())
1360 SG_ERROR(
"distance not initialized\n")
1365 ui->ui_distance->get_distance());
1366 SG_INFO(
"starting distance machine testing\n")
1373 CFeatures* testfeatures=
ui->ui_features->get_test_features();
1377 SG_ERROR(
"no classifier available\n")
1382 SG_ERROR(
"no test features available\n")
1387 SG_ERROR(
"testfeatures not based on DotFeatures\n")
1392 SG_INFO(
"starting linear classifier testing\n")
1398 CFeatures* testfeatures=
ui->ui_features->get_test_features();
1407 SG_ERROR(
"no test features available\n")
1413 SG_ERROR(
"testfeatures not of class STRING type BYTE\n")
1418 SG_INFO(
"starting linear classifier testing\n")
1424 CFeatures* trainfeatures=
ui->ui_features->get_train_features();
1425 CFeatures* testfeatures=
ui->ui_features->get_test_features();
1433 if (!
ui->ui_kernel->is_initialized())
1435 SG_ERROR(
"kernel not initialized\n")
1439 if (!
ui->ui_kernel->get_kernel() ||
1440 ui->ui_kernel->get_kernel()->get_kernel_type()!=
K_CUSTOM)
1444 SG_ERROR(
"no training features available\n")
1450 SG_ERROR(
"no test features available\n")
1456 ui->ui_kernel->get_kernel());
1480 if (strncmp(solver,
"NEWTON", 6)==0)
1482 SG_INFO(
"Using NEWTON solver.\n")
1485 else if (strncmp(solver,
"DIRECT", 6)==0)
1487 SG_INFO(
"Using DIRECT solver\n")
1490 else if (strncmp(solver,
"BLOCK_NORM", 9)==0)
1492 SG_INFO(
"Using BLOCK_NORM solver\n")
1495 else if (strncmp(solver,
"ELASTICNET", 10)==0)
1497 SG_INFO(
"Using ELASTICNET solver\n")
1500 else if (strncmp(solver,
"AUTO", 4)==0)
1502 SG_INFO(
"Automagically determining solver.\n")
1506 else if (strncmp(solver,
"CPLEX", 5)==0)
1508 SG_INFO(
"USING CPLEX METHOD selected\n")
1513 else if (strncmp(solver,
"GLPK", 4)==0)
1515 SG_INFO(
"Using GLPK solver\n")
1520 SG_ERROR(
"Unknown solver type, %s (not compiled in?)\n", solver)
1529 if (strcmp(name,
"LIBSVM_ONECLASS")==0)
1533 SG_INFO(
"created SVMlibsvm object for oneclass\n")
1535 else if (strcmp(name,
"LIBSVM_NU")==0)
1539 SG_INFO(
"created SVMlibsvm object\n")
1541 else if (strcmp(name,
"LIBSVM")==0)
1545 SG_INFO(
"created SVMlibsvm object\n")
1548 else if (strcmp(name,
"GPBTSVM")==0)
1552 SG_INFO(
"created GPBT-SVM object\n")
1554 else if (strcmp(name,
"MPDSVM")==0)
1558 SG_INFO(
"created MPD-SVM object\n")
1560 else if (strcmp(name,
"GNPPSVM")==0)
1564 SG_INFO(
"created GNPP-SVM object\n")
1566 else if (strcmp(name,
"LIBSVR")==0)
1570 SG_INFO(
"created SVRlibsvm object\n")
1574 SG_ERROR(
"Unknown SV-classifier %s.\n", name)