52 fRanges(ranges.size()),
58 fRandomGenerator =
new TRandom3( 100 );
59 fRandomGenerator->Uniform(0.,1.);
60 fRandomGenerator->SetSeed( seed );
62 for (
unsigned int i = 0; i < ranges.size(); ++i )
65 vector<Double_t> newEntry( fRanges.size() );
66 for (
int i = 0; i < size; ++i )
68 for (
unsigned int rIt = 0; rIt < fRanges.size(); ++rIt )
69 newEntry[rIt] = fRanges[rIt]->
Random();
73 fPopulationSizeLimit = size;
83 std::vector<GeneticRange*>::iterator it =
fRanges.begin();
84 for (;it!=
fRanges.end(); it++)
delete *it;
96 fRandomGenerator->SetSeed( seed );
108 for (std::vector<TMVA::GeneticGenes>::iterator it = fGenePool.begin();
109 it != fGenePool.end() && i < number;
111 GiveHint( it->GetFactors(), it->GetFitness() );
123 #ifdef _GLIBCXX_PARALLEL
127 for (
int it = 0; it < (int) (fGenePool.size() / 2); ++it )
129 Int_t pos = (
Int_t)fRandomGenerator->Integer( fGenePool.size()/2 );
130 fGenePool[(fGenePool.size() / 2) + it] = MakeSex( fGenePool[it], fGenePool[pos] );
142 vector< Double_t > child(fRanges.size());
143 for (
unsigned int i = 0; i < fRanges.size(); ++i) {
144 if (fRandomGenerator->Integer( 2 ) == 0) {
173 vector< Double_t>::iterator vec;
174 vector< TMVA::GeneticRange* >::iterator vecRange;
181 for (
int it = startIndex; it < (int) fGenePool.size(); ++it) {
182 vecRange = fRanges.begin();
183 for (vec = (fGenePool[it].GetFactors()).begin(); vec < (fGenePool[it].GetFactors()).end(); ++vec) {
184 if (fRandomGenerator->Uniform( 100 ) <= probability) {
185 (*vec) = (*vecRange)->Random( near, (*vec), spread, mirror );
199 return &(fGenePool[index]);
209 for (
unsigned int it = 0; it < fGenePool.size(); ++it )
212 if (untilIndex >= -1 ) {
213 if (untilIndex == -1 )
return;
216 Log() <<
"fitness: " << fGenePool[it].GetFitness() <<
" ";
217 for (vector< Double_t >::iterator vec = fGenePool[it].GetFactors().begin();
218 vec < fGenePool[it].GetFactors().end(); vec++ ) {
219 Log() <<
"f_" << n++ <<
": " << (*vec) <<
" ";
232 for (
unsigned int it = 0; it < fGenePool.size(); ++it ) {
234 if (untilIndex >= -1 ) {
235 if (untilIndex == -1 )
return;
238 out <<
"fitness: " << fGenePool[it].GetFitness() <<
" ";
239 for (vector< Double_t >::iterator vec = fGenePool[it].GetFactors().begin();
240 vec < fGenePool[it].GetFactors().end(); vec++ ) {
241 out <<
"f_" << n++ <<
": " << (*vec) <<
" ";
258 std::cout <<
"FAILED! TMVA::GeneticPopulation::VariableDistribution" << std::endl;
260 std::stringstream histName;
263 histName << varNumber;
275 std::cout <<
"FAILED! TMVA::GeneticPopulation::VariableDistribution" << std::endl;
277 vector< Double_t > varDist;
287 for (std::vector<TMVA::GeneticGenes>::iterator it = strangers->
fGenePool.begin();
288 it != strangers->
fGenePool.end(); it++ ) {
289 GiveHint( it->GetFactors(), it->GetFitness() );
298 AddPopulation(&strangers);
306 std::sort(fGenePool.begin(), fGenePool.end());
307 while ( fGenePool.size() > (
unsigned int) fPopulationSizeLimit )
308 fGenePool.pop_back();
320 fGenePool.push_back( g );
328 std::sort(fGenePool.begin(), fGenePool.end());
Random number generator class based on M.
static Vc_ALWAYS_INLINE int_v min(const int_v &x, const int_v &y)
MsgLogger & Endl(MsgLogger &ml)
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...
void MakeChildren()
does what the name says,...
1-D histogram with a float per channel (see TH1 documentation)}
void MakeCopies(int number)
produces offspring which is are copies of their parents Parameters: int number : the number of the la...
const TKDTreeBinning * bins
void AddPopulation(GeneticPopulation *strangers)
add another population (strangers) to the one of this GeneticPopulation
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::GeneticRange * > fRanges
virtual ~GeneticPopulation()
destructor
void SetFitness(Double_t fitness)
void TrimPopulation()
trim the population to the predefined size
void SetRandomSeed(UInt_t seed=0)
the random seed of the random generator
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
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...
std::vector< Double_t > & GetFactors()
static Vc_ALWAYS_INLINE int_v max(const int_v &x, const int_v &y)
Abstract ClassifierFactory template that handles arbitrary types.
ClassImp(TMVA::GeneticPopulation) using namespace std
TRandom3 * fRandomGenerator
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...