34 #ifdef _GLIBCXX_PARALLEL
61 TMVA::GeneticAlgorithm::GeneticAlgorithm( IFitterTarget& target,
Int_t populationSize,
62 const
std::vector<Interval*>& ranges,
UInt_t seed )
64 fFitterTarget( target ),
71 fPopulationSize(populationSize),
73 fPopulation(ranges, populationSize, seed),
74 fBestFitness(DBL_MAX),
75 fLogger( new MsgLogger("GeneticAlgorithm") )
77 fPopulation.SetRandomSeed( seed );
95 if ( fFirstTime ) fFirstTime =
kFALSE;
129 fBestFitness = DBL_MAX;
130 #ifdef _GLIBCXX_PARALLEL
132 const int nt = omp_get_num_threads();
134 for (
int i =0; i < nt; ++i )
135 bests[i] = fBestFitness;
139 int thread_number = omp_get_thread_num();
141 for (
int index = 0; index < fPopulation.GetPopulationSize(); ++index )
145 fFitterTarget.EstimatorFunction(genes->
GetFactors()) );
148 if ( bests[thread_number] > fitness )
149 bests[thread_number] = fitness;
153 fBestFitness = *std::min_element(bests, bests+nt);
157 for (
int index = 0; index < fPopulation.GetPopulationSize(); ++index ) {
160 fFitterTarget.EstimatorFunction(genes->
GetFactors()) );
163 if ( fBestFitness > fitness )
164 fBestFitness = fitness;
184 fPopulation.MakeCopies( 5 );
185 fPopulation.MakeChildren();
187 fPopulation.Mutate( 10, 3,
kTRUE, fSpread, fMirror );
188 fPopulation.Mutate( 40, fPopulation.GetPopulationSize()*3/4 );
210 if ( fBestFitness < fLastResult || fSuccessList.size() <=0 ) {
211 fLastResult = fBestFitness;
212 fSuccessList.push_front( 1 );
215 fSuccessList.push_front( 0 );
219 std::deque<Int_t>::iterator vec = fSuccessList.begin();
220 for (; vec != fSuccessList.end() ; vec++) {
225 if ( n >= ofSteps ) {
226 fSuccessList.pop_back();
227 if ( sum > successSteps ) {
231 else if ( sum == successSteps ) {
253 if (fConvCounter < 0) {
254 fConvValue = fBestFitness;
256 if (
TMath::Abs(fBestFitness - fConvValue) <= improvement || steps<0) {
261 fConvValue = fBestFitness;
264 if (fConvCounter < steps)
return kFALSE;
virtual Double_t CalculateFitness()
starts the evaluation of the fitness of all different individuals of the population.
virtual Double_t SpreadControl(Int_t steps, Int_t ofSteps, Double_t factor)
this function provides the ability to change the stepSize of a mutation according to the success of t...
ClassImp(TMVA::GeneticAlgorithm) TMVA
Constructor Parameters: int populationSize : defines the number of "Individuals" which are created an...
void SetFitness(Double_t fitness)
virtual ~GeneticAlgorithm()
Double_t GetFitness() const
virtual Bool_t HasConverged(Int_t steps=10, Double_t ratio=0.1)
gives back true if the last "steps" steps have lead to an improvement of the "fitness" of the "indivi...
std::vector< Double_t > & GetFactors()
virtual void Evolution()
this function is called from "init" and controls the evolution of the individuals.
Abstract ClassifierFactory template that handles arbitrary types.
virtual Double_t NewFitness(Double_t oldValue, Double_t newValue)
if the "fitnessFunction" is called multiple times for one set of factors (because i...
void Init()
calls evolution, but if it is not the first time.
const Bool_t GeneticAlgorithm__DEBUG__