MATLAB: In the ga function, how the average relative change in the best fitness value is calculated

gaGlobal Optimization Toolboxoptimization

In the optimization process using the ga function, the best fitness value is still decreasing from a generation to another but the process stops because the average change in the fitness value less than options.FunctionTolerance. So, I wonder how this average change is calculated to understand why the process stops.
Thank you very much for your answer,
Simon

Best Answer

As explained in Stopping Criteria Options, "The algorithm stops if the average relative change in the best fitness function value over Stall generations is less than or equal to Function tolerance."
You can control the value of both the function tolerance option (FunctionTolerance) and the number of stall generations (MaxStallGenerations) by setting their values using optimoptions.
This behavior changed in R2014a. If you have an older version of the toolbox, ga uses a geometrically-weighted window, which does not work well.See the R2014a Release Notes.
Alan Weiss
MATLAB mathematical toolbox documentation