A redwing blackbird sitting on a fence post.

LibertyBob.com

Not your candidate

Fun with Evolution

2005-01-18

Category: crafts

My latest project has kept me very busy. The concept was simple enough but I had a small logical error (embarrassing) that kept me from completion. Now I can start the next one. That?s right, it?s time for another genetic algorithm.

For those who don?t know, a genetic algorithm is a special kind of computer program that finds answers by letting potential solutions run around like savages until only one is in charge. It?s really kind of clever. The last project was simple and only evolved a population of integers (whole numbers) until they were greater than 63000. Like I said, it was pretty simple, but that was the assignment. The next one will be more interesting.

The procedure is pretty simple. You make a bunch of what ever it is you want to evolve. When you make them, you choose the attributes of the individuals at random. That means some will be ugly and others will be not quite so ugly. Some of the members will smart and others will be butt-stupid. (Think fondly of me the next time you describe someone as ?butt stupid?.) Then the fun begins.

First check your randomly picked possible winners to see if one of them has already solved the problem. If so, you?re all done. Otherwise you have to do the evolution thing. You make the next generation of your population by picking member randomly to go on. The ones that are closer to what you want have a better chance of surviving. The stupid ones have less chance to make it. The next generation will be made mostly of good ones with a few bad ones scattered within.

Then you have to breed a few of them. Again, the more fit will be more likely to breed and the less fit will be less likely to breed. This is where genetic algorithms don?t match human behavior; in humans the stupid breed incessantly. Anyway, your things now have mixed qualities from their parents. Hopefully, some of them are better than the last generation.

This will eventually move your entire population toward some kind of similar form. This is like those Appalachian villages where everybody has the same number of fingers (six per hand). To prevent this, there is a slight chance of mutation in every generation. A member is chose at random to be mutated, and then a feature of that member is randomly altered. Because this is random, it can happen more than once per generation. Theoretically, it could happen to the entire population like at the bus station.

After all this sex and mutation (didn?t think you?d read those words together in an post about computer science) it?s time to see if there are any winners. If you got a keeper, the algorithm is done. If not, you have to go through another generation. In example runs of my first program, I could get a winner in anywhere from zero to thirty-eight generations. It was cool (geek alert ).

You may be wondering, ?Who the hell cares? What?s it good for??

Let me tell you. Some things are too complex to solve easily with other computer methods. Other things are too hard to model with math. Take, for example, a business where you might be having trouble figuring how many people to hire, how much to spend on advertising, how to blah blah blah. You could throw all those combinations into a genetic algorithm and, in a few generations, have a plan to optimize your business.

But wait, there?s more! You can simulate all sorts of other situations. You can throw in scheduling constraints and have the program make an optimum schedule. You can throw in a set of rules for a game, checkers for example, and have the rules evolve to an optimal set that can defeat any old coot around the cracker barrel at the old general store. You can put in armies and let them fight it out.

My next project, provided I don?t decide it?s too much trouble and pick something easier in a fit of laziness, will be working with two species of animals that compete for the same food. It?ll be neat. I have to find a way represent the animals that the computer likes. Then I let them feed, at random, from a limited amount of food. Those that don?t eat die. It?s really kind of sad, so I?m making all the members of both species really ugly so no one will care if they slowly and painfully starve to death. The others get to fight it out to reproduce. Eventually, one species will evolve to get food more often. They?ll starve out the other species until it becomes extinct. The only way this could get more exciting was if one species ate the other. That?s more work than I want to do.

The class ends in ten days. I have to code all this by then and have it ready to turn in. I?m not too worried. As an uber-geek, I?m a pretty good coder. In no time at all I will have my little simulated animals suffering to death in my simulated harsh nature. (For those who are interested, I?m willing to sell the simulated skins of the more cool looking simulated animals and you could probably even purchase the simulated male member from one of the simulated animals to use as a simulated aphrodisiac. No simulated money, please.)

On the down side, this may cut into my blog related activities. I can tell you?re disappointed (most of the visiting web browsers have names ending in ?crawler? or ?bot?.) Oh well, just be aware that somewhere, out here in the world, there is a geek who is having a wonderful time doing one of the things he likes best (that don?t involve females).


Comments (9)