Fix function evaluations in ga

6 views (last 30 days)
sandeep singh chauhan
sandeep singh chauhan on 26 Jan 2016
Commented: Emily Kambalame on 26 Aug 2022
I want to fix my number of maximum function evaluation as stopping criteria in ga. How can i do it?
  2 Comments
Geoff Hayes
Geoff Hayes on 26 Jan 2016
Sandeep - do you mean that you want the genetic algorithm to iterate for some maximum number of iterations/generations?
sandeep singh chauhan
sandeep singh chauhan on 26 Jan 2016
No, I want to use genetic algorithm that will stop with maximum function evaluations

Sign in to comment.

Answers (2)

Brendan Hamm
Brendan Hamm on 26 Jan 2016
This is controlled in the Generations property of the Genetic Algorithm options. Obtain the default options:
>> options = gaoptimset(@ga)
options =
PopulationType: 'doubleVector'
PopInitRange: []
PopulationSize: '50 when numberOfVariables <= 5, else 200'
EliteCount: '0.05*PopulationSize'
CrossoverFraction: 0.8000
ParetoFraction: []
MigrationDirection: 'forward'
MigrationInterval: 20
MigrationFraction: 0.2000
Generations: '100*numberOfVariables'
TimeLimit: Inf
FitnessLimit: -Inf
StallGenLimit: 50
StallTest: 'averageChange'
StallTimeLimit: Inf
TolFun: 1.0000e-06
TolCon: 1.0000e-03
InitialPopulation: []
InitialScores: []
NonlinConAlgorithm: 'auglag'
InitialPenalty: 10
PenaltyFactor: 100
PlotInterval: 1
CreationFcn: @gacreationuniform
FitnessScalingFcn: @fitscalingrank
SelectionFcn: @selectionstochunif
CrossoverFcn: @crossoverscattered
MutationFcn: {@mutationgaussian [1] [1]}
DistanceMeasureFcn: []
HybridFcn: []
Display: 'final'
PlotFcns: []
OutputFcns: []
Vectorized: 'off'
UseParallel: 0
Now you can change the Generations and pass this in to the options input of your call to ga
>> options.Generations = '200*numberOfVariables';
>> ga(...,options); % Fill in the ... with your function, constraints, etc.
  4 Comments
UbuntuXenial
UbuntuXenial on 28 Mar 2019
Can you please explain how to determine the dependence? I want to run GA/MOGA only up to certain MaxFunctionEvaluations but this isn't a valid optimoption for these algorithms.
Emily Kambalame
Emily Kambalame on 26 Aug 2022
I also dont want to use the max generation but rather the maximum function evaluation as my stopping condition. How should i approach my problem? Take note that my constraints are satified using Epanet simulator and am NSGA 2 to optimise.

Sign in to comment.


Matt J
Matt J on 26 Jan 2016
Edited: Matt J on 26 Jan 2016
The following nested function strategy might be a way to cheat. Basically, it keeps a running count, funEvals, of the number of calls to the fitness function. When funEvals exceeds a specified MaxFunEvals, the FitnessFcn output is forced to -Inf, which I think must trigger the FitnessLimit stopping criterion.
function runEverything(MaxFunEvals)
funEvals=0;
bestFitness=inf;
[x,fval,exitflag,output,population,scores] = ga(@FitnessFcn,...);
fval=bestFitness;
function val = FitnessFcn(x)
...
bestFitness=min(bestFitness,val);
funEvals=funEvals+1; %increment counter
if funEvals>=MaxFunEvals
val=-inf;
end
end
end

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!