34 #ifdef _GLIBCXX_PARALLEL 68 fFitterTarget( target ),
75 fPopulationSize(populationSize),
77 fPopulation(ranges, populationSize, seed),
78 fBestFitness(DBL_MAX),
81 fPopulation.SetRandomSeed( seed );
99 if ( fFirstTime ) fFirstTime =
kFALSE;
133 fBestFitness = DBL_MAX;
134 #ifdef _GLIBCXX_PARALLEL 136 const int nt = omp_get_num_threads();
138 for (
int i =0; i < nt; ++i )
139 bests[i] = fBestFitness;
143 int thread_number = omp_get_thread_num();
145 for (
int index = 0; index < fPopulation.GetPopulationSize(); ++index )
149 fFitterTarget.EstimatorFunction(genes->
GetFactors()) );
152 if ( bests[thread_number] > fitness )
153 bests[thread_number] = fitness;
157 fBestFitness = *std::min_element(bests, bests+nt);
161 for (
int index = 0; index < fPopulation.GetPopulationSize(); ++index ) {
164 fFitterTarget.EstimatorFunction(genes->
GetFactors()) );
167 if ( fBestFitness > fitness )
168 fBestFitness = fitness;
188 fPopulation.MakeCopies( 5 );
189 fPopulation.MakeChildren();
191 fPopulation.Mutate( 10, 3,
kTRUE, fSpread, fMirror );
192 fPopulation.Mutate( 40, fPopulation.GetPopulationSize()*3/4 );
214 if ( fBestFitness < fLastResult || fSuccessList.size() <=0 ) {
215 fLastResult = fBestFitness;
216 fSuccessList.push_front( 1 );
219 fSuccessList.push_front( 0 );
223 std::deque<Int_t>::iterator vec = fSuccessList.begin();
224 for (; vec != fSuccessList.end() ; vec++) {
229 if ( n >= ofSteps ) {
230 fSuccessList.pop_back();
231 if ( sum > successSteps ) {
235 else if ( sum == successSteps ) {
257 if (fConvCounter < 0) {
258 fConvValue = fBestFitness;
260 if (
TMath::Abs(fBestFitness - fConvValue) <= improvement || steps<0) {
265 fConvValue = fBestFitness;
268 if (fConvCounter < steps)
return kFALSE;
static long int sum(long int i)
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...
void SetFitness(Double_t fitness)
Double_t GetFitness() const
virtual ~GeneticAlgorithm()
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__