51 fRanges(ranges.
size()),
52 fLogger( new
MsgLogger(
"GeneticPopulation") )
61 for (
unsigned int i = 0; i < ranges.size(); ++i )
64 vector<Double_t> newEntry(
fRanges.size() );
65 for (
int i = 0; i <
size; ++i )
67 for (
unsigned int rIt = 0; rIt <
fRanges.size(); ++rIt )
68 newEntry[rIt] =
fRanges[rIt]->Random();
80 if (fRandomGenerator != NULL)
delete fRandomGenerator;
82 std::vector<GeneticRange*>::iterator it = fRanges.begin();
83 for (;it!=fRanges.end(); ++it)
delete *it;
95 fRandomGenerator->SetSeed( seed );
107 for (std::vector<TMVA::GeneticGenes>::iterator it = fGenePool.begin();
108 it != fGenePool.end() && i < number;
110 GiveHint( it->GetFactors(), it->GetFitness() );
121#ifdef _GLIBCXX_PARALLEL
125 for (
int it = 0; it < (
int) (fGenePool.size() / 2); ++it )
127 Int_t pos = (
Int_t)fRandomGenerator->Integer( fGenePool.size()/2 );
128 fGenePool[(fGenePool.size() / 2) + it] = MakeSex( fGenePool[it], fGenePool[pos] );
139 vector< Double_t >
child(fRanges.size());
140 for (
unsigned int i = 0; i < fRanges.size(); ++i) {
141 if (fRandomGenerator->Integer( 2 ) == 0) {
171 vector< Double_t>::iterator
vec;
172 vector< TMVA::GeneticRange* >::iterator vecRange;
179 for (
int it = startIndex; it < (
int) fGenePool.size(); ++it) {
180 vecRange = fRanges.begin();
181 for (
vec = (fGenePool[it].GetFactors()).begin();
vec < (fGenePool[it].GetFactors()).end(); ++
vec) {
182 if (fRandomGenerator->Uniform( 100 ) <= probability) {
183 (*vec) = (*vecRange)->Random( near, (*
vec), spread, mirror );
196 return &(fGenePool[
index]);
205 for (
unsigned int it = 0; it < fGenePool.size(); ++it )
208 if (untilIndex >= -1 ) {
209 if (untilIndex == -1 )
return;
212 Log() <<
"fitness: " << fGenePool[it].GetFitness() <<
" ";
213 for (vector< Double_t >::iterator
vec = fGenePool[it].GetFactors().begin();
214 vec < fGenePool[it].GetFactors().end(); ++
vec ) {
215 Log() <<
"f_" <<
n++ <<
": " << (*vec) <<
" ";
227 for (
unsigned int it = 0; it < fGenePool.size(); ++it ) {
229 if (untilIndex >= -1 ) {
230 if (untilIndex == -1 )
return;
233 out <<
"fitness: " << fGenePool[it].GetFitness() <<
" ";
234 for (vector< Double_t >::iterator
vec = fGenePool[it].GetFactors().begin();
235 vec < fGenePool[it].GetFactors().end(); ++
vec ) {
236 out <<
"f_" <<
n++ <<
": " << (*vec) <<
" ";
254 std::cout <<
"FAILED! TMVA::GeneticPopulation::VariableDistribution" << std::endl;
256 std::stringstream histName;
259 histName << varNumber;
260 TH1F *hist =
new TH1F( histName.str().c_str(),histName.str().c_str(), bins,min,max );
270 std::cout <<
"FAILED! TMVA::GeneticPopulation::VariableDistribution" << std::endl;
272 vector< Double_t > varDist;
282 for (std::vector<TMVA::GeneticGenes>::iterator it = strangers->
fGenePool.begin();
283 it != strangers->
fGenePool.end(); ++it ) {
284 GiveHint( it->GetFactors(), it->GetFitness() );
293 AddPopulation(&strangers);
301 std::sort(fGenePool.begin(), fGenePool.end());
302 while ( fGenePool.size() > (
unsigned int) fPopulationSizeLimit )
303 fGenePool.pop_back();
313 g.SetFitness(fitness);
315 fGenePool.push_back(
g );
323 std::sort(fGenePool.begin(), fGenePool.end());
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t index
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t child
1-D histogram with a float per channel (see TH1 documentation)}
Cut optimisation interface class for genetic algorithm.
std::vector< Double_t > & GetFactors()
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
Int_t fPopulationSizeLimit
std::vector< TMVA::GeneticRange * > fRanges
contains the ranges in between the values of the coefficients have to be
TRandom3 * fRandomGenerator
random Generator for this population
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.
GeneticPopulation(const std::vector< TMVA::Interval * > &ranges, Int_t size, UInt_t seed=0)
Constructor.
void Print(Int_t untilIndex=-1)
make a little printout of the individuals up to index "untilIndex" this means, .
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
the "genePool" where the individuals of the current generation are stored
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.
Range definition for genetic algorithm.
ostringstream derivative to redirect and format output
Random number generator class based on M.
void SetSeed(ULong_t seed=0) override
Set the random generator sequence if seed is 0 (default value) a TUUID is generated and used to fill ...
virtual Double_t Uniform(Double_t x1=1)
Returns a uniform deviate on the interval (0, x1).
MsgLogger & Endl(MsgLogger &ml)