Java 遗传算法竞赛选择

Java 遗传算法竞赛选择,java,genetic-algorithm,evolutionary-algorithm,Java,Genetic Algorithm,Evolutionary Algorithm,我正在写一个遗传算法,我计划从轮盘赌到锦标赛,但我怀疑我的理解可能有缺陷 如果我只是选择总体中的n/2最佳解决方案,那么我的总体肯定会很快用完吗 我对算法的理解是: for(Member m in currentPopulation){ Member randomMember1 = random member of currentPopulation which is then removed from currentPopulation Member randomMember2

我正在写一个遗传算法,我计划从轮盘赌到锦标赛,但我怀疑我的理解可能有缺陷

如果我只是选择总体中的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);
    }
}

我理解正确吗?

在锦标赛选择中,所选个体不会从群体中移除。您可以选择同一个人参加多个锦标赛

仔细看了一下你的代码,我发现你还有另一个误解。您通常不会对锦标赛的所有成员进行变异/交叉。相反,您执行一个锦标赛,锦标赛的获胜者被选为个体进行变异/交叉。这意味着,对于变异,您的比赛规模必须至少为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);
    }
}

如果你在每一代从你的种群中选择n/2个个体,你最终会达到一个种群为1的点。除了选择之外,你想做的是使用变异或交叉为你的下一代创建新成员,通常是在锦标赛的胜利者身上


因此,对于每一代,你都有一个n大小的群体——你通过选择将其减少到n/2,然后这些n/2的成员繁殖和/或变异,为你的下一代多产生大约n/2的成员(平均而言,比上一代没有进步的成员“更适合”).

锦标赛选择:

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...
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
  • 锦标赛选择是一种从个体群体中选择个体的方法
  • 锦标赛选择包括在从人群中随机挑选的几个人中进行几场“锦标赛”
  • 选择每场比赛的获胜者(身体状况最佳者)进行交叉
  • 当竞赛规模较小时,竞赛选择也给所有个体一个被选择的机会,因此它保持了多样性,尽管保持多样性可能会降低收敛速度
  • 但如果比赛规模较大,弱者被选中的机会较小,从而导致多样性丧失
伪代码:

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...
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
确定性锦标赛选择在任何锦标赛中选择最佳个人(当p=1时)。单向锦标赛(k=1)选择等同于随机选择。如果需要,可将所选个体从进行选择的群体中移除,否则可为下一代多次选择个体。与(随机)适应度比例选择方法相比,由于缺乏随机噪声,比赛选择在实践中经常被实现


MatLab中的锦标赛选择:

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...
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

请正确设置代码的格式。哦,对不起!看起来其他人已经有了,下次我会记住这一点。它是如何得到比轮盘赌等选择方法更好的解决方案的?请参阅我的编辑。只有锦标赛的获胜者会经历变异/交叉,并进入下一个群体。也就是说,平均而言(如果我没有弄错的话),如果你做3个比较,66%的人群会经历变异/交叉。非常感谢,这正是我想要的。