In my opinion this behavior is expected since the initial population is random. Each time the genetic algorithm (GA) is evoked, the initial population could be located in a part of the domain where the surface geometry could be completely different from the previous GA calls. In some calls, the starting population might be located in a "favorable" region in the sense that the nature of the fitness function surface may be conducive to the tolerances being met faster as the generations progress.
In fact, this behavior is also observed in the documented example "Minimize Rastrigin's Function" with the genetic algorithm.
options = gaoptimset(@ga);
options.Display = 'iter';
[x fval exitflag] = ga(@rastriginsfcn, 2,options)
In the above example, you will notice that the number of iterations required to meet the default tolerances ranges from 50 - 200 iterations.
It seems to me that repeatability can be controlled by changing the mode of random number generation. The documentation page on "Minimize Rastrigin's Function" , suggests changing the random generation to the 'twister' option to improve repeatibility:
The specific command of interest would be:
I would also recommend modifying the solver options, such as the stopping criteria to see if it helps improve reproducibility.
Best Answer