【发布时间】:2016-04-29 22:13:22
【问题描述】:
我在GA中实现了Roulette wheel selection。
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
我理解算法错了吗?如果是,那么任何人都可以告诉我如何修改我的轮盘赌以排名选择吗?
【问题讨论】:
标签: matlab selection genetic-algorithm