Friday, March 11, 2011

Python Genetic "Hello World"

I've always enjoyed using computers to solve problems I'm too lazy to solve myself (see my Monte Carlo attack on an old math joke). That's why I got really excited when I read Howard Yeend's post on Genetic Algorithms, which made everything seem complex but accessible. My proven method for trying to understand something to write a program to do it for me (this dates back to learning the quadratic formula by writing a program for the TI-83 in high school), I figured I'd try my own Genetic "Hello World."
Here we can see the output from running the Genetic Hello World program. It took 76 generations to reach the target string.
There's many great resources for Genetic Algorithms, but here's a high level overview. A random sample of chromosomes is created. These chromosomes are combined, and the ones that score the best on a fitness function are kept for the next round of breeding. If you have a good fitness function, your solutions get better and better until you have an acceptable answer.

The source for this project is available on github. There's a README included that explains how to get set up and how to modify it to play with it yourself. I'm embedding the main script here so you can take a look: 

No comments:

Post a Comment