Published on

Published in: Economy & Finance, Technology
  • Be the first to comment

  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide


  1. 1. The Standard Genetic Algorithm Dr. Chrisantha Fernando Systems Biology Centre University of Birmingham
  2. 2. DIY Evolution.
  3. 3. Genotype <ul><li>Binary String </li></ul><ul><li>Real numbered String </li></ul>1101000101110101 1101011111110101 0.2, 0.5, 0.2, 0.83, 0.01, 0.3 0.6, 0.1, 0.5, 0.8, 0.9, 1.0 Represents length of left leg. Size of head, etc…
  4. 4. Evaluation <ul><li>Interpret the genotype to produce the phenotype. </li></ul><ul><li>In the simplest case they are the same thing. </li></ul><ul><li>E.g. Imagine we desire the string </li></ul><ul><ul><li>000000000 </li></ul></ul><ul><li>We can define fitness of any string as the number of places where it is the same as the above string, e.g. </li></ul><ul><ul><li>000000000 </li></ul></ul><ul><ul><li>010101010 </li></ul></ul><ul><ul><li>------------- </li></ul></ul><ul><ul><li>101010101 = 5 = Fitness </li></ul></ul>
  5. 5. A Trivial Example <ul><li>int evaluate(int *g) { </li></ul><ul><ul><li>int i, </li></ul></ul><ul><ul><li>r=0; </li></ul></ul><ul><ul><li>for (i=0;i<10;i++) </li></ul></ul><ul><ul><ul><li>r += (g(i) == 0); </li></ul></ul></ul><ul><ul><ul><li>return(r); </li></ul></ul></ul><ul><li>} </li></ul>I. Harvey
  6. 6. So first initialize a population <ul><li>int popn[30][10]; </li></ul><ul><li>void initialise_popn() { </li></ul><ul><li>int i,j; </li></ul><ul><li>for (i=0;i<30;i++) </li></ul><ul><ul><li>for (j=0;j<10;j++) </li></ul></ul><ul><ul><ul><li>popn[i][j]= flip_a_bit(); </li></ul></ul></ul><ul><li>} </li></ul>I. Harvey
  7. 7. Main Loop <ul><li>For n times round generation loop </li></ul><ul><ul><li>evaluate all the population (of 30) </li></ul></ul><ul><ul><li>select preferentially the fitter ones as parents </li></ul></ul><ul><ul><li>for 30 times round repro loop </li></ul></ul><ul><ul><li>pick 2 from parental pool </li></ul></ul><ul><ul><li>recombine to make 1 offspring </li></ul></ul><ul><ul><li>mutate the offspring </li></ul></ul><ul><ul><li>end repro loop </li></ul></ul><ul><ul><li>throw away parental generation and replace with offspring </li></ul></ul><ul><ul><li>End generation loop </li></ul></ul>I. Harvey
  8. 8. More complicated Evaluations <ul><li>Genotype encodes a neural network. </li></ul>Dario Floreano’s Lab
  9. 9. Even More Complicated Evaluations
  10. 10. Problems in Practice <ul><li>An evaluation may take a long time, in which case the genetic algorithm will be slow. </li></ul><ul><li>An evaluation may be noisy, so the same agent may have different fitness each time you make an evaluation. If it is too noisy, then good agents may be lost from the population. </li></ul>
  11. 11. Selection Methods <ul><li>Truncation Selection </li></ul><ul><ul><li>All parents come from top 50% or top 20% etc.. </li></ul></ul><ul><li>Fitness Proportionate Selection </li></ul><ul><ul><li>E.g. if all fitnesses are 2, 4, 6, 8, 9, then select parent using roulette wheel selection with probability 2/29, 4/29, 6/29, 8/29, 9/29 </li></ul></ul><ul><ul><li>Problems with this are </li></ul></ul><ul><ul><ul><li>If early on one agent dominates there is too much selective pressure. </li></ul></ul></ul><ul><ul><ul><li>If later agents have very similar fitnesses there is too little selective pressure. </li></ul></ul></ul><ul><ul><ul><li>Scaling methods can be used to get around these problems. </li></ul></ul></ul>
  12. 12. <ul><li>Rank Selection: Ignore absolute fitness, can use other slopes, but here the best is selected 2x more than the average. </li></ul>0 2
  13. 13. Elitism <ul><li>Force a direct un-mutated copy of the best of the last generation. </li></ul><ul><li>Never loose the best. </li></ul><ul><li>Useful if there is a lot of noise in fitness assessments, or if mutation is very likely to produce a low fitness offspring. </li></ul>
  14. 14. Mutation (Asexual Reproduction) <ul><li>Mutate at randomly chosen loci with a small probability. </li></ul><ul><li>Mutate all loci by a very small amount (vector mutation). </li></ul><ul><li>With binary you do bit flips, with real valued mutation you might multiply the value by a Gaussian distributed random number. </li></ul>
  15. 15. Recombination (Sexual Reproduction) 10100010 000111 00000011 101111 Parent A Parent B 10100010101111 00000011000111 1-point random equal crossover 0 01 0001 01 00111 Uniform crossover
  16. 16. The Competing Conventions Problem <ul><li>Head, Eye, Face, Leg </li></ul><ul><li>Face, Eye, Leg, Head </li></ul>Head, Eye, Face, Head Face, Eye, Leg, Leg OK, so two heads, and two legs. Sometimes competing conventions can help, some- times it can hinder.
  17. 17. Schema Theorem <ul><li>John Holland. </li></ul><ul><li>A theory of how GAs work. Not everyone agrees with this, but it is worth reading his book if you are interested. </li></ul>
  18. 18. A Black Art <ul><li>No universal algorithm suitable for all cases. </li></ul><ul><li>Need to get a feeling for it by doing it. </li></ul>
  19. 19. Relationship to Real Genomes <ul><li>Usually GAs use haploid genomes, not diploid ones, i.e. there is only one copy of each ‘gene’. </li></ul>
  20. 20. Homework. I’m happy to help if you need. [email_address] <ul><li>The Card Problem </li></ul><ul><ul><li>You have 10 cards numbered from 1 to 10. You have to choose a way of dividing them into 2 piles, so that the cards in Pile_0 SUM to a number as close as possible to 36, and the remaining cards in Pile_1 MULTIPLY to a number as close as possible to 360. </li></ul></ul><ul><li>Genotype encoding </li></ul><ul><ul><li>Each card can be in Pile_0 or Pile_1, there are 1024 possible ways of sorting them into 2 piles, and you have to find the best. Think of a sensible way of encoding any possible solution-attempt as a genotype. </li></ul></ul><ul><li>Fitness </li></ul><ul><ul><li>Some of these solution-attempts will be closer to the target than others. Think of a sensible way of evaluating any solution-attempt and scoring it with a fitness-measure. </li></ul></ul><ul><li>The GA </li></ul><ul><ul><li>Write a program, in any sensible programming language, to run a GA with your genotype encoding and Fitness function. Run it 100 times and see what results you get. </li></ul></ul><ul><li>Who can write the GA that solves the problem in the least number of generations? </li></ul>