Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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 <vector>
37
38#include "TMVA/GeneticGenes.h"
39#include "TMVA/Interval.h"
40#include "TMVA/GeneticRange.h"
41
42class TH1F;
43
44namespace TMVA {
45
46 class MsgLogger;
47
49
50 public:
51
52 GeneticPopulation(const std::vector<TMVA::Interval*>& ranges, Int_t size, UInt_t seed = 0);
53 virtual ~GeneticPopulation();
54
55 void SetRandomSeed( UInt_t seed = 0);
56
57 void MakeChildren();
58 void Mutate( Double_t probability = 20, Int_t startIndex = 0, Bool_t near = kFALSE,
59 Double_t spread = 0.1, Bool_t mirror = kFALSE );
60
61 GeneticGenes* GetGenes( Int_t index );
62 Int_t GetPopulationSize() const { return fGenePool.size(); }
63 Double_t GetFitness() const { return fGenePool.size()>0? fGenePool[0].GetFitness() : 0; }
64
65 const std::vector<TMVA::GeneticGenes>& GetGenePool() const { return fGenePool; }
66 const std::vector<TMVA::GeneticRange*>& GetRanges() const { return fRanges; }
67
68 std::vector<TMVA::GeneticGenes>& GetGenePool() { return fGenePool; }
69 std::vector<TMVA::GeneticRange*>& GetRanges() { return fRanges; }
70
71 void Print( Int_t untilIndex = -1 );
72 void Print( std::ostream & out, Int_t utilIndex = -1 );
73
74 TH1F* VariableDistribution( Int_t varNumber, Int_t bins, Int_t min, Int_t max );
75 std::vector< Double_t > VariableDistribution( Int_t varNumber );
76
77 // To keep compatibility: These methods might be reimplemented
78 // or just eliminated later on. They are used by the
79 // GeneticFitter class.
80
81 void MakeCopies( int number );
83 void AddPopulation( GeneticPopulation *strangers );
84 void AddPopulation( GeneticPopulation &strangers );
85 void TrimPopulation();
86 void GiveHint( std::vector< Double_t >& hint, Double_t fitness = 0 );
87 void Sort();
88
89 private:
91
92 private:
93
94 std::vector<TMVA::GeneticGenes> fGenePool; // the "genePool" where the individuals of the current generation are stored
95 std::vector<TMVA::GeneticRange*> fRanges; // contains the ranges inbetween the values of the coefficients have to be
96
97 TRandom3*fRandomGenerator; // random Generator for this population
98
99 mutable MsgLogger* fLogger; // message logger
100 MsgLogger& Log() const { return *fLogger; }
101
103
104 ClassDef(GeneticPopulation,0); //Population definition for genetic algorithm
105 };
106
107} // namespace TMVA
108
109#endif
const Bool_t kFALSE
Definition RtypesCore.h:92
double Double_t
Definition RtypesCore.h:59
#define ClassDef(name, id)
Definition Rtypes.h:325
1-D histogram with a float per channel (see TH1 documentation)}
Definition TH1.h:575
Cut optimisation interface class for genetic algorithm.
Population definition for genetic algorithm.
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.
virtual ~GeneticPopulation()
destructor
std::vector< TMVA::GeneticGenes > & GetGenePool()
const std::vector< TMVA::GeneticGenes > & GetGenePool() const
std::vector< TMVA::GeneticRange * > fRanges
void Sort()
sort the genepool according to the fitness of the individuals
void MakeCopies(int number)
Produces offspring which is are copies of their parents.
void TrimPopulation()
trim the population to the predefined size
GeneticGenes * GetGenes(Int_t index)
gives back the "Genes" of the population with the given index.
std::vector< TMVA::GeneticRange * > & GetRanges()
void Print(Int_t untilIndex=-1)
make a little printout of the individuals up to index "untilIndex" this means, .
const std::vector< TMVA::GeneticRange * > & GetRanges() const
void MakeChildren()
Creates children out of members of the current generation.
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...
std::vector< TMVA::GeneticGenes > fGenePool
void AddPopulation(GeneticPopulation *strangers)
add another population (strangers) to the one of this GeneticPopulation
void SetRandomSeed(UInt_t seed=0)
the random seed of the random generator
GeneticGenes MakeSex(GeneticGenes male, GeneticGenes female)
this function takes two individuals and produces offspring by mixing (recombining) their coefficients...
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
Double_t GetFitness() const
ostringstream derivative to redirect and format output
Definition MsgLogger.h:59
Random number generator class based on M.
Definition TRandom3.h:27
create variable transformations