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 #endif //HAVE_LAPACK
253 #ifdef HAVE_EIGEN3
254  else if (strcmp(name,"LDA")==0)
255  {
257  classifier= new CLDA();
258  SG_INFO("created LDA object\n")
259  }
260 #endif //HAVE_EIGEN3
261 #ifdef USE_CPLEX
262  else if (strcmp(name,"LPM")==0)
263  {
265  classifier= new CLPM();
266  ((CLPM*) classifier)->set_C(svm_C1, svm_C2);
267  ((CLPM*) classifier)->set_epsilon(svm_epsilon);
268  ((CLPM*) classifier)->set_bias_enabled(svm_use_bias);
269  ((CLPM*) classifier)->set_max_train_time(max_train_time);
270  SG_INFO("created LPM object\n")
271  }
272  else if (strcmp(name,"LPBOOST")==0)
273  {
275  classifier= new CLPBoost();
276  ((CLPBoost*) classifier)->set_C(svm_C1, svm_C2);
277  ((CLPBoost*) classifier)->set_epsilon(svm_epsilon);
278  ((CLPBoost*) classifier)->set_bias_enabled(svm_use_bias);
279  ((CLPBoost*) classifier)->set_max_train_time(max_train_time);
280  SG_INFO("created LPBoost object\n")
281  }
282 #endif //USE_CPLEX
283  else if (strncmp(name,"KNN", strlen("KNN"))==0)
284  {
286  classifier= new CKNN();
287  SG_INFO("created KNN object\n")
288  }
289  else if (strncmp(name,"KMEANS", strlen("KMEANS"))==0)
290  {
292  classifier= new CKMeans();
293  SG_INFO("created KMeans object\n")
294  }
295  else if (strncmp(name,"HIERARCHICAL", strlen("HIERARCHICAL"))==0)
296  {
298  classifier= new CHierarchical();
299  SG_INFO("created Hierarchical clustering object\n")
300  }
301  else if (strcmp(name,"SVMLIN")==0)
302  {
304  classifier= new CSVMLin();
305  ((CSVMLin*) classifier)->set_C(svm_C1, svm_C2);
306  ((CSVMLin*) classifier)->set_epsilon(svm_epsilon);
307  ((CSVMLin*) classifier)->set_bias_enabled(svm_use_bias);
308  SG_INFO("created SVMLin object\n")
309  }
310  else if (strncmp(name,"WDSVMOCAS", strlen("WDSVMOCAS"))==0)
311  {
313  classifier= new CWDSVMOcas(SVM_OCAS);
314 
315  ((CWDSVMOcas*) classifier)->set_bias_enabled(svm_use_bias);
316  ((CWDSVMOcas*) classifier)->set_degree(d, from_d);
317  ((CWDSVMOcas*) classifier)->set_C(svm_C1, svm_C2);
318  ((CWDSVMOcas*) classifier)->set_epsilon(svm_epsilon);
319  ((CWDSVMOcas*) classifier)->set_bufsize(svm_bufsize);
320  SG_INFO("created Weighted Degree Kernel SVM Ocas(OCAS) object of order %d (from order:%d)\n", d, from_d)
321  }
322  else if (strcmp(name,"SVMOCAS")==0)
323  {
325  classifier= new CSVMOcas(SVM_OCAS);
326 
327  ((CSVMOcas*) classifier)->set_C(svm_C1, svm_C2);
328  ((CSVMOcas*) classifier)->set_epsilon(svm_epsilon);
329  ((CSVMOcas*) classifier)->set_bufsize(svm_bufsize);
330  ((CSVMOcas*) classifier)->set_bias_enabled(svm_use_bias);
331  SG_INFO("created SVM Ocas(OCAS) object\n")
332  }
333  else if (strcmp(name,"SVMSGD")==0)
334  {
336  classifier= new CSVMSGD(svm_C1);
337  ((CSVMSGD*) classifier)->set_bias_enabled(svm_use_bias);
338  SG_INFO("created SVM SGD object\n")
339  }
340  else if (strcmp(name,"SVMBMRM")==0 || (strcmp(name,"SVMPERF")==0))
341  {
343  classifier= new CSVMOcas(SVM_BMRM);
344 
345  ((CSVMOcas*) classifier)->set_C(svm_C1, svm_C2);
346  ((CSVMOcas*) classifier)->set_epsilon(svm_epsilon);
347  ((CSVMOcas*) classifier)->set_bufsize(svm_bufsize);
348  ((CSVMOcas*) classifier)->set_bias_enabled(svm_use_bias);
349  SG_INFO("created SVM Ocas(BMRM/PERF) object\n")
350  }
351  else if (strcmp(name,"MKL_CLASSIFICATION")==0)
352  {
355  }
356  else if (strcmp(name,"MKL_ONECLASS")==0)
357  {
359  classifier= new CMKLOneClass();
360  }
361  else if (strcmp(name,"MKL_MULTICLASS")==0)
362  {
364  classifier= new CMKLMulticlass();
365  }
366  else if (strcmp(name,"MKL_REGRESSION")==0)
367  {
369  classifier= new CMKLRegression();
370  }
371  else
372  {
373  SG_ERROR("Unknown classifier %s.\n", name)
374  return false;
375  }
377 
378  return (classifier!=NULL);
379 }
380 
382 {
384  if (!mkl)
385  SG_ERROR("No MKL available.\n")
386 
387  CLabels* trainlabels=ui->ui_labels->get_train_labels();
388  if (!trainlabels)
389  SG_ERROR("No trainlabels available.\n")
390 
391  CKernel* kernel=ui->ui_kernel->get_kernel();
392  if (!kernel)
393  SG_ERROR("No kernel available.\n")
394 
395  bool success=ui->ui_kernel->init_kernel("TRAIN");
396 
397  if (!success || !ui->ui_kernel->is_initialized() || !kernel->has_features())
398  SG_ERROR("Kernel not initialized / no train features available.\n")
399 
400  int32_t num_vec=kernel->get_num_vec_lhs();
401  if (trainlabels->get_num_labels() != num_vec)
402  SG_ERROR("Number of train labels (%d) and training vectors (%d) differs!\n", trainlabels->get_num_labels(), num_vec)
403 
404  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)
405 
407  mkl->set_mkl_norm(mkl_norm);
408  //mkl->set_max_num_mkliters(-1);
411  mkl->set_epsilon(svm_epsilon);
414  mkl->set_nu(svm_nu);
415  mkl->set_C(svm_C1);
416  mkl->set_qpsize(svm_qpsize);
420 
421  ((CKernelMulticlassMachine*) mkl)->set_labels(trainlabels);
422  ((CKernelMulticlassMachine*) mkl)->set_kernel(kernel);
423 
424  return mkl->train();
425 }
426 
428 {
429  CMKL* mkl= (CMKL*) classifier;
430  if (!mkl)
431  SG_ERROR("No SVM available.\n")
432 
433  bool oneclass=(mkl->get_classifier_type()==CT_LIBSVMONECLASS);
434  CLabels* trainlabels=NULL;
435  if(!oneclass)
436  trainlabels=ui->ui_labels->get_train_labels();
437  else
438  SG_INFO("Training one class mkl.\n")
439  if (!trainlabels && !oneclass)
440  SG_ERROR("No trainlabels available.\n")
441 
442  CKernel* kernel=ui->ui_kernel->get_kernel();
443  if (!kernel)
444  SG_ERROR("No kernel available.\n")
445 
446  bool success=ui->ui_kernel->init_kernel("TRAIN");
447  if (!success || !ui->ui_kernel->is_initialized() || !kernel->has_features())
448  SG_ERROR("Kernel not initialized.\n")
449 
450  int32_t num_vec=kernel->get_num_vec_lhs();
451  if (!oneclass && trainlabels->get_num_labels() != num_vec)
452  SG_ERROR("Number of train labels (%d) and training vectors (%d) differs!\n", trainlabels->get_num_labels(), num_vec)
453 
454  SG_INFO("Starting SVM training on %ld vectors using C1=%lf C2=%lf epsilon=%lf\n", num_vec, svm_C1, svm_C2, svm_epsilon)
455 
460  mkl->set_epsilon(svm_epsilon);
463  mkl->set_nu(svm_nu);
464  mkl->set_C(svm_C1, svm_C2);
465  mkl->set_qpsize(svm_qpsize);
470  mkl->set_mkl_norm(mkl_norm);
473  mkl->set_C_mkl(C_mkl);
475 
477  {
478  CAUCKernel* auc_kernel = new CAUCKernel(10, kernel);
479  CLabels* auc_labels= auc_kernel->setup_auc_maximization(trainlabels);
480  ((CKernelMachine*) mkl)->set_labels(auc_labels);
481  ((CKernelMachine*) mkl)->set_kernel(auc_kernel);
482  SG_UNREF(auc_labels);
483  }
484  else
485  {
486  if(!oneclass)
487  ((CKernelMachine*) mkl)->set_labels(trainlabels);
488  ((CKernelMachine*) mkl)->set_kernel(kernel);
489  }
490 
491  bool result=mkl->train();
492 
493  return result;
494 }
495 
497 {
499 
500  if (!classifier)
501  SG_ERROR("No SVM available.\n")
502 
503  bool oneclass=(type==CT_LIBSVMONECLASS);
504  CLabels* trainlabels=NULL;
505  if(!oneclass)
506  trainlabels=ui->ui_labels->get_train_labels();
507  else
508  SG_INFO("Training one class svm.\n")
509  if (!trainlabels && !oneclass)
510  SG_ERROR("No trainlabels available.\n")
511 
512  CKernel* kernel=ui->ui_kernel->get_kernel();
513  if (!kernel)
514  SG_ERROR("No kernel available.\n")
515 
516  bool success=ui->ui_kernel->init_kernel("TRAIN");
517 
518  if (!success || !ui->ui_kernel->is_initialized() || !kernel->has_features())
519  SG_ERROR("Kernel not initialized / no train features available.\n")
520 
521  int32_t num_vec=kernel->get_num_vec_lhs();
522  if (!oneclass && trainlabels->get_num_labels() != num_vec)
523  SG_ERROR("Number of train labels (%d) and training vectors (%d) differs!\n", trainlabels->get_num_labels(), num_vec)
524 
525  SG_INFO("Starting SVM training on %ld vectors using C1=%lf C2=%lf epsilon=%lf\n", num_vec, svm_C1, svm_C2, svm_epsilon)
526 
527  if (type==CT_LARANK || type==CT_GMNPSVM || type==CT_LIBSVMMULTICLASS)
528  {
532  svm->set_epsilon(svm_epsilon);
535  svm->set_nu(svm_nu);
536  svm->set_C(svm_C1);
537  svm->set_qpsize(svm_qpsize);
541  }
542  else
543  {
544  CSVM* svm = (CSVM*)classifier;
547  svm->set_epsilon(svm_epsilon);
550  svm->set_nu(svm_nu);
551  svm->set_C(svm_C1, svm_C2);
552  svm->set_qpsize(svm_qpsize);
556  }
557 
558  if (type==CT_MKLMULTICLASS)
559  {
560  ((CMKLMulticlass *)classifier)->set_mkl_epsilon(svm_weight_epsilon);
561  }
562 
564  {
565  CAUCKernel* auc_kernel = new CAUCKernel(10, kernel);
566  CLabels* auc_labels = auc_kernel->setup_auc_maximization(trainlabels);
567  ((CKernelMachine*)classifier)->set_labels(auc_labels);
568  ((CKernelMachine*)classifier)->set_kernel(auc_kernel);
569  SG_UNREF(auc_labels);
570  }
571  else
572  {
573  if (type==CT_LARANK || type==CT_GMNPSVM || type==CT_LIBSVMMULTICLASS)
574  {
575  ((CKernelMulticlassMachine*)classifier)->set_labels(trainlabels);
576  ((CKernelMulticlassMachine*)classifier)->set_kernel(kernel);
577  }
578  else
579  {
580  if(!oneclass)
581  ((CKernelMachine*)classifier)->set_labels(trainlabels);
582 
583  ((CKernelMachine*)classifier)->set_kernel(kernel);
584  }
585  }
586 
587  bool result = classifier->train();
588 
589  return result;
590 }
591 
592 bool CGUIClassifier::train_clustering(int32_t k, int32_t max_iter)
593 {
594  bool result=false;
595  CDistance* distance=ui->ui_distance->get_distance();
596 
597  if (!distance)
598  SG_ERROR("No distance available\n")
599 
600  if (!ui->ui_distance->init_distance("TRAIN"))
601  SG_ERROR("Initializing distance with train features failed.\n")
602 
603  ((CDistanceMachine*) classifier)->set_distance(distance);
604 
606  switch (type)
607  {
608  case CT_KMEANS:
609  {
610  ((CKMeans*) classifier)->set_k(k);
611  ((CKMeans*) classifier)->set_max_iter(max_iter);
612  result=((CKMeans*) classifier)->train();
613  break;
614  }
615  case CT_HIERARCHICAL:
616  {
617  ((CHierarchical*) classifier)->set_merges(k);
618  result=((CHierarchical*) classifier)->train();
619  break;
620  }
621  default:
622  SG_ERROR("Unknown clustering type %d\n", type)
623  }
624 
625  return result;
626 }
627 
629 {
630  CLabels* trainlabels=ui->ui_labels->get_train_labels();
631  CDistance* distance=ui->ui_distance->get_distance();
632 
633  bool result=false;
634 
635  if (trainlabels)
636  {
637  if (distance)
638  {
639  if (!ui->ui_distance->init_distance("TRAIN"))
640  SG_ERROR("Initializing distance with train features failed.\n")
641  ((CKNN*) classifier)->set_labels(trainlabels);
642  ((CKNN*) classifier)->set_distance(distance);
643  ((CKNN*) classifier)->set_k(k);
644  result=((CKNN*) classifier)->train();
645  }
646  else
647  SG_ERROR("No distance available.\n")
648  }
649  else
650  SG_ERROR("No labels available\n")
651 
652  return result;
653 }
654 
656 {
657 #ifdef HAVE_LAPACK
659  if (!krr)
660  SG_ERROR("No SVM available.\n")
661 
662  CLabels* trainlabels=NULL;
663  trainlabels=ui->ui_labels->get_train_labels();
664  if (!trainlabels)
665  SG_ERROR("No trainlabels available.\n")
666 
667  CKernel* kernel=ui->ui_kernel->get_kernel();
668  if (!kernel)
669  SG_ERROR("No kernel available.\n")
670 
671  bool success=ui->ui_kernel->init_kernel("TRAIN");
672 
673  if (!success || !ui->ui_kernel->is_initialized() || !kernel->has_features())
674  SG_ERROR("Kernel not initialized / no train features available.\n")
675 
676  int32_t num_vec=kernel->get_num_vec_lhs();
677  if (trainlabels->get_num_labels() != num_vec)
678  SG_ERROR("Number of train labels (%d) and training vectors (%d) differs!\n", trainlabels->get_num_labels(), num_vec)
679 
680 
681  // Set training labels and kernel
682  krr->set_labels(trainlabels);
683  krr->set_kernel(kernel);
684 
685  bool result=krr->train();
686  return result;
687 #else
688  return false;
689 #endif
690 }
691 
693 {
696  CFeatures* trainfeatures=ui->ui_features->get_train_features();
697  CLabels* trainlabels=ui->ui_labels->get_train_labels();
698  bool result=false;
699 
700  if (!trainfeatures)
701  SG_ERROR("No trainfeatures available.\n")
702 
703  if (!trainfeatures->has_property(FP_DOT))
704  SG_ERROR("Trainfeatures not based on DotFeatures.\n")
705 
706  if (!trainlabels)
707  SG_ERROR("No labels available\n")
708 
709  if (ctype==CT_PERCEPTRON)
710  {
711  ((CPerceptron*) classifier)->set_learn_rate(perceptron_learnrate);
712  ((CPerceptron*) classifier)->set_max_iter(perceptron_maxiter);
713  }
714 
715 #ifdef HAVE_EIGEN3
716  if (ctype==CT_LDA)
717  {
718  if (trainfeatures->get_feature_type()!=F_DREAL ||
719  trainfeatures->get_feature_class()!=C_DENSE)
720  SG_ERROR("LDA requires train features of class SIMPLE type REAL.\n")
721  ((CLDA*) classifier)->set_gamma(gamma);
722  }
723 #endif //HAVE_EIGEN3
724 
725  if (ctype==CT_SVMOCAS)
726  ((CSVMOcas*) classifier)->set_C(svm_C1, svm_C2);
727 #ifdef HAVE_LAPACK
728  else if (ctype==CT_LIBLINEAR)
729  ((CLibLinear*) classifier)->set_C(svm_C1, svm_C2);
730 #endif
731  else if (ctype==CT_SVMLIN)
732  ((CSVMLin*) classifier)->set_C(svm_C1, svm_C2);
733  else if (ctype==CT_SVMSGD)
734  ((CSVMSGD*) classifier)->set_C(svm_C1, svm_C2);
735  else if (ctype==CT_LPM || ctype==CT_LPBOOST)
736  {
737  if (trainfeatures->get_feature_class()!=C_SPARSE ||
738  trainfeatures->get_feature_type()!=F_DREAL)
739  SG_ERROR("LPM and LPBOOST require trainfeatures of class SPARSE type REAL.\n")
740  }
741 
742  ((CLinearMachine*) classifier)->set_labels(trainlabels);
743  ((CLinearMachine*) classifier)->set_features((CDenseFeatures<float64_t>*) trainfeatures);
744  result=((CLinearMachine*) classifier)->train();
745 
746  return result;
747 }
748 
750 {
751  CFeatures* trainfeatures=ui->ui_features->get_train_features();
752  CLabels* trainlabels=ui->ui_labels->get_train_labels();
753 
754  bool result=false;
755 
756  if (!trainfeatures)
757  SG_ERROR("No trainfeatures available.\n")
758 
759  if (trainfeatures->get_feature_class()!=C_STRING ||
760  trainfeatures->get_feature_type()!=F_BYTE )
761  SG_ERROR("Trainfeatures are not of class STRING type BYTE.\n")
762 
763  if (!trainlabels)
764  SG_ERROR("No labels available.\n")
765 
766  ((CWDSVMOcas*) classifier)->set_labels(trainlabels);
767  ((CWDSVMOcas*) classifier)->set_features((CStringFeatures<uint8_t>*) trainfeatures);
768  result=((CWDSVMOcas*) classifier)->train();
769 
770  return result;
771 }
772 
773 bool CGUIClassifier::load(char* filename, char* type)
774 {
775  bool result=false;
776 
777  if (new_classifier(type))
778  {
779  FILE* model_file=fopen(filename, "r");
780  CSerializableAsciiFile* ascii_file = new CSerializableAsciiFile(model_file,'r');
781 
782  if (ascii_file)
783  {
784  if (classifier && classifier->load_serializable(ascii_file))
785  {
786  SG_DEBUG("file successfully read.\n")
787  result=true;
788  }
789  else
790  SG_ERROR("SVM/Classifier creation/loading failed on file %s.\n", filename)
791 
792  delete ascii_file;
793  }
794  else
795  SG_ERROR("Opening file %s failed.\n", filename)
796 
797  return result;
798  }
799  else
800  SG_ERROR("Type %s of SVM/Classifier unknown.\n", type)
801 
802  return false;
803 }
804 
805 bool CGUIClassifier::save(char* param)
806 {
807  bool result=false;
808  param=SGIO::skip_spaces(param);
809 
810  if (classifier)
811  {
812  FILE* file=fopen(param, "w");
813  CSerializableAsciiFile* ascii_file = new CSerializableAsciiFile(file,'w');
814 
815  if ((!ascii_file) || (!classifier->save_serializable(ascii_file)))
816  printf("writing to file %s failed!\n", param);
817  else
818  {
819  printf("successfully written classifier into \"%s\" !\n", param);
820  result=true;
821  }
822 
823  if (ascii_file)
824  delete ascii_file;
825  }
826  else
827  SG_ERROR("create classifier first\n")
828 
829  return result;
830 }
831 
833  float64_t learnrate, int32_t maxiter)
834 {
835  if (learnrate<=0)
837  else
838  perceptron_learnrate=learnrate;
839 
840  if (maxiter<=0)
841  perceptron_maxiter=1000;
842  else
843  perceptron_maxiter=maxiter;
844  SG_INFO("Setting to perceptron parameters (learnrate %f and maxiter: %d\n", perceptron_learnrate, perceptron_maxiter)
845 
846  return true;
847 }
848 
850 {
851  if (epsilon<0)
852  svm_epsilon=1e-4;
853  else
855  SG_INFO("Set to svm_epsilon=%f.\n", svm_epsilon)
856 
857  return true;
858 }
859 
861 {
862  if (max>0)
863  {
864  max_train_time=max;
865  SG_INFO("Set to max_train_time=%f.\n", max_train_time)
866  }
867  else
868  SG_INFO("Disabling max_train_time.\n")
869 
870  return true;
871 }
872 
874 {
875  if (!classifier)
876  SG_ERROR("No regression method allocated\n")
877 
881  {
882  SG_ERROR("Underlying method not capable of SV-regression\n")
883  }
884 
885  if (tube_epsilon<0)
886  svm_tube_epsilon=1e-2;
887  svm_tube_epsilon=tube_epsilon;
888 
889  ((CSVM*) classifier)->set_tube_epsilon(svm_tube_epsilon);
890  SG_INFO("Set to svr_tube_epsilon=%f.\n", svm_tube_epsilon)
891 
892  return true;
893 }
894 
896 {
897  if (nu<0 || nu>1)
898  nu=0.5;
899 
900  svm_nu=nu;
901  SG_INFO("Set to nu=%f.\n", svm_nu)
902 
903  return true;
904 }
905 
907  float64_t weight_epsilon, float64_t C, float64_t norm)
908 {
909  if (weight_epsilon<0)
910  weight_epsilon=1e-4;
911  if (C<0)
912  C=0;
913  if (norm<0)
914  SG_ERROR("MKL norm >= 0\n")
915 
916  svm_weight_epsilon=weight_epsilon;
917  C_mkl=C;
918  mkl_norm=norm;
919 
920  SG_INFO("Set to weight_epsilon=%f.\n", svm_weight_epsilon)
921  SG_INFO("Set to C_mkl=%f.\n", C_mkl)
922  SG_INFO("Set to mkl_norm=%f.\n", mkl_norm)
923 
924  return true;
925 }
926 
928 {
929  if (lambda<0 || lambda>1)
930  SG_ERROR("0 <= ent_lambda <= 1\n")
931 
932  ent_lambda = lambda;
933  return true;
934 }
935 
937 {
938  if (mkl_bnorm<1)
939  SG_ERROR("1 <= mkl_block_norm <= inf\n")
940 
941  mkl_block_norm=mkl_bnorm;
942  return true;
943 }
944 
945 
947 {
948  if (C1<0)
949  svm_C1=1.0;
950  else
951  svm_C1=C1;
952 
953  if (C2<0)
954  svm_C2=svm_C1;
955  else
956  svm_C2=C2;
957 
958  SG_INFO("Set to C1=%f C2=%f.\n", svm_C1, svm_C2)
959 
960  return true;
961 }
962 
963 bool CGUIClassifier::set_svm_qpsize(int32_t qpsize)
964 {
965  if (qpsize<2)
966  svm_qpsize=41;
967  else
968  svm_qpsize=qpsize;
969  SG_INFO("Set qpsize to svm_qpsize=%d.\n", svm_qpsize)
970 
971  return true;
972 }
973 
974 bool CGUIClassifier::set_svm_max_qpsize(int32_t max_qpsize)
975 {
976  if (max_qpsize<50)
977  svm_max_qpsize=50;
978  else
979  svm_max_qpsize=max_qpsize;
980  SG_INFO("Set max qpsize to svm_max_qpsize=%d.\n", svm_max_qpsize)
981 
982  return true;
983 }
984 
985 bool CGUIClassifier::set_svm_bufsize(int32_t bufsize)
986 {
987  if (svm_bufsize<0)
988  svm_bufsize=3000;
989  else
990  svm_bufsize=bufsize;
991  SG_INFO("Set bufsize to svm_bufsize=%d.\n", svm_bufsize)
992 
993  return true ;
994 }
995 
997 {
998  svm_use_shrinking=enabled;
999  if (svm_use_shrinking)
1000  SG_INFO("Enabling shrinking optimization.\n")
1001  else
1002  SG_INFO("Disabling shrinking optimization.\n")
1003 
1004  return true;
1005 }
1006 
1008 {
1009  svm_use_batch_computation=enabled;
1011  SG_INFO("Enabling batch computation.\n")
1012  else
1013  SG_INFO("Disabling batch computation.\n")
1014 
1015  return true;
1016 }
1017 
1019 {
1020  svm_use_linadd=enabled;
1021  if (svm_use_linadd)
1022  SG_INFO("Enabling LINADD optimization.\n")
1023  else
1024  SG_INFO("Disabling LINADD optimization.\n")
1025 
1026  return true;
1027 }
1028 
1030 {
1031  svm_use_bias=enabled;
1032  if (svm_use_bias)
1033  SG_INFO("Enabling svm bias.\n")
1034  else
1035  SG_INFO("Disabling svm bias.\n")
1036 
1037  return true;
1038 }
1039 
1041 {
1042  mkl_use_interleaved=enabled;
1043  if (mkl_use_interleaved)
1044  SG_INFO("Enabling mkl interleaved optimization.\n")
1045  else
1046  SG_INFO("Disabling mkl interleaved optimization.\n")
1047 
1048  return true;
1049 }
1050 
1052 {
1053  svm_do_auc_maximization=do_auc;
1054 
1056  SG_INFO("Enabling AUC maximization.\n")
1057  else
1058  SG_INFO("Disabling AUC maximization.\n")
1059 
1060  return true;
1061 }
1062 
1063 
1065 {
1067 
1068  switch (classifier->get_classifier_type())
1069  {
1070  case CT_LIGHT:
1071  case CT_LIGHTONECLASS:
1072  case CT_LIBSVM:
1073  case CT_SCATTERSVM:
1074  case CT_MPD:
1075  case CT_GPBT:
1076  case CT_CPLEXSVM:
1077  case CT_GMNPSVM:
1078  case CT_GNPPSVM:
1079  case CT_LIBSVR:
1080  case CT_LIBSVMMULTICLASS:
1081  case CT_LIBSVMONECLASS:
1082  case CT_SVRLIGHT:
1083  case CT_MKLCLASSIFICATION:
1084  case CT_MKLMULTICLASS:
1085  case CT_MKLREGRESSION:
1086  case CT_MKLONECLASS:
1088  return classify_kernelmachine();
1089  case CT_KNN:
1090  return classify_distancemachine();
1091  case CT_PERCEPTRON:
1092  case CT_LDA:
1093  return classify_linear();
1094  case CT_SVMLIN:
1095  case CT_SVMPERF:
1096  case CT_SVMOCAS:
1097  case CT_SVMSGD:
1098  case CT_LPM:
1099  case CT_LPBOOST:
1100  case CT_LIBLINEAR:
1101  return classify_linear();
1102  case CT_WDSVMOCAS:
1103  return classify_byte_linear();
1104  default:
1105  SG_ERROR("unknown classifier type\n")
1106  break;
1107  };
1108 
1109  return NULL;
1110 }
1111 
1113 {
1114  CFeatures* trainfeatures=ui->ui_features->get_train_features();
1115  CFeatures* testfeatures=ui->ui_features->get_test_features();
1116 
1117  if (!classifier)
1118  SG_ERROR("No kernelmachine available.\n")
1119 
1120  bool success=true;
1121 
1122  REQUIRE(ui->ui_kernel->get_kernel(), "No kernel set");
1123  if (ui->ui_kernel->get_kernel()->get_kernel_type()!=K_CUSTOM)
1124  {
1125  if (ui->ui_kernel->get_kernel()->get_kernel_type()==K_COMBINED
1126  && ( !trainfeatures || !testfeatures ))
1127  {
1128  SG_DEBUG("skipping initialisation of combined kernel "
1129  "as train/test features are unavailable\n")
1130  }
1131  else
1132  {
1133  if (!trainfeatures)
1134  SG_ERROR("No training features available.\n")
1135  if (!testfeatures)
1136  SG_ERROR("No test features available.\n")
1137 
1138  success=ui->ui_kernel->init_kernel("TEST");
1139  }
1140  }
1141 
1142  if (!success || !ui->ui_kernel->is_initialized())
1143  SG_ERROR("Kernel not initialized.\n")
1144 
1146  if (type==CT_LARANK || type==CT_GMNPSVM || type==CT_LIBSVMMULTICLASS ||
1147  type==CT_MKLMULTICLASS)
1148  {
1150  kmcm->set_kernel(ui->ui_kernel->get_kernel());
1151  }
1152  else
1153  {
1155  km->set_kernel(ui->ui_kernel->get_kernel());
1157  }
1158 
1159  SG_INFO("Starting kernel machine testing.\n")
1160  return classifier->apply();
1161 }
1162 
1164  float64_t* &weights, int32_t &rows, int32_t &cols, float64_t*& bias,
1165  int32_t& brows, int32_t& bcols,
1166  int32_t idx) // which SVM for Multiclass
1167 {
1169 
1170  switch (classifier->get_classifier_type())
1171  {
1172  case CT_SCATTERSVM:
1173  case CT_GNPPSVM:
1174  case CT_LIBSVMMULTICLASS:
1175  case CT_LIGHT:
1176  case CT_LIGHTONECLASS:
1177  case CT_LIBSVM:
1178  case CT_MPD:
1179  case CT_GPBT:
1180  case CT_CPLEXSVM:
1181  case CT_GMNPSVM:
1182  case CT_LIBSVR:
1183  case CT_LIBSVMONECLASS:
1184  case CT_SVRLIGHT:
1185  case CT_MKLCLASSIFICATION:
1186  case CT_MKLREGRESSION:
1187  case CT_MKLONECLASS:
1188  case CT_MKLMULTICLASS:
1190  return get_svm(weights, rows, cols, bias, brows, bcols, idx);
1191  break;
1192  case CT_PERCEPTRON:
1193  case CT_LDA:
1194  case CT_LPM:
1195  case CT_LPBOOST:
1196  case CT_SVMOCAS:
1197  case CT_SVMSGD:
1198  case CT_SVMLIN:
1199  case CT_SVMPERF:
1200  case CT_LIBLINEAR:
1201  return get_linear(weights, rows, cols, bias, brows, bcols);
1202  break;
1203  case CT_KMEANS:
1204  case CT_HIERARCHICAL:
1205  return get_clustering(weights, rows, cols, bias, brows, bcols);
1206  break;
1207  case CT_KNN:
1208  SG_ERROR("not implemented")
1209  break;
1210  default:
1211  SG_ERROR("unknown classifier type\n")
1212  break;
1213  };
1214  return false;
1215 }
1216 
1217 
1219 {
1221  return ((CMulticlassSVM*) classifier)->get_num_machines();
1222 }
1223 
1225  float64_t* &weights, int32_t& rows, int32_t& cols, float64_t*& bias,
1226  int32_t& brows, int32_t& bcols, int32_t idx)
1227 {
1228  CSVM* svm=(CSVM*) classifier;
1229 
1230  if (idx>-1) // should be MulticlassSVM
1231  svm=((CMulticlassSVM*) svm)->get_svm(idx);
1232 
1233  if (svm)
1234  {
1235  brows=1;
1236  bcols=1;
1237  bias=SG_MALLOC(float64_t, 1);
1238  *bias=svm->get_bias();
1239 
1240  rows=svm->get_num_support_vectors();
1241  cols=2;
1242  weights=SG_MALLOC(float64_t, rows*cols);
1243 
1244  for (int32_t i=0; i<rows; i++)
1245  {
1246  weights[i]=svm->get_alpha(i);
1247  weights[i+rows]=svm->get_support_vector(i);
1248  }
1249 
1250  return true;
1251  }
1252 
1253  return false;
1254 }
1255 
1257  float64_t* &centers, int32_t& rows, int32_t& cols, float64_t*& radi,
1258  int32_t& brows, int32_t& bcols)
1259 {
1260  if (!classifier)
1261  return false;
1262 
1263  switch (classifier->get_classifier_type())
1264  {
1265  case CT_KMEANS:
1266  {
1267  CKMeans* clustering=(CKMeans*) classifier;
1268 
1269  bcols=1;
1270  SGVector<float64_t> r=clustering->get_radiuses();
1271  brows=r.vlen;
1272  radi=SG_MALLOC(float64_t, brows);
1273  memcpy(radi, r.vector, sizeof(float64_t)*brows);
1274 
1275  cols=1;
1276  SGMatrix<float64_t> c=clustering->get_cluster_centers();
1277  rows=c.num_rows;
1278  cols=c.num_cols;
1279  centers=SG_MALLOC(float64_t, rows*cols);
1280  memcpy(centers, c.matrix, sizeof(float64_t)*rows*cols);
1281  break;
1282  }
1283 
1284  case CT_HIERARCHICAL:
1285  {
1286  CHierarchical* clustering=(CHierarchical*) classifier;
1287 
1288  // radi == merge_distances, centers == pairs
1289  bcols=1;
1290  SGVector<float64_t> r=clustering->get_merge_distances();
1291  brows=r.vlen;
1292  radi=SG_MALLOC(float64_t, brows);
1293  memcpy(radi, r.vector, sizeof(float64_t)*brows);
1294 
1295  SGMatrix<int32_t> p=clustering->get_cluster_pairs();
1296  rows=p.num_rows;
1297  cols=p.num_cols;
1298  centers=SG_MALLOC(float64_t, rows*cols);
1299  for (int32_t i=0; i<rows*cols; i++)
1300  centers[i]=(float64_t) p.matrix[i];
1301 
1302  break;
1303  }
1304 
1305  default:
1306  SG_ERROR("internal error - unknown clustering type\n")
1307  }
1308 
1309  return true;
1310 }
1311 
1313  float64_t* &weights, int32_t& rows, int32_t& cols, float64_t*& bias,
1314  int32_t& brows, int32_t& bcols)
1315 {
1317 
1318  if (!linear)
1319  return false;
1320 
1321  bias=SG_MALLOC(float64_t, 1);
1322  *bias=linear->get_bias();
1323  brows=1;
1324  bcols=1;
1325 
1326  SGVector<float64_t> w=linear->get_w();
1327  cols=1;
1328  rows=w.vlen;
1329 
1330  weights= SG_MALLOC(float64_t, w.vlen);
1331  memcpy(weights, w.vector, sizeof(float64_t)*w.vlen);
1332 
1333  return true;
1334 }
1335 
1337 {
1338  CFeatures* trainfeatures=ui->ui_features->get_train_features();
1339  CFeatures* testfeatures=ui->ui_features->get_test_features();
1340 
1341  if (!classifier)
1342  {
1343  SG_ERROR("no kernelmachine available\n")
1344  return NULL;
1345  }
1346  if (!trainfeatures)
1347  {
1348  SG_ERROR("no training features available\n")
1349  return NULL;
1350  }
1351 
1352  if (!testfeatures)
1353  {
1354  SG_ERROR("no test features available\n")
1355  return NULL;
1356  }
1357 
1358  bool success=ui->ui_distance->init_distance("TEST");
1359 
1360  if (!success || !ui->ui_distance->is_initialized())
1361  {
1362  SG_ERROR("distance not initialized\n")
1363  return NULL;
1364  }
1365 
1366  ((CDistanceMachine*) classifier)->set_distance(
1367  ui->ui_distance->get_distance());
1368  SG_INFO("starting distance machine testing\n")
1369  return classifier->apply();
1370 }
1371 
1372 
1374 {
1375  CFeatures* testfeatures=ui->ui_features->get_test_features();
1376 
1377  if (!classifier)
1378  {
1379  SG_ERROR("no classifier available\n")
1380  return NULL;
1381  }
1382  if (!testfeatures)
1383  {
1384  SG_ERROR("no test features available\n")
1385  return NULL;
1386  }
1387  if (!(testfeatures->has_property(FP_DOT)))
1388  {
1389  SG_ERROR("testfeatures not based on DotFeatures\n")
1390  return NULL;
1391  }
1392 
1393  ((CLinearMachine*) classifier)->set_features((CDotFeatures*) testfeatures);
1394  SG_INFO("starting linear classifier testing\n")
1395  return classifier->apply();
1396 }
1397 
1399 {
1400  CFeatures* testfeatures=ui->ui_features->get_test_features();
1401 
1402  if (!classifier)
1403  {
1404  SG_ERROR("no svm available\n")
1405  return NULL;
1406  }
1407  if (!testfeatures)
1408  {
1409  SG_ERROR("no test features available\n")
1410  return NULL;
1411  }
1412  if (testfeatures->get_feature_class() != C_STRING ||
1413  testfeatures->get_feature_type() != F_BYTE )
1414  {
1415  SG_ERROR("testfeatures not of class STRING type BYTE\n")
1416  return NULL;
1417  }
1418 
1419  ((CWDSVMOcas*) classifier)->set_features((CStringFeatures<uint8_t>*) testfeatures);
1420  SG_INFO("starting linear classifier testing\n")
1421  return classifier->apply();
1422 }
1423 
1425 {
1426  CFeatures* trainfeatures=ui->ui_features->get_train_features();
1427  CFeatures* testfeatures=ui->ui_features->get_test_features();
1428 
1429  if (!classifier)
1430  {
1431  SG_ERROR("no svm available\n")
1432  return false;
1433  }
1434 
1435  if (!ui->ui_kernel->is_initialized())
1436  {
1437  SG_ERROR("kernel not initialized\n")
1438  return false;
1439  }
1440 
1441  if (!ui->ui_kernel->get_kernel() ||
1442  ui->ui_kernel->get_kernel()->get_kernel_type()!=K_CUSTOM)
1443  {
1444  if (!trainfeatures)
1445  {
1446  SG_ERROR("no training features available\n")
1447  return false;
1448  }
1449 
1450  if (!testfeatures)
1451  {
1452  SG_ERROR("no test features available\n")
1453  return false;
1454  }
1455  }
1456 
1457  ((CKernelMachine*) classifier)->set_kernel(
1458  ui->ui_kernel->get_kernel());
1459 
1460  result=((CKernelMachine*)classifier)->apply_one(idx);
1461  return true ;
1462 }
1463 
1464 
1466 {
1467 #ifdef HAVE_LAPACK
1468  krr_tau=tau;
1469  ((CKernelRidgeRegression*) classifier)->set_tau(krr_tau);
1470  SG_INFO("Set to krr_tau=%f.\n", krr_tau)
1471 
1472  return true;
1473 #else
1474  return false;
1475 #endif
1476 }
1477 
1478 bool CGUIClassifier::set_solver(char* solver)
1479 {
1480  ESolverType s=ST_AUTO;
1481 
1482  if (strncmp(solver,"NEWTON", 6)==0)
1483  {
1484  SG_INFO("Using NEWTON solver.\n")
1485  s=ST_NEWTON;
1486  }
1487  else if (strncmp(solver,"DIRECT", 6)==0)
1488  {
1489  SG_INFO("Using DIRECT solver\n")
1490  s=ST_DIRECT;
1491  }
1492  else if (strncmp(solver,"BLOCK_NORM", 9)==0)
1493  {
1494  SG_INFO("Using BLOCK_NORM solver\n")
1495  s=ST_BLOCK_NORM;
1496  }
1497  else if (strncmp(solver,"ELASTICNET", 10)==0)
1498  {
1499  SG_INFO("Using ELASTICNET solver\n")
1500  s=ST_ELASTICNET;
1501  }
1502  else if (strncmp(solver,"AUTO", 4)==0)
1503  {
1504  SG_INFO("Automagically determining solver.\n")
1505  s=ST_AUTO;
1506  }
1507 #ifdef USE_CPLEX
1508  else if (strncmp(solver, "CPLEX", 5)==0)
1509  {
1510  SG_INFO("USING CPLEX METHOD selected\n")
1511  s=ST_CPLEX;
1512  }
1513 #endif
1514 #ifdef USE_GLPK
1515  else if (strncmp(solver,"GLPK", 4)==0)
1516  {
1517  SG_INFO("Using GLPK solver\n")
1518  s=ST_GLPK;
1519  }
1520 #endif
1521  else
1522  SG_ERROR("Unknown solver type, %s (not compiled in?)\n", solver)
1523 
1524 
1525  solver_type=s;
1526  return true;
1527 }
1528 
1530 {
1531  if (strcmp(name,"LIBSVM_ONECLASS")==0)
1532  {
1535  SG_INFO("created SVMlibsvm object for oneclass\n")
1536  }
1537  else if (strcmp(name,"LIBSVM_NU")==0)
1538  {
1540  constraint_generator= new CLibSVM(LIBSVM_NU_SVC);
1541  SG_INFO("created SVMlibsvm object\n")
1542  }
1543  else if (strcmp(name,"LIBSVM")==0)
1544  {
1547  SG_INFO("created SVMlibsvm object\n")
1548  }
1549 
1550  else if (strcmp(name,"GPBTSVM")==0)
1551  {
1554  SG_INFO("created GPBT-SVM object\n")
1555  }
1556  else if (strcmp(name,"MPDSVM")==0)
1557  {
1560  SG_INFO("created MPD-SVM object\n")
1561  }
1562  else if (strcmp(name,"GNPPSVM")==0)
1563  {
1566  SG_INFO("created GNPP-SVM object\n")
1567  }
1568  else if (strcmp(name,"LIBSVR")==0)
1569  {
1572  SG_INFO("created SVRlibsvm object\n")
1573  }
1574  else
1575  {
1576  SG_ERROR("Unknown SV-classifier %s.\n", name)
1577  return false;
1578  }
1580 
1581  return (constraint_generator!=NULL);
1582 }
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:179
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:119
void set_max_train_time(float64_t t)
Definition: Machine.cpp:90
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:261
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:42
static char * skip_spaces(char *str)
Definition: SGIO.cpp:258
SGVector< float64_t > get_merge_distances()
class WDSVMOcas
Definition: WDSVMOcas.h:28
Class Distance, a base class for all the distances used in the Shogun toolbox.
Definition: Distance.h:83
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:30
The class Labels models labels, i.e. class assignments of objects.
Definition: Labels.h:43
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:24
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:95
#define SG_ERROR(...)
Definition: SGIO.h:130
#define REQUIRE(x,...)
Definition: SGIO.h:207
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:52
Multiple Kernel Learning for one-class-classification.
Definition: MKLOneClass.h:27
Agglomerative hierarchical single linkage clustering.
Definition: Hierarchical.h:39
Features that support dot products among other operations.
Definition: DotFeatures.h:44
virtual int32_t get_num_vec_lhs()
Definition: Kernel.h:513
class LibSVMMultiClass. Does one vs one classification.
Multiple Kernel Learning for regression.
Definition: MKLRegression.h:27
Class LDA implements regularized Linear Discriminant Analysis.
Definition: LDA.h:90
A generic DistanceMachine interface.
virtual void set_mkl_norm(float64_t norm)
class LibSVMOneClass
void set_nu(float64_t nue)
Definition: SVM.h:107
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:35
static const float64_t epsilon
Definition: libbmrm.cpp:24
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:202
SGVector< float64_t > get_radiuses()
Definition: KMeans.cpp:365
Class SGObject is the base class of all shogun objects.
Definition: SGObject.h:98
void set_constraint_generator(CSVM *s)
Definition: MKL.h:112
class MultiClassSVM
Definition: MulticlassSVM.h:28
void set_batch_computation_enabled(bool enable)
KMeans clustering, partitions the data into k (a-priori specified) clusters.
Definition: KMeans.h:50
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:50
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:320
This class provides an interface to the LibLinear library for large- scale linear learning focusing o...
Definition: LibLinear.h:61
#define SG_REF(x)
Definition: SGRefObject.h:34
bool set_mkl_interleaved_enabled(bool enabled)
class SVMSGD
Definition: SVMSGD.h:36
Multiple Kernel Learning for two-class-classification.
void set_qpsize(int32_t qps)
Definition: SVM.h:143
L2 regularized SVM with L2-loss using dual coordinate descent.
Definition: LibLinear.h:30
index_t num_rows
Definition: SGMatrix.h:298
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:57
Class LinearMachine is a generic interface for all kinds of linear machines like classifiers.
Definition: LinearMachine.h:64
Multiple Kernel Learning.
Definition: MKL.h:95
index_t num_cols
Definition: SGMatrix.h:300
bool set_svm_bias_enabled(bool enabled)
virtual EMachineType get_classifier_type()
Definition: Machine.cpp:100
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:24
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:72
Class Perceptron implements the standard linear (online) perceptron.
Definition: Perceptron.h:32
ScatterSVM - Multiclass SVM.
Definition: ScatterSVM.h:50
#define SG_DEBUG(...)
Definition: SGIO.h:108
Class GMNPSVM implements a one vs. rest MultiClass SVM.
Definition: GMNPSVM.h:26
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:68
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:47
void set_mkl_epsilon(float64_t eps)
A generic Support Vector Machine Interface.
Definition: SVM.h:49
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:309
The Kernel base class.
Definition: Kernel.h:153
void set_bias_enabled(bool enable_bias)
class SVMOcas
Definition: SVMOcas.h:34
CLabels * classify_byte_linear()
void set_epsilon(float64_t eps)
Definition: SVM.h:125
L2 regularized linear SVM with L1-loss using dual coordinate descent.
Definition: LibLinear.h:35
class GNPPSVM
Definition: GNPPSVM.h:21
void set_kernel(CKernel *k)
bool has_property(EFeatureProperty p) const
Definition: Features.cpp:292
virtual bool has_features()
Definition: Kernel.h:531
virtual void set_labels(CLabels *lab)
Definition: Machine.cpp:73
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:105
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:118
index_t vlen
Definition: SGVector.h:707
bool set_max_train_time(float64_t max)
void set_tube_epsilon(float64_t eps)
Definition: SVM.h:131
SGMatrix< float64_t > get_cluster_centers()
Definition: KMeans.cpp:370
virtual CLabels * apply(CFeatures *data=NULL)
Definition: Machine.cpp:160

SHOGUN Machine Learning Toolbox - Documentation