ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups 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 #ifndef ROOT_TMVA_IFitterTarget
41 #include "TMVA/IFitterTarget.h"
42 #endif
43 #ifndef ROOT_TMVA_GeneticPopulation
44 #include "TMVA/GeneticPopulation.h"
45 #endif
46 #ifndef ROOT_TMVA_Types
47 #include "TMVA/Types.h"
48 #endif
49 
50 namespace TMVA {
51 
52  class IFitterTarget;
53  class Interval;
54  class MsgLogger;
55 
57 
58  public:
59 
60  GeneticAlgorithm( IFitterTarget& target, Int_t populationSize,
61  const std::vector<TMVA::Interval*>& ranges, UInt_t seed = 0 );
62  virtual ~GeneticAlgorithm();
63 
64  void Init();
65 
66  virtual Bool_t HasConverged(Int_t steps = 10, Double_t ratio = 0.1);
67  virtual Double_t SpreadControl(Int_t steps, Int_t ofSteps,
68  Double_t factor);
69  virtual Double_t NewFitness(Double_t oldValue, Double_t newValue);
70  virtual Double_t CalculateFitness();
71  virtual void Evolution();
72 
74 
75  Double_t GetSpread() const { return fSpread; }
76  void SetSpread(Double_t s) { fSpread = s; }
77 
78  void SetMakeCopies(Bool_t s) { fMakeCopies = s; }
80 
81  Int_t fConvCounter; // converging? ... keeps track of the number of improvements
82 
83  protected:
84 
85  IFitterTarget& fFitterTarget; // the fitter target
86 
87  Double_t fConvValue; // keeps track of the quantity of improvement
88 
89  // spread-control (stepsize)
90  // successList keeps track of the improvements to be able
91 
92  std::deque<Int_t> fSuccessList; // to adjust the stepSize
93  Double_t fLastResult; // remembers the last obtained result (for internal use)
94 
95  Double_t fSpread; // regulates the spread of the value change at mutation (sigma)
96  Bool_t fMirror; // new values for mutation are mirror-mapped if outside of constraints
97  Bool_t fFirstTime; // if true its the first time, so no evolution yet
98  Bool_t fMakeCopies; // if true, the population will make copies of the first individuals
99  // avoid for speed performance.
100  Int_t fPopulationSize; // the size of the population
101 
102  const std::vector<TMVA::Interval*>& fRanges; // parameter ranges
103 
104  GeneticPopulation fPopulation; // contains and controls the "individual"
106 
107  mutable MsgLogger* fLogger; // message logger
108  MsgLogger& Log() const { return *fLogger; }
109 
110  ClassDef(GeneticAlgorithm, 0) // Genetic algorithm controller
111  };
112 
113 } // namespace TMVA
114 
115 #endif
MsgLogger & Log() const
virtual Double_t CalculateFitness()
starts the evaluation of the fitness of all different individuals of the population.
GeneticPopulation & GetGeneticPopulation()
virtual Double_t SpreadControl(Int_t steps, Int_t ofSteps, Double_t factor)
this function provides the ability to change the stepSize of a mutation according to the success of t...
GeneticPopulation fPopulation
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const std::vector< TMVA::Interval * > & fRanges
#define ClassDef(name, id)
Definition: Rtypes.h:254
void SetMakeCopies(Bool_t s)
IFitterTarget & fFitterTarget
GeneticAlgorithm(IFitterTarget &target, Int_t populationSize, const std::vector< TMVA::Interval * > &ranges, UInt_t seed=0)
unsigned int UInt_t
Definition: RtypesCore.h:42
double Double_t
Definition: RtypesCore.h:55
std::deque< Int_t > fSuccessList
virtual Bool_t HasConverged(Int_t steps=10, Double_t ratio=0.1)
gives back true if the last "steps" steps have lead to an improvement of the "fitness" of the "indivi...
virtual void Evolution()
this function is called from "init" and controls the evolution of the individuals.
virtual Double_t NewFitness(Double_t oldValue, Double_t newValue)
if the "fitnessFunction" is called multiple times for one set of factors (because i...
Double_t GetSpread() const
void Init()
calls evolution, but if it is not the first time.
void SetSpread(Double_t s)