Setting the Amount of Mutation
The genetic algorithm applies mutations using the MutationFcn option. The
default mutation option, @mutationgaussian, adds a random number,
or mutation, chosen from a Gaussian distribution, to each entry
of the parent vector. Typically, the amount of mutation, which is proportional to
the standard deviation of the distribution, decreases at each new generation. You
can control the average amount of mutation that the algorithm applies to a parent in
each generation through the Scale and Shrink
inputs that you include in a cell array:
options = optimoptions('ga',...
'MutationFcn',{@mutationgaussian Scale Shrink});
Scale and Shrink are scalars with default
values 1 each.
Scale controls the standard deviation of the mutation
at the first generation. This value is Scale multiplied
by the range of the initial population, which you specify by the
InitialPopulationRange option.
Shrink controls the rate at which the average amount of
mutation decreases. The standard deviation decreases linearly so that its
final value equals 1 – Shrink times its
initial value at the first generation. For example, if
Shrink has the default value of
1, then the amount of mutation decreases to 0 at the
final step.
You can see the effect of mutation by selecting the plot functions
@gaplotdistance and @gaplotrange, and then
running the genetic algorithm on a problem such as the one described in Minimize Rastrigin's Function. The following figure shows the plot
after setting the random number generator.
rng default % For reproducibility
options = optimoptions('ga','PlotFcn',{@gaplotdistance,@gaplotrange},...
'MaxStallGenerations',200); % to get a long run
[x,fval] = ga(@rastriginsfcn,2,[],[],[],[],[],[],[],options);
The upper plot displays the average distance between points
in each generation. As the amount of mutation decreases, so does the
average distance between individuals, which is approximately 0 at
the final generation. The lower plot displays a vertical line at each
generation, showing the range from the smallest to the largest fitness
value, as well as mean fitness value. As the amount of mutation decreases,
so does the range. These plots show that reducing the amount of mutation
decreases the diversity of subsequent generations.
For comparison, the following figure shows the same plots when you set
Shrink to 0.5.
options = optimoptions('ga',options,...
'MutationFcn',{@mutationgaussian,1,.5});
[x,fval] = ga(@rastriginsfcn,2,[],[],[],[],[],[],[],options);
This time, the average amount of mutation decreases by a factor of 1/2 by the final
generation. As a result, the average distance between individuals decreases less
than before.