Roulette Wheel Selection Procedure

Is it possible to evaluate each person in the population using the fitness value without finding the probability in the form of the following pseudocode

For all members of population sum += fitness ( member) End for Loop until new population is full Do this twice Number = Random between 0 and sum Currentfitness = 0.0 For each member in population Currentfitness += fitness (member) if Number > Currentfitness then select member End for End Create offspring End loop 

and what does the next part of the code do?

 Do this twice 

I really confuse how a roulette wheel picks a pair of parents. can any help? thanks in advance

+4
source share
2 answers

The code is designed to select a random element, but with probabilities in accordance with a certain weight.

Example:

  • We want to select from a two-element array with the following weights: {1, 9}
  • Total Weight {1, 10}
  • Total weight 10
  • We pick a random number between 1 and 10
  • We will look at the total weighted array and find the first index, where our random number is greater than the element
  • This index is the index of a randomly selected item.

Intuitively, this example makes sense: 9 out of ten times a random number will fall between 1 and 9, forcing the first element to be drawn with a probability of 0.9 (exactly the same as the weights indicated).

+2
source

The number must be less than Currentfitness, otherwise it is highly biased towards the first member of the population.

Example:

  • Consider the weights {1, 2, 7}
  • Cumulative weights {1, 3, 10}
  • Total weight 10
  • Choose a random double from 0 to 10 with r.NextDouble (10.0)
  • 90% of time 1 is selected with the given pseudo-code. Must be 10%
+3
source

Source: https://habr.com/ru/post/1414506/


All Articles