Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
GeneticPopulation.h
Go to the documentation of this file.
1 // @(#)root/tmva $Id$
2 // Author: Peter Speckmayer
3 
4 /**********************************************************************************
5  * Project: TMVA - a Root-integrated toolkit for multivariate data analysis *
6  * Package: TMVA *
7  * Class : GeneticPopulation *
8  * Web : http://tmva.sourceforge.net *
9  * *
10  * Description: *
11  * Population definition for genetic algorithm *
12  * *
13  * Authors (alphabetical): *
14  * Peter Speckmayer <speckmay@mail.cern.ch> - CERN, Switzerland *
15  * *
16  * Copyright (c) 2005: *
17  * CERN, Switzerland *
18  * MPI-K Heidelberg, Germany *
19  * *
20  * Redistribution and use in source and binary forms, with or without *
21  * modification, are permitted according to the terms listed in LICENSE *
22  * (http://tmva.sourceforge.net/LICENSE) *
23  **********************************************************************************/
24 
25 #ifndef ROOT_TMVA_GeneticPopulation
26 #define ROOT_TMVA_GeneticPopulation
27 
28 //////////////////////////////////////////////////////////////////////////
29 // //
30 // GeneticPopulation //
31 // //
32 // Population definition for genetic algorithm //
33 // //
34 //////////////////////////////////////////////////////////////////////////
35 
36 #include <string>
37 #include <vector>
38 
39 #include "TMVA/GeneticGenes.h"
40 #include "TMVA/Interval.h"
41 #include "TMVA/GeneticRange.h"
42 
43 class TH1F;
44 
45 namespace TMVA {
46 
47  class MsgLogger;
48 
49  class GeneticPopulation {
50 
51  public:
52 
53  GeneticPopulation(const std::vector<TMVA::Interval*>& ranges, Int_t size, UInt_t seed = 0);
54  virtual ~GeneticPopulation();
55 
56  void SetRandomSeed( UInt_t seed = 0);
57 
58  void MakeChildren();
59  void Mutate( Double_t probability = 20, Int_t startIndex = 0, Bool_t near = kFALSE,
60  Double_t spread = 0.1, Bool_t mirror = kFALSE );
61 
62  GeneticGenes* GetGenes( Int_t index );
63  Int_t GetPopulationSize() const { return fGenePool.size(); }
64  Double_t GetFitness() const { return fGenePool.size()>0? fGenePool[0].GetFitness() : 0; }
65 
66  const std::vector<TMVA::GeneticGenes>& GetGenePool() const { return fGenePool; }
67  const std::vector<TMVA::GeneticRange*>& GetRanges() const { return fRanges; }
68 
69  std::vector<TMVA::GeneticGenes>& GetGenePool() { return fGenePool; }
70  std::vector<TMVA::GeneticRange*>& GetRanges() { return fRanges; }
71 
72  void Print( Int_t untilIndex = -1 );
73  void Print( std::ostream & out, Int_t utilIndex = -1 );
74 
75  TH1F* VariableDistribution( Int_t varNumber, Int_t bins, Int_t min, Int_t max );
76  std::vector< Double_t > VariableDistribution( Int_t varNumber );
77 
78  // To keep compatibility: These methods might be reimplemented
79  // or just eliminated later on. They are used by the
80  // GeneticFitter class.
81 
82  void MakeCopies( int number );
83  void NextGeneration() {}
84  void AddPopulation( GeneticPopulation *strangers );
85  void AddPopulation( GeneticPopulation &strangers );
86  void TrimPopulation();
87  void GiveHint( std::vector< Double_t >& hint, Double_t fitness = 0 );
88  void Sort();
89 
90  private:
91  GeneticGenes MakeSex( GeneticGenes male, GeneticGenes female );
92 
93  private:
94 
95  std::vector<TMVA::GeneticGenes> fGenePool; // the "genePool" where the individuals of the current generation are stored
96  std::vector<TMVA::GeneticRange*> fRanges; // contains the ranges inbetween the values of the coefficients have to be
97 
98  TRandom3*fRandomGenerator; // random Generator for this population
99 
100  mutable MsgLogger* fLogger; // message logger
101  MsgLogger& Log() const { return *fLogger; }
102 
103  Int_t fPopulationSizeLimit;
104 
105  ClassDef(GeneticPopulation,0); //Population definition for genetic algorithm
106  };
107 
108 } // namespace TMVA
109 
110 #endif