Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:10:59

0001 // @(#)root/tmva $Id$
0002 // Author: Peter Speckmayer
0003 
0004 /**********************************************************************************
0005  * Project: TMVA - a Root-integrated toolkit for multivariate data analysis       *
0006  * Package: TMVA                                                                  *
0007  * Class  : GeneticAlgorithm                                                      *
0008  *                                             *
0009  *                                                                                *
0010  * Description:                                                                   *
0011  *      Base definition for genetic algorithm                                     *
0012  *                                                                                *
0013  * Authors (alphabetical):                                                        *
0014  *      Peter Speckmayer <speckmay@mail.cern.ch>  - CERN, Switzerland             *
0015  *                                                                                *
0016  * Copyright (c) 2005:                                                            *
0017  *      CERN, Switzerland                                                         *
0018  *      MPI-K Heidelberg, Germany                                                 *
0019  *                                                                                *
0020  * Redistribution and use in source and binary forms, with or without             *
0021  * modification, are permitted according to the terms listed in LICENSE           *
0022  * (see tmva/doc/LICENSE)                                          *
0023  **********************************************************************************/
0024 
0025 #ifndef ROOT_TMVA_GeneticAlgorithm
0026 #define ROOT_TMVA_GeneticAlgorithm
0027 
0028 //////////////////////////////////////////////////////////////////////////
0029 //                                                                      //
0030 // GeneticAlgorithm                                                     //
0031 //                                                                      //
0032 // Base definition for genetic algorithm                                //
0033 //                                                                      //
0034 //////////////////////////////////////////////////////////////////////////
0035 
0036 #include <vector>
0037 #include <deque>
0038 #include <iosfwd>
0039 
0040 #include "TMVA/IFitterTarget.h"
0041 #include "TMVA/GeneticPopulation.h"
0042 #include "TMVA/Types.h"
0043 
0044 namespace TMVA {
0045 
0046    class IFitterTarget;
0047    class Interval;
0048    class MsgLogger;
0049 
0050    class GeneticAlgorithm {
0051 
0052    public:
0053 
0054       GeneticAlgorithm( IFitterTarget& target, Int_t populationSize,
0055                         const std::vector<TMVA::Interval*>& ranges, UInt_t seed = 0 );
0056       virtual ~GeneticAlgorithm();
0057 
0058       void Init();
0059 
0060       virtual Bool_t   HasConverged(Int_t steps = 10, Double_t ratio = 0.1);
0061       virtual Double_t SpreadControl(Int_t steps, Int_t ofSteps,
0062                                      Double_t factor);
0063       virtual Double_t NewFitness(Double_t oldValue, Double_t newValue);
0064       virtual Double_t CalculateFitness();
0065       virtual void Evolution();
0066 
0067       GeneticPopulation& GetGeneticPopulation() { return fPopulation; }
0068 
0069       Double_t GetSpread() const { return fSpread; }
0070       void     SetSpread(Double_t s) { fSpread = s; }
0071 
0072       void   SetMakeCopies(Bool_t s) { fMakeCopies = s; }
0073       Bool_t GetMakeCopies() { return fMakeCopies; }
0074 
0075       Int_t    fConvCounter;              // converging? ... keeps track of the number of improvements
0076 
0077    protected:
0078 
0079       IFitterTarget&    fFitterTarget;    // the fitter target
0080 
0081       Double_t fConvValue;                // keeps track of the quantity of improvement
0082 
0083       // spread-control (stepsize)
0084       // successList keeps track of the improvements to be able
0085 
0086       std::deque<Int_t> fSuccessList;     // to adjust the stepSize
0087       Double_t          fLastResult;      // remembers the last obtained result (for internal use)
0088 
0089       Double_t          fSpread;          // regulates the spread of the value change at mutation (sigma)
0090       Bool_t            fMirror;          // new values for mutation are mirror-mapped if outside of constraints
0091       Bool_t            fFirstTime;       // if true its the first time, so no evolution yet
0092       Bool_t            fMakeCopies;      // if true, the population will make copies of the first individuals
0093                                           // avoid for speed performance.
0094       Int_t             fPopulationSize;  // the size of the population
0095 
0096       const std::vector<TMVA::Interval*>& fRanges; // parameter ranges
0097 
0098       GeneticPopulation fPopulation;      // contains and controls the "individual"
0099       Double_t fBestFitness;
0100 
0101       mutable MsgLogger* fLogger;         //! message logger
0102       MsgLogger& Log() const { return *fLogger; }
0103 
0104       ClassDef(GeneticAlgorithm, 0);  // Genetic algorithm controller
0105    };
0106 
0107 } // namespace TMVA
0108 
0109 #endif