SHOGUN  v2.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GUIClassifier.cpp
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 3 of the License, or
5  * (at your option) any later version.
6  *
7  * Written (W) 1999-2009 Soeren Sonnenburg
8  * Written (W) 1999-2008 Gunnar Raetsch
9  * Copyright (C) 1999-2009 Fraunhofer Institute FIRST and Max-Planck-Society
10  */
12 #include <shogun/ui/SGInterface.h>
13 
14 #include <shogun/lib/config.h>
15 #include <shogun/io/SGIO.h>
16 
19 #include <shogun/labels/Labels.h>
20 
22 
23 #include <shogun/multiclass/KNN.h>
27 
28 #include <shogun/classifier/LDA.h>
29 #include <shogun/classifier/LPM.h>
32 
34 
35 #ifdef USE_SVMLIGHT
39 #endif //USE_SVMLIGHT
40 
50 
53 
59 
66 
68 
69 using namespace shogun;
70 
72 : CSGObject(), ui(ui_)
73 {
75  classifier=NULL;
77 
78  // Perceptron parameters
80  perceptron_maxiter=1000;
81 
82  // SVM parameters
83  svm_qpsize=41;
84  svm_bufsize=3000;
85  svm_max_qpsize=1000;
86  mkl_norm=1;
87  ent_lambda=0;
89  svm_C1=1;
90  svm_C2=1;
91  C_mkl=0;
93  svm_weight_epsilon=1e-5;
94  svm_epsilon=1e-5;
95  svm_tube_epsilon=1e-2;
96  svm_nu=0.5;
97  svm_use_shrinking = true ;
98 
99  svm_use_bias = true;
101  svm_use_linadd = true ;
102  svm_do_auc_maximization = false ;
103 
104  // KRR parameters
105  krr_tau=1;
106 
108 }
109 
111 {
114 }
115 
116 bool CGUIClassifier::new_classifier(char* name, int32_t d, int32_t from_d)
117 {
118  if (strcmp(name,"LIBSVM_ONECLASS")==0)
119  {
121  classifier = new CLibSVMOneClass();
122  SG_INFO("created SVMlibsvm object for oneclass\n");
123  }
124  else if (strcmp(name,"LIBSVM_MULTICLASS")==0)
125  {
128  SG_INFO("created SVMlibsvm object for multiclass\n");
129  }
130  else if (strcmp(name,"LIBSVM_NUMULTICLASS")==0)
131  {
133  classifier= new CMulticlassLibSVM(LIBSVM_NU_SVC);
134  SG_INFO("created SVMlibsvm object for multiclass\n") ;
135  }
136 #ifdef USE_SVMLIGHT
137  else if (strcmp(name,"SCATTERSVM_NO_BIAS_SVMLIGHT")==0)
138  {
141  SG_INFO("created ScatterSVM NO BIAS SVMLIGHT object\n") ;
142  }
143 #endif //USE_SVMLIGHT
144  else if (strcmp(name,"SCATTERSVM_NO_BIAS_LIBSVM")==0)
145  {
148  SG_INFO("created ScatterSVM NO BIAS LIBSVM object\n") ;
149  }
150  else if (strcmp(name,"SCATTERSVM_TESTRULE1")==0)
151  {
154  SG_INFO("created ScatterSVM TESTRULE1 object\n") ;
155  }
156  else if (strcmp(name,"SCATTERSVM_TESTRULE2")==0)
157  {
160  SG_INFO("created ScatterSVM TESTRULE2 object\n") ;
161  }
162  else if (strcmp(name,"LIBSVM_NU")==0)
163  {
165  classifier= new CLibSVM(LIBSVM_NU_SVC);
166  SG_INFO("created SVMlibsvm object\n") ;
167  }
168  else if (strcmp(name,"LIBSVM")==0)
169  {
171  classifier= new CLibSVM();
172  SG_INFO("created SVMlibsvm object\n") ;
173  }
174  else if (strcmp(name,"LARANK")==0)
175  {
177  classifier= new CLaRank();
178  SG_INFO("created LaRank object\n") ;
179  }
180 #ifdef USE_SVMLIGHT
181  else if ((strcmp(name,"LIGHT")==0) || (strcmp(name,"SVMLIGHT")==0))
182  {
184  classifier= new CSVMLight();
185  SG_INFO("created SVMLight object\n") ;
186  }
187  else if (strcmp(name,"SVMLIGHT_ONECLASS")==0)
188  {
191  SG_INFO("created SVMLightOneClass object\n") ;
192  }
193  else if (strcmp(name,"SVRLIGHT")==0)
194  {
196  classifier= new CSVRLight();
197  SG_INFO("created SVRLight object\n") ;
198  }
199 #endif //USE_SVMLIGHT
200  else if (strcmp(name,"GPBTSVM")==0)
201  {
203  classifier= new CGPBTSVM();
204  SG_INFO("created GPBT-SVM object\n") ;
205  }
206  else if (strcmp(name,"MPDSVM")==0)
207  {
209  classifier= new CMPDSVM();
210  SG_INFO("created MPD-SVM object\n") ;
211  }
212  else if (strcmp(name,"GNPPSVM")==0)
213  {
215  classifier= new CGNPPSVM();
216  SG_INFO("created GNPP-SVM object\n") ;
217  }
218  else if (strcmp(name,"GMNPSVM")==0)
219  {
221  classifier= new CGMNPSVM();
222  SG_INFO("created GMNP-SVM object\n") ;
223  }
224  else if (strcmp(name,"LIBSVR")==0)
225  {
227  classifier= new CLibSVR();
228  SG_INFO("created SVRlibsvm object\n") ;
229  }
230 #ifdef HAVE_LAPACK
231  else if (strcmp(name, "KERNELRIDGEREGRESSION")==0)
232  {
234  classifier=new CKernelRidgeRegression(krr_tau, ui->ui_kernel->get_kernel(),
235  ui->ui_labels->get_train_labels());
236  SG_INFO("created KernelRidgeRegression object %p\n", classifier);
237  }
238 #endif //HAVE_LAPACK
239  else if (strcmp(name,"PERCEPTRON")==0)
240  {
242  classifier= new CPerceptron();
243  SG_INFO("created Perceptron object\n") ;
244  }
245 #ifdef HAVE_LAPACK
246  else if (strncmp(name,"LIBLINEAR",9)==0)
247  {
249 
250  if (strcmp(name,"LIBLINEAR_L2R_LR")==0)
251  {
252  st=L2R_LR;
253  SG_INFO("created LibLinear l2 regularized logistic regression object\n") ;
254  }
255  else if (strcmp(name,"LIBLINEAR_L2R_L2LOSS_SVC_DUAL")==0)
256  {
258  SG_INFO("created LibLinear l2 regularized l2 loss SVM dual object\n") ;
259  }
260  else if (strcmp(name,"LIBLINEAR_L2R_L2LOSS_SVC")==0)
261  {
262  st=L2R_L2LOSS_SVC;
263  SG_INFO("created LibLinear l2 regularized l2 loss SVM primal object\n") ;
264  }
265  else if (strcmp(name,"LIBLINEAR_L1R_L2LOSS_SVC")==0)
266  {
267  st=L1R_L2LOSS_SVC;
268  SG_INFO("created LibLinear l1 regularized l2 loss SVM primal object\n") ;
269  }
270  else if (strcmp(name,"LIBLINEAR_L2R_L1LOSS_SVC_DUAL")==0)
271  {
273  SG_INFO("created LibLinear l2 regularized l1 loss dual SVM object\n") ;
274  }
275  else
276  SG_ERROR("unknown liblinear type\n");
277 
279  classifier= new CLibLinear(st);
280  ((CLibLinear*) classifier)->set_C(svm_C1, svm_C2);
281  ((CLibLinear*) classifier)->set_epsilon(svm_epsilon);
282  ((CLibLinear*) classifier)->set_bias_enabled(svm_use_bias);
283  }
284  else if (strcmp(name,"LDA")==0)
285  {
287  classifier= new CLDA();
288  SG_INFO("created LDA object\n") ;
289  }
290 #endif //HAVE_LAPACK
291 #ifdef USE_CPLEX
292  else if (strcmp(name,"LPM")==0)
293  {
295  classifier= new CLPM();
296  ((CLPM*) classifier)->set_C(svm_C1, svm_C2);
297  ((CLPM*) classifier)->set_epsilon(svm_epsilon);
298  ((CLPM*) classifier)->set_bias_enabled(svm_use_bias);
299  ((CLPM*) classifier)->set_max_train_time(max_train_time);
300  SG_INFO("created LPM object\n") ;
301  }
302  else if (strcmp(name,"LPBOOST")==0)
303  {
305  classifier= new CLPBoost();
306  ((CLPBoost*) classifier)->set_C(svm_C1, svm_C2);
307  ((CLPBoost*) classifier)->set_epsilon(svm_epsilon);
308  ((CLPBoost*) classifier)->set_bias_enabled(svm_use_bias);
309  ((CLPBoost*) classifier)->set_max_train_time(max_train_time);
310  SG_INFO("created LPBoost object\n") ;
311  }
312  else if (strcmp(name,"SUBGRADIENTLPM")==0)
313  {
316 
317  ((CSubGradientLPM*) classifier)->set_bias_enabled(svm_use_bias);
318  ((CSubGradientLPM*) classifier)->set_qpsize(svm_qpsize);
319  ((CSubGradientLPM*) classifier)->set_qpsize_max(svm_max_qpsize);
320  ((CSubGradientLPM*) classifier)->set_C(svm_C1, svm_C2);
321  ((CSubGradientLPM*) classifier)->set_epsilon(svm_epsilon);
322  ((CSubGradientLPM*) classifier)->set_max_train_time(max_train_time);
323  SG_INFO("created Subgradient LPM object\n") ;
324  }
325 #endif //USE_CPLEX
326  else if (strncmp(name,"KNN", strlen("KNN"))==0)
327  {
329  classifier= new CKNN();
330  SG_INFO("created KNN object\n") ;
331  }
332  else if (strncmp(name,"KMEANS", strlen("KMEANS"))==0)
333  {
335  classifier= new CKMeans();
336  SG_INFO("created KMeans object\n") ;
337  }
338  else if (strncmp(name,"HIERARCHICAL", strlen("HIERARCHICAL"))==0)
339  {
341  classifier= new CHierarchical();
342  SG_INFO("created Hierarchical clustering object\n") ;
343  }
344  else if (strcmp(name,"SVMLIN")==0)
345  {
347  classifier= new CSVMLin();
348  ((CSVMLin*) classifier)->set_C(svm_C1, svm_C2);
349  ((CSVMLin*) classifier)->set_epsilon(svm_epsilon);
350  ((CSVMLin*) classifier)->set_bias_enabled(svm_use_bias);
351  SG_INFO("created SVMLin object\n") ;
352  }
353  else if (strcmp(name,"SUBGRADIENTSVM")==0)
354  {
357 
358  ((CSubGradientSVM*) classifier)->set_bias_enabled(svm_use_bias);
359  ((CSubGradientSVM*) classifier)->set_qpsize(svm_qpsize);
360  ((CSubGradientSVM*) classifier)->set_qpsize_max(svm_max_qpsize);
361  ((CSubGradientSVM*) classifier)->set_C(svm_C1, svm_C2);
362  ((CSubGradientSVM*) classifier)->set_epsilon(svm_epsilon);
363  ((CSubGradientSVM*) classifier)->set_max_train_time(max_train_time);
364  SG_INFO("created Subgradient SVM object\n") ;
365  }
366  else if (strncmp(name,"WDSVMOCAS", strlen("WDSVMOCAS"))==0)
367  {
369  classifier= new CWDSVMOcas(SVM_OCAS);
370 
371  ((CWDSVMOcas*) classifier)->set_bias_enabled(svm_use_bias);
372  ((CWDSVMOcas*) classifier)->set_degree(d, from_d);
373  ((CWDSVMOcas*) classifier)->set_C(svm_C1, svm_C2);
374  ((CWDSVMOcas*) classifier)->set_epsilon(svm_epsilon);
375  ((CWDSVMOcas*) classifier)->set_bufsize(svm_bufsize);
376  SG_INFO("created Weighted Degree Kernel SVM Ocas(OCAS) object of order %d (from order:%d)\n", d, from_d) ;
377  }
378  else if (strcmp(name,"SVMOCAS")==0)
379  {
381  classifier= new CSVMOcas(SVM_OCAS);
382 
383  ((CSVMOcas*) classifier)->set_C(svm_C1, svm_C2);
384  ((CSVMOcas*) classifier)->set_epsilon(svm_epsilon);
385  ((CSVMOcas*) classifier)->set_bufsize(svm_bufsize);
386  ((CSVMOcas*) classifier)->set_bias_enabled(svm_use_bias);
387  SG_INFO("created SVM Ocas(OCAS) object\n") ;
388  }
389  else if (strcmp(name,"SVMSGD")==0)
390  {
392  classifier= new CSVMSGD(svm_C1);
393  ((CSVMSGD*) classifier)->set_bias_enabled(svm_use_bias);
394  SG_INFO("created SVM SGD object\n") ;
395  }
396  else if (strcmp(name,"SVMBMRM")==0 || (strcmp(name,"SVMPERF")==0))
397  {
399  classifier= new CSVMOcas(SVM_BMRM);
400 
401  ((CSVMOcas*) classifier)->set_C(svm_C1, svm_C2);
402  ((CSVMOcas*) classifier)->set_epsilon(svm_epsilon);
403  ((CSVMOcas*) classifier)->set_bufsize(svm_bufsize);
404  ((CSVMOcas*) classifier)->set_bias_enabled(svm_use_bias);
405  SG_INFO("created SVM Ocas(BMRM/PERF) object\n") ;
406  }
407  else if (strcmp(name,"MKL_CLASSIFICATION")==0)
408  {
411  }
412  else if (strcmp(name,"MKL_ONECLASS")==0)
413  {
415  classifier= new CMKLOneClass();
416  }
417  else if (strcmp(name,"MKL_MULTICLASS")==0)
418  {
420  classifier= new CMKLMulticlass();
421  }
422  else if (strcmp(name,"MKL_REGRESSION")==0)
423  {
425  classifier= new CMKLRegression();
426  }
427  else
428  {
429  SG_ERROR("Unknown classifier %s.\n", name);
430  return false;
431  }
433 
434  return (classifier!=NULL);
435 }
436 
438 {
440  if (!mkl)
441  SG_ERROR("No MKL available.\n");
442 
443  CLabels* trainlabels=ui->ui_labels->get_train_labels();
444  if (!trainlabels)
445  SG_ERROR("No trainlabels available.\n");
446 
447  CKernel* kernel=ui->ui_kernel->get_kernel();
448  if (!kernel)
449  SG_ERROR("No kernel available.\n");
450 
451  bool success=ui->ui_kernel->init_kernel("TRAIN");
452 
453  if (!success || !ui->ui_kernel->is_initialized() || !kernel->has_features())
454  SG_ERROR("Kernel not initialized / no train features available.\n");
455 
456  int32_t num_vec=kernel->get_num_vec_lhs();
457  if (trainlabels->get_num_labels() != num_vec)
458  SG_ERROR("Number of train labels (%d) and training vectors (%d) differs!\n", trainlabels->get_num_labels(), num_vec);
459 
460  SG_INFO("Starting MC-MKL training on %ld vectors using C1=%lf C2=%lf epsilon=%lf\n", num_vec, svm_C1, svm_C2, svm_epsilon);
461 
463  mkl->set_mkl_norm(mkl_norm);
464  //mkl->set_max_num_mkliters(-1);
467  mkl->set_epsilon(svm_epsilon);
470  mkl->set_nu(svm_nu);
471  mkl->set_C(svm_C1);
472  mkl->set_qpsize(svm_qpsize);
476 
477  ((CKernelMulticlassMachine*) mkl)->set_labels(trainlabels);
478  ((CKernelMulticlassMachine*) mkl)->set_kernel(kernel);
479 
480  return mkl->train();
481 }
482 
484 {
485  CMKL* mkl= (CMKL*) classifier;
486  if (!mkl)
487  SG_ERROR("No SVM available.\n");
488 
489  bool oneclass=(mkl->get_classifier_type()==CT_LIBSVMONECLASS);
490  CLabels* trainlabels=NULL;
491  if(!oneclass)
492  trainlabels=ui->ui_labels->get_train_labels();
493  else
494  SG_INFO("Training one class mkl.\n");
495  if (!trainlabels && !oneclass)
496  SG_ERROR("No trainlabels available.\n");
497 
498  CKernel* kernel=ui->ui_kernel->get_kernel();
499  if (!kernel)
500  SG_ERROR("No kernel available.\n");
501 
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");
505 
506  int32_t num_vec=kernel->get_num_vec_lhs();
507  if (!oneclass && trainlabels->get_num_labels() != num_vec)
508  SG_ERROR("Number of train labels (%d) and training vectors (%d) differs!\n", trainlabels->get_num_labels(), num_vec);
509 
510  SG_INFO("Starting SVM training on %ld vectors using C1=%lf C2=%lf epsilon=%lf\n", num_vec, svm_C1, svm_C2, svm_epsilon);
511 
516  mkl->set_epsilon(svm_epsilon);
519  mkl->set_nu(svm_nu);
520  mkl->set_C(svm_C1, svm_C2);
521  mkl->set_qpsize(svm_qpsize);
526  mkl->set_mkl_norm(mkl_norm);
529  mkl->set_C_mkl(C_mkl);
531 
533  {
534  CAUCKernel* auc_kernel = new CAUCKernel(10, kernel);
535  CLabels* auc_labels= auc_kernel->setup_auc_maximization(trainlabels);
536  ((CKernelMachine*) mkl)->set_labels(auc_labels);
537  ((CKernelMachine*) mkl)->set_kernel(auc_kernel);
538  SG_UNREF(auc_labels);
539  }
540  else
541  {
542  if(!oneclass)
543  ((CKernelMachine*) mkl)->set_labels(trainlabels);
544  ((CKernelMachine*) mkl)->set_kernel(kernel);
545  }
546 
547  bool result=mkl->train();
548 
549  return result;
550 }
551 
553 {
555 
556  if (!classifier)
557  SG_ERROR("No SVM available.\n");
558 
559  bool oneclass=(type==CT_LIBSVMONECLASS);
560  CLabels* trainlabels=NULL;
561  if(!oneclass)
562  trainlabels=ui->ui_labels->get_train_labels();
563  else
564  SG_INFO("Training one class svm.\n");
565  if (!trainlabels && !oneclass)
566  SG_ERROR("No trainlabels available.\n");
567 
568  CKernel* kernel=ui->ui_kernel->get_kernel();
569  if (!kernel)
570  SG_ERROR("No kernel available.\n");
571 
572  bool success=ui->ui_kernel->init_kernel("TRAIN");
573 
574  if (!success || !ui->ui_kernel->is_initialized() || !kernel->has_features())
575  SG_ERROR("Kernel not initialized / no train features available.\n");
576 
577  int32_t num_vec=kernel->get_num_vec_lhs();
578  if (!oneclass && trainlabels->get_num_labels() != num_vec)
579  SG_ERROR("Number of train labels (%d) and training vectors (%d) differs!\n", trainlabels->get_num_labels(), num_vec);
580 
581  SG_INFO("Starting SVM training on %ld vectors using C1=%lf C2=%lf epsilon=%lf\n", num_vec, svm_C1, svm_C2, svm_epsilon);
582 
583  if (type==CT_LARANK || type==CT_GMNPSVM || type==CT_LIBSVMMULTICLASS)
584  {
588  svm->set_epsilon(svm_epsilon);
591  svm->set_nu(svm_nu);
592  svm->set_C(svm_C1);
593  svm->set_qpsize(svm_qpsize);
597  }
598  else
599  {
600  CSVM* svm = (CSVM*)classifier;
603  svm->set_epsilon(svm_epsilon);
606  svm->set_nu(svm_nu);
607  svm->set_C(svm_C1, svm_C2);
608  svm->set_qpsize(svm_qpsize);
612  }
613 
614  if (type==CT_MKLMULTICLASS)
615  {
616  ((CMKLMulticlass *)classifier)->set_mkl_epsilon(svm_weight_epsilon);
617  }
618 
620  {
621  CAUCKernel* auc_kernel = new CAUCKernel(10, kernel);
622  CLabels* auc_labels = auc_kernel->setup_auc_maximization(trainlabels);
623  ((CKernelMachine*)classifier)->set_labels(auc_labels);
624  ((CKernelMachine*)classifier)->set_kernel(auc_kernel);
625  SG_UNREF(auc_labels);
626  }
627  else
628  {
629  if (type==CT_LARANK || type==CT_GMNPSVM || type==CT_LIBSVMMULTICLASS)
630  {
631  ((CKernelMulticlassMachine*)classifier)->set_labels(trainlabels);
632  ((CKernelMulticlassMachine*)classifier)->set_kernel(kernel);
633  }
634  else
635  {
636  if(!oneclass)
637  ((CKernelMachine*)classifier)->set_labels(trainlabels);
638 
639  ((CKernelMachine*)classifier)->set_kernel(kernel);
640  }
641  }
642 
643  bool result = classifier->train();
644 
645  return result;
646 }
647 
648 bool CGUIClassifier::train_clustering(int32_t k, int32_t max_iter)
649 {
650  bool result=false;
651  CDistance* distance=ui->ui_distance->get_distance();
652 
653  if (!distance)
654  SG_ERROR("No distance available\n");
655 
656  if (!ui->ui_distance->init_distance("TRAIN"))
657  SG_ERROR("Initializing distance with train features failed.\n");
658 
659  ((CDistanceMachine*) classifier)->set_distance(distance);
660 
662  switch (type)
663  {
664  case CT_KMEANS:
665  {
666  ((CKMeans*) classifier)->set_k(k);
667  ((CKMeans*) classifier)->set_max_iter(max_iter);
668  result=((CKMeans*) classifier)->train();
669  break;
670  }
671  case CT_HIERARCHICAL:
672  {
673  ((CHierarchical*) classifier)->set_merges(k);
674  result=((CHierarchical*) classifier)->train();
675  break;
676  }
677  default:
678  SG_ERROR("Unknown clustering type %d\n", type);
679  }
680 
681  return result;
682 }
683 
685 {
686  CLabels* trainlabels=ui->ui_labels->get_train_labels();
687  CDistance* distance=ui->ui_distance->get_distance();
688 
689  bool result=false;
690 
691  if (trainlabels)
692  {
693  if (distance)
694  {
695  if (!ui->ui_distance->init_distance("TRAIN"))
696  SG_ERROR("Initializing distance with train features failed.\n");
697  ((CKNN*) classifier)->set_labels(trainlabels);
698  ((CKNN*) classifier)->set_distance(distance);
699  ((CKNN*) classifier)->set_k(k);
700  result=((CKNN*) classifier)->train();
701  }
702  else
703  SG_ERROR("No distance available.\n");
704  }
705  else
706  SG_ERROR("No labels available\n");
707 
708  return result;
709 }
710 
712 {
713 #ifdef HAVE_LAPACK
715  if (!krr)
716  SG_ERROR("No SVM available.\n");
717 
718  CLabels* trainlabels=NULL;
719  trainlabels=ui->ui_labels->get_train_labels();
720  if (!trainlabels)
721  SG_ERROR("No trainlabels available.\n");
722 
723  CKernel* kernel=ui->ui_kernel->get_kernel();
724  if (!kernel)
725  SG_ERROR("No kernel available.\n");
726 
727  bool success=ui->ui_kernel->init_kernel("TRAIN");
728 
729  if (!success || !ui->ui_kernel->is_initialized() || !kernel->has_features())
730  SG_ERROR("Kernel not initialized / no train features available.\n");
731 
732  int32_t num_vec=kernel->get_num_vec_lhs();
733  if (trainlabels->get_num_labels() != num_vec)
734  SG_ERROR("Number of train labels (%d) and training vectors (%d) differs!\n", trainlabels->get_num_labels(), num_vec);
735 
736 
737  // Set training labels and kernel
738  krr->set_labels(trainlabels);
739  krr->set_kernel(kernel);
740 
741  bool result=krr->train();
742  return result;
743 #else
744  return false;
745 #endif
746 }
747 
749 {
752  CFeatures* trainfeatures=ui->ui_features->get_train_features();
753  CLabels* trainlabels=ui->ui_labels->get_train_labels();
754  bool result=false;
755 
756  if (!trainfeatures)
757  SG_ERROR("No trainfeatures available.\n");
758 
759  if (!trainfeatures->has_property(FP_DOT))
760  SG_ERROR("Trainfeatures not based on DotFeatures.\n");
761 
762  if (!trainlabels)
763  SG_ERROR("No labels available\n");
764 
765  if (ctype==CT_PERCEPTRON)
766  {
767  ((CPerceptron*) classifier)->set_learn_rate(perceptron_learnrate);
768  ((CPerceptron*) classifier)->set_max_iter(perceptron_maxiter);
769  }
770 
771 #ifdef HAVE_LAPACK
772  if (ctype==CT_LDA)
773  {
774  if (trainfeatures->get_feature_type()!=F_DREAL ||
775  trainfeatures->get_feature_class()!=C_DENSE)
776  SG_ERROR("LDA requires train features of class SIMPLE type REAL.\n");
777  ((CLDA*) classifier)->set_gamma(gamma);
778  }
779 #endif
780 
781  if (ctype==CT_SVMOCAS)
782  ((CSVMOcas*) classifier)->set_C(svm_C1, svm_C2);
783 #ifdef HAVE_LAPACK
784  else if (ctype==CT_LIBLINEAR)
785  ((CLibLinear*) classifier)->set_C(svm_C1, svm_C2);
786 #endif
787  else if (ctype==CT_SVMLIN)
788  ((CSVMLin*) classifier)->set_C(svm_C1, svm_C2);
789  else if (ctype==CT_SVMSGD)
790  ((CSVMSGD*) classifier)->set_C(svm_C1, svm_C2);
791  else if (ctype==CT_SUBGRADIENTSVM)
792  ((CSubGradientSVM*) classifier)->set_C(svm_C1, svm_C2);
793 
794  else if (ctype==CT_LPM || ctype==CT_LPBOOST)
795  {
796  if (trainfeatures->get_feature_class()!=C_SPARSE ||
797  trainfeatures->get_feature_type()!=F_DREAL)
798  SG_ERROR("LPM and LPBOOST require trainfeatures of class SPARSE type REAL.\n");
799  }
800 
801  ((CLinearMachine*) classifier)->set_labels(trainlabels);
802  ((CLinearMachine*) classifier)->set_features((CDenseFeatures<float64_t>*) trainfeatures);
803  result=((CLinearMachine*) classifier)->train();
804 
805  return result;
806 }
807 
809 {
810  CFeatures* trainfeatures=ui->ui_features->get_train_features();
811  CLabels* trainlabels=ui->ui_labels->get_train_labels();
812 
813  bool result=false;
814 
815  if (!trainfeatures)
816  SG_ERROR("No trainfeatures available.\n");
817 
818  if (trainfeatures->get_feature_class()!=C_STRING ||
819  trainfeatures->get_feature_type()!=F_BYTE )
820  SG_ERROR("Trainfeatures are not of class STRING type BYTE.\n");
821 
822  if (!trainlabels)
823  SG_ERROR("No labels available.\n");
824 
825  ((CWDSVMOcas*) classifier)->set_labels(trainlabels);
826  ((CWDSVMOcas*) classifier)->set_features((CStringFeatures<uint8_t>*) trainfeatures);
827  result=((CWDSVMOcas*) classifier)->train();
828 
829  return result;
830 }
831 
832 bool CGUIClassifier::load(char* filename, char* type)
833 {
834  bool result=false;
835 
836  if (new_classifier(type))
837  {
838  FILE* model_file=fopen(filename, "r");
839  CSerializableAsciiFile* ascii_file = new CSerializableAsciiFile(model_file,'r');
840 
841  if (ascii_file)
842  {
843  if (classifier && classifier->load_serializable(ascii_file))
844  {
845  SG_DEBUG("file successfully read.\n");
846  result=true;
847  }
848  else
849  SG_ERROR("SVM/Classifier creation/loading failed on file %s.\n", filename);
850 
851  delete ascii_file;
852  }
853  else
854  SG_ERROR("Opening file %s failed.\n", filename);
855 
856  return result;
857  }
858  else
859  SG_ERROR("Type %s of SVM/Classifier unknown.\n", type);
860 
861  return false;
862 }
863 
864 bool CGUIClassifier::save(char* param)
865 {
866  bool result=false;
867  param=SGIO::skip_spaces(param);
868 
869  if (classifier)
870  {
871  FILE* file=fopen(param, "w");
872  CSerializableAsciiFile* ascii_file = new CSerializableAsciiFile(file,'w');
873 
874  if ((!ascii_file) || (!classifier->save_serializable(ascii_file)))
875  printf("writing to file %s failed!\n", param);
876  else
877  {
878  printf("successfully written classifier into \"%s\" !\n", param);
879  result=true;
880  }
881 
882  if (ascii_file)
883  delete ascii_file;
884  }
885  else
886  SG_ERROR("create classifier first\n");
887 
888  return result;
889 }
890 
892  float64_t learnrate, int32_t maxiter)
893 {
894  if (learnrate<=0)
896  else
897  perceptron_learnrate=learnrate;
898 
899  if (maxiter<=0)
900  perceptron_maxiter=1000;
901  else
902  perceptron_maxiter=maxiter;
903  SG_INFO("Setting to perceptron parameters (learnrate %f and maxiter: %d\n", perceptron_learnrate, perceptron_maxiter);
904 
905  return true;
906 }
907 
909 {
910  if (epsilon<0)
911  svm_epsilon=1e-4;
912  else
914  SG_INFO("Set to svm_epsilon=%f.\n", svm_epsilon);
915 
916  return true;
917 }
918 
920 {
921  if (max>0)
922  {
923  max_train_time=max;
924  SG_INFO("Set to max_train_time=%f.\n", max_train_time);
925  }
926  else
927  SG_INFO("Disabling max_train_time.\n");
928 
929  return true;
930 }
931 
933 {
934  if (!classifier)
935  SG_ERROR("No regression method allocated\n");
936 
940  {
941  SG_ERROR("Underlying method not capable of SV-regression\n");
942  }
943 
944  if (tube_epsilon<0)
945  svm_tube_epsilon=1e-2;
946  svm_tube_epsilon=tube_epsilon;
947 
948  ((CSVM*) classifier)->set_tube_epsilon(svm_tube_epsilon);
949  SG_INFO("Set to svr_tube_epsilon=%f.\n", svm_tube_epsilon);
950 
951  return true;
952 }
953 
955 {
956  if (nu<0 || nu>1)
957  nu=0.5;
958 
959  svm_nu=nu;
960  SG_INFO("Set to nu=%f.\n", svm_nu);
961 
962  return true;
963 }
964 
966  float64_t weight_epsilon, float64_t C, float64_t norm)
967 {
968  if (weight_epsilon<0)
969  weight_epsilon=1e-4;
970  if (C<0)
971  C=0;
972  if (norm<0)
973  SG_ERROR("MKL norm >= 0\n");
974 
975  svm_weight_epsilon=weight_epsilon;
976  C_mkl=C;
977  mkl_norm=norm;
978 
979  SG_INFO("Set to weight_epsilon=%f.\n", svm_weight_epsilon);
980  SG_INFO("Set to C_mkl=%f.\n", C_mkl);
981  SG_INFO("Set to mkl_norm=%f.\n", mkl_norm);
982 
983  return true;
984 }
985 
987 {
988  if (lambda<0 || lambda>1)
989  SG_ERROR("0 <= ent_lambda <= 1\n");
990 
991  ent_lambda = lambda;
992  return true;
993 }
994 
996 {
997  if (mkl_bnorm<1)
998  SG_ERROR("1 <= mkl_block_norm <= inf\n");
999 
1000  mkl_block_norm=mkl_bnorm;
1001  return true;
1002 }
1003 
1004 
1006 {
1007  if (C1<0)
1008  svm_C1=1.0;
1009  else
1010  svm_C1=C1;
1011 
1012  if (C2<0)
1013  svm_C2=svm_C1;
1014  else
1015  svm_C2=C2;
1016 
1017  SG_INFO("Set to C1=%f C2=%f.\n", svm_C1, svm_C2);
1018 
1019  return true;
1020 }
1021 
1023 {
1024  if (qpsize<2)
1025  svm_qpsize=41;
1026  else
1027  svm_qpsize=qpsize;
1028  SG_INFO("Set qpsize to svm_qpsize=%d.\n", svm_qpsize);
1029 
1030  return true;
1031 }
1032 
1033 bool CGUIClassifier::set_svm_max_qpsize(int32_t max_qpsize)
1034 {
1035  if (max_qpsize<50)
1036  svm_max_qpsize=50;
1037  else
1038  svm_max_qpsize=max_qpsize;
1039  SG_INFO("Set max qpsize to svm_max_qpsize=%d.\n", svm_max_qpsize);
1040 
1041  return true;
1042 }
1043 
1044 bool CGUIClassifier::set_svm_bufsize(int32_t bufsize)
1045 {
1046  if (svm_bufsize<0)
1047  svm_bufsize=3000;
1048  else
1049  svm_bufsize=bufsize;
1050  SG_INFO("Set bufsize to svm_bufsize=%d.\n", svm_bufsize);
1051 
1052  return true ;
1053 }
1054 
1056 {
1057  svm_use_shrinking=enabled;
1058  if (svm_use_shrinking)
1059  SG_INFO("Enabling shrinking optimization.\n");
1060  else
1061  SG_INFO("Disabling shrinking optimization.\n");
1062 
1063  return true;
1064 }
1065 
1067 {
1068  svm_use_batch_computation=enabled;
1070  SG_INFO("Enabling batch computation.\n");
1071  else
1072  SG_INFO("Disabling batch computation.\n");
1073 
1074  return true;
1075 }
1076 
1078 {
1079  svm_use_linadd=enabled;
1080  if (svm_use_linadd)
1081  SG_INFO("Enabling LINADD optimization.\n");
1082  else
1083  SG_INFO("Disabling LINADD optimization.\n");
1084 
1085  return true;
1086 }
1087 
1089 {
1090  svm_use_bias=enabled;
1091  if (svm_use_bias)
1092  SG_INFO("Enabling svm bias.\n");
1093  else
1094  SG_INFO("Disabling svm bias.\n");
1095 
1096  return true;
1097 }
1098 
1100 {
1101  mkl_use_interleaved=enabled;
1102  if (mkl_use_interleaved)
1103  SG_INFO("Enabling mkl interleaved optimization.\n");
1104  else
1105  SG_INFO("Disabling mkl interleaved optimization.\n");
1106 
1107  return true;
1108 }
1109 
1111 {
1112  svm_do_auc_maximization=do_auc;
1113 
1115  SG_INFO("Enabling AUC maximization.\n");
1116  else
1117  SG_INFO("Disabling AUC maximization.\n");
1118 
1119  return true;
1120 }
1121 
1122 
1124 {
1125  ASSERT(classifier);
1126 
1127  switch (classifier->get_classifier_type())
1128  {
1129  case CT_LIGHT:
1130  case CT_LIGHTONECLASS:
1131  case CT_LIBSVM:
1132  case CT_SCATTERSVM:
1133  case CT_MPD:
1134  case CT_GPBT:
1135  case CT_CPLEXSVM:
1136  case CT_GMNPSVM:
1137  case CT_GNPPSVM:
1138  case CT_LIBSVR:
1139  case CT_LIBSVMMULTICLASS:
1140  case CT_LIBSVMONECLASS:
1141  case CT_SVRLIGHT:
1142  case CT_MKLCLASSIFICATION:
1143  case CT_MKLMULTICLASS:
1144  case CT_MKLREGRESSION:
1145  case CT_MKLONECLASS:
1147  return classify_kernelmachine();
1148  case CT_KNN:
1149  return classify_distancemachine();
1150  case CT_PERCEPTRON:
1151  case CT_LDA:
1152  return classify_linear();
1153  case CT_SVMLIN:
1154  case CT_SVMPERF:
1155  case CT_SUBGRADIENTSVM:
1156  case CT_SVMOCAS:
1157  case CT_SVMSGD:
1158  case CT_LPM:
1159  case CT_LPBOOST:
1160  case CT_SUBGRADIENTLPM:
1161  case CT_LIBLINEAR:
1162  return classify_linear();
1163  case CT_WDSVMOCAS:
1164  return classify_byte_linear();
1165  default:
1166  SG_ERROR("unknown classifier type\n");
1167  break;
1168  };
1169 
1170  return NULL;
1171 }
1172 
1174 {
1175  CFeatures* trainfeatures=ui->ui_features->get_train_features();
1176  CFeatures* testfeatures=ui->ui_features->get_test_features();
1177 
1178  if (!classifier)
1179  SG_ERROR("No kernelmachine available.\n");
1180 
1181  bool success=true;
1182 
1183  if (ui->ui_kernel->get_kernel()->get_kernel_type()!=K_CUSTOM)
1184  {
1185  if (ui->ui_kernel->get_kernel()->get_kernel_type()==K_COMBINED
1186  && ( !trainfeatures || !testfeatures ))
1187  {
1188  SG_DEBUG("skipping initialisation of combined kernel "
1189  "as train/test features are unavailable\n");
1190  }
1191  else
1192  {
1193  if (!trainfeatures)
1194  SG_ERROR("No training features available.\n");
1195  if (!testfeatures)
1196  SG_ERROR("No test features available.\n");
1197 
1198  success=ui->ui_kernel->init_kernel("TEST");
1199  }
1200  }
1201 
1202  if (!success || !ui->ui_kernel->is_initialized())
1203  SG_ERROR("Kernel not initialized.\n");
1204 
1206  if (type==CT_LARANK || type==CT_GMNPSVM || type==CT_LIBSVMMULTICLASS ||
1207  type==CT_MKLMULTICLASS)
1208  {
1210  kmcm->set_kernel(ui->ui_kernel->get_kernel());
1211  }
1212  else
1213  {
1215  km->set_kernel(ui->ui_kernel->get_kernel());
1217  }
1218 
1219  SG_INFO("Starting kernel machine testing.\n");
1220  return classifier->apply();
1221 }
1222 
1224  float64_t* &weights, int32_t &rows, int32_t &cols, float64_t*& bias,
1225  int32_t& brows, int32_t& bcols,
1226  int32_t idx) // which SVM for Multiclass
1227 {
1228  ASSERT(classifier);
1229 
1230  switch (classifier->get_classifier_type())
1231  {
1232  case CT_SCATTERSVM:
1233  case CT_GNPPSVM:
1234  case CT_LIBSVMMULTICLASS:
1235  case CT_LIGHT:
1236  case CT_LIGHTONECLASS:
1237  case CT_LIBSVM:
1238  case CT_MPD:
1239  case CT_GPBT:
1240  case CT_CPLEXSVM:
1241  case CT_GMNPSVM:
1242  case CT_LIBSVR:
1243  case CT_LIBSVMONECLASS:
1244  case CT_SVRLIGHT:
1245  case CT_MKLCLASSIFICATION:
1246  case CT_MKLREGRESSION:
1247  case CT_MKLONECLASS:
1248  case CT_MKLMULTICLASS:
1250  return get_svm(weights, rows, cols, bias, brows, bcols, idx);
1251  break;
1252  case CT_PERCEPTRON:
1253  case CT_LDA:
1254  case CT_LPM:
1255  case CT_LPBOOST:
1256  case CT_SUBGRADIENTLPM:
1257  case CT_SVMOCAS:
1258  case CT_SVMSGD:
1259  case CT_SVMLIN:
1260  case CT_SVMPERF:
1261  case CT_SUBGRADIENTSVM:
1262  case CT_LIBLINEAR:
1263  return get_linear(weights, rows, cols, bias, brows, bcols);
1264  break;
1265  case CT_KMEANS:
1266  case CT_HIERARCHICAL:
1267  return get_clustering(weights, rows, cols, bias, brows, bcols);
1268  break;
1269  case CT_KNN:
1270  SG_ERROR("not implemented");
1271  break;
1272  default:
1273  SG_ERROR("unknown classifier type\n");
1274  break;
1275  };
1276  return false;
1277 }
1278 
1279 
1281 {
1282  ASSERT(classifier);
1283  return ((CMulticlassSVM*) classifier)->get_num_machines();
1284 }
1285 
1287  float64_t* &weights, int32_t& rows, int32_t& cols, float64_t*& bias,
1288  int32_t& brows, int32_t& bcols, int32_t idx)
1289 {
1290  CSVM* svm=(CSVM*) classifier;
1291 
1292  if (idx>-1) // should be MulticlassSVM
1293  svm=((CMulticlassSVM*) svm)->get_svm(idx);
1294 
1295  if (svm)
1296  {
1297  brows=1;
1298  bcols=1;
1299  bias=SG_MALLOC(float64_t, 1);
1300  *bias=svm->get_bias();
1301 
1302  rows=svm->get_num_support_vectors();
1303  cols=2;
1304  weights=SG_MALLOC(float64_t, rows*cols);
1305 
1306  for (int32_t i=0; i<rows; i++)
1307  {
1308  weights[i]=svm->get_alpha(i);
1309  weights[i+rows]=svm->get_support_vector(i);
1310  }
1311 
1312  return true;
1313  }
1314 
1315  return false;
1316 }
1317 
1319  float64_t* &centers, int32_t& rows, int32_t& cols, float64_t*& radi,
1320  int32_t& brows, int32_t& bcols)
1321 {
1322  if (!classifier)
1323  return false;
1324 
1325  switch (classifier->get_classifier_type())
1326  {
1327  case CT_KMEANS:
1328  {
1329  CKMeans* clustering=(CKMeans*) classifier;
1330 
1331  bcols=1;
1332  SGVector<float64_t> r=clustering->get_radiuses();
1333  brows=r.vlen;
1334  radi=SG_MALLOC(float64_t, brows);
1335  memcpy(radi, r.vector, sizeof(float64_t)*brows);
1336 
1337  cols=1;
1338  SGMatrix<float64_t> c=clustering->get_cluster_centers();
1339  rows=c.num_rows;
1340  cols=c.num_cols;
1341  centers=SG_MALLOC(float64_t, rows*cols);
1342  memcpy(centers, c.matrix, sizeof(float64_t)*rows*cols);
1343  break;
1344  }
1345 
1346  case CT_HIERARCHICAL:
1347  {
1348  CHierarchical* clustering=(CHierarchical*) classifier;
1349 
1350  // radi == merge_distances, centers == pairs
1351  bcols=1;
1352  SGVector<float64_t> r=clustering->get_merge_distances();
1353  brows=r.vlen;
1354  radi=SG_MALLOC(float64_t, brows);
1355  memcpy(radi, r.vector, sizeof(float64_t)*brows);
1356 
1357  SGMatrix<int32_t> p=clustering->get_cluster_pairs();
1358  rows=p.num_rows;
1359  cols=p.num_cols;
1360  centers=SG_MALLOC(float64_t, rows*cols);
1361  for (int32_t i=0; i<rows*cols; i++)
1362  centers[i]=(float64_t) p.matrix[i];
1363 
1364  break;
1365  }
1366 
1367  default:
1368  SG_ERROR("internal error - unknown clustering type\n");
1369  }
1370 
1371  return true;
1372 }
1373 
1375  float64_t* &weights, int32_t& rows, int32_t& cols, float64_t*& bias,
1376  int32_t& brows, int32_t& bcols)
1377 {
1379 
1380  if (!linear)
1381  return false;
1382 
1383  bias=SG_MALLOC(float64_t, 1);
1384  *bias=linear->get_bias();
1385  brows=1;
1386  bcols=1;
1387 
1388  SGVector<float64_t> w=linear->get_w();
1389  cols=1;
1390  rows=w.vlen;
1391 
1392  weights= SG_MALLOC(float64_t, w.vlen);
1393  memcpy(weights, w.vector, sizeof(float64_t)*w.vlen);
1394 
1395  return true;
1396 }
1397 
1399 {
1400  CFeatures* trainfeatures=ui->ui_features->get_train_features();
1401  CFeatures* testfeatures=ui->ui_features->get_test_features();
1402 
1403  if (!classifier)
1404  {
1405  SG_ERROR("no kernelmachine available\n") ;
1406  return NULL;
1407  }
1408  if (!trainfeatures)
1409  {
1410  SG_ERROR("no training features available\n") ;
1411  return NULL;
1412  }
1413 
1414  if (!testfeatures)
1415  {
1416  SG_ERROR("no test features available\n") ;
1417  return NULL;
1418  }
1419 
1420  bool success=ui->ui_distance->init_distance("TEST");
1421 
1422  if (!success || !ui->ui_distance->is_initialized())
1423  {
1424  SG_ERROR("distance not initialized\n") ;
1425  return NULL;
1426  }
1427 
1428  ((CDistanceMachine*) classifier)->set_distance(
1429  ui->ui_distance->get_distance());
1430  SG_INFO("starting distance machine testing\n") ;
1431  return classifier->apply();
1432 }
1433 
1434 
1436 {
1437  CFeatures* testfeatures=ui->ui_features->get_test_features();
1438 
1439  if (!classifier)
1440  {
1441  SG_ERROR("no classifier available\n") ;
1442  return NULL;
1443  }
1444  if (!testfeatures)
1445  {
1446  SG_ERROR("no test features available\n") ;
1447  return NULL;
1448  }
1449  if (!(testfeatures->has_property(FP_DOT)))
1450  {
1451  SG_ERROR("testfeatures not based on DotFeatures\n") ;
1452  return NULL;
1453  }
1454 
1455  ((CLinearMachine*) classifier)->set_features((CDotFeatures*) testfeatures);
1456  SG_INFO("starting linear classifier testing\n") ;
1457  return classifier->apply();
1458 }
1459 
1461 {
1462  CFeatures* testfeatures=ui->ui_features->get_test_features();
1463 
1464  if (!classifier)
1465  {
1466  SG_ERROR("no svm available\n") ;
1467  return NULL;
1468  }
1469  if (!testfeatures)
1470  {
1471  SG_ERROR("no test features available\n") ;
1472  return NULL;
1473  }
1474  if (testfeatures->get_feature_class() != C_STRING ||
1475  testfeatures->get_feature_type() != F_BYTE )
1476  {
1477  SG_ERROR("testfeatures not of class STRING type BYTE\n") ;
1478  return NULL;
1479  }
1480 
1481  ((CWDSVMOcas*) classifier)->set_features((CStringFeatures<uint8_t>*) testfeatures);
1482  SG_INFO("starting linear classifier testing\n") ;
1483  return classifier->apply();
1484 }
1485 
1487 {
1488  CFeatures* trainfeatures=ui->ui_features->get_train_features();
1489  CFeatures* testfeatures=ui->ui_features->get_test_features();
1490 
1491  if (!classifier)
1492  {
1493  SG_ERROR("no svm available\n") ;
1494  return false;
1495  }
1496 
1497  if (!ui->ui_kernel->is_initialized())
1498  {
1499  SG_ERROR("kernel not initialized\n") ;
1500  return false;
1501  }
1502 
1503  if (!ui->ui_kernel->get_kernel() ||
1504  !ui->ui_kernel->get_kernel()->get_kernel_type()==K_CUSTOM)
1505  {
1506  if (!trainfeatures)
1507  {
1508  SG_ERROR("no training features available\n") ;
1509  return false;
1510  }
1511 
1512  if (!testfeatures)
1513  {
1514  SG_ERROR("no test features available\n") ;
1515  return false;
1516  }
1517  }
1518 
1519  ((CKernelMachine*) classifier)->set_kernel(
1520  ui->ui_kernel->get_kernel());
1521 
1522  result=((CKernelMachine*)classifier)->apply_one(idx);
1523  return true ;
1524 }
1525 
1526 
1528 {
1529 #ifdef HAVE_LAPACK
1530  krr_tau=tau;
1531  ((CKernelRidgeRegression*) classifier)->set_tau(krr_tau);
1532  SG_INFO("Set to krr_tau=%f.\n", krr_tau);
1533 
1534  return true;
1535 #else
1536  return false;
1537 #endif
1538 }
1539 
1540 bool CGUIClassifier::set_solver(char* solver)
1541 {
1542  ESolverType s=ST_AUTO;
1543 
1544  if (strncmp(solver,"NEWTON", 6)==0)
1545  {
1546  SG_INFO("Using NEWTON solver.\n");
1547  s=ST_NEWTON;
1548  }
1549  else if (strncmp(solver,"DIRECT", 6)==0)
1550  {
1551  SG_INFO("Using DIRECT solver\n");
1552  s=ST_DIRECT;
1553  }
1554  else if (strncmp(solver,"BLOCK_NORM", 9)==0)
1555  {
1556  SG_INFO("Using BLOCK_NORM solver\n");
1557  s=ST_BLOCK_NORM;
1558  }
1559  else if (strncmp(solver,"ELASTICNET", 10)==0)
1560  {
1561  SG_INFO("Using ELASTICNET solver\n");
1562  s=ST_ELASTICNET;
1563  }
1564  else if (strncmp(solver,"AUTO", 4)==0)
1565  {
1566  SG_INFO("Automagically determining solver.\n");
1567  s=ST_AUTO;
1568  }
1569 #ifdef USE_CPLEX
1570  else if (strncmp(solver, "CPLEX", 5)==0)
1571  {
1572  SG_INFO("USING CPLEX METHOD selected\n");
1573  s=ST_CPLEX;
1574  }
1575 #endif
1576 #ifdef USE_GLPK
1577  else if (strncmp(solver,"GLPK", 4)==0)
1578  {
1579  SG_INFO("Using GLPK solver\n");
1580  s=ST_GLPK;
1581  }
1582 #endif
1583  else
1584  SG_ERROR("Unknown solver type, %s (not compiled in?)\n", solver);
1585 
1586 
1587  solver_type=s;
1588  return true;
1589 }
1590 
1592 {
1593  if (strcmp(name,"LIBSVM_ONECLASS")==0)
1594  {
1597  SG_INFO("created SVMlibsvm object for oneclass\n");
1598  }
1599  else if (strcmp(name,"LIBSVM_NU")==0)
1600  {
1602  constraint_generator= new CLibSVM(LIBSVM_NU_SVC);
1603  SG_INFO("created SVMlibsvm object\n") ;
1604  }
1605  else if (strcmp(name,"LIBSVM")==0)
1606  {
1609  SG_INFO("created SVMlibsvm object\n") ;
1610  }
1611 #ifdef USE_SVMLIGHT
1612  else if ((strcmp(name,"LIGHT")==0) || (strcmp(name,"SVMLIGHT")==0))
1613  {
1616  SG_INFO("created SVMLight object\n") ;
1617  }
1618  else if (strcmp(name,"SVMLIGHT_ONECLASS")==0)
1619  {
1622  SG_INFO("created SVMLightOneClass object\n") ;
1623  }
1624  else if (strcmp(name,"SVRLIGHT")==0)
1625  {
1628  SG_INFO("created SVRLight object\n") ;
1629  }
1630 #endif //USE_SVMLIGHT
1631  else if (strcmp(name,"GPBTSVM")==0)
1632  {
1635  SG_INFO("created GPBT-SVM object\n") ;
1636  }
1637  else if (strcmp(name,"MPDSVM")==0)
1638  {
1641  SG_INFO("created MPD-SVM object\n") ;
1642  }
1643  else if (strcmp(name,"GNPPSVM")==0)
1644  {
1647  SG_INFO("created GNPP-SVM object\n") ;
1648  }
1649  else if (strcmp(name,"LIBSVR")==0)
1650  {
1653  SG_INFO("created SVRlibsvm object\n") ;
1654  }
1655  else
1656  {
1657  SG_ERROR("Unknown SV-classifier %s.\n", name);
1658  return false;
1659  }
1661 
1662  return (constraint_generator!=NULL);
1663 }

SHOGUN Machine Learning Toolbox - Documentation