65 DeclareOptionRef( fPopSize=300,
"PopSize",
"Population size for GA" );
66 DeclareOptionRef( fNsteps=40,
"Steps",
"Number of steps for convergence" );
67 DeclareOptionRef( fCycles=3,
"Cycles",
"Independent cycles of GA fitting" );
68 DeclareOptionRef( fSC_steps=10,
"SC_steps",
"Spread control, steps" );
69 DeclareOptionRef( fSC_rate=5,
"SC_rate",
"Spread control, rate: factor is changed depending on the rate" );
70 DeclareOptionRef( fSC_factor=0.95,
"SC_factor",
"Spread control, factor" );
71 DeclareOptionRef( fConvCrit=0.001,
"ConvCrit",
"Convergence criteria" );
73 DeclareOptionRef( fSaveBestFromGeneration=1,
"SaveBestGen",
74 "Saves the best n results from each generation. They are included in the last cycle" );
75 DeclareOptionRef( fSaveBestFromCycle=10,
"SaveBestCycle",
76 "Saves the best n results from each cycle. They are included in the last cycle. The value should be set to at least 1.0" );
78 DeclareOptionRef( fTrim=
kFALSE,
"Trim",
79 "Trim the population to PopSize after assessing the fitness of each individual" );
80 DeclareOptionRef( fSeed=100,
"Seed",
"Set seed of random generator (0 gives random seeds)" );
108 Log() << kHEADER <<
"<GeneticFitter> Optimisation, please be patient "
109 <<
"... (inaccurate progress timing for GA)" <<
Endl;
111 GetFitterTarget().ProgressNotifier(
"GA",
"init" );
118 if (fIPyMaxIter) *fIPyMaxIter = 100*(fCycles);
119 timer.DrawProgressBar( 0 );
123 for (
Int_t cycle = 0; cycle < fCycles; cycle++) {
124 if (fIPyCurrentIter) *fIPyCurrentIter = 100*(cycle);
125 if (fExitFromTraining && *fExitFromTraining)
break;
126 GetFitterTarget().ProgressNotifier(
"GA",
"cycle" );
133 if ( pars.size() == fRanges.size() ){
134 ga.GetGeneticPopulation().GiveHint( pars, 0.0 );
136 if (cycle==fCycles-1) {
137 GetFitterTarget().ProgressNotifier(
"GA",
"last" );
138 ga.GetGeneticPopulation().AddPopulation(
gstore.GetGeneticPopulation() );
141 GetFitterTarget().ProgressNotifier(
"GA",
"iteration" );
143 ga.CalculateFitness();
144 ga.GetGeneticPopulation().TrimPopulation();
148 GetFitterTarget().ProgressNotifier(
"GA",
"iteration" );
150 ga.CalculateFitness();
151 if ( fTrim )
ga.GetGeneticPopulation().TrimPopulation();
152 ga.SpreadControl( fSC_steps, fSC_rate, fSC_factor );
161 ga.GetGeneticPopulation().Sort();
162 for (
Int_t i = 0; i<fSaveBestFromGeneration && i<fPopSize; i++ ) {
163 gstore.GetGeneticPopulation().GiveHint(
ga.GetGeneticPopulation().GetGenes(i)->GetFactors(),
164 ga.GetGeneticPopulation().GetGenes(i)->GetFitness() );
166 }
while (!
ga.HasConverged( fNsteps, fConvCrit ));
168 timer.DrawProgressBar( 100*(cycle+1) );
170 ga.GetGeneticPopulation().Sort();
171 for (
Int_t i = 0; i<fSaveBestFromGeneration && i<fPopSize; i++ ) {
172 gstore.GetGeneticPopulation().GiveHint(
ga.GetGeneticPopulation().GetGenes(i)->GetFactors(),
173 ga.GetGeneticPopulation().GetGenes(i)->GetFitness() );
178 Log() << kINFO <<
"Elapsed time: " <<
timer.GetElapsedTime()
182 gstore.GetGeneticPopulation().Sort();
183 pars.swap(
gstore.GetGeneticPopulation().GetGenes(0)->GetFactors() );
185 GetFitterTarget().ProgressNotifier(
"GA",
"stop" );
void SetParameters(Int_t cycles, Int_t nsteps, Int_t popSize, Int_t SC_steps, Int_t SC_rate, Double_t SC_factor, Double_t convCrit)
set GA configuration parameters