我有一个问题,在获得健身比例概率时,如何处理适合度(适应度'?)为0。如果成员的容器首先按最高适应度排序,那么请执行与此类似的代码:
for all members of population
sum += fitness of this individual
end for
for all members of population
probability = sum of probabilities + (fitness / sum)
sum of probabilities += probability
end for
loop until new population is full
do this twice
number = Random between 0 and 1
for all members of population
if number > probability but less than next probability then you have been selected
end for
end
create offspring
end loop
当我通过随机生成的成员手动进行一次迭代时,我看到的问题是我有一些成员的健身为0,但是当得到这些成员的概率时,它保持与最后一个非零成员。有没有办法可以将非零概率与零概率分开?我在想,即使我根据最高适应度排序,最后一个非零成员的概率与零概率相同。
答案 0 :(得分:2)
考虑这个例子:
individual fitness(i) probability(i) partial_sum(i)
1 10 10/20 = 0.50 0.50
2 3 3/20 = 0.15 0.5+0.15 = 0.65
3 2 2/20 = 0.10 0.5+0.15+0.1 = 0.75
4 0 0/20 = 0.00 0.5+0.15+0.1+0.0 = 0.75
5 5 5/20 = 0.25 0.5+0.15+0.1+0.0+0.25 = 1.00
------
Sum 20
现在如果number = Random between [0;1[
我们要选择个人i
,如果:{/ p>
individual condition
1 0.00 <= number < partial_sum(1) = 0.50
2 0.50 = partial_sum(1) <= number < partial_sum(2) = 0.65
3 0.65 = partial_sum(2) <= number < partial_sum(3) = 0.75
4 0.75 = partial_sum(3) <= number < partial_sum(4) = 0.75
5 0.75 = partial_sum(4) <= number < partial_sum(5) = 1.00
如果一个人有健身0
(例如我 4 ),则由于其选择条件而无法选择(例如,我 4 具有相关条件{ {1}})。