A genetic algorithm example in Erlang.

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.



This entry was posted in Uncategorized and tagged , , , , , , , . Bookmark the permalink.

3 Responses to A genetic algorithm example in Erlang.

  1. Anonymous says:

    appreciate the effort

  2. Pingback: Erlang: Links, News And Resources (14) | Angel "Java" Lopez on Blog

  3. Pingback: Genetic Algorithms: Links And Resources (4) | Angel "Java" Lopez on Blog

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s