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

ltiParetoFrontTester.h

00001 /*
00002  * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003
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 .......: ltiParetoFront.h
00027  * authors ....: Pablo Alvarado
00028  * organization: LTI, RWTH Aachen
00029  * creation ...: 25.11.2003
00030  * revisions ..: $Id: ltiParetoFrontTester.h,v 1.2 2004/05/03 18:50:56 ltilib Exp $
00031  */
00032 
00033 #ifndef _LTI_PARETO_FRONT_TESTER_H_
00034 #define _LTI_PARETO_FRONT_TESTER_H_
00035 
00036 #include "ltiParetoFront.h"
00037 
00038 namespace lti {
00039 
00040   /**
00041    * A dummy functor that is evaluated with the paretoFront
00042    */
00043   class dummyFunctor : public functor {
00044   public:
00045     /**
00046      * The parameters for the class dummyFunctor
00047      */
00048     class parameters : public functor::parameters {
00049     public:
00050       /**
00051        * Default constructor
00052        */
00053       parameters();
00054 
00055       /**
00056        * Copy constructor
00057        * @param other the parameters object to be copied
00058        */
00059       parameters(const parameters& other);
00060 
00061       /**
00062        * Destructor
00063        */
00064       ~parameters();
00065 
00066       /**
00067        * Returns name of this type
00068        */
00069       const char* getTypeName() const;
00070 
00071       /**
00072        * Copy the contents of a parameters object
00073        * @param other the parameters object to be copied
00074        * @return a reference to this parameters object
00075        */
00076       parameters& copy(const parameters& other);
00077 
00078       /**
00079        * Copy the contents of a parameters object
00080        * @param other the parameters object to be copied
00081        * @return a reference to this parameters object
00082        */
00083       parameters& operator=(const parameters& other);
00084 
00085 
00086       /**
00087        * Returns a pointer to a clone of the parameters
00088        */
00089       virtual functor::parameters* clone() const;
00090 
00091       /**
00092        * Write the parameters in the given ioHandler
00093        * @param handler the ioHandler to be used
00094        * @param complete if true (the default) the enclosing begin/end will
00095        *        be also written, otherwise only the data block will be written.
00096        * @return true if write was successful
00097        */
00098       virtual bool write(ioHandler& handler,const bool& complete=true) const;
00099 
00100       /**
00101        * Read the parameters from the given ioHandler
00102        * @param handler the ioHandler to be used
00103        * @param complete if true (the default) the enclosing begin/end will
00104        *        be also written, otherwise only the data block will be written.
00105        * @return true if write was successful
00106        */
00107       virtual bool read(ioHandler& handler,const bool& complete=true);
00108 
00109 #     ifdef _LTI_MSC_6
00110       /**
00111        * This function is required by MSVC only, as a workaround for a
00112        * very awful bug, which exists since MSVC V.4.0, and still by
00113        * V.6.0 with all bugfixes (so called "service packs") remains
00114        * there...  This method is also public due to another bug, so please
00115        * NEVER EVER call this method directly: use read() instead
00116        */
00117       bool readMS(ioHandler& handler,const bool& complete=true);
00118 
00119       /**
00120        * This function is required by MSVC only, as a workaround for a
00121        * very awful bug, which exists since MSVC V.4.0, and still by
00122        * V.6.0 with all bugfixes (so called "service packs") remains
00123        * there...  This method is also public due to another bug, so please
00124        * NEVER EVER call this method directly: use write() instead
00125        */
00126       bool writeMS(ioHandler& handler,const bool& complete=true) const;
00127 #     endif
00128 
00129       // ------------------------------------------------
00130       // the parameters
00131       // ------------------------------------------------
00132 
00133       /**
00134        * The time the functor takes is given by this parameter.
00135        */
00136       float linear;
00137 
00138       /**
00139        * A second quality measure is given by this.
00140        */
00141       float quadratic;
00142 
00143     };
00144 
00145     /**
00146      * Default constructor
00147      */
00148     dummyFunctor();
00149 
00150     /**
00151      * Construct a functor using the given parameters
00152      */
00153     dummyFunctor(const parameters& par);
00154 
00155     /**
00156      * Copy constructor
00157      * @param other the object to be copied
00158      */
00159     dummyFunctor(const dummyFunctor& other);
00160 
00161     /**
00162      * Destructor
00163      */
00164     virtual ~dummyFunctor();
00165 
00166     /**
00167      * Returns the name of this type ("dummyFunctor")
00168      */
00169     virtual const char* getTypeName() const;
00170 
00171     /**
00172      * operates on a copy of the given %parameters.
00173      * @param src double with the source data.
00174      * @param dest double where the result will be left.
00175      * @return true if apply successful or false otherwise.
00176      */
00177     bool apply(const double& src,double& dest) const;
00178 
00179     /**
00180      * Copy data of "other" functor.
00181      * @param other the functor to be copied
00182      * @return a reference to this functor object
00183      */
00184     dummyFunctor& copy(const dummyFunctor& other);
00185 
00186     /**
00187      * Alias for copy member
00188      * @param other the functor to be copied
00189      * @return a reference to this functor object
00190      */
00191     dummyFunctor& operator=(const dummyFunctor& other);
00192 
00193     /**
00194      * Returns a pointer to a clone of this functor.
00195      */
00196     virtual functor* clone() const;
00197 
00198     /**
00199      * Returns used parameters
00200      */
00201     const parameters& getParameters() const;
00202   };
00203   
00204   // -------------------------------------------------------------------------
00205   //
00206   // P A R E T O   T E S T E R
00207   //
00208   // -------------------------------------------------------------------------
00209 
00210 
00211 
00212   /**
00213    * The Pareto Front Tester functor is a simple example of an evaluation
00214    * framework using the Pareto Front class. 
00215    */
00216   class paretoFrontTester : public paretoFront {
00217   public:
00218 
00219     /**
00220      * Default constructor
00221      */
00222     paretoFrontTester();
00223 
00224     /**
00225      * Construct a functor using the given parameters
00226      */
00227     paretoFrontTester(const parameters& par);
00228 
00229     /**
00230      * Copy constructor
00231      * @param other the object to be copied
00232      */
00233     paretoFrontTester(const paretoFrontTester& other);
00234 
00235     /**
00236      * Destructor
00237      */
00238     virtual ~paretoFrontTester();
00239 
00240     /**
00241      * Returns the name of this type ("paretoFrontTester")
00242      */
00243     virtual const char* getTypeName() const;
00244 
00245     /**
00246      * Returns a pointer to a clone of this functor.
00247      */
00248     virtual functor* clone() const;
00249 
00250     /**
00251      * @name Public methods to be reimplemented
00252      */
00253     //@{
00254 
00255     /**
00256      * Convert a binary-chain representation of a chromosome to a valid
00257      * parameter object.
00258      */
00259     virtual bool chromosomeToPhenotype(const chromosome& genotype,
00260                                        functor::parameters& phenotype) const;
00261 
00262     /**
00263      * Return a fresh allocated parameters for the evaluated functor, which is
00264      * equivalent to the given genotype.
00265      */
00266     virtual functor::parameters* 
00267     chromosomeToPhenotype(const chromosome& genotype) const;
00268 
00269     /**
00270      * Convert a valid parameters object (phenotype) into binary-chain
00271      * representation of a chromosome.
00272      */
00273     virtual bool phenotypeToChromosome(const functor::parameters& phenotype,
00274                                        chromosome& genotype) const;
00275 
00276     /**
00277      * Return the length in bits for a chromosome.
00278      *
00279      * This method needs to be reimplemented, in order to get some 
00280      * default implementations to work.
00281      */
00282     virtual int getChromosomeSize() const;
00283 
00284     /**
00285      * Evaluate Chromosome
00286      *
00287      * This method is one of the most important ones for the pareto evaluation.
00288      * Its task is to produce a multidimensional fitness measure for a given
00289      * chromosome.
00290      *
00291      * It returns true if the evaluation was successful, of false if the
00292      * phenotype represents some invalid parameterization.  It is highly 
00293      * recomended that the mutation and crossover methods are reimplemented to 
00294      * avoid invalid parameterizations.
00295      *
00296      * There are mainly two types of fitness measures that can be
00297      * analyzed with this functor of this kind: empirical goodness and
00298      * empirical discrepancy (Zhang).  The empirical goodness computes some
00299      * measure using exclusively the test data, without requiring any ground
00300      * truth.  The empirical discrepancy assumes the existency of ground truth
00301      * and provides as measure some distance between the result of an algorithm
00302      * and the ground truth.  Each class derived from paretoFrontTester should
00303      * specify clearly which kind of fitness measures it provides.
00304      * 
00305      */
00306     virtual bool evaluateChromosome(const chromosome& individual,
00307                                     dvector& fitness); 
00308 
00309     //@}
00310 
00311   protected:
00312     /**
00313      * @name Methods to be reimplemented
00314      */
00315     //@{
00316 
00317     /**
00318      * Generate a random individual.
00319      *
00320      * You usually will need to reimplement this method to ensure that
00321      * the generated random individuals have a valid phenotype, i.e. that
00322      * the chromosome binary representation in "genotype" has an equivalent
00323      * parameter object for the class you are using.
00324      *
00325      * Return true if successful, false otherwise.
00326      */
00327     virtual bool randomIndividual(chromosome& genotype);
00328 
00329     /**
00330      * Mutate the given chromosome.
00331      *
00332      * This should be reimplemented to ensure that the mutation is a 
00333      * valid phenotype.
00334      *
00335      * The default implementation flips the bits with the probability
00336      * given in the parameters.
00337      */
00338     virtual bool mutate(const chromosome& parent,
00339                         chromosome& mutant);
00340 
00341     /**
00342      * Crossover between two chromosomes.
00343      * 
00344      * This should be reimplemented to ensure that the crossover produces a 
00345      * valid phenotype.
00346      *
00347      * The default implementation does a so called uniform crossover, in
00348      * which each pair of corresponding bits are exchanged with a 
00349      * probability of 0.5.
00350      */
00351     virtual bool crossover(const chromosome& parent1,
00352                            const chromosome& parent2,
00353                            chromosome& child);
00354 
00355     //@}
00356 
00357   };
00358 }
00359 
00360 #endif
00361 

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