GeneticPopulation.h

Go to the documentation of this file.
00001 // @(#)root/tmva $Id: GeneticPopulation.h 31574 2009-12-05 18:23:21Z stelzer $    
00002 // Author: Peter Speckmayer
00003 
00004 /**********************************************************************************
00005  * Project: TMVA - a Root-integrated toolkit for multivariate data analysis       *
00006  * Package: TMVA                                                                  *
00007  * Class  : GeneticPopulation                                                     *
00008  * Web    : http://tmva.sourceforge.net                                           *
00009  *                                                                                *
00010  * Description:                                                                   *
00011  *    Population definition for genetic algorithm                                 *
00012  *                                                                                *
00013  * Authors (alphabetical):                                                        *
00014  *      Peter Speckmayer <speckmay@mail.cern.ch>  - CERN, Switzerland             *
00015  *                                                                                *
00016  * Copyright (c) 2005:                                                            *
00017  *      CERN, Switzerland                                                         * 
00018  *      MPI-K Heidelberg, Germany                                                 * 
00019  *                                                                                *
00020  * Redistribution and use in source and binary forms, with or without             *
00021  * modification, are permitted according to the terms listed in LICENSE           *
00022  * (http://tmva.sourceforge.net/LICENSE)                                          *
00023  **********************************************************************************/
00024 
00025 #ifndef ROOT_TMVA_GeneticPopulation
00026 #define ROOT_TMVA_GeneticPopulation
00027 
00028 //////////////////////////////////////////////////////////////////////////
00029 //                                                                      //
00030 // GeneticPopulation                                                    //
00031 //                                                                      //
00032 // Population definition for genetic algorithm                          //
00033 //                                                                      //
00034 //////////////////////////////////////////////////////////////////////////
00035 
00036 #include <string>
00037 #include <vector>
00038 
00039 #ifndef ROOT_Riosfwd
00040 #include "Riosfwd.h"
00041 #endif
00042 #ifndef ROOT_TMVA_GeneticGenes
00043 #include "TMVA/GeneticGenes.h"
00044 #endif
00045 #ifndef ROOT_TMVA_Interval
00046 #include "TMVA/Interval.h"
00047 #endif
00048 #ifndef ROOT_TMVA_GeneticRange
00049 #include "TMVA/GeneticRange.h"
00050 #endif
00051 
00052 class TH1F;
00053 
00054 namespace TMVA {
00055 
00056    class MsgLogger;
00057 
00058    class GeneticPopulation {
00059 
00060    public:
00061 
00062       GeneticPopulation(const std::vector<TMVA::Interval*>& ranges, Int_t size, UInt_t seed = 0);
00063       virtual ~GeneticPopulation();
00064 
00065       void SetRandomSeed( UInt_t seed = 0);
00066 
00067       void MakeChildren();
00068       void Mutate( Double_t probability = 20, Int_t startIndex = 0, Bool_t near = kFALSE, 
00069                    Double_t spread = 0.1, Bool_t mirror = kFALSE  );
00070 
00071       GeneticGenes* GetGenes( Int_t index );
00072       Int_t         GetPopulationSize() const { return fGenePool.size(); }
00073       Double_t      GetFitness() const { return fGenePool.size()>0? fGenePool[0].GetFitness() : 0; }
00074 
00075       const std::vector<TMVA::GeneticGenes>& GetGenePool() const { return fGenePool; }
00076       const std::vector<TMVA::GeneticRange*>& GetRanges() const { return fRanges; }
00077 
00078       std::vector<TMVA::GeneticGenes>&  GetGenePool() { return fGenePool; }
00079       std::vector<TMVA::GeneticRange*>& GetRanges()   { return fRanges; }
00080 
00081       void Print( Int_t untilIndex = -1 );
00082       void Print( ostream & out, Int_t utilIndex = -1 );
00083 
00084       TH1F* VariableDistribution( Int_t varNumber, Int_t bins, Int_t min, Int_t max  );
00085       std::vector< Double_t > VariableDistribution( Int_t varNumber );
00086 
00087       // To keep compatibility: These methods might be reimplemented
00088       // or just eliminated later on. They are used by the
00089       // GeneticFitter class.
00090      
00091       void MakeCopies( int number );
00092       void NextGeneration() {}
00093       void AddPopulation( GeneticPopulation *strangers );
00094       void AddPopulation( GeneticPopulation &strangers );
00095       void TrimPopulation();
00096       void GiveHint( std::vector< Double_t >& hint, Double_t fitness = 0 );
00097       void Sort();
00098 
00099    private:
00100       GeneticGenes MakeSex( GeneticGenes male, GeneticGenes female );
00101   
00102    private:
00103 
00104       std::vector<TMVA::GeneticGenes>  fGenePool;    // the "genePool" where the individuals of the current generation are stored
00105       std::vector<TMVA::GeneticRange*> fRanges;      // contains the ranges inbetween the values of the coefficients have to be
00106 
00107       TRandom3*fRandomGenerator;    // random Generator for this population
00108 
00109       mutable MsgLogger* fLogger;   // message logger
00110       MsgLogger& Log() const { return *fLogger; }    
00111 
00112       Int_t fPopulationSizeLimit;
00113 
00114       ClassDef(GeneticPopulation,0) //Population definition for genetic algorithm
00115    };
00116 
00117 } // namespace TMVA
00118 
00119 #endif

Generated on Tue Jul 5 14:27:29 2011 for ROOT_528-00b_version by  doxygen 1.5.1