Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 10:22:52

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  : GeneticPopulation                                                     *
0008  *                                             *
0009  *                                                                                *
0010  * Description:                                                                   *
0011  *    Population 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_GeneticPopulation
0026 #define ROOT_TMVA_GeneticPopulation
0027 
0028 //////////////////////////////////////////////////////////////////////////
0029 //                                                                      //
0030 // GeneticPopulation                                                    //
0031 //                                                                      //
0032 // Population definition for genetic algorithm                          //
0033 //                                                                      //
0034 //////////////////////////////////////////////////////////////////////////
0035 
0036 #include <vector>
0037 
0038 #include "TMVA/GeneticGenes.h"
0039 #include "TMVA/Interval.h"
0040 #include "TMVA/GeneticRange.h"
0041 
0042 class TH1F;
0043 
0044 namespace TMVA {
0045 
0046    class MsgLogger;
0047 
0048    class GeneticPopulation {
0049 
0050    public:
0051 
0052       GeneticPopulation(const std::vector<TMVA::Interval*>& ranges, Int_t size, UInt_t seed = 0);
0053       virtual ~GeneticPopulation();
0054 
0055       void SetRandomSeed( UInt_t seed = 0);
0056 
0057       void MakeChildren();
0058       void Mutate( Double_t probability = 20, Int_t startIndex = 0, Bool_t near = kFALSE,
0059                    Double_t spread = 0.1, Bool_t mirror = kFALSE  );
0060 
0061       GeneticGenes* GetGenes( Int_t index );
0062       Int_t         GetPopulationSize() const { return fGenePool.size(); }
0063       Double_t      GetFitness() const { return fGenePool.size()>0? fGenePool[0].GetFitness() : 0; }
0064 
0065       const std::vector<TMVA::GeneticGenes>& GetGenePool() const { return fGenePool; }
0066       const std::vector<TMVA::GeneticRange*>& GetRanges() const { return fRanges; }
0067 
0068       std::vector<TMVA::GeneticGenes>&  GetGenePool() { return fGenePool; }
0069       std::vector<TMVA::GeneticRange*>& GetRanges()   { return fRanges; }
0070 
0071       void Print( Int_t untilIndex = -1 );
0072       void Print( std::ostream & out, Int_t utilIndex = -1 );
0073 
0074       TH1F* VariableDistribution( Int_t varNumber, Int_t bins, Int_t min, Int_t max  );
0075       std::vector< Double_t > VariableDistribution( Int_t varNumber );
0076 
0077       // To keep compatibility: These methods might be reimplemented
0078       // or just eliminated later on. They are used by the
0079       // GeneticFitter class.
0080 
0081       void MakeCopies( int number );
0082       void NextGeneration() {}
0083       void AddPopulation( GeneticPopulation *strangers );
0084       void AddPopulation( GeneticPopulation &strangers );
0085       void TrimPopulation();
0086       void GiveHint( std::vector< Double_t >& hint, Double_t fitness = 0 );
0087       void Sort();
0088 
0089    private:
0090       GeneticGenes MakeSex( GeneticGenes male, GeneticGenes female );
0091 
0092    private:
0093 
0094       std::vector<TMVA::GeneticGenes>  fGenePool;    ///< the "genePool" where the individuals of the current generation are stored
0095       std::vector<TMVA::GeneticRange*> fRanges;      ///< contains the ranges in between the values of the coefficients have to be
0096 
0097       TRandom3*fRandomGenerator;    ///< random Generator for this population
0098 
0099       mutable MsgLogger* fLogger;   ///<! message logger
0100       MsgLogger& Log() const { return *fLogger; }
0101 
0102       Int_t fPopulationSizeLimit;
0103 
0104       ClassDef(GeneticPopulation,0); //Population definition for genetic algorithm
0105    };
0106 
0107 } // namespace TMVA
0108 
0109 #endif