algorithmgenetic-algorithmfitnessroulette-wheel-selection

Fitness Proportionate Selection when some fitnesses are 0


I have a question about what to do with the fitnesses (fitness'?) that are 0 when getting the fitness proportionate probabilities. Should the container for the members be sorted by highest fitness first, then do code similar to this:

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

My problem that I am seeing as I go through one iteration by hand with randomly generated members is that I have some member's fitness as 0, but when getting the probability of those members, it keeps the same probability as the last non zero member. Is there a way I can separate the non zero probabilities from the zero probabilities? I was thinking that even if I sort based on highest fitness, the last non zero member would have the same probability as the zero probabilities.


Solution

  • Consider this example:

    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
    

    Now if number = Random between [0;1[ we are going to pick individual i if:

    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
    

    If an individual has fitness 0 (e.g. I4) it cannot be selected because of its selection condition (e.g. I4 has the associated condition 0.75 <= number < 0.75).