Logo ROOT   6.16/01
Reference Guide
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"
42#include "TMVA/Types.h"
43
44namespace TMVA {
45
46 class IFitterTarget;
47 class Interval;
48 class MsgLogger;
49
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
68
69 Double_t GetSpread() const { return fSpread; }
71
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"
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
int Int_t
Definition: RtypesCore.h:41
unsigned int UInt_t
Definition: RtypesCore.h:42
bool Bool_t
Definition: RtypesCore.h:59
double Double_t
Definition: RtypesCore.h:55
#define ClassDef(name, id)
Definition: Rtypes.h:324
Base definition for genetic algorithm.
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...
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...
const std::vector< TMVA::Interval * > & fRanges
GeneticPopulation fPopulation
GeneticPopulation & GetGeneticPopulation()
void Init()
calls evolution, but if it is not the first time.
std::deque< Int_t > fSuccessList
virtual void Evolution()
this function is called from "init" and controls the evolution of the individuals.
Double_t GetSpread() const
IFitterTarget & fFitterTarget
virtual Double_t CalculateFitness()
starts the evaluation of the fitness of all different individuals of the population.
GeneticAlgorithm(IFitterTarget &target, Int_t populationSize, const std::vector< TMVA::Interval * > &ranges, UInt_t seed=0)
Constructor.
void SetMakeCopies(Bool_t s)
virtual Double_t NewFitness(Double_t oldValue, Double_t newValue)
if the "fitnessFunction" is called multiple times for one set of factors (because i....
MsgLogger & Log() const
void SetSpread(Double_t s)
Population definition for genetic algorithm.
Interface for a fitter 'target'.
Definition: IFitterTarget.h:44
ostringstream derivative to redirect and format output
Definition: MsgLogger.h:59
static constexpr double s
Abstract ClassifierFactory template that handles arbitrary types.