Genetic algorithm custom crossover/mutation argument questions
16 次查看(过去 30 天)
显示 更早的评论
Hi,
I have custom crossover and mutation functions for an implementation of MATLAB's build-in genetic algorithm (ga). I was able to get them to work, but I have some questions about the arguments being passed in. Please note that I am also feeding in the initial population which is produced prior to my code calling the ga.
The documentation for how to do this is here: https://www.mathworks.com/help/gads/genetic-algorithm-options.html#f20829. This is the syntax for the custom functions:
xoverKids = myfun(parents, options, nvars, FitnessFcn, ...
unused,thisPopulation)
mutationChildren = myfun(parents, options, nvars,
FitnessFcn, state, thisScore, thisPopulation)
First I should note that the documentation has an error for 'unused' for the crossover function. As of R2017b at least, it appears that this argument is a vector of the population scores.
I would like the behavior of the mutation and crossover functions to be dependent on the scores of the parents involved (crossover particularly). I would also like to log how a new better solution was produced (was one parent elite? was it produced through mutation? etc). I have the code in place to do that, but I'm encountering some peculiarities from the inputs my custom crossover/mutation functions are receiving.
My understanding is that each index of thisScore should correspond to the score of each index of thisPopulation. The population is produced by concatenating [eliteKids; xoverkids; mutationkids] in stepGA.m. Thus for populationSize = 100, eliteCount = 10, crossoverFraction = 0.5, I would expect:
thisPopulation(1:10) are elite, thisPopulation(11:55) are crossover, thisPopulation(56:100) are mutation. Likewise for thisScore.
When I query the scores in the middle of running the ga, this is what I see for the first 16 elements (with an elite count of 9 in this case):
1614386 % I expect this to be the first elite score
1615044
1615044
1615044
1615044
1615044
1615044
1616655
1616655 % I expect this to be the last elite score
1685827 % I expect this to be the first crossover score
1621767
1632825
1663424
1614386 % Here is an example where a lower/better score than some of the elites is in the wrong place?
1618049
1616655
The last comment shows a score in the crossover area that is better than some in the elite area. This does not match my expectation of how the inputs should be working.
Can someone clarify how this is supposed to work or if this is a bug?
If it matters, my call to the ga looks like this:
[x,fval,exitflag,output,population,scores] = ga(fitnessFunctionGA, ...
nVars, [], [], [], [], [], ...
[], [], [], opts);
and I have set the options to run in parallel, use my custom initial population, use my custom crossover/mutation functions. Nothing fancy outside of that.
回答(1 个)
Herbert Triceratops
2021-8-13
I think the point is that elites can also be regular parents (hmm...), I don't think there is such a thing as "elite area" or "crossover area". I didn't find anything in MATLAB documentation that says this outright (although I didn't spend that much time looking), but the following quote from MATLAB documentation suggests it: "Because elite individuals have already been evaluated, ga does not reevaluate the fitness function of elite individuals during reproduction." This statement would have no purpose if elites were disjoint from parents. What do you think?
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Genetic Algorithm 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!