Sometime mid-December I read a blog with a brilliant little piece of genetic programming, wherein a set of pseudo-DNA is used to generate an image out of a set of, at maximum, fifty semitransparent, overlapping polygons, in an effort to “evolve” this pseudo-DNA toward looking as much as possible like the Mona Lisa. The idea is, can something specific evolve through only a series of randomly generated mutations?
As genetic programming goes, this is a great example, however I have to take issue with the approach as being an example of “evolution” — by my understanding, at least, not that I’m a geneticist, biologist, or even a decent programmer. The original program has a population of two, the original and the slightly-mutated “offspring”. The offspring is compared to the target image, and if it is more like the target image than the original, then it replaces the original for the next iteration. After almost a million iterations, as shown on his blog, the image looks significantly like the original.
More on my attempt at this same concept below the fold…
This is where the shortcoming comes in — that’s not how evolution works. In my opinion, that’s far too much pressure being applied on the selection process, much more than any real environment would apply to an organism (except, I suppose, in extreme circumstances, and where the parent has unlimited tries to create the more-fit offspring at the risk of extinction).
In a real environment, the only analog to Alsing’s code that I could think of would be whether or not a creature’s appearance allows it to blend into its environment, and thus avoid predators. In researching genetic programming when my interest was piqued by this project, I found a small Flash applet by scikidus, wherein “color creatures” are evolved through random mutation toward a specific background color, due to the population’s least-similar colors getting “eaten by predators”, leaving the more successful color creatures to cross-breed and repopulate. The idea is sound, and while still a hill-climbing algorithm, it’s a better emulation of real evolution than Alsing’s example. A larger population, with predators culling the most visible creatures, emulates a much more realistic, more “natural” scenario. Forcing only the more-fit creature to survive, as Alsing’s experiment did, is more like “intelligent design that happens to use evolution as its mechanism” than it is true evolution.
So, being the do-it-yourself kind of geek, I decided to try my hands at crossing both examples together — making a population of polygon creatures that evolve toward looking as much like their “environment”, the target image, as possible, while not making it explicit or 100% certain that the more-fit creatures get selected.
Thus far, I have managed to duplicate Alsing’s original concept, even if my code is horribly unoptimized and ugly. The random mutations that are possible include changing the background color, adding a randomly generated polygon, deleting a polygon, modifying a polygon by adding or removing points or changing its color, reshuffling the order in which the polygons are drawn, changing the percent likelihood that this creature will create a male as opposed to a female, and changing the creature’s current mutation drift rate (e.g., the number of mutations that happen in the next generation). At the moment, since all I’ve implemented is a duplication of Alsing’s original concept, the gender of the offspring is not used, however it will be once I code the cross-breeding routine.
In a bit of a Murphy’s Law moment, however, my laptop’s power supply started beeping today, indicating that it took some kind of surge or something and would no longer provide power to my laptop. I’m posting this from another computer, and I unfortunately didn’t manage to get my Python folder when I was panickedly copying everything of import from it to my portable drive while the laptop’s battery was slowly draining away. So, sadly, I can’t post the code I have so far at the moment. I swear this program exists — both Pickles and Jodi have seen it in action, and I even showed Abby the outcome of one of my tests. Rest assured, I have every intention of posting it, along with complete instructions on how to set up a Python environment so you can run the program. I also intend on making it so that you can pass it in the command line switches to make it run like Alsing’s original, like my new-and-improved version, and to generate optional, detailed debug logs if you happen to be skeptical that my code could actually be generating this stuff randomly, et cetera.
Tomorrow I should be able to either use a generic multi-laptop power supply, or at least put my laptop’s hard drive into another laptop in order to recover the files to my portable drive. Either way, I’ll be able to post the code as it stands tomorrow. And I’ll be back into my laptop within the week to be able to continue programming. Though I’ll probably end up procrastinating more.
Here are some links to tide you over, if you’re actually actively interested in this project.
An attempt to evolve “painter programs” toward a portrait of Darwin, using many more paint tools than polygons, written in Java
Update: I got another power supply for my laptop; luckily Staples carries HP power supplies.