Logo ROOT   6.10/09
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 #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 
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:
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 
104 
105  ClassDef(GeneticPopulation,0); //Population definition for genetic algorithm
106  };
107 
108 } // namespace TMVA
109 
110 #endif
Random number generator class based on M.
Definition: TRandom3.h:27
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()
Creates children out of members of the current generation.
tomato 1-D histogram with a float per channel (see TH1 documentation)}
Definition: TH1.h:551
void MakeCopies(int number)
Produces offspring which is are copies of their parents.
const std::vector< TMVA::GeneticRange * > & GetRanges() const
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
void AddPopulation(GeneticPopulation *strangers)
add another population (strangers) to the one of this GeneticPopulation
#define ClassDef(name, id)
Definition: Rtypes.h:297
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.
std::vector< TMVA::GeneticGenes > & GetGenePool()
std::vector< TMVA::GeneticRange * > fRanges
Cut optimisation interface class for genetic algorithm.
Definition: GeneticGenes.h:41
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, .
const Bool_t kFALSE
Definition: RtypesCore.h:92
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...
ostringstream derivative to redirect and format output
Definition: MsgLogger.h:59
Abstract ClassifierFactory template that handles arbitrary types.
Population definition for genetic algorithm.
TH1F * VariableDistribution(Int_t varNumber, Int_t bins, Int_t min, Int_t max)
give back a histogram with the distribution of the coefficients.
MsgLogger & Log() const
const std::vector< TMVA::GeneticGenes > & GetGenePool() const