我在GA
中实施了Roulette wheel selection
。
GA中的排名选择?
TotalFitness=sum(Fitness);
ProbSelection=zeros(PopLength,1);
CumProb=zeros(PopLength,1);
for i=1:PopLength
ProbSelection(i)=Fitness(i)/TotalFitness;
if i==1
CumProb(i)=ProbSelection(i);
else
CumProb(i)=CumProb(i-1)+ProbSelection(i);
end
end
SelectInd=rand(PopLength,1);
for i=1:PopLength
flag=0;
for j=1:PopLength
if(CumProb(j)<SelectInd(i) && CumProb(j+1)>=SelectInd(i))
SelectedPop(i,1:IndLength)=CurrentPop(j+1,1:IndLength);
flag=1;
break;
end
end
if(flag==0)
SelectedPop(i,1:IndLength)=CurrentPop(1,1:IndLength);
end
end
现在我试图在GA
实现rank selection
。我了解到:
排名选择排名第一的人口,然后每一个染色体从这个排名接收健身。
最糟糕的是健身1,第二最差2等,最好的健身N(人口中的染色体数量)。
首先,我要排序的人口的健身价值。
那么如果人口数量是10,那么我会给人口的选择概率如0.1,0.2,0.3,...,1.0。
- 然后我会计算累积健身,如轮盘。
- 接下来的步骤与轮盘相同。
我的实现:
NewFitness=sort(Fitness);
NewPop=round(rand(PopLength,IndLength));
for i=1:PopLength
for j=1:PopLength
if(NewFitness(i)==Fitness(j))
NewPop(i,1:IndLength)=CurrentPop(j,1:IndLength);
break;
end
end
end
CurrentPop=NewPop;
ProbSelection=zeros(PopLength,1);
CumProb=zeros(PopLength,1);
for i=1:PopLength
ProbSelection(i)=i/PopLength;
if i==1
CumProb(i)=ProbSelection(i);
else
CumProb(i)=CumProb(i-1)+ProbSelection(i);
end
end
SelectInd=rand(PopLength,1);
for i=1:PopLength
flag=0;
for j=1:PopLength
if(CumProb(j)<SelectInd(i) && CumProb(j+1)>=SelectInd(i))
SelectedPop(i,1:IndLength)=CurrentPop(j+1,1:IndLength);
flag=1;
break;
end
end
if(flag==0)
SelectedPop(i,1:IndLength)=CurrentPop(1,1:IndLength);
end
end
我是理解错误算法中?如果是的话,任何人都可以给我任何想法如何修改我的轮盘赌轮以选择等级?
我已经实现了代码,并且实现了像pop0ength = 10时给出0.1,0.2,0.3,... 1.0的功能。但是你告诉我给1/55,2/55,3/55 ...就像所以最后的候选人会得到10/55。是吗? –
正确(答案已经写在你编辑之前)。关键是,分配给每个人的“健身”只取决于**的位置,而不取决于实际的健身。与等级相关的值(.1,2或1/55,2/55 ...)与选择压力有关,这对于算法的性能非常重要,但不是主要方面。主要方面是基于等级的选择在进化搜索 中保持不受“超个人”影响的恒定压力。 – manlio