LTI-Lib latest version v1.9 - last update 10 Apr 2010

ltiBagging.h

00001 /*
00002  * Copyright (C) 2003, 2004, 2005, 2006
00003  * Lehrstuhl fuer Technische Informatik, RWTH-Aachen, Germany
00004  *
00005  * This file is part of the LTI-Computer Vision Library (LTI-Lib)
00006  *
00007  * The LTI-Lib is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public License (LGPL)
00009  * as published by the Free Software Foundation; either version 2.1 of
00010  * the License, or (at your option) any later version.
00011  *
00012  * The LTI-Lib is distributed in the hope that it will be
00013  * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
00014  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with the LTI-Lib; see the file LICENSE.  If
00019  * not, write to the Free Software Foundation, Inc., 59 Temple Place -
00020  * Suite 330, Boston, MA 02111-1307, USA.
00021  */
00022 
00023 
00024 /*--------------------------------------------------------------------
00025  * project ....: LTI-Lib: Image Processing and Computer Vision Library
00026  * file .......: ltiBagging.h
00027  * authors ....: Jens Paustenbach
00028  * organization: LTI, RWTH Aachen
00029  * creation ...: 24.2.2003
00030  * revisions ..: $Id: ltiBagging.h,v 1.6 2006/02/07 18:11:49 ltilib Exp $
00031  */
00032 
00033 #ifndef _LTI_BAGGING_H_
00034 #define _LTI_BAGGING_H_
00035 
00036 #include "ltiClassifier.h"
00037 #include "ltiMatrix.h"
00038 #include "ltiCombination.h"
00039 #include "ltiSupervisedInstanceClassifier.h"
00040 
00041 #include "ltiSupervisedInstanceClassifierFactory.h"
00042 
00043 namespace lti {
00044   /**
00045    * Implementation of bagging classification.
00046    * For the bagging a set of classifiers, the ensemble, is trained with
00047    * randomly drawn subsets of the training data. For classication 
00048    * each classifier in the ensemble is classifies the data and the 
00049    * different results of each classifier are combined to a single result.
00050    */
00051   class bagging : public classifier {
00052   public:
00053     /**
00054      * the parameters for the class bagging
00055      */
00056     class parameters : public classifier::parameters {
00057     public:
00058 
00059 //         enum eClassifiers {
00060 //             ManualCrispDecisionTree=0,
00061 //             Lvq,
00062 //             MLP,
00063 //             Rbf,
00064 //             ShClassifier,
00065 //             Svm
00066 //         };
00067 
00068       /**
00069        * default constructor
00070        */
00071       parameters();
00072 
00073       /**
00074        * copy constructor
00075        * @param other the parameters object to be copied
00076        */
00077       parameters(const parameters& other);
00078 
00079       /**
00080        * destructor
00081        */
00082       ~parameters();
00083 
00084       /**
00085        * returns name of this type
00086        */
00087       const char* getTypeName() const;
00088 
00089       /**
00090        * copy the contents of a parameters object
00091        * @param other the parameters object to be copied
00092        * @return a reference to this parameters object
00093        */
00094       parameters& copy(const parameters& other);
00095 
00096       /**
00097        * copy the contents of a parameters object
00098        * @param other the parameters object to be copied
00099        * @return a reference to this parameters object
00100        */
00101       parameters& operator=(const parameters& other);
00102 
00103 
00104       /**
00105        * returns a pointer to a clone of the parameters
00106        */
00107       virtual classifier::parameters* clone() const;
00108 
00109       /**
00110        * write the parameters in the given ioHandler
00111        * @param handler the ioHandler to be used
00112        * @param complete if true (the default) the enclosing begin/end will
00113        *        be also written, otherwise only the data block will be written.
00114        * @return true if write was successful
00115        */
00116       virtual bool write(ioHandler& handler,const bool complete=true) const;
00117 
00118       /**
00119        * read the parameters from the given ioHandler
00120        * @param handler the ioHandler to be used
00121        * @param complete if true (the default) the enclosing begin/end will
00122        *        be also written, otherwise only the data block will be written.
00123        * @return true if write was successful
00124        */
00125       virtual bool read(ioHandler& handler,const bool complete=true);
00126 
00127 #     ifdef _LTI_MSC_6
00128       /**
00129        * this function is required by MSVC only, as a workaround for a
00130        * very awful bug, which exists since MSVC V.4.0, and still by
00131        * V.6.0 with all bugfixes (so called "service packs") remains
00132        * there...  This method is also public due to another bug, so please
00133        * NEVER EVER call this method directly: use read() instead
00134        */
00135       bool readMS(ioHandler& handler,const bool complete=true);
00136 
00137       /**
00138        * this function is required by MSVC only, as a workaround for a
00139        * very awful bug, which exists since MSVC V.4.0, and still by
00140        * V.6.0 with all bugfixes (so called "service packs") remains
00141        * there...  This method is also public due to another bug, so please
00142        * NEVER EVER call this method directly: use write() instead
00143        */
00144       bool writeMS(ioHandler& handler,const bool complete=true) const;
00145 #     endif
00146 
00147       // ------------------------------------------------
00148       // the parameters
00149       // ------------------------------------------------
00150 
00151       /**
00152        * number of classifiers in the ensemble
00153        */
00154       int nbClassifiers;
00155 
00156       /**
00157        * number of elements in each ensemble
00158        */
00159       int nbTrainingVectors;
00160 
00161       /**
00162        * The classifier that is used for building the ensemble
00163        */
00164       std::string useClassifier;
00165 
00166       /**
00167        * The classifier that is used for building the ensemble
00168        */
00169       supervisedInstanceClassifier::parameters *classifierParam;
00170 
00171       /**
00172        * The parameter object for the combine object that is used for
00173        * aggregating.
00174        */
00175       combination::parameters combineParam;
00176 
00177 
00178     };
00179 
00180     /**
00181      * default constructor
00182      */
00183     bagging();
00184 
00185     /**
00186      * Construct a classifier using the given parameters
00187      */
00188     bagging(const parameters& par);
00189 
00190     /**
00191      * copy constructor
00192      * @param other the object to be copied
00193      */
00194     bagging(const bagging& other);
00195 
00196     /**
00197      * destructor
00198      */
00199     virtual ~bagging();
00200 
00201     /**
00202      * returns the name of this type ("bagging")
00203      */
00204     virtual const char* getTypeName() const;
00205 
00206     /**
00207      * training of the ensembles
00208      */ 
00209     bool train(const dmatrix& input, const ivector& ids);
00210 
00211     /**
00212      * classification and aggregating
00213      */ 
00214     bool classify(const dvector& feature,
00215                   classifier::outputVector& result) const;
00216 
00217     /**
00218      * copy data of "other" classifier.
00219      * @param other the classifier to be copied
00220      * @return a reference to this classifier object
00221      */
00222     bagging& copy(const bagging& other);
00223 
00224     /**
00225      * alias for copy member
00226      * @param other the classifier to be copied
00227      * @return a reference to this classifier object
00228      */
00229     bagging& operator=(const bagging& other);
00230 
00231     /**
00232      * returns a pointer to a clone of this classifier.
00233      */
00234     virtual classifier* clone() const;
00235 
00236     /**
00237      * returns used parameters
00238      */
00239     const parameters& getParameters() const;
00240 
00241     /**
00242      * read the bagging classifier from the given ioHandler
00243      */
00244     bool read(ioHandler& handler,const bool complete=true);
00245 
00246     /**
00247      * write to bagging classifier object to the given ioHandler
00248      */
00249     bool write(ioHandler& handler,const bool complete=true) const;
00250 
00251   protected: 
00252 
00253     /** 
00254      * list that collects all classifiers that are trained with different
00255      * training data sets.
00256      */
00257    std::list<supervisedInstanceClassifier*> *ensemble;
00258 
00259     /**
00260      * object factory for constructing the classifiers in ensemble
00261      */
00262    supervisedInstanceClassifierFactory factory;
00263 
00264   };
00265 }
00266 
00267 #endif

Generated on Sat Apr 10 15:25:08 2010 for LTI-Lib by Doxygen 1.6.1