Fitness proportionate selection

Fitness proportionate selection, also known as roulette wheel selection, is a genetic operator used in genetic algorithms for selecting potentially useful solutions for recombination.

In fitness proportionate selection, as in all selection methods, the fitness function assigns a fitness to possible solutions or chromosomes. This fitness level is used to associate a probability of selection with each individual chromosome. If is the fitness of individual in the population, its probability of being selected is , where is the number of individuals in the population.

This could be imagined similar to a Roulette wheel in a casino. Usually a proportion of the wheel is assigned to each of the possible selections based on their fitness value. This could be achieved by dividing the fitness of a selection by the total fitness of all the selections, thereby normalizing them to 1. Then a random selection is made similar to how the roulette wheel is rotated.

While candidate solutions with a higher fitness will be less likely to be eliminated, there is still a chance that they may be. Contrast this with a less sophisticated selection algorithm, such as truncation selection, which will eliminate a fixed percentage of the weakest candidates. With fitness proportionate selection there is a chance some weaker solutions may survive the selection process; this is an advantage, as though a solution may be weak, it may include some component which could prove useful following the recombination process.

The analogy to a roulette wheel can be envisaged by imagining a roulette wheel in which each candidate solution represents a pocket on the wheel; the size of the pockets are proportionate to the probability of selection of the solution. Selecting N chromosomes from the population is equivalent to playing N games on the roulette wheel, as each candidate is drawn independently.

The naive implementation is carried out by first generating the cumulative probability distribution (CDF) over the list of individuals using a probability proportional to the fitness of the individual. A uniform random number from the range [0,1) is chosen and the inverse of the CDF for that number gives an individual. This corresponds to the roulette ball falling in the bin of an individual with a probability proportional to its width. The "bin" corresponding to the inverse of the uniform random number can be found most quickly by using a binary search over the elements of the CDF. It takes in the O(log n) time to choose an individual. A faster alternative that generates individuals in O(1) time will be to use the alias method.

Recently, a very simple O(1) algorithm was introduced that is based on "stochastic acceptance".[2] The algorithm randomly selects an individual (say ) and accepts the selection with probability , where is the maximum fitness in the population.

Contents

For example, if you have a population with fitnesses [1, 2, 3, 4], then the sum is 10 (1 + 2 + 3 + 4). Therefore, you would want the probabilities or chances to be [1/10, 2/10, 3/10, 4/10] or [0.1, 0.2, 0.3, 0.4]. If you were to visually normalize this between 0.0 and 1.0, it would be grouped like below with [red = 1/10, green = 2/10, blue = 3/10, black = 4/10]:

0.1 ]
0.2 \
0.3 /
0.4 \
0.5 |
0.6 /
0.7 \
0.8 |
0.9 |
1.0 /

Using the above example numbers, this is how to determine the probabilities:

// Returns the selected index based on the weights(probabilities)introuletteSelect(double[]weight){// calculate the total weightdoubleweight_sum=0;for(inti=0;i<weight.length;i++){weight_sum+=weight[i];}// get a random valuedoublevalue=randUniformPositive()*weight_sum;// locate the random value based on the weightsfor(inti=0;i<weight.length;i++){value-=weight[i];if(value<=0)returni;}// only when rounding errors occurreturnweight.length-1;}// Returns a uniformly distributed double value between 0.0 and 1.0doublerandUniformPositive(){// easiest implementationreturnnewRandom().nextDouble();}

publicclassroulette{/* program n_select=1000 times selects one of n=4 elements with weights weight[i]. * Selections are summed up in counter[i]. For the weights as given in the example * below one expects that elements 0,1,2 and 3 will be selected (on average) * 200, 150, 600 and 50 times, respectively. In good agreement with exemplary run. */publicstaticvoidmain(String[]args){intn=4;double[]weight=newdouble[n];weight[0]=0.4;weight[1]=0.3;weight[2]=1.2;weight[3]=0.1;doublemax_weight=1.2;int[]counter=newint[n];intn_select=1000;intindex=0;booleannotaccepted;for(inti=0;i<n_select;i++){notaccepted=true;while(notaccepted){index=(int)(n*Math.random());if(Math.random()<weight[index]/max_weight){notaccepted=false;}}counter[index]++;}for(inti=0;i<n;i++){System.out.println("counter["+i+"]="+counter[i]);}}/* The program uses stochastic acceptance instead of linear (or binary) search. * More on http://arxiv.org/abs/1109.3627 */}#Exemplaryoutput:#counter[0]=216#counter[1]=135#counter[2]=595#counter[3]=54

