Project of the week: Genetic Algorithms
Sunday, December 14th, 2008So it seems like every other week or so I start work on another little side project that ultimately won’t amount to much but expands my knowledge and abilities. This week, that project was the creation of a genetic algorithm that attempts to recreate images using only 140 colored, translucent circles.
The way it works is it starts out with a base population of 24 random sets of circles and uses a simple image-difference fitness function to determine the “fittest” images, which are then picked and “mated” with each other at random to produce offspring for the next population of 24, along with a clone of the fittest image and a random candidate from the set of “losers”. Some of these circles are also mutated at random, which is of course necessary for new “genetic material” to enter the population. Of course, the objective here is that an increasingly accurate image will gradually “evolve” and since it’s mathematically impossible to have a “correct” solution with only 140 circles, the image will continue “evolving” forever, although I’m sure at some point it will stop being able to progress.
So far, I’ve had some interesting success. The program is still running, and here are the current results (this will be updated every few seconds or so for a while… it’s continually running):
Target Image:

Current Results:

The Code
Only 160 lines of Python
EDIT (12/28/08):
I have stopped the program because it seemed to reach a point where no progress was being made. It seems there is only so much one can do with 140 colored circles.
