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_LIBSVM = 20,
00032     CT_LIBSVMONECLASS=30,
00033     CT_LIBSVMMULTICLASS=40,
00034     CT_MPD = 50,
00035     CT_GPBT = 60,
00036     CT_CPLEXSVM = 70,
00037     CT_PERCEPTRON = 80,
00038     CT_KERNELPERCEPTRON = 90,
00039     CT_LDA = 100,
00040     CT_LPM = 110,
00041     CT_LPBOOST = 120,
00042     CT_KNN = 130,
00043     CT_SVMLIN=140,
00044     CT_KRR = 150,
00045     CT_GNPPSVM = 160,
00046     CT_GMNPSVM = 170,
00047     CT_SUBGRADIENTSVM = 180,
00048     CT_SUBGRADIENTLPM = 190,
00049     CT_SVMPERF = 200,
00050     CT_LIBSVR = 210,
00051     CT_SVRLIGHT = 220,
00052     CT_LIBLINEAR = 230,
00053     CT_KMEANS = 240,
00054     CT_HIERARCHICAL = 250,
00055     CT_SVMOCAS = 260,
00056     CT_WDSVMOCAS = 270,
00057     CT_SVMSGD = 280,
00058     CT_MKLMULTICLASS = 290,
00059     CT_MKLCLASSIFICATION = 300,
00060     CT_MKLONECLASS = 310,
00061     CT_MKLREGRESSION = 320,
00062     CT_SCATTERSVM = 330,
00063     CT_DASVM = 340,
00064     CT_LARANK = 350
00065 };
00066 
00067 enum ESolverType
00068 {
00069     ST_AUTO=0,
00070     ST_CPLEX=1,
00071     ST_GLPK=2,
00072     ST_NEWTON=3,
00073     ST_DIRECT=4
00074 };
00075 
00087 class CClassifier : public CSGObject
00088 {
00089     public:
00091         CClassifier();
00092         virtual ~CClassifier();
00093 
00102         virtual bool train(CFeatures* data=NULL)
00103         {
00104             SG_NOTIMPLEMENTED;
00105             return false;
00106         }
00107 
00112         virtual CLabels* classify()=0;
00113 
00119         virtual CLabels* classify(CFeatures* data)=0;
00120 
00128         virtual float64_t classify_example(int32_t num)
00129         {
00130             SG_NOTIMPLEMENTED;
00131             return CMath::INFTY;
00132         }
00133 
00141         virtual bool load(FILE* srcfile) { ASSERT(srcfile); return false; }
00142 
00150         virtual bool save(FILE* dstfile) { ASSERT(dstfile); return false; }
00151 
00156         virtual inline void set_labels(CLabels* lab)
00157         {
00158             SG_UNREF(labels);
00159             SG_REF(lab);
00160             labels=lab;
00161         }
00162 
00167         virtual inline CLabels* get_labels() { SG_REF(labels); return labels; }
00168 
00174         virtual inline float64_t get_label(int32_t i) { return labels->get_label(i); }
00175 
00180         inline void set_max_train_time(float64_t t) { max_train_time=t; }
00181 
00186         inline float64_t get_max_train_time() { return max_train_time; }
00187 
00192         virtual inline EClassifierType get_classifier_type() { return CT_NONE; }
00193 
00198         inline void set_solver_type(ESolverType st) { solver_type=st; }
00199 
00204         inline ESolverType get_solver_type() { return solver_type; }
00205 
00206 #ifdef HAVE_BOOST_SERIALIZATION
00207     private:
00208 
00209         friend class ::boost::serialization::access;
00210         template<class Archive>
00211             void serialize(Archive & ar, const unsigned int archive_version)
00212             {
00213 
00214                 SG_DEBUG("archiving CClassifier\n");
00215 
00216                 ar & ::boost::serialization::base_object<CSGObject>(*this);
00217                 ar & max_train_time;
00218                 ar & labels;
00219 
00220                 SG_DEBUG("done with CClassifier\n");
00221 
00222             }
00223 #endif //HAVE_BOOST_SERIALIZATION
00224 
00225     protected:
00227         float64_t max_train_time;
00228 
00230         CLabels* labels;
00231 
00233         ESolverType solver_type;
00234 };
00235 }
00236 #endif // _CLASSIFIER_H__

SHOGUN Machine Learning Toolbox - Documentation