Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
GeneticAlgorithm.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 : GeneticAlgorithm *
8  * Web : http://tmva.sourceforge.net *
9  * *
10  * Description: *
11  * Base 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_GeneticAlgorithm
26 #define ROOT_TMVA_GeneticAlgorithm
27 
28 //////////////////////////////////////////////////////////////////////////
29 // //
30 // GeneticAlgorithm //
31 // //
32 // Base definition for genetic algorithm //
33 // //
34 //////////////////////////////////////////////////////////////////////////
35 
36 #include <vector>
37 #include <deque>
38 #include <iosfwd>
39 
40 #include "TMVA/IFitterTarget.h"
41 #include "TMVA/GeneticPopulation.h"
42 #include "TMVA/Types.h"
43 
44 namespace TMVA {
45 
46  class IFitterTarget;
47  class Interval;
48  class MsgLogger;
49 
50  class GeneticAlgorithm {
51 
52  public:
53 
54  GeneticAlgorithm( IFitterTarget& target, Int_t populationSize,
55  const std::vector<TMVA::Interval*>& ranges, UInt_t seed = 0 );
56  virtual ~GeneticAlgorithm();
57 
58  void Init();
59 
60  virtual Bool_t HasConverged(Int_t steps = 10, Double_t ratio = 0.1);
61  virtual Double_t SpreadControl(Int_t steps, Int_t ofSteps,
62  Double_t factor);
63  virtual Double_t NewFitness(Double_t oldValue, Double_t newValue);
64  virtual Double_t CalculateFitness();
65  virtual void Evolution();
66 
67  GeneticPopulation& GetGeneticPopulation() { return fPopulation; }
68 
69  Double_t GetSpread() const { return fSpread; }
70  void SetSpread(Double_t s) { fSpread = s; }
71 
72  void SetMakeCopies(Bool_t s) { fMakeCopies = s; }
73  Bool_t GetMakeCopies() { return fMakeCopies; }
74 
75  Int_t fConvCounter; // converging? ... keeps track of the number of improvements
76 
77  protected:
78 
79  IFitterTarget& fFitterTarget; // the fitter target
80 
81  Double_t fConvValue; // keeps track of the quantity of improvement
82 
83  // spread-control (stepsize)
84  // successList keeps track of the improvements to be able
85 
86  std::deque<Int_t> fSuccessList; // to adjust the stepSize
87  Double_t fLastResult; // remembers the last obtained result (for internal use)
88 
89  Double_t fSpread; // regulates the spread of the value change at mutation (sigma)
90  Bool_t fMirror; // new values for mutation are mirror-mapped if outside of constraints
91  Bool_t fFirstTime; // if true its the first time, so no evolution yet
92  Bool_t fMakeCopies; // if true, the population will make copies of the first individuals
93  // avoid for speed performance.
94  Int_t fPopulationSize; // the size of the population
95 
96  const std::vector<TMVA::Interval*>& fRanges; // parameter ranges
97 
98  GeneticPopulation fPopulation; // contains and controls the "individual"
99  Double_t fBestFitness;
100 
101  mutable MsgLogger* fLogger; // message logger
102  MsgLogger& Log() const { return *fLogger; }
103 
104  ClassDef(GeneticAlgorithm, 0); // Genetic algorithm controller
105  };
106 
107 } // namespace TMVA
108 
109 #endif