123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- #ifndef _NICE_OBJREC_GENERICCLASSIFIERSELECTION_INCLUDE
- #define _NICE_OBJREC_GENERICCLASSIFIERSELECTION_INCLUDE
- #include "core/basics/StringTools.h"
- #include "vislearning/classifier/vclassifier/VCAmitSVM.h"
- #include "vislearning/classifier/vclassifier/VCSimpleGaussian.h"
- #include "vislearning/classifier/vclassifier/VCNearestNeighbour.h"
- #include "vislearning/classifier/vclassifier/VCCrossGeneralization.h"
- #include "vislearning/classifier/classifierinterfaces/VCFeaturePool.h"
- #include "vislearning/classifier/vclassifier/VCOneVsOne.h"
- #include "vislearning/classifier/vclassifier/VCOneVsAll.h"
- #include "vislearning/classifier/vclassifier/VCDTSVM.h"
- #ifdef NICE_USELIB_SVMLIGHT
- #include "vislearning/classifier/vclassifier/VCSVMLight.h"
- #include "vislearning/classifier/kernelclassifier/KCSVMLight.h"
- #include "vislearning/classifier/vclassifier/VCSVMOneClass.h"
- #endif
- #ifdef NICE_USELIB_NICEDTSVM
- #include "nice-dtsvm/VCTreeBasedClassifier.h"
- #endif
- #include "vislearning/classifier/kernelclassifier/KCGPRegression.h"
- #include "vislearning/classifier/kernelclassifier/KCGPLaplace.h"
- #include "vislearning/classifier/kernelclassifier/KCGPLaplaceOneVsAll.h"
- #include "vislearning/classifier/kernelclassifier/KCOneVsAll.h"
- #include "vislearning/classifier/kernelclassifier/KCGPRegOneVsAll.h"
- #include "vislearning/classifier/kernelclassifier/KCMinimumEnclosingBall.h"
- #include "vislearning/classifier/kernelclassifier/KCGPOneClass.h"
- #include "vislearning/math/kernels/KernelStd.h"
- #include "vislearning/math/kernels/KernelExp.h"
- #include "vislearning/math/kernels/KernelRBF.h"
- #include "vislearning/classifier/vclassifier/VCTransform.h"
- #include "vislearning/classifier/fpclassifier/boosting/FPCBoosting.h"
- #include "vislearning/classifier/fpclassifier/randomforest/FPCRandomForests.h"
- #include "vislearning/classifier/fpclassifier/randomforest/FPCDecisionTree.h"
- #include "vislearning/classifier/fpclassifier/logisticregression/FPCSMLR.h"
- #include "vislearning/classifier/classifiercombination/VCPreRandomForest.h"
- #include "vislearning/math/kernels/genericKernel.h"
- #include <vector>
- namespace OBJREC {
- class GenericClassifierSelection
- {
- public:
- static VecClassifier *selectVecClassifier ( const NICE::Config *conf, std::string classifier_type )
- {
- std::vector<std::string> submatches;
- VecClassifier *classifier = NULL;
- if ( classifier_type == "amit" ) {
- classifier = new VCAmitSVM ( conf );
- } else if ( classifier_type == "nn" ) {
- classifier = new VCNearestNeighbour( conf, new NICE::EuclidianDistance<double>() );
- #ifdef NICE_USELIB_ICE
- } else if ( classifier_type == "gauss" ) {
- classifier = new VCSimpleGaussian( conf );
- #endif
- } else if ( classifier_type == "random_forest" ) {
- FeaturePoolClassifier *fpc = new FPCRandomForests ( conf, "RandomForest" );
- classifier = new VCFeaturePool ( conf, fpc );
-
- } else if ( classifier_type == "sparse_logistic_regression" ) {
- FeaturePoolClassifier *fpc = new FPCSMLR ( conf, "SparseLogisticRegression" );
- classifier = new VCFeaturePool ( conf, fpc );
-
- } else if ( classifier_type == "boost" ) {
- FeaturePoolClassifier *fpc = new FPCBoosting ( conf, "Boost" );
- classifier = new VCFeaturePool ( conf, fpc );
-
- } else if ( classifier_type == "decision_tree" ) {
- FeaturePoolClassifier *fpc = new FPCDecisionTree ( conf, "DecisionTree" );
- classifier = new VCFeaturePool ( conf, fpc );
- #ifdef NICE_USELIB_ICE
- } else if ( (classifier_type == "cross_generalization") || (classifier_type == "bart") ) {
- classifier = new VCCrossGeneralization ( conf );
- #endif
- #ifdef NICE_USELIB_SVMLIGHT
- } else if ( (classifier_type == "svmlight") || (classifier_type == "svm") ) {
- classifier = new VCSVMLight ( conf );
- } else if ( (classifier_type == "svm_onevsone") ) {
- classifier = new VCOneVsOne ( conf, new VCSVMLight(conf) );
- } else if ( (classifier_type == "svm_onevsall") ) {
- classifier = new VCOneVsAll ( conf, new VCSVMLight(conf) );
- } else if ( (classifier_type == "svmlight_kernel")) {
- classifier = new KCSVMLight ( conf, new KernelStd() );
- } else if ( (classifier_type == "svm_one_class")) {
- classifier = new VCSVMOneClass( conf, "VCSVMLight" );
- #endif
- #ifdef NICE_USELIB_NICEDTSVM
- // this classifier requires nice-dtsvm, which is an optional
- // nice sub-library
- } else if ( classifier_type == "treebased" ) {
- classifier = new VCTreeBasedClassifier ( conf );
- #endif
- } else if ( (classifier_type == "dtgp") ) {
- classifier = new VCDTSVM ( conf );
- } else if ( (classifier_type == "minimum_enclosing_ball")) {
- string kernel_type = conf->gS("Kernel", "kernel_function", "rbf" );
- classifier = new KCMinimumEnclosingBall ( conf, GenericKernelSelection::selectKernel ( conf, kernel_type ) );
- } else if ( (classifier_type == "gp_one_class")) {
- string kernel_type = conf->gS("Kernel", "kernel_function", "rbf" );
- classifier = new KCGPOneClass ( conf, GenericKernelSelection::selectKernel ( conf, kernel_type ) );
- } else if ( (classifier_type == "gp_regression_rbf")) {
- string kernel_type = conf->gS("Kernel", "kernel_function", "rbf" );
- classifier = new KCGPRegression ( conf, GenericKernelSelection::selectKernel ( conf, kernel_type ) );
- } else if ( (classifier_type == "gp_laplace_rbf")) {
- string kernel_type = conf->gS("Kernel", "kernel_function", "rbf" );
- classifier = new KCGPLaplace ( conf, GenericKernelSelection::selectKernel ( conf, kernel_type ) );
- } else if ( (classifier_type == "gp_regression_rbf_onevsall" ) ) {
- string kernel_type = conf->gS("Kernel", "kernel_function", "rbf" );
- classifier = new KCGPRegOneVsAll ( conf, GenericKernelSelection::selectKernel ( conf, kernel_type ) );
- } else if ( (classifier_type == "gp_laplace_rbf_onevsall" ) ) {
- string kernel_type = conf->gS("Kernel", "kernel_function", "rbf" );
- classifier = new KCGPLaplaceOneVsAll ( conf, GenericKernelSelection::selectKernel ( conf, kernel_type ) );
- } else if ( StringTools::regexMatch ( classifier_type, "^one_vs_one\\(([^\\)]+)\\)$", submatches ) && (submatches.size() == 2)) {
- classifier = new VCOneVsOne ( conf, selectVecClassifier( conf, submatches[1] ) );
- } else if ( StringTools::regexMatch ( classifier_type, "^one_vs_all\\(([^\\)]+)\\)$", submatches ) && (submatches.size() == 2)) {
- classifier = new VCOneVsAll ( conf, selectVecClassifier( conf, submatches[1] ) );
- } else if ( StringTools::regexMatch ( classifier_type, "^random_forest\\(([^\\)]+)\\)$", submatches ) && (submatches.size() == 2)) {
- classifier = new VCPreRandomForest ( conf, "VCPreRandomForest", selectVecClassifier(conf, submatches[1] ) );
- } else {
- fthrow ( Exception, "Classifier type " << classifier_type << " not (yet) supported." << endl <<
- "(genericClassifierSelection.h contains a list of classifiers to choose from)");
- }
- return classifier;
- }
- };
- }
- #endif
|