Genetic Algorithm (GA) for binary (bitstring) population type - how will crossover and mutation work on binary vectors?

13 visualizzazioni (ultimi 30 giorni)
I am trying to run genetic algorithm with binary array as population type by setting 'PopulationType' to 'bitstring' in optimoptions function.
Could someone explain how crossover function ('crossoverarithmetic') and mutation funtion ('mutationuniform') work for this binary case?
Crossover Options - 'crossoverarithmetic'
It says Arithmetic ('crossoverarithmetic') creates children that are the weighted arithmetic mean of two parents.
If two parents selected are, for example,
parent1 = [1 0 0 1 0];
parent2 = [0 0 1 1 1];
Will the children from 'crossoverarithmetic' be parent1 | parent2 ? so children = [1 0 1 1 1]?
Mutation Options - 'mutationuniform'
Documentation says the following: Uniform ('mutationuniform') - uniform mutation is a two-step process. First, the algorithm selects a fraction of the vector entries of an individual for mutation, where each entry has a probability Rate of being mutated. The default value of Rate is 0.01. In the second step, the algorithm replaces each selected entry by a random number selected uniformly from the range for the entry.
Does this mean, if a parent selected is [1 0 0 1 0], each entry has Rate chance of value being flipped?
  4 Commenti
Walter Roberson
Walter Roberson il 5 Mag 2020
The code is along the lines of
R = rand(1,N);
for K = 1:N
if R(K) < rate
variable(K) = randi([lb(K), ub(K)]) ;
end
end
for bitstring 0 1, randi 0 1 has a 50% chance of being different than it currently is.
Whereas you are imagining
t = setdiff(lb(K) : ub(K), variable(K)) ;
variable(K) = t(randi(length(t)) ;
which is guaranteed to be different from the current value 100%

Accedi per commentare.

Risposte (1)

Walter Roberson
Walter Roberson il 5 Mag 2020
crossoverfcn is not to be used with integer problems, and bitstring are integer problems
  1 Commento
Louis
Louis il 5 Mag 2020
I have successfully ran with the following option (I am trying to use this to do genetic algorithm-based feature selection, so my objective function/fitness value is the classification model accuracy using the subset of features selected my this ga). It seems to have give me a subset of features that performed better than using the complete feature set. What do you mean by crossoverfcn is not to be used with bitstring? What would this have done in the backend? Will it not perform crossover at all? Or is there a default behavior of crossover for bitstring? Is there a way for me to perform some sort of crossover (using OR or XOR, for example) on the bitstring?
populationSize = 50;
tournamentSize = 10;
eliteSize = 2;
mutationRate = 0.01;
xoverFraction = 0.8;
nMaxStall = 50;
stopTolerance = 0.01;
options = optimoptions('ga', ...
'CreationFcn', @initializepopulation, ...
'PopulationType', 'bitstring', ...
'PopulationSize', populationSize, ...
'SelectionFcn', {@selectiontournament, tournamentSize}, ...
'EliteCount', eliteSize, ...
'MutationFcn', {@mutationuniform, mutationRate}, ...
'CrossoverFcn', {@crossoverarithmetic, xoverFraction}, ...
'MaxStallGenerations', nMaxStall, ...
'FunctionTolerance', stopTolerance, ...
'PlotFcn', 'gaplotbestf', ...
'Display', 'iter');

Accedi per commentare.

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by