File indexing completed on 2025-01-30 10:22:52
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025 #ifndef ROOT_TMVA_GeneticPopulation
0026 #define ROOT_TMVA_GeneticPopulation
0027
0028
0029
0030
0031
0032
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
0078
0079
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;
0095 std::vector<TMVA::GeneticRange*> fRanges;
0096
0097 TRandom3*fRandomGenerator;
0098
0099 mutable MsgLogger* fLogger;
0100 MsgLogger& Log() const { return *fLogger; }
0101
0102 Int_t fPopulationSizeLimit;
0103
0104 ClassDef(GeneticPopulation,0);
0105 };
0106
0107 }
0108
0109 #endif