Monkeys and shakespeare: genetic algorithms with Jenes

The other night at a bar, we started talking about evolution which somehow sparked a discussion about the law of large numbers and the probability that humanity is just a cosmic fluke. Eventually, someone brought up the “monkeys on a typewriter” argument which caused uproar among the philosophers in the group.

This morning, I decided to see what Wikipedia had to say about monkeys and typewriters and eventually stumbled across an article about the “Weasel program” which Richard Dawkins wrote to demonstrate “random variation and non-random cumulative selection in natural and artificial evolutionary systems.” Basically, it simulates the monkeys on a typewriter to produce a line from Hamlet. At this point, I was hooked – I wanted to make one.

I’d experimented with genetic algorithms in a class I took at Tufts and I’ve been increasingly curious since the “evolving Mona Lisa” code got out on the web.

Anyway, I decided to use the Jenes library to whip up some code to “evolve” strings. The Jenes library is absolutely fantastic. It is easy to setup, easy to use, and the documentation is well written and easy to follow.

My implementation is online at: http://setfive.com/evolve.php

And it evolves Dawkin’s Hamlet line in about 3 seconds – link

The code to run the genetic algorithms is written in Java and uses a Jetty container to accept and processes HTTP requests. Using an embedded Jetty container proved to be seamless and the application server seems to running pretty smoothly.

A zip file containing an Eclipse project for the code is available here.

Additionally, a self contained JAR for the server is available here . Start it with java -jar wordga-jetty.jar

As always, questions and comments are welcome.

Posted In: Demo

Tags: , ,

  • Jack Glover

    Hi,

    I am interested in your use of the Jenes library with Eclipse. I agree that it looks more simple to use than other EC/GA libraries I’ve looked at for Java but I’m not finding it so easy to setup and get started with.

    I’m not new to programming but am new to Java and Eclipse (my brief background is in C++ and a little C# so not all concepts are alien to me).

    My main issue is setting up the library and IDE to a point where I can start using the algorithms to evolve African drum rhythms being initialized and rendered by a max/msp patch. In what form and how do I use the library in the java build path? And perhaps you could briefly explain what you had to build on top of the library to use the algorithm?

    Perhaps that last question will be answered if I can get to a point where I can build one of the tutorials, but I don’t find it so intuitive to get to that point yet.

    Thanks for any help you can offer.

    Jack