Practical Evolutionary Computation: Elitism

Posted in Evolutionary Computation, Java, Software Development by Dan on February 12th, 2009

In my previous article about evolutionary computation, I glossed over the concept of elitism. The Watchmaker Framework‘s evolve methods require you to specify an elite count. I told you to set this parameter to zero and forget about it. This brief article ties up that loose end by explaining how to use elitism to improve the performance of your evolutionary algorithm.

In an evolutionary algorithm (EA), sometimes good candidates can be lost when cross-over or mutation results in offspring that are weaker than the parents. Often the EA will re-discover these lost improvements in a subsequent generation but there is no guarantee of this. To combat this we can use a feature known as elitism. Elitism involves copying a small proportion of the fittest candidates, unchanged, into the next generation. This can sometimes have a dramatic impact on performance by ensuring that the EA does not waste time re-discovering previously discarded partial solutions. Candidate solutions that are preserved unchanged through elitism remain eligible for selection as parents when breeding the remainder of the next generation.

NOTE: One potential downside of elitism is that it may make it more likely that the evolution converges on a sub-optimal local maximum.

The Watchmaker Framework supports elitism via the second parameter to the evolve method of an EvolutionEngine. This elite count is the number of candidates in a generation that should be copied unchanged from the previous generation, rather than created via evolution. Collectively these candidates are the elite. So for a population size of 100, setting the elite count to 5 will result in the fittest 5% of each generation being copied, without modification, into the next generation.

If you run the Hello World example from the previous article both with and without elitism, you will see that it completes in fewer generations with elitism enabled (22 generations vs. 40 when I ran it – though your mileage may vary due to the random nature of the evolution).

Source code for the Hello World example (and several other, more interesting evolutionary programs) is included in the download.

This is the third in a short and irregular series of articles on practical Evolutionary Computation, based on the work-in-progress documentation for the Watchmaker Framework for Evolutionary Computation.  The first article provided an introduction to the field of evolutionary computation and the second article showed how to implement a simple evolutionary algorithm using the Watchmaker Framework.

Further Reading

An Introduction to Genetic Algorithms Introduction to Evolutionary Computing The Blind Watchmaker

Finding the Dolphin – The Great Twitter Experiment, Day 0

Posted in The Internet by Dan on February 11th, 2009

I’ve said it before, I don’t get Twitter.  For me, the hysteria generated by the flat-lined signal-to-noise ratio of this limited medium is deeply confusing. The last time I felt like this was back in the early 90s as I stared cross-eyed and frustrated at one of those Magic Eye pictures, trying to find the dolphin. How come everybody else can see something in it while to me it’s just nonsense?

Since I last wrote on the subject of Twitter, the hype has increased still further. Somebody used TwitPic to post a picture of the AirBus that landed in the Hudson River in New York. As a result, this “citizen journalist” earned himself 15 minutes of international fame, including featuring on the BBC’s television news at least twice. I somehow suspect that had he chosen to upload his snap to Flickr instead, the BBC would not have been nearly as interested. Somebody at BBC News is a Twitter lover. The corporation’s online coverage of the recent attacks in Mumbai prominently featured information sourced from Twitter, whether accurate or not.

If further evidence were needed that with Twitter the medium really is more important than the message, it arrived last week. What was this seismic event that many are heralding as the tipping point for the microblogging revolution?  Stephen Fry got stuck in a lift. No, really, that’s it. Had General Melchett used his Blackberry to phone a journalist instead of to tweet, he could not have bribed them to write about this unfortunate but utterly banal occurrence.

I am not alone in my dismissal of Twitter as an irrelevance. Terence Blacker writing in the Independent aptly described it as “self-stalking” and summed it up as follows:

Twitter may have novelty value but it is more than mere surface silliness. It is anti-thought, the deadening white noise of modern life with all its pointless business. As for the dotty idea that short computer messages are full of wit, insight or observation – that is, to quote the master twitter himself, “arse, poo and widdle”.

I discovered the Independent article via Graham Linehan’s blog. Linehan (co-writer of the peerless Father Ted) has a different take on the value of Twitter:

…the manifold possibilities of Twitter are enough to make you giddy. This is a new world, people! We are officially in the future, not with jetpacks, but with something much cooler – the hive mind. Ignore those grumpy luddites in the broadsheets and elsewhere, who don’t understand it, can’t be bothered to learn how it works and are frightened at the prospect that people are entertaining themselves in a way that doesn’t involve accepted media forms.

By now, I think that I’ve firmly established that I don’t really see the point of Twitter, but I don’t want to be dismissed as a “luddite” who “can’t be bothered to learn how it works”. So it’s time to take the red pill and see for myself how deep this rabbit hole goes. Today I’m embarking on an experiment: a two-week trial to see whether there is any substance to the Twitter hype. I’m deeply sceptical but also approaching it with an open mind. Will I experience a higher level of conciousness or will I endure and proliferate a fortnight of pointless anti-thought?

I’ve just signed up for a Twitter account. If you’re already a Twitter user, I need some followers (sounds like I’m starting my own religion here). I also need interesting people to follow. Please also send me tips on how to get the most out of Twitter. If you are one of the many people who responded to my previous post agreeing that Twitter was pointless, I will report back here at regular intervals in the next couple of weeks and let you know how it’s going on the other side.

Stand back, I’m going in…

Debugging Java Web Start Applications

Posted in Java by Dan on February 6th, 2009

How do you attach a debugger to a Java Web Start application? Normally you probably wouldn’t bother, just start the application without Web Start and debug as normal. However, if you have a bug that shows up only when running in the Web Start sandbox, as I did today, that won’t help. The Security Manager restrictions were causing a different branch of my code to be executed than when launching the application from IDEA or the command line.

It was not immediately obvious how to attach the debugger to the Web-Started VM. In IDEA, to remotely attach a debugger to the JVM, you should start the VM with following set of switches (or similar):

  -Xdebug
  -Xnoagent
  -Djava.compiler=NONE
  -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005

Where do these switches go when launching a Web Start application? Normally you launch the application by just clicking a JNLP link in your browser.

One option, which doesn’t work, is to specify the JVM arguments in JNLP file. You can already do something like this:

  <j2se version="1.5+" java-vm-args="-ea -server"/>

Adding the debug switches is trivial… and futile. The problem is that remote debugging requires the VM to open up a socket to accept connections from the debugger. Rather sensibly, Web Start does not permit untrusted applications to open sockets on users’ machines. I don’t know if it would work if the application was signed, I was too lazy to go through the hassle of signing the code.

If you want to open a socket on the client machine for debugging purposes, you are going to have to do it from the client machine rather than the JNLP file. The solution is to set the JAVAWS_VM_ARGS environment variable to include the debug switches and then to launch the javaws executable and point it at the unmodified JNLP file. From a bash shell it looks like this:

  export JAVAWS_VM_ARGS="-Xdebug -Xnoagent blah blah"
  javaws http://www.example.com/path_to/application.jnlp

You can then attach the debugger as normal.

Uncommons Maths 1.2

Posted in Java by Dan on February 5th, 2009

Version 1.2 of Uncommons Maths is now available.  This adds two new RNGs, one that is extremely fast and one that has an extremely long period (both are simply translations of George Marsaglia’s C code).  This release also includes a Rational number type to enable exact arithmetic with fractional values.