遗传算法比赛选择
我正在编写遗传算法,我计划从轮盘赌选择转向锦标赛选择,但我怀疑我的理解可能有缺陷。
如果我只选择总体中的 n/2 个最佳解决方案,我肯定很快就会用完总体吗?
我对算法的理解是:
for(Member m in currentPopulation){
Member randomMember1 = random member of currentPopulation which is then removed from currentPopulation
Member randomMember2 = as above;
//Mutate and crossover
if(randomMember1.getScore() > randomMember2.getScore()){
nextGeneration.add(randomMember1);
} else {
nextGeneration.add(randomMember2);
}
}
我理解正确吗?
I'm writing a genetic algorithm and I plan to move from roulette wheel selection to tournament selection, but I suspect my understanding may be flawed.
If I'm only selecting the n/2 best solutions in the population, surely I run out of population quite quickly?
My understanding of the algorithm is:
for(Member m in currentPopulation){
Member randomMember1 = random member of currentPopulation which is then removed from currentPopulation
Member randomMember2 = as above;
//Mutate and crossover
if(randomMember1.getScore() > randomMember2.getScore()){
nextGeneration.add(randomMember1);
} else {
nextGeneration.add(randomMember2);
}
}
Am I understanding this correctly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在锦标赛选择中,选定的个体不会从种群中删除。您可以选择相同的个人参加多个锦标赛。
仔细查看您的代码后,我发现您确实还有另一个误解。您通常不会突变/交叉锦标赛的所有成员。相反,您进行一场锦标赛,并选择该锦标赛的获胜者作为个体进行突变/交叉。这意味着对于突变,您的锦标赛大小必须至少为 2,而对于交叉,大小必须至少为 3,其中最好的 2 个获胜(或者您可以执行 2 个单独的锦标赛来选择每个父级进行交叉)。
一些伪代码可能会有所帮助:
In tournament selection the selected individuals are not removed from the population. You may select the same individuals to take part in multiple tournaments.
Having looked at your code a little closer, I see you do have another misunderstanding. You would not typically mutate/crossover all members of the tournament. Instead, you perform a tournament, with the winner of that tournament being select as an individual to undergo mutation/crossover. This means that for mutation your tournament size must be at least 2, and for crossover the size must be at least 3 with the best 2 winning (or you can perform 2 separate tournaments to choose each of the parents to crossover).
Some pseudo-code might help:
如果您在每一代中从种群中选择 n/2 个个体,您最终将达到种群数量为 1 的程度。除了选择之外,您还要做的是使用突变或为下一代创建新成员交叉,通常针对那些在锦标赛中获胜的人。
因此,对于每一代,您的人口规模为 n - 通过选择将其减少到 n/2,然后这些 n/2 成员繁殖和/或变异,为您的下一代产生大约 n/2 个成员(平均而言,它将比上一代没有进步的人“更健康”)。
If you're selecting n/2 individuals from your population in every generation, you will eventually reach a point where you have a population of 1. What you want to do in addition to selection is create new members for your next generation using mutation or crossover, generally on those that were victors in the tournament.
So, for each generation, you have a population of size n - you reduce this to n/2 through your selection, and then those n/2 members reproduce and/or mutate to produce roughly n/2 more members for your next generation (which, on average, will be 'fitter' than those that didn't progress from the previous generation).
锦标赛选择:
伪代码:
确定性锦标赛选择会在任何锦标赛中选择最佳个体(当 p = 1 时)。 1 路锦标赛 (k = 1) 选择相当于随机选择。如果需要,可以将所选择的个体从进行选择的群体中移除,否则可以为下一代多次选择个体。与(随机)适应度比例选择方法相比,锦标赛选择由于缺乏随机噪声而在实践中经常被实施。
MatLab 中的比赛选择:
Tournament Selection:
PseudoCode:
Deterministic tournament selection selects the best individual (when p = 1) in any tournament. A 1-way tournament (k = 1) selection is equivalent to random selection. The chosen individual can be removed from the population that the selection is made from if desired, otherwise individuals can be selected more than once for the next generation. In comparison with the (stochastic) fitness proportionate selection method, tournament selection is often implemented in practice due to its lack of stochastic noise.
Tournament Selection in MatLab: