I’ve never cared too much about genetic algorithms. It sounded way too far fetched and impractical, so I’d absolutely no interest or knowledge about it. That was, until today – and this awesome article explaining genetic algorithms. There’s nothing like a well written article, and this was surely one of that kind. At the very least, it inspired me to write my own version of the idea, although without the fancy graphs, etc. Since the time I read the article, I’ve already had a few places where I think such an idea could easily be put to work :).
The idea behind this program is to begin with a base population of X people, and try to breed/mutate into Y ( where Y is specified on the command line ), through general selection and random mutation. Basically, what this means is that we can select the population fit to breed, and can randomly mutate the progenies formed out of the mating. Varying the parameters (like the policy with which we select the population fit to mate, or the probabiliy with which mutation occurs, leads to interesting results!)
So here it is in erlang, in all its glory http://pastebin.com/hk8yNEi3
1. Download and save as genetic.erl
2. Compile as erlc genetic.erl
3. Run from the command line as erl genetic.erl -s genetic test dinosaur -s init stop (If you want to evolve into a ‘dinosaur’).
The output will display a series of cross-breeding, followed by random mutations until a ‘dinosaur’ is formed ( from random 8 lettered words ).
To reiterate – please read the post linked to, it’s awesome.