遗传算法比赛选择

发布于 2024-10-15 15:20:11 字数 532 浏览 8 评论 0原文

我正在编写遗传算法,我计划从轮盘赌选择转向锦标赛选择,但我怀疑我的理解可能有缺陷。

如果我只选择总体中的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

就此别过 2024-10-22 15:20:11

在锦标赛选择中,选定的个体不会从种群中删除。您可以选择相同的个人参加多个锦标赛。

仔细查看您的代码后,我发现您确实还有另一个误解。您通常不会突变/交叉锦标赛的所有成员。相反,您进行一场锦标赛,并选择该锦标赛的获胜者作为个体进行突变/交叉。这意味着对于突变,您的锦标赛大小必须至少为 2,而对于交叉,大小必须至少为 3,其中最好的 2 个获胜(或者您可以执行 2 个单独的锦标赛来选择每个父级进行交叉)。

一些伪代码可能会有所帮助:

while (nextPopulation too small) {
    Members tournament = randomly choose x members from currentPopulation

    if(crossover){
        Member parents = select best two members from tournament
        Member children = crossover(parents)
        nextPopulation.add(children);
    } else {
        Member parent = select best one member from tournament
        Member child = mutate(parent)
        nextPopulation.add(child);
    }
}

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:

while (nextPopulation too small) {
    Members tournament = randomly choose x members from currentPopulation

    if(crossover){
        Member parents = select best two members from tournament
        Member children = crossover(parents)
        nextPopulation.add(children);
    } else {
        Member parent = select best one member from tournament
        Member child = mutate(parent)
        nextPopulation.add(child);
    }
}
陌路终见情 2024-10-22 15:20:11

如果您在每一代中从种群中选择 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).

浅忆 2024-10-22 15:20:11

锦标赛选择:

  • 锦标赛选择是一种从个体群体中选择个体的方法。
  • 锦标赛选择涉及在从人群中随机选择的少数个体中举办几场“锦标赛”。
  • 每场比赛的获胜者(体能最好的那个)都会被选择进行交叉。
  • 当锦标赛规模较小时,锦标赛选择也为所有个体提供了被选择的机会,因此它保留了多样性,尽管保持多样性可能会降低收敛速度。
  • 但如果锦标赛规模较大,弱个体被选中的机会就会较小,从而导致多样性的丧失。

伪代码

choose k (the tournament size) individuals from the population at random
choose the best individual from pool/tournament with probability p
choose the second best individual with probability p*(1-p)
choose the third best individual with probability p*((1-p)^2)
and so on...

确定性锦标赛选择会在任何锦标赛中选择最佳个体(当 p = 1 时)。 1 路锦标赛 (k = 1) 选择相当于随机选择。如果需要,可以将所选择的个体从进行选择的群体中移除,否则可以为下一代多次选择个体。与(随机)适应度比例选择方法相比,锦标赛选择由于缺乏随机噪声而在实践中经常被实施。

MatLab 中的比赛选择:

Matepool=randi(PopLength,PopLength,2);%%select two individuals randomly for tournament and chooose the one with best fitness value
%% number of tournament is equal to the number of population size
for i=1:PopLength
    if Fitness(Matepool(i,1))>= Fitness(Matepool(i,2))
        SelectedPop(i,1:IndLength)=CurrentPop(Matepool(i,1),1:IndLength);
    else
        SelectedPop(i,1:IndLength)=CurrentPop(Matepool(i,2),1:IndLength);
    end
end

Tournament Selection:

  • Tournament selection is a method of selecting an individual from a population of individuals.
  • Tournament selection involves running several "tournaments" among a few individuals chosen at random from the population.
  • The winner of each tournament (the one with the best fitness) is selected for crossover.
  • When the tournament size is smaller, Tournament selection also gives a chance to all individuals to be selected and thus it preserves diversity, although keeping diversity may degrade the convergence speed.
  • But if the tournament size is larger, weak individuals have a smaller chance to be selected causes loss of diversity .

PseudoCode:

choose k (the tournament size) individuals from the population at random
choose the best individual from pool/tournament with probability p
choose the second best individual with probability p*(1-p)
choose the third best individual with probability p*((1-p)^2)
and so on...

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:

Matepool=randi(PopLength,PopLength,2);%%select two individuals randomly for tournament and chooose the one with best fitness value
%% number of tournament is equal to the number of population size
for i=1:PopLength
    if Fitness(Matepool(i,1))>= Fitness(Matepool(i,2))
        SelectedPop(i,1:IndLength)=CurrentPop(Matepool(i,1),1:IndLength);
    else
        SelectedPop(i,1:IndLength)=CurrentPop(Matepool(i,2),1:IndLength);
    end
end
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文