genericClassifierSelection.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. #ifndef _NICE_OBJREC_GENERICCLASSIFIERSELECTION_INCLUDE
  2. #define _NICE_OBJREC_GENERICCLASSIFIERSELECTION_INCLUDE
  3. //STL
  4. #include <vector>
  5. //core
  6. #include "core/basics/StringTools.h"
  7. //vislearning -- vector classifiers
  8. #include "vislearning/classifier/vclassifier/VCAmitSVM.h"
  9. #include "vislearning/classifier/vclassifier/VCNearestClassMean.h"
  10. #include "vislearning/classifier/vclassifier/VCSimpleGaussian.h"
  11. #include "vislearning/classifier/vclassifier/VCNearestNeighbour.h"
  12. #include "vislearning/classifier/vclassifier/VCCrossGeneralization.h"
  13. #include "vislearning/classifier/classifierinterfaces/VCFeaturePool.h"
  14. #include "vislearning/classifier/vclassifier/VCOneVsOne.h"
  15. #include "vislearning/classifier/vclassifier/VCOneVsAll.h"
  16. #include "vislearning/classifier/vclassifier/VCDTSVM.h"
  17. #include "vislearning/classifier/vclassifier/VCTransform.h"
  18. //vislearning -- kernel classifiers
  19. #include "vislearning/classifier/kernelclassifier/KCGPRegression.h"
  20. #include "vislearning/classifier/kernelclassifier/KCGPLaplace.h"
  21. #include "vislearning/classifier/kernelclassifier/KCGPLaplaceOneVsAll.h"
  22. #include "vislearning/classifier/kernelclassifier/KCOneVsAll.h"
  23. #include "vislearning/classifier/kernelclassifier/KCGPRegOneVsAll.h"
  24. #include "vislearning/classifier/kernelclassifier/KCMinimumEnclosingBall.h"
  25. #include "vislearning/classifier/kernelclassifier/KCGPOneClass.h"
  26. //vislearning -- kernels
  27. #include "vislearning/math/kernels/KernelStd.h"
  28. #include "vislearning/math/kernels/KernelExp.h"
  29. #include "vislearning/math/kernels/KernelRBF.h"
  30. #include "vislearning/math/kernels/genericKernel.h"
  31. //vislearning -- feature pool classifier
  32. #include "vislearning/classifier/fpclassifier/boosting/FPCBoosting.h"
  33. #include "vislearning/classifier/fpclassifier/randomforest/FPCRandomForests.h"
  34. #include "vislearning/classifier/fpclassifier/randomforest/FPCDecisionTree.h"
  35. #include "vislearning/classifier/fpclassifier/logisticregression/FPCSMLR.h"
  36. //vislearning -- classifier combinations
  37. #include "vislearning/classifier/classifiercombination/VCPreRandomForest.h"
  38. //vislearning -- SVM-based classifiers (vclassifier, kernelclassifier)
  39. #ifdef NICE_USELIB_SVMLIGHT
  40. #include "vislearning/classifier/vclassifier/VCSVMLight.h"
  41. #include "vislearning/classifier/vclassifier/VCSVMOneClass.h"
  42. #include "vislearning/classifier/kernelclassifier/KCSVMLight.h"
  43. #endif
  44. //external stuff
  45. #ifdef NICE_USELIB_NICEDTSVM
  46. #include "nice-dtsvm/VCTreeBasedClassifier.h"
  47. #endif
  48. // #include "gp-hik-exp/GPHIKClassifierNICE.h"
  49. namespace OBJREC {
  50. class GenericClassifierSelection
  51. {
  52. public:
  53. static VecClassifier *selectVecClassifier ( const NICE::Config *conf, std::string classifier_type )
  54. {
  55. std::vector<std::string> submatches;
  56. VecClassifier *classifier = NULL;
  57. if ( classifier_type == "amit" ) {
  58. classifier = new VCAmitSVM ( conf );
  59. } else if ( classifier_type == "nn" ) {
  60. classifier = new VCNearestNeighbour( conf, new NICE::EuclidianDistance<double>() );
  61. #ifdef NICE_USELIB_ICE
  62. } else if ( classifier_type == "gauss" ) {
  63. classifier = new VCSimpleGaussian( conf );
  64. } else if ( classifier_type == "nearest_classmean" ) {
  65. classifier = new VCNearestClassMean( conf, new NICE::EuclidianDistance<double>() );
  66. #endif
  67. }
  68. ////////////////////////////////////////
  69. // //
  70. // all Feature Pool Classifiers //
  71. // //
  72. ////////////////////////////////////////
  73. // else if ( classifier_type == "GPHIK" ) {
  74. // FeaturePoolClassifier *fpc = new GPHIKClassifierNICE ( conf, "GPHIK" );
  75. // classifier = new VCFeaturePool ( conf, fpc );
  76. // }
  77. else if ( classifier_type == "random_forest" ) {
  78. FeaturePoolClassifier *fpc = new FPCRandomForests ( conf, "RandomForest" );
  79. classifier = new VCFeaturePool ( conf, fpc );
  80. }
  81. else if ( classifier_type == "sparse_logistic_regression" ) {
  82. FeaturePoolClassifier *fpc = new FPCSMLR ( conf, "SparseLogisticRegression" );
  83. classifier = new VCFeaturePool ( conf, fpc );
  84. } else if ( classifier_type == "boost" ) {
  85. FeaturePoolClassifier *fpc = new FPCBoosting ( conf, "Boost" );
  86. classifier = new VCFeaturePool ( conf, fpc );
  87. } else if ( classifier_type == "decision_tree" ) {
  88. FeaturePoolClassifier *fpc = new FPCDecisionTree ( conf, "DecisionTree" );
  89. classifier = new VCFeaturePool ( conf, fpc );
  90. #ifdef NICE_USELIB_ICE
  91. } else if ( ( classifier_type == "cross_generalization" ) || ( classifier_type == "bart" ) ) {
  92. classifier = new VCCrossGeneralization ( conf );
  93. #endif
  94. #ifdef NICE_USELIB_SVMLIGHT
  95. } else if ( ( classifier_type == "svmlight" ) || ( classifier_type == "svm" ) ) {
  96. classifier = new VCSVMLight ( conf );
  97. } else if ( ( classifier_type == "svm_onevsone" ) ) {
  98. classifier = new VCOneVsOne ( conf, new VCSVMLight ( conf ) );
  99. } else if ( ( classifier_type == "svm_onevsall" ) ) {
  100. classifier = new VCOneVsAll ( conf, new VCSVMLight ( conf ) );
  101. } else if ( ( classifier_type == "svmlight_kernel" ) ) {
  102. classifier = new KCSVMLight ( conf, new KernelStd() );
  103. } else if ( ( classifier_type == "svm_one_class" ) ) {
  104. classifier = new VCSVMOneClass ( conf, "VCSVMLight" );
  105. #endif
  106. #ifdef NICE_USELIB_NICEDTSVM
  107. // this classifier requires nice-dtsvm, which is an optional
  108. // nice sub-library
  109. } else if ( classifier_type == "treebased" ) {
  110. classifier = new VCTreeBasedClassifier ( conf );
  111. #endif
  112. } else if ( ( classifier_type == "dtgp" ) ) {
  113. classifier = new VCDTSVM ( conf );
  114. } else if ( ( classifier_type == "minimum_enclosing_ball" ) ) {
  115. std::string kernel_type = conf->gS ( "Kernel", "kernel_function", "rbf" );
  116. classifier = new KCMinimumEnclosingBall ( conf, GenericKernelSelection::selectKernel ( conf, kernel_type ) );
  117. } else if ( ( classifier_type == "gp_one_class" ) ) {
  118. std::string kernel_type = conf->gS ( "Kernel", "kernel_function", "rbf" );
  119. classifier = new KCGPOneClass ( conf, GenericKernelSelection::selectKernel ( conf, kernel_type ) );
  120. } else if ( ( classifier_type == "gp_regression_rbf" ) ) {
  121. std::string kernel_type = conf->gS ( "Kernel", "kernel_function", "rbf" );
  122. classifier = new KCGPRegression ( conf, GenericKernelSelection::selectKernel ( conf, kernel_type ) );
  123. } else if ( ( classifier_type == "gp_laplace_rbf" ) ) {
  124. std::string kernel_type = conf->gS ( "Kernel", "kernel_function", "rbf" );
  125. classifier = new KCGPLaplace ( conf, GenericKernelSelection::selectKernel ( conf, kernel_type ) );
  126. } else if ( ( classifier_type == "gp_regression_rbf_onevsall" ) ) {
  127. std::string kernel_type = conf->gS ( "Kernel", "kernel_function", "rbf" );
  128. classifier = new KCGPRegOneVsAll ( conf, GenericKernelSelection::selectKernel ( conf, kernel_type ) );
  129. } else if ( ( classifier_type == "gp_laplace_rbf_onevsall" ) ) {
  130. std::string kernel_type = conf->gS ( "Kernel", "kernel_function", "rbf" );
  131. classifier = new KCGPLaplaceOneVsAll ( conf, GenericKernelSelection::selectKernel ( conf, kernel_type ) );
  132. } else if ( NICE::StringTools::regexMatch ( classifier_type, "^one_vs_one\\(([^\\)]+)\\)$", submatches ) && ( submatches.size() == 2 ) ) {
  133. classifier = new VCOneVsOne ( conf, selectVecClassifier ( conf, submatches[1] ) );
  134. } else if ( NICE::StringTools::regexMatch ( classifier_type, "^one_vs_all\\(([^\\)]+)\\)$", submatches ) && ( submatches.size() == 2 ) ) {
  135. classifier = new VCOneVsAll ( conf, selectVecClassifier ( conf, submatches[1] ) );
  136. } else if ( NICE::StringTools::regexMatch ( classifier_type, "^random_forest\\(([^\\)]+)\\)$", submatches ) && ( submatches.size() == 2 ) ) {
  137. classifier = new VCPreRandomForest ( conf, "VCPreRandomForest", selectVecClassifier ( conf, submatches[1] ) );
  138. } else {
  139. fthrow ( NICE::Exception, "Classifier type " << classifier_type << " not (yet) supported." << std::endl <<
  140. "(genericClassifierSelection.h contains a list of classifiers to choose from)" );
  141. }
  142. return classifier;
  143. }
  144. };
  145. }
  146. #endif