我用遗传算法对比赛进行了如下选择:
从种群中选择k个随机个体,从中选出两个最好的个体作为父母。
是对的吗?
发布于 2015-08-11 05:38:35
考虑到您使用的是健身标准,这里有一个可以帮助您的伪代码。
func tournament_selection(pop, k):
best = null
for i=1 to k
ind = pop[random(1, N)]
if (best == null) or fitness(ind) > fitness(best)
best = ind
return best因此,基本上,您所遵循的方法是好的。虽然有更多,如交叉和其他东西,我想你已经处理好了。
有一个很好的解决方案的参考链接- Tournament Selection in Genetic Algorithms
要扩展这一点,请使用另一个变量“更好”。做些类似于-
better = best
best = ind在返回时,返回一个对象,它是这两个变量的一对。
或者另一种方法是--两次调用同一个函数实例,它将返回最好的和最好的-1。需要在代码中进行一些调整来处理示例。
PS:这可能不是一个最佳的方法。
发布于 2016-01-26 13:37:09
锦标赛选择:
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...决定论的比赛选择选择最佳个人(当p= 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发布于 2017-10-08 11:48:13
比赛选择是众多选择父母的技术之一,就像轮盘赌一样。我亦想指出,除适合度外,分类器的经验/年龄亦应作选择。贝塔是对健康的贡献因素,1-贝塔是对经验的贡献。代码片段在java中。
ArrayList<Genotype> Crossover (ArrayList Population){
ArrayList<Genotype> selected= ArrayList<Genotype>();
Geneotype best=NULL, second_best=NULL;
for(int i=0; i<k;i++){
int prob= Math.random()+Population.size(); // generate a number between 0 and last index of arraylist
if(best==NULL || best.fitness<Population.get(prob).fitness)
best= Population.get(prob);
else{
if(second_best.fitness<Population.get(prob).fitness)
best= Population.get(prob);
}
Population.remove(prob); // Wil not affect the actual population because parameters are pass by value not reference
selected.add(best);
selected.add(second_best);
return selected;
}https://stackoverflow.com/questions/31933784
复制相似问题