Logo ROOT   6.08/07
Reference Guide
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 #ifndef ROOT_Riosfwd
40 #include "Riosfwd.h"
41 #endif
42 #ifndef ROOT_TMVA_GeneticGenes
43 #include "TMVA/GeneticGenes.h"
44 #endif
45 #ifndef ROOT_TMVA_Interval
46 #include "TMVA/Interval.h"
47 #endif
48 #ifndef ROOT_TMVA_GeneticRange
49 #include "TMVA/GeneticRange.h"
50 #endif
51 
52 class TH1F;
53 
54 namespace TMVA {
55 
56  class MsgLogger;
57 
59 
60  public:
61 
62  GeneticPopulation(const std::vector<TMVA::Interval*>& ranges, Int_t size, UInt_t seed = 0);
63  virtual ~GeneticPopulation();
64 
65  void SetRandomSeed( UInt_t seed = 0);
66 
67  void MakeChildren();
68  void Mutate( Double_t probability = 20, Int_t startIndex = 0, Bool_t near = kFALSE,
69  Double_t spread = 0.1, Bool_t mirror = kFALSE );
70 
71  GeneticGenes* GetGenes( Int_t index );
72  Int_t GetPopulationSize() const { return fGenePool.size(); }
73  Double_t GetFitness() const { return fGenePool.size()>0? fGenePool[0].GetFitness() : 0; }
74 
75  const std::vector<TMVA::GeneticGenes>& GetGenePool() const { return fGenePool; }
76  const std::vector<TMVA::GeneticRange*>& GetRanges() const { return fRanges; }
77 
78  std::vector<TMVA::GeneticGenes>& GetGenePool() { return fGenePool; }
79  std::vector<TMVA::GeneticRange*>& GetRanges() { return fRanges; }
80 
81  void Print( Int_t untilIndex = -1 );
82  void Print( std::ostream & out, Int_t utilIndex = -1 );
83 
84  TH1F* VariableDistribution( Int_t varNumber, Int_t bins, Int_t min, Int_t max );
85  std::vector< Double_t > VariableDistribution( Int_t varNumber );
86 
87  // To keep compatibility: These methods might be reimplemented
88  // or just eliminated later on. They are used by the
89  // GeneticFitter class.
90 
91  void MakeCopies( int number );
92  void NextGeneration() {}
93  void AddPopulation( GeneticPopulation *strangers );
94  void AddPopulation( GeneticPopulation &strangers );
95  void TrimPopulation();
96  void GiveHint( std::vector< Double_t >& hint, Double_t fitness = 0 );
97  void Sort();
98 
99  private:
101 
102  private:
103 
104  std::vector<TMVA::GeneticGenes> fGenePool; // the "genePool" where the individuals of the current generation are stored
105  std::vector<TMVA::GeneticRange*> fRanges; // contains the ranges inbetween the values of the coefficients have to be
106 
107  TRandom3*fRandomGenerator; // random Generator for this population
108 
109  mutable MsgLogger* fLogger; // message logger
110  MsgLogger& Log() const { return *fLogger; }
111 
113 
114  ClassDef(GeneticPopulation,0); //Population definition for genetic algorithm
115  };
116 
117 } // namespace TMVA
118 
119 #endif
Random number generator class based on M.
Definition: TRandom3.h:29
void GiveHint(std::vector< Double_t > &hint, Double_t fitness=0)
add an individual (a set of variables) to the population if there is a set of variables which is know...
Double_t GetFitness() const
Int_t GetPopulationSize() const
void MakeChildren()
does what the name says,...
tomato 1-D histogram with a float per channel (see TH1 documentation)}
Definition: TH1.h:575
void MakeCopies(int number)
produces offspring which is are copies of their parents Parameters: int number : the number of the la...
const std::vector< TMVA::GeneticRange * > & GetRanges() const
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
void AddPopulation(GeneticPopulation *strangers)
add another population (strangers) to the one of this GeneticPopulation
#define ClassDef(name, id)
Definition: Rtypes.h:254
void Mutate(Double_t probability=20, Int_t startIndex=0, Bool_t near=kFALSE, Double_t spread=0.1, Bool_t mirror=kFALSE)
mutates the individuals in the genePool Parameters: double probability : gives the probability (in pe...
std::vector< TMVA::GeneticGenes > & GetGenePool()
std::vector< TMVA::GeneticRange * > fRanges
virtual ~GeneticPopulation()
destructor
GeneticPopulation(const std::vector< TMVA::Interval *> &ranges, Int_t size, UInt_t seed=0)
Constructor.
void TrimPopulation()
trim the population to the predefined size
void SetRandomSeed(UInt_t seed=0)
the random seed of the random generator
unsigned int UInt_t
Definition: RtypesCore.h:42
std::vector< TMVA::GeneticRange * > & GetRanges()
GeneticGenes * GetGenes(Int_t index)
gives back the "Genes" of the population with the given index.
void Print(Int_t untilIndex=-1)
make a little printout of the individuals up to index "untilIndex" this means, .
std::vector< TMVA::GeneticGenes > fGenePool
double Double_t
Definition: RtypesCore.h:55
void Sort()
sort the genepool according to the fitness of the individuals
GeneticGenes MakeSex(GeneticGenes male, GeneticGenes female)
this function takes two individuals and produces offspring by mixing (recombining) their coefficients...
Abstract ClassifierFactory template that handles arbitrary types.
TH1F * VariableDistribution(Int_t varNumber, Int_t bins, Int_t min, Int_t max)
give back a histogram with the distribution of the coefficients parameters: int bins : number of bins...
MsgLogger & Log() const
const std::vector< TMVA::GeneticGenes > & GetGenePool() const