I485: Biologically Inspired Computing
Lab 4: Genetic Algorithms
Summary
- Section 3.5 in de Castro's Fundamentals of Natural Computing provides a good introduction to evolutionary computing. Read it, especially section 3.5.1, which covers 'standard genetic algorithms'.
- Complete the following problems. Complete lab is worth 5 points.
- Attach answers as separate Python files to your submission for 'Assignment 3' in Oncourse
- Assignment is due by 1pm on Wednesday, April 8th
Questions or problems? See my email and office hours information.
The problems:
- Write a detailed pseudocode layout for a Python-based genetic algorithm. You will need to refer to variables for things like the array of genotypes in your population, the maximum number of generations, and the per-symbol mutation rate. You can refer to the following functions inside your loops & other control code:
init()- Initializes genotype population to random valuesget_fitness(genotype)- Evaluates fitness of passed-in genotypemutate(genotype)- Returns mutated copy of passed-in genotypeget_new_population(genotypes, fitnesses)- Uses fitness values to reproduce successful members of genotype population
- Its time to actually do a real GA run! Using a population size, genome size, and number of iterations of your preference, evolve a textual genotype to contain as many (lowercase) a's as possible. Your
init()should initialize each genotype in your population to consist of a string of random alphabet characters. Each generation, print out the best performing genotype.
- This is similar to the last question, except now we are going to be evolving the L-system grammars that we used to generate trees in Lab 2. A good encoding scheme to use — though you are welcome to use another one if you'd like — is to create our genotypes out of
['F','[',']','+', '-', ' ']characters, and interpret this as the production rule for the symbolF(in other words, you axioms will be{'F':genotype}. The space (' '), however, would not get interpreted, but rather used to indicate the end of the replacement in the production rule, so we could have variable-length rules. Use either roulette (recommended) or elite selection algorithms.
As for parameters and (most importantly) the fitness function, make these up yourself, but try to create a fitness function that a) has some plausible story of biological significancy, and b) produces interesting, organic shapes. I myself had decent luck evolving successful trees in 20 generations using a population size of ~50 genotypes, of 10 symbols each, with a per-symbol mutation rate of 0.2 and roulette wheel selection. Fitness function went like this: I believe that successful trees are good at photosynthesis, so we would select for trees with many horizontal leaves. Thus, in our formalism, I took every genotype, evaluated it as a production rule with an angle of 22 degrees, step size of 5, and interation depth of 4 steps, and for every branch that was closed with a ']' character, added to the genotype's fitness evaluation the branch's horizontal size (up to a maximum of 10 pixels, arguing that leaves generally reside on the ends of branches). Keep in mind you might have to run your GA a couple of times to get good results.
By the way, it helps a lot (both me and you) to draw your 'best-so-far' L-system every GA generation.
More
Acknowledgements
- Lab prepared by Artemy Kolchinsky.
Links
I485/I585 Biologically-inspired Computing