# Normalizes an array that potentially contains negative numbers by shifting# all of them up to be positive (0 is left alone).## +pop_fit+ array of each individual's fitness in a population to normalizedefnorm_pop(pop_fit)least_fit=pop_fit.min.abs+1# Absolute value so can shift up# +1 so that it doesn't become 0pop_fit.map!do|f|(f!=0)?(f+least_fit):fendreturnpop_fitend# Returns an array of each individual's probability between 0.0 and 1.0 fitted# onto an imaginary roulette wheel (or pie).## This will NOT work for negative fitness numbers, as a negative piece of a pie# (i.e., roulette wheel) does not make sense. Therefore, if you have negative# numbers, you will have to normalize the population first before using this.## +pop_fit+ array of each individual's fitness in the population# +is_high_fit+ true if high fitness is best or false if low fitness is bestdefget_probs(pop_fit,is_high_fit=true)fit_sum=0.0# Sum of each individual's fitness in the populationprob_sum=0.0# You can think of this in 2 ways; either...# 1) Current sum of each individual's probability in the# population# or...# 2) Last (most recently processed) individual's probability# in the populationprobs=[]best_fit=nil# Only used if is_high_fit is false# Get fitness sum and best fitnesspop_fit.eachdo|f|fit_sum+=fifbest_fit==nilorf>best_fitbest_fit=fendendputs"Best fitness: #{best_fit}"puts"Fitness sum: #{fit_sum}"best_fit+=1# So that we don't get best_fit-best_fit=0# Get probabilitiespop_fit.each_indexdo|i|f=pop_fit[i]ifis_high_fitprobs[i]=prob_sum+(f/fit_sum)elseprobs[i]=(f!=0)?(prob_sum+((best_fit-f)/fit_sum)):0.0endprob_sum=probs[i]endprobs[probs.size-1]=1.0# Ensure that the last individual is 1.0 due to# decimal problems in computers (can be 0.99...)returnprobsend# Selects and returns a random index using an array of probabilities that were# created to mirror a roulette wheel type of selection.## +probs+ array of probabilities between 0.0 and 1.0 that total to 1.0defroulette_select(probs)r=rand# Random number between 0.0 and 1.0probs.each_indexdo|i|ifr<probs[i]returniendendreturnprobs.size-1# This shouldn't happenendpop_fit=[1,2,3,4]pop_sum=Float(pop_fit.inject{|p,f|p+f})probs=get_probs(pop_fit,true)# These should all have the exact same outputputsprobs.inspectputsget_probs([4,3,2,1],false).inspectputsget_probs(norm_pop([-4,-3,-2,-1]),true).inspectputsget_probs(norm_pop([-1,-2,-3,-4]),false).inspectputs# Check the mathprev_prob=0.0puts"Math check:"foriin0..pop_fit.size-1puts"%.4f|%.4f|%.4f"%[probs[i],probs[i]-prev_prob,pop_fit[i]/pop_sum]prev_prob=probs[i]endputs# Observe some random selectionsobserved_probs=Array.new(pop_fit.size,0)observed_count=1000foriin1..observed_countobserved_probs[roulette_select(probs)]+=1endputs"Observed:"observed_probs.each_indexdo|i|prob=observed_probs[i]/Float(observed_count)puts"#{i}: #{prob}"end# Example output:## Best fitness: 4# Fitness sum: 10.0# [0.1, 0.30000000000000004, 0.6000000000000001, 1.0]# Best fitness: 4# Fitness sum: 10.0# [0.1, 0.30000000000000004, 0.6000000000000001, 1.0]# Best fitness: 4# Fitness sum: 10.0# [0.1, 0.30000000000000004, 0.6000000000000001, 1.0]# Best fitness: 4# Fitness sum: 10.0# [0.1, 0.30000000000000004, 0.6000000000000001, 1.0]## Math check:# 0.1000|0.1000|0.1000# 0.3000|0.2000|0.2000# 0.6000|0.3000|0.3000# 1.0000|0.4000|0.4000## Observed:# 0: 0.108# 1: 0.191# 2: 0.296# 3: 0.405