MATLAB: How to choose population and generations for GA

genetic algorithmMATLABoptimization

Hello everyone,
I would like to know if there is a method to properly define a good number of generations and population for running an optimization with GA? Is there any rule of thumb to choose the correct order of magnitude of those two parameters?
Thank you in advance

Best Answer

I use an optimoptions structure for this.
Example —
PopSz = 500;
Parms = 3;
opts = optimoptions('ga', 'PopulationSize',PopSz, 'InitialPopulationMatrix',randi(1E+4,PopSz,Parms).*[1E-3 1E-1 1E+2], 'MaxGenerations',2E3, 'PlotFcn',@gaplotbestf, 'PlotInterval',1);
It is then possible to scale the individual columns of the 'InitialPopulationMatrix' aas I do here, so that it is easier for ga to find an appropriate solution. Providing a relatively large number of rows (individuals) can slightly slow the function, however in my experience it decreases the number of generations required for ga to converge.
Related Question