Showing posts with label genetic algortithm. Show all posts
Showing posts with label genetic algortithm. Show all posts

Thursday, September 1, 2011

The Evolution of Lines

Good evening, ladies and gentlemen...

Bang Goes the Theory had a segment using the repeated freehand tracing of a single line to illustrate some of the basic mechanisms of evolution. It lacked any selective pressure, so I whipped up a program to add some. I started with ten perfectly straight lines, each of which had ten offspring with a small chance of containing replication errors (1% to shift each pixel one place right or left). From that pool of one hundred, I then chose the ten that most resembled my target shape and repeated the process. To keep it simple, I didn't require the line be continuous (in fact, it's not technically a line as there's only one pixel for each vertical position on the image). I used the sum of the horizontal distance squared for each pixel from it's target x value as a measure of fitness. You may recognize the final shape, which took 2,200 generations to settle upon. Its efficiency could be increased dramatically as the algorithm employed was crude.

This is a lot less involved (asexual reproduction for a start) than many genetic algorithms I've written, but it's much less abstract.