Classifier.h

Go to the documentation of this file.
00001 /*
00002  * This program is free software; you can redistribute it and/or modify
00003  * it under the terms of the GNU General Public License as published by
00004  * the Free Software Foundation; either version 3 of the License, or
00005  * (at your option) any later version.
00006  *
00007  * Written (W) 1999-2009 Soeren Sonnenburg
00008  * Copyright (C) 1999-2009 Fraunhofer Institute FIRST and Max-Planck-Society
00009  */
00010 
00011 #ifndef _CLASSIFIER_H__
00012 #define _CLASSIFIER_H__
00013 
00014 #include "lib/common.h"
00015 #include "base/SGObject.h"
00016 #include "lib/Mathematics.h"
00017 #include "features/Labels.h"
00018 #include "features/Features.h"
00019 
00020 namespace shogun
00021 {
00022 
00023 class CFeatures;
00024 class CLabels;
00025 class CMath;
00026 
00027 enum EClassifierType
00028 {
00029     CT_NONE = 0,
00030     CT_LIGHT = 10,
00031     CT_LIGHTONECLASS = 11,
00032     CT_LIBSVM = 20,
00033     CT_LIBSVMONECLASS=30,
00034     CT_LIBSVMMULTICLASS=40,
00035     CT_MPD = 50,
00036     CT_GPBT = 60,
00037     CT_CPLEXSVM = 70,
00038     CT_PERCEPTRON = 80,
00039     CT_KERNELPERCEPTRON = 90,
00040     CT_LDA = 100,
00041     CT_LPM = 110,
00042     CT_LPBOOST = 120,
00043     CT_KNN = 130,
00044     CT_SVMLIN=140,
00045     CT_KRR = 150,
00046     CT_GNPPSVM = 160,
00047     CT_GMNPSVM = 170,
00048     CT_SUBGRADIENTSVM = 180,
00049     CT_SUBGRADIENTLPM = 190,
00050     CT_SVMPERF = 200,
00051     CT_LIBSVR = 210,
00052     CT_SVRLIGHT = 220,
00053     CT_LIBLINEAR = 230,
00054     CT_KMEANS = 240,
00055     CT_HIERARCHICAL = 250,
00056     CT_SVMOCAS = 260,
00057     CT_WDSVMOCAS = 270,
00058     CT_SVMSGD = 280,
00059     CT_MKLMULTICLASS = 290,
00060     CT_MKLCLASSIFICATION = 300,
00061     CT_MKLONECLASS = 310,
00062     CT_MKLREGRESSION = 320,
00063     CT_SCATTERSVM = 330,
00064     CT_DASVM = 340,
00065     CT_LARANK = 350,
00066     CT_DASVMLINEAR = 360
00067 };
00068 
00069 enum ESolverType
00070 {
00071     ST_AUTO=0,
00072     ST_CPLEX=1,
00073     ST_GLPK=2,
00074     ST_NEWTON=3,
00075     ST_DIRECT=4,
00076     ST_ELASTICNET=5
00077 };
00078 
00090 class CClassifier : public CSGObject
00091 {
00092     public:
00094         CClassifier();
00095         virtual ~CClassifier();
00096 
00105         virtual bool train(CFeatures* data=NULL)
00106         {
00107             SG_NOTIMPLEMENTED;
00108             return false;
00109         }
00110 
00115         virtual CLabels* classify()=0;
00116 
00122         virtual CLabels* classify(CFeatures* data)=0;
00123 
00131         virtual float64_t classify_example(int32_t num)
00132         {
00133             SG_NOTIMPLEMENTED;
00134             return CMath::INFTY;
00135         }
00136 
00144         virtual bool load(FILE* srcfile) { ASSERT(srcfile); return false; }
00145 
00153         virtual bool save(FILE* dstfile) { ASSERT(dstfile); return false; }
00154 
00159         virtual inline void set_labels(CLabels* lab)
00160         {
00161             SG_UNREF(labels);
00162             SG_REF(lab);
00163             labels=lab;
00164         }
00165 
00170         virtual inline CLabels* get_labels() { SG_REF(labels); return labels; }
00171 
00177         virtual inline float64_t get_label(int32_t i)
00178         {
00179             if (!labels)
00180                 SG_ERROR("No Labels assigned\n");
00181 
00182             return labels->get_label(i);
00183         }
00184 
00189         inline void set_max_train_time(float64_t t) { max_train_time=t; }
00190 
00195         inline float64_t get_max_train_time() { return max_train_time; }
00196 
00201         virtual inline EClassifierType get_classifier_type() { return CT_NONE; }
00202 
00207         inline void set_solver_type(ESolverType st) { solver_type=st; }
00208 
00213         inline ESolverType get_solver_type() { return solver_type; }
00214 
00215     protected:
00217         float64_t max_train_time;
00218 
00220         CLabels* labels;
00221 
00223         ESolverType solver_type;
00224 };
00225 }
00226 #endif // _CLASSIFIER_H__
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation