A Genetic Algorithm By Hand

String     Init       x    x    select    expected  Roulette
 No.       Pop.      val  Sqd              count    Wheel    
 1       0 1 1 0 1   13   169   0.14        0.58       1
 2       1 1 0 0 0   24   576   0.49        1.97       2
 3       0 1 0 0 0    8    64   0.06        0.22       0
 4       1 0 0 1 1   19   361   0.31        1.23       1
                Sum      1179    
  • In the the strings above each gene (0 or 1 bit) was randomly created by a "coin toss".
  • The x value was gotten by simply treating each string as a binary number and finding its decimal equivalent.
  • It was squared because. . . . we were solving for a max of x squared in the interval from 0 to 31 . . .
  • Each number in the select column is the number divided by the total. An evaluation of the individual in com- parison to the total population.
  • The expected count is the select column multiplied by 4 - there are to be strings in the new population.
  • Although the roulette wheel is random, it is weighted so that some strings are more likely than others to be chosen to mate.
Strings      Mate  Crossover     New          x       x
to Mate      with.    Site     Population     val    Sqd     
0 1 1 0| 1    2      4         0 1 1 0 0     12     144   
1 1 0 0| 0    1      4         1 1 0 0 1     25     625   
1 1| 0 0 0    4      2         1 1 0 1 1     27     729  
1 0| 0 1 1    3      2         1 0 0 0 0     16     256      
             Sum                                   1754   
  • The new mating pool with the cross site marked. The pairings for mating are also chosen randomly, and, in this case each string mates once and only once.
  • The crossover site is randomly selected.
  • Each new string in the population has some part of a string from each parent.
  • The x value for each string is calculated and the cycle begins again.
The population in the new generation is stronger than the old - the sum is higher. If the mutation probability is assumed to be 0.001 then no mutations were expected in a single generation and none are shown. taken from a book "Genetic Algorithms in Search, Optimization & Machine Learning" by David E. Goldberg