genericClassifierSelection.h 7.1 KB

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