SHOGUN  3.2.1
 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 
36 
46 
49 
55 
60 
62 
63 using namespace shogun;
64 
66 : CSGObject(), ui(ui_)
67 {
69  classifier=NULL;
71 
72  // Perceptron parameters
74  perceptron_maxiter=1000;
75 
76  // SVM parameters
77  svm_qpsize=41;
78  svm_bufsize=3000;
79  svm_max_qpsize=1000;
80  mkl_norm=1;
81  ent_lambda=0;
83  svm_C1=1;
84  svm_C2=1;
85  C_mkl=0;
87  svm_weight_epsilon=1e-5;
88  svm_epsilon=1e-5;
89  svm_tube_epsilon=1e-2;
90  svm_nu=0.5;
91  svm_use_shrinking = true ;
92 
93  svm_use_bias = true;
95  svm_use_linadd = true ;
96  svm_do_auc_maximization = false ;
97 
98  // KRR parameters
99  krr_tau=1;
100 
102 }
103 
105 {
108 }
109 
110 bool CGUIClassifier::new_classifier(char* name, int32_t d, int32_t from_d)
111 {
112  if (strcmp(name,"LIBSVM_ONECLASS")==0)
113  {
115  classifier = new CLibSVMOneClass();
116  SG_INFO("created SVMlibsvm object for oneclass\n")
117  }
118  else if (strcmp(name,"LIBSVM_MULTICLASS")==0)
119  {
122  SG_INFO("created SVMlibsvm object for multiclass\n")
123  }
124  else if (strcmp(name,"LIBSVM_NUMULTICLASS")==0)
125  {
127  classifier= new CMulticlassLibSVM(LIBSVM_NU_SVC);
128  SG_INFO("created SVMlibsvm object for multiclass\n")
129  }
130 
131  else if (strcmp(name,"SCATTERSVM_NO_BIAS_LIBSVM")==0)
132  {
135  SG_INFO("created ScatterSVM NO BIAS LIBSVM object\n")
136  }
137  else if (strcmp(name,"SCATTERSVM_TESTRULE1")==0)
138  {
141  SG_INFO("created ScatterSVM TESTRULE1 object\n")
142  }
143  else if (strcmp(name,"SCATTERSVM_TESTRULE2")==0)
144  {
147  SG_INFO("created ScatterSVM TESTRULE2 object\n")
148  }
149  else if (strcmp(name,"LIBSVM_NU")==0)
150  {
152  classifier= new CLibSVM(LIBSVM_NU_SVC);
153  SG_INFO("created SVMlibsvm object\n")
154  }
155  else if (strcmp(name,"LIBSVM")==0)
156  {
158  classifier= new CLibSVM();
159  SG_INFO("created SVMlibsvm object\n")
160  }
161  else if (strcmp(name,"LARANK")==0)
162  {
164  classifier= new CLaRank();
165  SG_INFO("created LaRank object\n")
166  }
167 
168  else if (strcmp(name,"GPBTSVM")==0)
169  {
171  classifier= new CGPBTSVM();
172  SG_INFO("created GPBT-SVM object\n")
173  }
174  else if (strcmp(name,"MPDSVM")==0)
175  {
177  classifier= new CMPDSVM();
178  SG_INFO("created MPD-SVM object\n")
179  }
180  else if (strcmp(name,"GNPPSVM")==0)
181  {
183  classifier= new CGNPPSVM();
184  SG_INFO("created GNPP-SVM object\n")
185  }
186  else if (strcmp(name,"GMNPSVM")==0)
187  {
189  classifier= new CGMNPSVM();
190  SG_INFO("created GMNP-SVM object\n")
191  }
192  else if (strcmp(name,"LIBSVR")==0)
193  {
195  classifier= new CLibSVR();
196  SG_INFO("created SVRlibsvm object\n")
197  }
198 #ifdef HAVE_LAPACK
199  else if (strcmp(name, "KERNELRIDGEREGRESSION")==0)
200  {
202  classifier=new CKernelRidgeRegression(krr_tau, ui->ui_kernel->get_kernel(),
203  ui->ui_labels->get_train_labels());
204  SG_INFO("created KernelRidgeRegression object %p\n", classifier)
205  }
206 #endif //HAVE_LAPACK
207  else if (strcmp(name,"PERCEPTRON")==0)
208  {
210  classifier= new CPerceptron();
211  SG_INFO("created Perceptron object\n")
212  }
213 #ifdef HAVE_LAPACK
214  else if (strncmp(name,"LIBLINEAR",9)==0)
215  {
217 
218  if (strcmp(name,"LIBLINEAR_L2R_LR")==0)
219  {
220  st=L2R_LR;
221  SG_INFO("created LibLinear l2 regularized logistic regression object\n")
222  }
223  else if (strcmp(name,"LIBLINEAR_L2R_L2LOSS_SVC_DUAL")==0)
224  {
226  SG_INFO("created LibLinear l2 regularized l2 loss SVM dual object\n")
227  }
228  else if (strcmp(name,"LIBLINEAR_L2R_L2LOSS_SVC")==0)
229  {
230  st=L2R_L2LOSS_SVC;
231  SG_INFO("created LibLinear l2 regularized l2 loss SVM primal object\n")
232  }
233  else if (strcmp(name,"LIBLINEAR_L1R_L2LOSS_SVC")==0)
234  {
235  st=L1R_L2LOSS_SVC;
236  SG_INFO("created LibLinear l1 regularized l2 loss SVM primal object\n")
237  }
238  else if (strcmp(name,"LIBLINEAR_L2R_L1LOSS_SVC_DUAL")==0)
239  {
241  SG_INFO("created LibLinear l2 regularized l1 loss dual SVM object\n")
242  }
243  else
244  SG_ERROR("unknown liblinear type\n")
245 
247  classifier= new CLibLinear(st);
248  ((CLibLinear*) classifier)->set_C(svm_C1, svm_C2);
249  ((CLibLinear*) classifier)->set_epsilon(svm_epsilon);
250  ((CLibLinear*) classifier)->set_bias_enabled(svm_use_bias);
251  }
252  else if (strcmp(name,"LDA")==0)
253  {
255  classifier= new CLDA();
256  SG_INFO("created LDA object\n")
257  }
258 #endif //HAVE_LAPACK
259 #ifdef USE_CPLEX
260  else if (strcmp(name,"LPM")==0)
261  {
263  classifier= new CLPM();
264  ((CLPM*) classifier)->set_C(svm_C1, svm_C2);
265  ((CLPM*) classifier)->set_epsilon(svm_epsilon);
266  ((CLPM*) classifier)->set_bias_enabled(svm_use_bias);
267  ((CLPM*) classifier)->set_max_train_time(max_train_time);
268  SG_INFO("created LPM object\n")
269  }
270  else if (strcmp(name,"LPBOOST")==0)
271  {
273  classifier= new CLPBoost();
274  ((CLPBoost*) classifier)->set_C(svm_C1, svm_C2);
275  ((CLPBoost*) classifier)->set_epsilon(svm_epsilon);
276  ((CLPBoost*) classifier)->set_bias_enabled(svm_use_bias);
277  ((CLPBoost*) classifier)->set_max_train_time(max_train_time);
278  SG_INFO("created LPBoost object\n")
279  }
280 #endif //USE_CPLEX
281  else if (strncmp(name,"KNN", strlen("KNN"))==0)
282  {
284  classifier= new CKNN();
285  SG_INFO("created KNN object\n")
286  }
287  else if (strncmp(name,"KMEANS", strlen("KMEANS"))==0)
288  {
290  classifier= new CKMeans();
291  SG_INFO("created KMeans object\n")
292  }
293  else if (strncmp(name,"HIERARCHICAL", strlen("HIERARCHICAL"))==0)
294  {
296  classifier= new CHierarchical();
297  SG_INFO("created Hierarchical clustering object\n")
298  }
299  else if (strcmp(name,"SVMLIN")==0)
300  {
302  classifier= new CSVMLin();
303  ((CSVMLin*) classifier)->set_C(svm_C1, svm_C2);
304  ((CSVMLin*) classifier)->set_epsilon(svm_epsilon);
305  ((CSVMLin*) classifier)->set_bias_enabled(svm_use_bias);
306  SG_INFO("created SVMLin object\n")
307  }
308  else if (strncmp(name,"WDSVMOCAS", strlen("WDSVMOCAS"))==0)
309  {
311  classifier= new CWDSVMOcas(SVM_OCAS);
312 
313  ((CWDSVMOcas*) classifier)->set_bias_enabled(svm_use_bias);
314  ((CWDSVMOcas*) classifier)->set_degree(d, from_d);
315  ((CWDSVMOcas*) classifier)->set_C(svm_C1, svm_C2);
316  ((CWDSVMOcas*) classifier)->set_epsilon(svm_epsilon);
317  ((CWDSVMOcas*) classifier)->set_bufsize(svm_bufsize);
318  SG_INFO("created Weighted Degree Kernel SVM Ocas(OCAS) object of order %d (from order:%d)\n", d, from_d)
319  }
320  else if (strcmp(name,"SVMOCAS")==0)
321  {
323  classifier= new CSVMOcas(SVM_OCAS);
324 
325  ((CSVMOcas*) classifier)->set_C(svm_C1, svm_C2);
326  ((CSVMOcas*) classifier)->set_epsilon(svm_epsilon);
327  ((CSVMOcas*) classifier)->set_bufsize(svm_bufsize);
328  ((CSVMOcas*) classifier)->set_bias_enabled(svm_use_bias);
329  SG_INFO("created SVM Ocas(OCAS) object\n")
330  }
331  else if (strcmp(name,"SVMSGD")==0)
332  {
334  classifier= new CSVMSGD(svm_C1);
335  ((CSVMSGD*) classifier)->set_bias_enabled(svm_use_bias);
336  SG_INFO("created SVM SGD object\n")
337  }
338  else if (strcmp(name,"SVMBMRM")==0 || (strcmp(name,"SVMPERF")==0))
339  {
341  classifier= new CSVMOcas(SVM_BMRM);
342 
343  ((CSVMOcas*) classifier)->set_C(svm_C1, svm_C2);
344  ((CSVMOcas*) classifier)->set_epsilon(svm_epsilon);
345  ((CSVMOcas*) classifier)->set_bufsize(svm_bufsize);
346  ((CSVMOcas*) classifier)->set_bias_enabled(svm_use_bias);
347  SG_INFO("created SVM Ocas(BMRM/PERF) object\n")
348  }
349  else if (strcmp(name,"MKL_CLASSIFICATION")==0)
350  {
353  }
354  else if (strcmp(name,"MKL_ONECLASS")==0)
355  {
357  classifier= new CMKLOneClass();
358  }
359  else if (strcmp(name,"MKL_MULTICLASS")==0)
360  {
362  classifier= new CMKLMulticlass();
363  }
364  else if (strcmp(name,"MKL_REGRESSION")==0)
365  {
367  classifier= new CMKLRegression();
368  }
369  else
370  {
371  SG_ERROR("Unknown classifier %s.\n", name)
372  return false;
373  }
375 
376  return (classifier!=NULL);
377 }
378 
380 {
382  if (!mkl)
383  SG_ERROR("No MKL available.\n")
384 
385  CLabels* trainlabels=ui->ui_labels->get_train_labels();
386  if (!trainlabels)
387  SG_ERROR("No trainlabels available.\n")
388 
389  CKernel* kernel=ui->ui_kernel->get_kernel();
390  if (!kernel)
391  SG_ERROR("No kernel available.\n")
392 
393  bool success=ui->ui_kernel->init_kernel("TRAIN");
394 
395  if (!success || !ui->ui_kernel->is_initialized() || !kernel->has_features())
396  SG_ERROR("Kernel not initialized / no train features available.\n")
397 
398  int32_t num_vec=kernel->get_num_vec_lhs();
399  if (trainlabels->get_num_labels() != num_vec)
400  SG_ERROR("Number of train labels (%d) and training vectors (%d) differs!\n", trainlabels->get_num_labels(), num_vec)
401 
402  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)
403 
405  mkl->set_mkl_norm(mkl_norm);
406  //mkl->set_max_num_mkliters(-1);
409  mkl->set_epsilon(svm_epsilon);
412  mkl->set_nu(svm_nu);
413  mkl->set_C(svm_C1);
414  mkl->set_qpsize(svm_qpsize);
418 
419  ((CKernelMulticlassMachine*) mkl)->set_labels(trainlabels);
420  ((CKernelMulticlassMachine*) mkl)->set_kernel(kernel);
421 
422  return mkl->train();
423 }
424 
426 {
427  CMKL* mkl= (CMKL*) classifier;
428  if (!mkl)
429  SG_ERROR("No SVM available.\n")
430 
431  bool oneclass=(mkl->get_classifier_type()==CT_LIBSVMONECLASS);
432  CLabels* trainlabels=NULL;
433  if(!oneclass)
434  trainlabels=ui->ui_labels->get_train_labels();
435  else
436  SG_INFO("Training one class mkl.\n")
437  if (!trainlabels && !oneclass)
438  SG_ERROR("No trainlabels available.\n")
439 
440  CKernel* kernel=ui->ui_kernel->get_kernel();
441  if (!kernel)
442  SG_ERROR("No kernel available.\n")
443 
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")
447 
448  int32_t num_vec=kernel->get_num_vec_lhs();
449  if (!oneclass && trainlabels->get_num_labels() != num_vec)
450  SG_ERROR("Number of train labels (%d) and training vectors (%d) differs!\n", trainlabels->get_num_labels(), num_vec)
451 
452  SG_INFO("Starting SVM training on %ld vectors using C1=%lf C2=%lf epsilon=%lf\n", num_vec, svm_C1, svm_C2, svm_epsilon)
453 
458  mkl->set_epsilon(svm_epsilon);
461  mkl->set_nu(svm_nu);
462  mkl->set_C(svm_C1, svm_C2);
463  mkl->set_qpsize(svm_qpsize);
468  mkl->set_mkl_norm(mkl_norm);
471  mkl->set_C_mkl(C_mkl);
473 
475  {
476  CAUCKernel* auc_kernel = new CAUCKernel(10, kernel);
477  CLabels* auc_labels= auc_kernel->setup_auc_maximization(trainlabels);
478  ((CKernelMachine*) mkl)->set_labels(auc_labels);
479  ((CKernelMachine*) mkl)->set_kernel(auc_kernel);
480  SG_UNREF(auc_labels);
481  }
482  else
483  {
484  if(!oneclass)
485  ((CKernelMachine*) mkl)->set_labels(trainlabels);
486  ((CKernelMachine*) mkl)->set_kernel(kernel);
487  }
488 
489  bool result=mkl->train();
490 
491  return result;
492 }
493 
495 {
497 
498  if (!classifier)
499  SG_ERROR("No SVM available.\n")
500 
501  bool oneclass=(type==CT_LIBSVMONECLASS);
502  CLabels* trainlabels=NULL;
503  if(!oneclass)
504  trainlabels=ui->ui_labels->get_train_labels();
505  else
506  SG_INFO("Training one class svm.\n")
507  if (!trainlabels && !oneclass)
508  SG_ERROR("No trainlabels available.\n")
509 
510  CKernel* kernel=ui->ui_kernel->get_kernel();
511  if (!kernel)
512  SG_ERROR("No kernel available.\n")
513 
514  bool success=ui->ui_kernel->init_kernel("TRAIN");
515 
516  if (!success || !ui->ui_kernel->is_initialized() || !kernel->has_features())
517  SG_ERROR("Kernel not initialized / no train features available.\n")
518 
519  int32_t num_vec=kernel->get_num_vec_lhs();
520  if (!oneclass && trainlabels->get_num_labels() != num_vec)
521  SG_ERROR("Number of train labels (%d) and training vectors (%d) differs!\n", trainlabels->get_num_labels(), num_vec)
522 
523  SG_INFO("Starting SVM training on %ld vectors using C1=%lf C2=%lf epsilon=%lf\n", num_vec, svm_C1, svm_C2, svm_epsilon)
524 
525  if (type==CT_LARANK || type==CT_GMNPSVM || type==CT_LIBSVMMULTICLASS)
526  {
530  svm->set_epsilon(svm_epsilon);
533  svm->set_nu(svm_nu);
534  svm->set_C(svm_C1);
535  svm->set_qpsize(svm_qpsize);
539  }
540  else
541  {
542  CSVM* svm = (CSVM*)classifier;
545  svm->set_epsilon(svm_epsilon);
548  svm->set_nu(svm_nu);
549  svm->set_C(svm_C1, svm_C2);
550  svm->set_qpsize(svm_qpsize);
554  }
555 
556  if (type==CT_MKLMULTICLASS)
557  {
558  ((CMKLMulticlass *)classifier)->set_mkl_epsilon(svm_weight_epsilon);
559  }
560 
562  {
563  CAUCKernel* auc_kernel = new CAUCKernel(10, kernel);
564  CLabels* auc_labels = auc_kernel->setup_auc_maximization(trainlabels);
565  ((CKernelMachine*)classifier)->set_labels(auc_labels);
566  ((CKernelMachine*)classifier)->set_kernel(auc_kernel);
567  SG_UNREF(auc_labels);
568  }
569  else
570  {
571  if (type==CT_LARANK || type==CT_GMNPSVM || type==CT_LIBSVMMULTICLASS)
572  {
573  ((CKernelMulticlassMachine*)classifier)->set_labels(trainlabels);
574  ((CKernelMulticlassMachine*)classifier)->set_kernel(kernel);
575  }
576  else
577  {
578  if(!oneclass)
579  ((CKernelMachine*)classifier)->set_labels(trainlabels);
580 
581  ((CKernelMachine*)classifier)->set_kernel(kernel);
582  }
583  }
584 
585  bool result = classifier->train();
586 
587  return result;
588 }
589 
590 bool CGUIClassifier::train_clustering(int32_t k, int32_t max_iter)
591 {
592  bool result=false;
593  CDistance* distance=ui->ui_distance->get_distance();
594 
595  if (!distance)
596  SG_ERROR("No distance available\n")
597 
598  if (!ui->ui_distance->init_distance("TRAIN"))
599  SG_ERROR("Initializing distance with train features failed.\n")
600 
601  ((CDistanceMachine*) classifier)->set_distance(distance);
602 
604  switch (type)
605  {
606  case CT_KMEANS:
607  {
608  ((CKMeans*) classifier)->set_k(k);
609  ((CKMeans*) classifier)->set_max_iter(max_iter);
610  result=((CKMeans*) classifier)->train();
611  break;
612  }
613  case CT_HIERARCHICAL:
614  {
615  ((CHierarchical*) classifier)->set_merges(k);
616  result=((CHierarchical*) classifier)->train();
617  break;
618  }
619  default:
620  SG_ERROR("Unknown clustering type %d\n", type)
621  }
622 
623  return result;
624 }
625 
627 {
628  CLabels* trainlabels=ui->ui_labels->get_train_labels();
629  CDistance* distance=ui->ui_distance->get_distance();
630 
631  bool result=false;
632 
633  if (trainlabels)
634  {
635  if (distance)
636  {
637  if (!ui->ui_distance->init_distance("TRAIN"))
638  SG_ERROR("Initializing distance with train features failed.\n")
639  ((CKNN*) classifier)->set_labels(trainlabels);
640  ((CKNN*) classifier)->set_distance(distance);
641  ((CKNN*) classifier)->set_k(k);
642  result=((CKNN*) classifier)->train();
643  }
644  else
645  SG_ERROR("No distance available.\n")
646  }
647  else
648  SG_ERROR("No labels available\n")
649 
650  return result;
651 }
652 
654 {
655 #ifdef HAVE_LAPACK
657  if (!krr)
658  SG_ERROR("No SVM available.\n")
659 
660  CLabels* trainlabels=NULL;
661  trainlabels=ui->ui_labels->get_train_labels();
662  if (!trainlabels)
663  SG_ERROR("No trainlabels available.\n")
664 
665  CKernel* kernel=ui->ui_kernel->get_kernel();
666  if (!kernel)
667  SG_ERROR("No kernel available.\n")
668 
669  bool success=ui->ui_kernel->init_kernel("TRAIN");
670 
671  if (!success || !ui->ui_kernel->is_initialized() || !kernel->has_features())
672  SG_ERROR("Kernel not initialized / no train features available.\n")
673 
674  int32_t num_vec=kernel->get_num_vec_lhs();
675  if (trainlabels->get_num_labels() != num_vec)
676  SG_ERROR("Number of train labels (%d) and training vectors (%d) differs!\n", trainlabels->get_num_labels(), num_vec)
677 
678 
679  // Set training labels and kernel
680  krr->set_labels(trainlabels);
681  krr->set_kernel(kernel);
682 
683  bool result=krr->train();
684  return result;
685 #else
686  return false;
687 #endif
688 }
689 
691 {
694  CFeatures* trainfeatures=ui->ui_features->get_train_features();
695  CLabels* trainlabels=ui->ui_labels->get_train_labels();
696  bool result=false;
697 
698  if (!trainfeatures)
699  SG_ERROR("No trainfeatures available.\n")
700 
701  if (!trainfeatures->has_property(FP_DOT))
702  SG_ERROR("Trainfeatures not based on DotFeatures.\n")
703 
704  if (!trainlabels)
705  SG_ERROR("No labels available\n")
706 
707  if (ctype==CT_PERCEPTRON)
708  {
709  ((CPerceptron*) classifier)->set_learn_rate(perceptron_learnrate);
710  ((CPerceptron*) classifier)->set_max_iter(perceptron_maxiter);
711  }
712 
713 #ifdef HAVE_LAPACK
714  if (ctype==CT_LDA)
715  {
716  if (trainfeatures->get_feature_type()!=F_DREAL ||
717  trainfeatures->get_feature_class()!=C_DENSE)
718  SG_ERROR("LDA requires train features of class SIMPLE type REAL.\n")
719  ((CLDA*) classifier)->set_gamma(gamma);
720  }
721 #endif
722 
723  if (ctype==CT_SVMOCAS)
724  ((CSVMOcas*) classifier)->set_C(svm_C1, svm_C2);
725 #ifdef HAVE_LAPACK
726  else if (ctype==CT_LIBLINEAR)
727  ((CLibLinear*) classifier)->set_C(svm_C1, svm_C2);
728 #endif
729  else if (ctype==CT_SVMLIN)
730  ((CSVMLin*) classifier)->set_C(svm_C1, svm_C2);
731  else if (ctype==CT_SVMSGD)
732  ((CSVMSGD*) classifier)->set_C(svm_C1, svm_C2);
733  else if (ctype==CT_LPM || ctype==CT_LPBOOST)
734  {
735  if (trainfeatures->get_feature_class()!=C_SPARSE ||
736  trainfeatures->get_feature_type()!=F_DREAL)
737  SG_ERROR("LPM and LPBOOST require trainfeatures of class SPARSE type REAL.\n")
738  }
739 
740  ((CLinearMachine*) classifier)->set_labels(trainlabels);
741  ((CLinearMachine*) classifier)->set_features((CDenseFeatures<float64_t>*) trainfeatures);
742  result=((CLinearMachine*) classifier)->train();
743 
744  return result;
745 }
746 
748 {
749  CFeatures* trainfeatures=ui->ui_features->get_train_features();
750  CLabels* trainlabels=ui->ui_labels->get_train_labels();
751 
752  bool result=false;
753 
754  if (!trainfeatures)
755  SG_ERROR("No trainfeatures available.\n")
756 
757  if (trainfeatures->get_feature_class()!=C_STRING ||
758  trainfeatures->get_feature_type()!=F_BYTE )
759  SG_ERROR("Trainfeatures are not of class STRING type BYTE.\n")
760 
761  if (!trainlabels)
762  SG_ERROR("No labels available.\n")
763 
764  ((CWDSVMOcas*) classifier)->set_labels(trainlabels);
765  ((CWDSVMOcas*) classifier)->set_features((CStringFeatures<uint8_t>*) trainfeatures);
766  result=((CWDSVMOcas*) classifier)->train();
767 
768  return result;
769 }
770 
771 bool CGUIClassifier::load(char* filename, char* type)
772 {
773  bool result=false;
774 
775  if (new_classifier(type))
776  {
777  FILE* model_file=fopen(filename, "r");
778  CSerializableAsciiFile* ascii_file = new CSerializableAsciiFile(model_file,'r');
779 
780  if (ascii_file)
781  {
782  if (classifier && classifier->load_serializable(ascii_file))
783  {
784  SG_DEBUG("file successfully read.\n")
785  result=true;
786  }
787  else
788  SG_ERROR("SVM/Classifier creation/loading failed on file %s.\n", filename)
789 
790  delete ascii_file;
791  }
792  else
793  SG_ERROR("Opening file %s failed.\n", filename)
794 
795  return result;
796  }
797  else
798  SG_ERROR("Type %s of SVM/Classifier unknown.\n", type)
799 
800  return false;
801 }
802 
803 bool CGUIClassifier::save(char* param)
804 {
805  bool result=false;
806  param=SGIO::skip_spaces(param);
807 
808  if (classifier)
809  {
810  FILE* file=fopen(param, "w");
811  CSerializableAsciiFile* ascii_file = new CSerializableAsciiFile(file,'w');
812 
813  if ((!ascii_file) || (!classifier->save_serializable(ascii_file)))
814  printf("writing to file %s failed!\n", param);
815  else
816  {
817  printf("successfully written classifier into \"%s\" !\n", param);
818  result=true;
819  }
820 
821  if (ascii_file)
822  delete ascii_file;
823  }
824  else
825  SG_ERROR("create classifier first\n")
826 
827  return result;
828 }
829 
831  float64_t learnrate, int32_t maxiter)
832 {
833  if (learnrate<=0)
835  else
836  perceptron_learnrate=learnrate;
837 
838  if (maxiter<=0)
839  perceptron_maxiter=1000;
840  else
841  perceptron_maxiter=maxiter;
842  SG_INFO("Setting to perceptron parameters (learnrate %f and maxiter: %d\n", perceptron_learnrate, perceptron_maxiter)
843 
844  return true;
845 }
846 
848 {
849  if (epsilon<0)
850  svm_epsilon=1e-4;
851  else
853  SG_INFO("Set to svm_epsilon=%f.\n", svm_epsilon)
854 
855  return true;
856 }
857 
859 {
860  if (max>0)
861  {
862  max_train_time=max;
863  SG_INFO("Set to max_train_time=%f.\n", max_train_time)
864  }
865  else
866  SG_INFO("Disabling max_train_time.\n")
867 
868  return true;
869 }
870 
872 {
873  if (!classifier)
874  SG_ERROR("No regression method allocated\n")
875 
879  {
880  SG_ERROR("Underlying method not capable of SV-regression\n")
881  }
882 
883  if (tube_epsilon<0)
884  svm_tube_epsilon=1e-2;
885  svm_tube_epsilon=tube_epsilon;
886 
887  ((CSVM*) classifier)->set_tube_epsilon(svm_tube_epsilon);
888  SG_INFO("Set to svr_tube_epsilon=%f.\n", svm_tube_epsilon)
889 
890  return true;
891 }
892 
894 {
895  if (nu<0 || nu>1)
896  nu=0.5;
897 
898  svm_nu=nu;
899  SG_INFO("Set to nu=%f.\n", svm_nu)
900 
901  return true;
902 }
903 
905  float64_t weight_epsilon, float64_t C, float64_t norm)
906 {
907  if (weight_epsilon<0)
908  weight_epsilon=1e-4;
909  if (C<0)
910  C=0;
911  if (norm<0)
912  SG_ERROR("MKL norm >= 0\n")
913 
914  svm_weight_epsilon=weight_epsilon;
915  C_mkl=C;
916  mkl_norm=norm;
917 
918  SG_INFO("Set to weight_epsilon=%f.\n", svm_weight_epsilon)
919  SG_INFO("Set to C_mkl=%f.\n", C_mkl)
920  SG_INFO("Set to mkl_norm=%f.\n", mkl_norm)
921 
922  return true;
923 }
924 
926 {
927  if (lambda<0 || lambda>1)
928  SG_ERROR("0 <= ent_lambda <= 1\n")
929 
930  ent_lambda = lambda;
931  return true;
932 }
933 
935 {
936  if (mkl_bnorm<1)
937  SG_ERROR("1 <= mkl_block_norm <= inf\n")
938 
939  mkl_block_norm=mkl_bnorm;
940  return true;
941 }
942 
943 
945 {
946  if (C1<0)
947  svm_C1=1.0;
948  else
949  svm_C1=C1;
950 
951  if (C2<0)
952  svm_C2=svm_C1;
953  else
954  svm_C2=C2;
955 
956  SG_INFO("Set to C1=%f C2=%f.\n", svm_C1, svm_C2)
957 
958  return true;
959 }
960 
961 bool CGUIClassifier::set_svm_qpsize(int32_t qpsize)
962 {
963  if (qpsize<2)
964  svm_qpsize=41;
965  else
966  svm_qpsize=qpsize;
967  SG_INFO("Set qpsize to svm_qpsize=%d.\n", svm_qpsize)
968 
969  return true;
970 }
971 
972 bool CGUIClassifier::set_svm_max_qpsize(int32_t max_qpsize)
973 {
974  if (max_qpsize<50)
975  svm_max_qpsize=50;
976  else
977  svm_max_qpsize=max_qpsize;
978  SG_INFO("Set max qpsize to svm_max_qpsize=%d.\n", svm_max_qpsize)
979 
980  return true;
981 }
982 
983 bool CGUIClassifier::set_svm_bufsize(int32_t bufsize)
984 {
985  if (svm_bufsize<0)
986  svm_bufsize=3000;
987  else
988  svm_bufsize=bufsize;
989  SG_INFO("Set bufsize to svm_bufsize=%d.\n", svm_bufsize)
990 
991  return true ;
992 }
993 
995 {
996  svm_use_shrinking=enabled;
997  if (svm_use_shrinking)
998  SG_INFO("Enabling shrinking optimization.\n")
999  else
1000  SG_INFO("Disabling shrinking optimization.\n")
1001 
1002  return true;
1003 }
1004 
1006 {
1007  svm_use_batch_computation=enabled;
1009  SG_INFO("Enabling batch computation.\n")
1010  else
1011  SG_INFO("Disabling batch computation.\n")
1012 
1013  return true;
1014 }
1015 
1017 {
1018  svm_use_linadd=enabled;
1019  if (svm_use_linadd)
1020  SG_INFO("Enabling LINADD optimization.\n")
1021  else
1022  SG_INFO("Disabling LINADD optimization.\n")
1023 
1024  return true;
1025 }
1026 
1028 {
1029  svm_use_bias=enabled;
1030  if (svm_use_bias)
1031  SG_INFO("Enabling svm bias.\n")
1032  else
1033  SG_INFO("Disabling svm bias.\n")
1034 
1035  return true;
1036 }
1037 
1039 {
1040  mkl_use_interleaved=enabled;
1041  if (mkl_use_interleaved)
1042  SG_INFO("Enabling mkl interleaved optimization.\n")
1043  else
1044  SG_INFO("Disabling mkl interleaved optimization.\n")
1045 
1046  return true;
1047 }
1048 
1050 {
1051  svm_do_auc_maximization=do_auc;
1052 
1054  SG_INFO("Enabling AUC maximization.\n")
1055  else
1056  SG_INFO("Disabling AUC maximization.\n")
1057 
1058  return true;
1059 }
1060 
1061 
1063 {
1065 
1066  switch (classifier->get_classifier_type())
1067  {
1068  case CT_LIGHT:
1069  case CT_LIGHTONECLASS:
1070  case CT_LIBSVM:
1071  case CT_SCATTERSVM:
1072  case CT_MPD:
1073  case CT_GPBT:
1074  case CT_CPLEXSVM:
1075  case CT_GMNPSVM:
1076  case CT_GNPPSVM:
1077  case CT_LIBSVR:
1078  case CT_LIBSVMMULTICLASS:
1079  case CT_LIBSVMONECLASS:
1080  case CT_SVRLIGHT:
1081  case CT_MKLCLASSIFICATION:
1082  case CT_MKLMULTICLASS:
1083  case CT_MKLREGRESSION:
1084  case CT_MKLONECLASS:
1086  return classify_kernelmachine();
1087  case CT_KNN:
1088  return classify_distancemachine();
1089  case CT_PERCEPTRON:
1090  case CT_LDA:
1091  return classify_linear();
1092  case CT_SVMLIN:
1093  case CT_SVMPERF:
1094  case CT_SVMOCAS:
1095  case CT_SVMSGD:
1096  case CT_LPM:
1097  case CT_LPBOOST:
1098  case CT_LIBLINEAR:
1099  return classify_linear();
1100  case CT_WDSVMOCAS:
1101  return classify_byte_linear();
1102  default:
1103  SG_ERROR("unknown classifier type\n")
1104  break;
1105  };
1106 
1107  return NULL;
1108 }
1109 
1111 {
1112  CFeatures* trainfeatures=ui->ui_features->get_train_features();
1113  CFeatures* testfeatures=ui->ui_features->get_test_features();
1114 
1115  if (!classifier)
1116  SG_ERROR("No kernelmachine available.\n")
1117 
1118  bool success=true;
1119 
1120  REQUIRE(ui->ui_kernel->get_kernel(), "No kernel set");
1121  if (ui->ui_kernel->get_kernel()->get_kernel_type()!=K_CUSTOM)
1122  {
1123  if (ui->ui_kernel->get_kernel()->get_kernel_type()==K_COMBINED
1124  && ( !trainfeatures || !testfeatures ))
1125  {
1126  SG_DEBUG("skipping initialisation of combined kernel "
1127  "as train/test features are unavailable\n")
1128  }
1129  else
1130  {
1131  if (!trainfeatures)
1132  SG_ERROR("No training features available.\n")
1133  if (!testfeatures)
1134  SG_ERROR("No test features available.\n")
1135 
1136  success=ui->ui_kernel->init_kernel("TEST");
1137  }
1138  }
1139 
1140  if (!success || !ui->ui_kernel->is_initialized())
1141  SG_ERROR("Kernel not initialized.\n")
1142 
1144  if (type==CT_LARANK || type==CT_GMNPSVM || type==CT_LIBSVMMULTICLASS ||
1145  type==CT_MKLMULTICLASS)
1146  {
1148  kmcm->set_kernel(ui->ui_kernel->get_kernel());
1149  }
1150  else
1151  {
1153  km->set_kernel(ui->ui_kernel->get_kernel());
1155  }
1156 
1157  SG_INFO("Starting kernel machine testing.\n")
1158  return classifier->apply();
1159 }
1160 
1162  float64_t* &weights, int32_t &rows, int32_t &cols, float64_t*& bias,
1163  int32_t& brows, int32_t& bcols,
1164  int32_t idx) // which SVM for Multiclass
1165 {
1167 
1168  switch (classifier->get_classifier_type())
1169  {
1170  case CT_SCATTERSVM:
1171  case CT_GNPPSVM:
1172  case CT_LIBSVMMULTICLASS:
1173  case CT_LIGHT:
1174  case CT_LIGHTONECLASS:
1175  case CT_LIBSVM:
1176  case CT_MPD:
1177  case CT_GPBT:
1178  case CT_CPLEXSVM:
1179  case CT_GMNPSVM:
1180  case CT_LIBSVR:
1181  case CT_LIBSVMONECLASS:
1182  case CT_SVRLIGHT:
1183  case CT_MKLCLASSIFICATION:
1184  case CT_MKLREGRESSION:
1185  case CT_MKLONECLASS:
1186  case CT_MKLMULTICLASS:
1188  return get_svm(weights, rows, cols, bias, brows, bcols, idx);
1189  break;
1190  case CT_PERCEPTRON:
1191  case CT_LDA:
1192  case CT_LPM:
1193  case CT_LPBOOST:
1194  case CT_SVMOCAS:
1195  case CT_SVMSGD:
1196  case CT_SVMLIN:
1197  case CT_SVMPERF:
1198  case CT_LIBLINEAR:
1199  return get_linear(weights, rows, cols, bias, brows, bcols);
1200  break;
1201  case CT_KMEANS:
1202  case CT_HIERARCHICAL:
1203  return get_clustering(weights, rows, cols, bias, brows, bcols);
1204  break;
1205  case CT_KNN:
1206  SG_ERROR("not implemented")
1207  break;
1208  default:
1209  SG_ERROR("unknown classifier type\n")
1210  break;
1211  };
1212  return false;
1213 }
1214 
1215 
1217 {
1219  return ((CMulticlassSVM*) classifier)->get_num_machines();
1220 }
1221 
1223  float64_t* &weights, int32_t& rows, int32_t& cols, float64_t*& bias,
1224  int32_t& brows, int32_t& bcols, int32_t idx)
1225 {
1226  CSVM* svm=(CSVM*) classifier;
1227 
1228  if (idx>-1) // should be MulticlassSVM
1229  svm=((CMulticlassSVM*) svm)->get_svm(idx);
1230 
1231  if (svm)
1232  {
1233  brows=1;
1234  bcols=1;
1235  bias=SG_MALLOC(float64_t, 1);
1236  *bias=svm->get_bias();
1237 
1238  rows=svm->get_num_support_vectors();
1239  cols=2;
1240  weights=SG_MALLOC(float64_t, rows*cols);
1241 
1242  for (int32_t i=0; i<rows; i++)
1243  {
1244  weights[i]=svm->get_alpha(i);
1245  weights[i+rows]=svm->get_support_vector(i);
1246  }
1247 
1248  return true;
1249  }
1250 
1251  return false;
1252 }
1253 
1255  float64_t* &centers, int32_t& rows, int32_t& cols, float64_t*& radi,
1256  int32_t& brows, int32_t& bcols)
1257 {
1258  if (!classifier)
1259  return false;
1260 
1261  switch (classifier->get_classifier_type())
1262  {
1263  case CT_KMEANS:
1264  {
1265  CKMeans* clustering=(CKMeans*) classifier;
1266 
1267  bcols=1;
1268  SGVector<float64_t> r=clustering->get_radiuses();
1269  brows=r.vlen;
1270  radi=SG_MALLOC(float64_t, brows);
1271  memcpy(radi, r.vector, sizeof(float64_t)*brows);
1272 
1273  cols=1;
1274  SGMatrix<float64_t> c=clustering->get_cluster_centers();
1275  rows=c.num_rows;
1276  cols=c.num_cols;
1277  centers=SG_MALLOC(float64_t, rows*cols);
1278  memcpy(centers, c.matrix, sizeof(float64_t)*rows*cols);
1279  break;
1280  }
1281 
1282  case CT_HIERARCHICAL:
1283  {
1284  CHierarchical* clustering=(CHierarchical*) classifier;
1285 
1286  // radi == merge_distances, centers == pairs
1287  bcols=1;
1288  SGVector<float64_t> r=clustering->get_merge_distances();
1289  brows=r.vlen;
1290  radi=SG_MALLOC(float64_t, brows);
1291  memcpy(radi, r.vector, sizeof(float64_t)*brows);
1292 
1293  SGMatrix<int32_t> p=clustering->get_cluster_pairs();
1294  rows=p.num_rows;
1295  cols=p.num_cols;
1296  centers=SG_MALLOC(float64_t, rows*cols);
1297  for (int32_t i=0; i<rows*cols; i++)
1298  centers[i]=(float64_t) p.matrix[i];
1299 
1300  break;
1301  }
1302 
1303  default:
1304  SG_ERROR("internal error - unknown clustering type\n")
1305  }
1306 
1307  return true;
1308 }
1309 
1311  float64_t* &weights, int32_t& rows, int32_t& cols, float64_t*& bias,
1312  int32_t& brows, int32_t& bcols)
1313 {
1315 
1316  if (!linear)
1317  return false;
1318 
1319  bias=SG_MALLOC(float64_t, 1);
1320  *bias=linear->get_bias();
1321  brows=1;
1322  bcols=1;
1323 
1324  SGVector<float64_t> w=linear->get_w();
1325  cols=1;
1326  rows=w.vlen;
1327 
1328  weights= SG_MALLOC(float64_t, w.vlen);
1329  memcpy(weights, w.vector, sizeof(float64_t)*w.vlen);
1330 
1331  return true;
1332 }
1333 
1335 {
1336  CFeatures* trainfeatures=ui->ui_features->get_train_features();
1337  CFeatures* testfeatures=ui->ui_features->get_test_features();
1338 
1339  if (!classifier)
1340  {
1341  SG_ERROR("no kernelmachine available\n")
1342  return NULL;
1343  }
1344  if (!trainfeatures)
1345  {
1346  SG_ERROR("no training features available\n")
1347  return NULL;
1348  }
1349 
1350  if (!testfeatures)
1351  {
1352  SG_ERROR("no test features available\n")
1353  return NULL;
1354  }
1355 
1356  bool success=ui->ui_distance->init_distance("TEST");
1357 
1358  if (!success || !ui->ui_distance->is_initialized())
1359  {
1360  SG_ERROR("distance not initialized\n")
1361  return NULL;
1362  }
1363 
1364  ((CDistanceMachine*) classifier)->set_distance(
1365  ui->ui_distance->get_distance());
1366  SG_INFO("starting distance machine testing\n")
1367  return classifier->apply();
1368 }
1369 
1370 
1372 {
1373  CFeatures* testfeatures=ui->ui_features->get_test_features();
1374 
1375  if (!classifier)
1376  {
1377  SG_ERROR("no classifier available\n")
1378  return NULL;
1379  }
1380  if (!testfeatures)
1381  {
1382  SG_ERROR("no test features available\n")
1383  return NULL;
1384  }
1385  if (!(testfeatures->has_property(FP_DOT)))
1386  {
1387  SG_ERROR("testfeatures not based on DotFeatures\n")
1388  return NULL;
1389  }
1390 
1391  ((CLinearMachine*) classifier)->set_features((CDotFeatures*) testfeatures);
1392  SG_INFO("starting linear classifier testing\n")
1393  return classifier->apply();
1394 }
1395 
1397 {
1398  CFeatures* testfeatures=ui->ui_features->get_test_features();
1399 
1400  if (!classifier)
1401  {
1402  SG_ERROR("no svm available\n")
1403  return NULL;
1404  }
1405  if (!testfeatures)
1406  {
1407  SG_ERROR("no test features available\n")
1408  return NULL;
1409  }
1410  if (testfeatures->get_feature_class() != C_STRING ||
1411  testfeatures->get_feature_type() != F_BYTE )
1412  {
1413  SG_ERROR("testfeatures not of class STRING type BYTE\n")
1414  return NULL;
1415  }
1416 
1417  ((CWDSVMOcas*) classifier)->set_features((CStringFeatures<uint8_t>*) testfeatures);
1418  SG_INFO("starting linear classifier testing\n")
1419  return classifier->apply();
1420 }
1421 
1423 {
1424  CFeatures* trainfeatures=ui->ui_features->get_train_features();
1425  CFeatures* testfeatures=ui->ui_features->get_test_features();
1426 
1427  if (!classifier)
1428  {
1429  SG_ERROR("no svm available\n")
1430  return false;
1431  }
1432 
1433  if (!ui->ui_kernel->is_initialized())
1434  {
1435  SG_ERROR("kernel not initialized\n")
1436  return false;
1437  }
1438 
1439  if (!ui->ui_kernel->get_kernel() ||
1440  ui->ui_kernel->get_kernel()->get_kernel_type()!=K_CUSTOM)
1441  {
1442  if (!trainfeatures)
1443  {
1444  SG_ERROR("no training features available\n")
1445  return false;
1446  }
1447 
1448  if (!testfeatures)
1449  {
1450  SG_ERROR("no test features available\n")
1451  return false;
1452  }
1453  }
1454 
1455  ((CKernelMachine*) classifier)->set_kernel(
1456  ui->ui_kernel->get_kernel());
1457 
1458  result=((CKernelMachine*)classifier)->apply_one(idx);
1459  return true ;
1460 }
1461 
1462 
1464 {
1465 #ifdef HAVE_LAPACK
1466  krr_tau=tau;
1467  ((CKernelRidgeRegression*) classifier)->set_tau(krr_tau);
1468  SG_INFO("Set to krr_tau=%f.\n", krr_tau)
1469 
1470  return true;
1471 #else
1472  return false;
1473 #endif
1474 }
1475 
1476 bool CGUIClassifier::set_solver(char* solver)
1477 {
1478  ESolverType s=ST_AUTO;
1479 
1480  if (strncmp(solver,"NEWTON", 6)==0)
1481  {
1482  SG_INFO("Using NEWTON solver.\n")
1483  s=ST_NEWTON;
1484  }
1485  else if (strncmp(solver,"DIRECT", 6)==0)
1486  {
1487  SG_INFO("Using DIRECT solver\n")
1488  s=ST_DIRECT;
1489  }
1490  else if (strncmp(solver,"BLOCK_NORM", 9)==0)
1491  {
1492  SG_INFO("Using BLOCK_NORM solver\n")
1493  s=ST_BLOCK_NORM;
1494  }
1495  else if (strncmp(solver,"ELASTICNET", 10)==0)
1496  {
1497  SG_INFO("Using ELASTICNET solver\n")
1498  s=ST_ELASTICNET;
1499  }
1500  else if (strncmp(solver,"AUTO", 4)==0)
1501  {
1502  SG_INFO("Automagically determining solver.\n")
1503  s=ST_AUTO;
1504  }
1505 #ifdef USE_CPLEX
1506  else if (strncmp(solver, "CPLEX", 5)==0)
1507  {
1508  SG_INFO("USING CPLEX METHOD selected\n")
1509  s=ST_CPLEX;
1510  }
1511 #endif
1512 #ifdef USE_GLPK
1513  else if (strncmp(solver,"GLPK", 4)==0)
1514  {
1515  SG_INFO("Using GLPK solver\n")
1516  s=ST_GLPK;
1517  }
1518 #endif
1519  else
1520  SG_ERROR("Unknown solver type, %s (not compiled in?)\n", solver)
1521 
1522 
1523  solver_type=s;
1524  return true;
1525 }
1526 
1528 {
1529  if (strcmp(name,"LIBSVM_ONECLASS")==0)
1530  {
1533  SG_INFO("created SVMlibsvm object for oneclass\n")
1534  }
1535  else if (strcmp(name,"LIBSVM_NU")==0)
1536  {
1538  constraint_generator= new CLibSVM(LIBSVM_NU_SVC);
1539  SG_INFO("created SVMlibsvm object\n")
1540  }
1541  else if (strcmp(name,"LIBSVM")==0)
1542  {
1545  SG_INFO("created SVMlibsvm object\n")
1546  }
1547 
1548  else if (strcmp(name,"GPBTSVM")==0)
1549  {
1552  SG_INFO("created GPBT-SVM object\n")
1553  }
1554  else if (strcmp(name,"MPDSVM")==0)
1555  {
1558  SG_INFO("created MPD-SVM object\n")
1559  }
1560  else if (strcmp(name,"GNPPSVM")==0)
1561  {
1564  SG_INFO("created GNPP-SVM object\n")
1565  }
1566  else if (strcmp(name,"LIBSVR")==0)
1567  {
1570  SG_INFO("created SVRlibsvm object\n")
1571  }
1572  else
1573  {
1574  SG_ERROR("Unknown SV-classifier %s.\n", name)
1575  return false;
1576  }
1578 
1579  return (constraint_generator!=NULL);
1580 }
void set_epsilon(float64_t eps)
float distance(CJLCoverTreePoint p1, CJLCoverTreePoint p2, float64_t upper_bound)
void set_shrinking_enabled(bool enable)
Definition: SVM.h:177
bool set_perceptron_parameters(float64_t lernrate, int32_t maxiter)
bool set_svm_epsilon(float64_t epsilon)
class SVMLin
Definition: SVMLin.h:22
void set_bias_enabled(bool enable_bias)
EMachineType
Definition: Machine.h:33
void set_mkl_block_norm(float64_t q)
Definition: MKL.cpp:394
Class KernelRidgeRegression implements Kernel Ridge Regression - a regularized least square method fo...
bool get_trained_classifier(float64_t *&weights, int32_t &rows, int32_t &cols, float64_t *&bias, int32_t &brows, int32_t &bcols, int32_t idx=-1)
#define SG_INFO(...)
Definition: SGIO.h:120
void set_max_train_time(float64_t t)
Definition: Machine.cpp:92
double norm(double *v, double p, int n)
Definition: epph.cpp:452
bool set_svm_shrinking_enabled(bool enabled)
virtual bool save_serializable(CSerializableFile *file, const char *prefix="", int32_t param_version=Version::get_version_parameter())
Definition: SGObject.cpp:252
bool set_svm_linadd_enabled(bool enabled)
bool train_knn(int32_t k=3)
MKLMulticlass is a class for L1-norm Multiclass MKL.
Definition: MKLMulticlass.h:41
static char * skip_spaces(char *str)
Definition: SGIO.cpp:257
SGVector< float64_t > get_merge_distances()
class WDSVMOcas
Definition: WDSVMOcas.h:26
Class Distance, a base class for all the distances used in the Shogun toolbox.
Definition: Distance.h:80
void set_qpsize(int32_t qps)
bool set_constraint_generator(char *cg)
bool train_clustering(int32_t k=3, int32_t max_iter=1000)
no bias w/ libsvm
Definition: ScatterSVM.h:28
LibSVM.
Definition: LibSVM.h:28
The class Labels models labels, i.e. class assignments of objects.
Definition: Labels.h:35
virtual int32_t get_num_labels() const =0
bool set_svm_mkl_parameters(float64_t weight_epsilon, float64_t C_mkl, float64_t mkl_norm)
void set_shrinking_enabled(bool enable)
float64_t perceptron_learnrate
#define SG_UNREF(x)
Definition: SGRefObject.h:35
bool set_do_auc_maximization(bool do_auc)
L2 regularized SVM with L2-loss using newton in the primal.
Definition: LibLinear.h:32
class MPDSVM
Definition: MPDSVM.h:21
Class LPM trains a linear classifier called Linear Programming Machine, i.e. a SVM using a norm regu...
Definition: LPM.h:43
bool set_svm_nu(float64_t nu)
ESolverType
Definition: Machine.h:94
#define SG_ERROR(...)
Definition: SGIO.h:131
#define REQUIRE(x,...)
Definition: SGIO.h:208
bool save(char *param)
L1 regularized SVM with L2-loss using dual coordinate descent.
Definition: LibLinear.h:37
CLabels * setup_auc_maximization(CLabels *labels)
Definition: AUCKernel.cpp:46
void set_mkl_norm(float64_t norm)
Definition: MKL.cpp:372
A generic KernelMachine interface.
Definition: KernelMachine.h:50
Multiple Kernel Learning for one-class-classification.
Definition: MKLOneClass.h:25
Agglomerative hierarchical single linkage clustering.
Definition: Hierarchical.h:37
Features that support dot products among other operations.
Definition: DotFeatures.h:41
virtual int32_t get_num_vec_lhs()
Definition: Kernel.h:355
class LibSVMMultiClass. Does one vs one classification.
Multiple Kernel Learning for regression.
Definition: MKLRegression.h:25
Class LDA implements regularized Linear Discriminant Analysis.
Definition: LDA.h:52
A generic DistanceMachine interface.
virtual void set_mkl_norm(float64_t norm)
class LibSVMOneClass
void set_nu(float64_t nue)
Definition: SVM.h:105
bool classify_example(int32_t idx, float64_t &result)
bool set_svm_batch_computation_enabled(bool enabled)
CLabels * classify_distancemachine()
The AUC kernel can be used to maximize the area under the receiver operator characteristic curve (AUC...
Definition: AUCKernel.h:33
static const float64_t epsilon
Definition: libbmrm.cpp:25
void set_mkl_epsilon(float64_t eps)
Definition: MKL.h:209
void set_interleaved_optimization_enabled(bool enable)
Definition: MKL.h:169
CLabels * classify_kernelmachine()
LIBLINEAR_SOLVER_TYPE
Definition: LibLinear.h:25
bool new_classifier(char *name, int32_t d=6, int32_t from_d=40)
bool set_svr_tube_epsilon(float64_t tube_epsilon)
#define ASSERT(x)
Definition: SGIO.h:203
SGVector< float64_t > get_radiuses()
Definition: KMeans.cpp:365
Class SGObject is the base class of all shogun objects.
Definition: SGObject.h:102
void set_constraint_generator(CSVM *s)
Definition: MKL.h:112
class MultiClassSVM
Definition: MulticlassSVM.h:26
void set_batch_computation_enabled(bool enable)
KMeans clustering, partitions the data into k (a-priori specified) clusters.
Definition: KMeans.h:48
void set_batch_computation_enabled(bool enable)
bool set_svm_max_qpsize(int32_t max_qpsize)
void set_nu(float64_t nue)
bool set_solver(char *solver)
SGMatrix< int32_t > get_cluster_pairs()
L2 regularized linear logistic regression.
Definition: LibLinear.h:28
double float64_t
Definition: common.h:48
bool set_mkl_block_norm(float64_t mkl_bnorm)
void set_C(float64_t C)
virtual bool load_serializable(CSerializableFile *file, const char *prefix="", int32_t param_version=Version::get_version_parameter())
Definition: SGObject.cpp:311
class to implement LibLinear
Definition: LibLinear.h:45
#define SG_REF(x)
Definition: SGRefObject.h:34
bool set_mkl_interleaved_enabled(bool enabled)
class SVMSGD
Definition: SVMSGD.h:34
Multiple Kernel Learning for two-class-classification.
void set_qpsize(int32_t qps)
Definition: SVM.h:141
L2 regularized SVM with L2-loss using dual coordinate descent.
Definition: LibLinear.h:30
index_t num_rows
Definition: SGMatrix.h:301
void set_tube_epsilon(float64_t eps)
bool set_svm_bufsize(int32_t bufsize)
float64_t get_alpha(int32_t idx)
virtual EFeatureClass get_feature_class() const =0
Class KNN, an implementation of the standard k-nearest neigbor classifier.
Definition: KNN.h:55
Class LinearMachine is a generic interface for all kinds of linear machines like classifiers.
Definition: LinearMachine.h:61
Multiple Kernel Learning.
Definition: MKL.h:95
index_t num_cols
Definition: SGMatrix.h:303
bool set_svm_bias_enabled(bool enabled)
virtual EMachineType get_classifier_type()
Definition: Machine.cpp:102
bool get_clustering(float64_t *&weights, int32_t &rows, int32_t &cols, float64_t *&bias, int32_t &brows, int32_t &bcols)
class GPBTSVM
Definition: GPBTSVM.h:22
virtual SGVector< float64_t > get_w() const
int32_t get_support_vector(int32_t idx)
bool get_svm(float64_t *&weights, int32_t &rows, int32_t &cols, float64_t *&bias, int32_t &brows, int32_t &bcols, int32_t idx=-1)
Class LPBoost trains a linear classifier called Linear Programming Machine, i.e. a SVM using a norm ...
Definition: LPBoost.h:48
bool get_linear(float64_t *&weights, int32_t &rows, int32_t &cols, float64_t *&bias, int32_t &brows, int32_t &bcols)
bool train_linear(float64_t gamma=0)
Class LibSVR, performs support vector regression using LibSVM.
Definition: LibSVR.h:70
Class Perceptron implements the standard linear (online) perceptron.
Definition: Perceptron.h:30
ScatterSVM - Multiclass SVM.
Definition: ScatterSVM.h:50
#define SG_DEBUG(...)
Definition: SGIO.h:109
Class GMNPSVM implements a one vs. rest MultiClass SVM.
Definition: GMNPSVM.h:24
training with bias using test rule 2
Definition: ScatterSVM.h:33
The class Features is the base class of all feature objects.
Definition: Features.h:62
training with bias using test rule 1
Definition: ScatterSVM.h:31
void set_linadd_enabled(bool enable)
virtual float64_t get_bias()
virtual bool train(CFeatures *data=NULL)
Definition: Machine.cpp:49
void set_mkl_epsilon(float64_t eps)
A generic Support Vector Machine Interface.
Definition: SVM.h:47
void set_linadd_enabled(bool enable)
void set_elasticnet_lambda(float64_t elasticnet_lambda)
Definition: MKL.cpp:381
the LaRank multiclass SVM machine
Definition: LaRank.h:307
The Kernel base class.
Definition: Kernel.h:150
void set_bias_enabled(bool enable_bias)
class SVMOcas
Definition: SVMOcas.h:32
CLabels * classify_byte_linear()
void set_epsilon(float64_t eps)
Definition: SVM.h:123
L2 regularized linear SVM with L1-loss using dual coordinate descent.
Definition: LibLinear.h:35
class GNPPSVM
Definition: GNPPSVM.h:20
void set_kernel(CKernel *k)
bool has_property(EFeatureProperty p) const
Definition: Features.cpp:292
virtual bool has_features()
Definition: Kernel.h:373
virtual void set_labels(CLabels *lab)
Definition: Machine.cpp:75
bool set_krr_tau(float64_t tau=1)
bool set_svm_C(float64_t C1, float64_t C2)
bool load(char *filename, char *type)
void set_solver_type(ESolverType st)
Definition: Machine.cpp:107
bool set_elasticnet_lambda(float64_t lambda)
bool set_svm_qpsize(int32_t qpsize)
void set_C_mkl(float64_t C)
Definition: MKL.h:142
virtual EFeatureType get_feature_type() const =0
void set_C(float64_t c_neg, float64_t c_pos)
Definition: SVM.h:116
index_t vlen
Definition: SGVector.h:706
bool set_max_train_time(float64_t max)
void set_tube_epsilon(float64_t eps)
Definition: SVM.h:129
SGMatrix< float64_t > get_cluster_centers()
Definition: KMeans.cpp:370
virtual CLabels * apply(CFeatures *data=NULL)
Definition: Machine.cpp:162

SHOGUN Machine Learning Toolbox - Documentation