35#ifdef _GLIBCXX_PARALLEL
70 const std::vector<Interval*>& ranges,
UInt_t seed )
72 fFitterTarget( target ),
79 fPopulationSize(populationSize),
81 fPopulation(ranges, populationSize, seed),
82 fBestFitness(DBL_MAX),
83 fLogger( new
MsgLogger(
"GeneticAlgorithm") )
103 if ( fFirstTime ) fFirstTime =
kFALSE;
137 fBestFitness = DBL_MAX;
138#ifdef _GLIBCXX_PARALLEL
140 const int nt = omp_get_num_threads();
142 for (
int i =0; i < nt; ++i )
143 bests[i] = fBestFitness;
147 int thread_number = omp_get_thread_num();
149 for (
int index = 0; index < fPopulation.GetPopulationSize(); ++index )
153 fFitterTarget.EstimatorFunction(genes->
GetFactors()) );
156 if ( bests[thread_number] > fitness )
157 bests[thread_number] = fitness;
161 fBestFitness = *std::min_element(bests, bests+nt);
165 for (
int index = 0; index < fPopulation.GetPopulationSize(); ++index ) {
168 fFitterTarget.EstimatorFunction(genes->
GetFactors()) );
171 if ( fBestFitness > fitness )
172 fBestFitness = fitness;
193 fPopulation.MakeCopies( 5 );
194 fPopulation.MakeChildren();
196 fPopulation.Mutate( 10, 3,
kTRUE, fSpread, fMirror );
197 fPopulation.Mutate( 40, fPopulation.GetPopulationSize()*3/4 );
220 if ( fBestFitness < fLastResult || fSuccessList.size() <=0 ) {
221 fLastResult = fBestFitness;
222 fSuccessList.push_front( 1 );
225 fSuccessList.push_front( 0 );
229 std::deque<Int_t>::iterator vec = fSuccessList.begin();
230 for (; vec != fSuccessList.end() ; ++vec) {
235 if (
n >= ofSteps ) {
236 fSuccessList.pop_back();
237 if (
sum > successSteps ) {
239 if (GeneticAlgorithm__DEBUG__) Log() << kINFO <<
">" << std::flush;
241 else if (
sum == successSteps ) {
242 if (GeneticAlgorithm__DEBUG__) Log() <<
"=" << std::flush;
246 if (GeneticAlgorithm__DEBUG__) Log() <<
"<" << std::flush;
262 if (fConvCounter < 0) {
263 fConvValue = fBestFitness;
265 if (
TMath::Abs(fBestFitness - fConvValue) <= improvement || steps<0) {
270 fConvValue = fBestFitness;
272 if (GeneticAlgorithm__DEBUG__) Log() <<
"." << std::flush;
273 if (fConvCounter < steps)
return kFALSE;
Base definition for genetic algorithm.
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...
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...
GeneticPopulation fPopulation
void Init()
calls evolution, but if it is not the first time.
virtual void Evolution()
this function is called from "init" and controls the evolution of the individuals.
virtual ~GeneticAlgorithm()
virtual Double_t CalculateFitness()
starts the evaluation of the fitness of all different individuals of the population.
GeneticAlgorithm(IFitterTarget &target, Int_t populationSize, const std::vector< TMVA::Interval * > &ranges, UInt_t seed=0)
Constructor.
virtual Double_t NewFitness(Double_t oldValue, Double_t newValue)
if the "fitnessFunction" is called multiple times for one set of factors (because i....
Cut optimisation interface class for genetic algorithm.
void SetFitness(Double_t fitness)
std::vector< Double_t > & GetFactors()
Double_t GetFitness() const
void SetRandomSeed(UInt_t seed=0)
the random seed of the random generator
Interface for a fitter 'target'.
ostringstream derivative to redirect and format output
create variable transformations
static uint64_t sum(uint64_t i)