Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Choosing individuals from a population, by a fitness function

I've been working on an algorithm, where I need to choose n individuals from a population of size k, where k is much bigger than n. All individuals have a fitness value, therefore the selection should favor higher fitness values. However, I don't want to simply choose best n individuals, the worse ones should have a chance also. (Natural selection)

So, I decided to find the min and max fitness values within population. So, any individual would have

p = (current - min) / (max - min)

probability to be chosen, but I can not just iterate over all of them, roll the dice and choose one if the probability holds, because then I end up with more than n individuals. I could shuffle the list and iterate from front, till I obtain up to n individuals, but that might miss great ones to the end of list.

I also could perform more than one passes, until the remaining population size reaches to n. But this might favor better ones a lot, and converge to the naive selection method I mentioned.

Any suggestion, or references to such a selection process? I could do some reading on relevant statistical methods if you can refer any.

Thanks.

like image 530
Ekin Koc Avatar asked Mar 09 '11 09:03

Ekin Koc


People also ask

How do you choose fitness function in genetic algorithm?

Consider three variables x, y and z. The problem is to find the best set of values for x, y and z so that their total value is equal to a value t. We have to reduce the sum x+y+z from deviating from t, i.e. |x + y + z — t| should be zero. Hence the fitness function can be considered as the inverse of |x + y + z - t|.

What is the use of fitness function?

A fitness function is a particular type of objective function that is used to summarise, as a single figure of merit, how close a given design solution is to achieving the set aims. Fitness functions are used in genetic programming and genetic algorithms to guide simulations towards optimal design solutions.

What is the role of fitness function and population in evolutionary algorithm?

Evolutionary algorithms are based on concepts of biological evolution. A 'population' of possible solutions to the problem is first created with each solution being scored using a 'fitness function' that indicates how good they are. The population evolves over time and (hopefully) identifies better solutions.

How does the fitness function evaluate next generation?

A Fitness Function determines which pairs are to be chosen for an intermediate population IP that will mate to form the next generation. A root Evaluation function is able to provide a computable evaluation of the suitability of an individuals being a possible solution.


1 Answers

Use Roulette-wheel selection. The basic idea is that you assign an area of the roulette-wheel relative to the probability size:

Roulette wheel

Then you simply spin it n times to select the individuals you want.

Sample implementation in ruby:

def roulette(population, n)
  probs = population.map { |gene| gene.probability } # TODO: Implement this
  selected = []

  n.times do 
    r, inc = rand * probs.max, 0 # pick a random number and select the  individual 
                     # corresponding to that roulette-wheel area
    population.each_index do |i| 
      if r < (inc += probs[i])
        selected << population[i]
        # make selection not pick sample twice
        population.delete_at i
        probs.delete_at i
        break
      end
    end
  end
  return selected
end

Note: if you are a Ruby hacker, you see that the code could be much shorter with more Rubyisms, however I wanted the algorithm to be as clear as possible.

like image 91
Jakub Hampl Avatar answered Oct 08 '22 19:10

Jakub Hampl