Unexpected Consequences

One of the things that’s always fascinated me the most about simulated evolution is the way in which simulated organisms have a tendency to exploit any loophole or weakness in your code for an evolutionary advantage. Although I’ve designed and attempted to design a handful of evolutionary simulations, I’d never until today seen an example of this Darwinian cleverness.

A few days ago, I threw together a simple little evolution simulator in NetLogo. Each of the agents in the simulation had three genes: xcor (position along the x-axis), ycor (position along the y-axis), breednum (the number of daughter agents it spawns when it reproduces), and killpropensity (how likely the agent is to kill a random nearby agent). The simulation produced some interesting — although not terribly fascinating — behavior: those agents that produced the most offspring had a tendency to dominate. There was an interesting dynamic between the “killer” agents and the “peaceful” agents. The killers tended to form low-density groups (since if any of them were too close together, they’d usually kill each other), while the “pacifists” formed dense blooms. For a while, the killers would hold back the pacifists, but eventually, the pacifists would encroach and squeeze out the killers altogether. A typical run looked like this:

The agents inherit the color of their parents, so the coloration isn’t exactly by “species,” but it’s pretty close. As you can see, the green agents are fast-breeding pacifists, rapidly encroaching on the slower-breeding killers toward the center.

Then — and this is where the unexpected behavior and exploitation of loopholes I was talking about comes in — I introduced a new variable: mutationrate. It controls, obviously enough, how rapidly the agents mutate. Very quickly, every run started to look like this:

As you can see, this blue species has very rapidly come to dominate. You can’t see it, but this species has a rather high mutation rate. It took me a while to figure out why the fast-mutators were at such an enormous advantage. Then, I remembered that, in this simulation, the agents were competing for space, and in such a competition, the fittest organisms would be the ones that can maximize the space filled by their offspring. Since x-position and y-position were treated as genes, they were being mutated right along with the other variables, and since a rapidly-mutating position allowed the agents to jump farther from their parents and fill space more rapidly, fast mutation was an enormous advantage. It was such an enormous advantage that, even though the extremely large mutations the fast-mutators experienced prevented the evolution of any other behavior (because those genes tended to get so randomized that they effectively didn’t get passed on), they were still far more successful than any of the other species.

After I corrected for this ludicrous advantage (by setting it so that mutation rate couldn’t work on the position genes), this is what I got:

For a moment, I thought I’d solved the problem, until I inspected some of the agents and discovered that they had stopped mutating altogether. The sneaky intelligence of the genetic algorithm strikes again! I suppose that mutating would become something of a maladaptive behavior once the organism had optimized all of its other behaviors, since, after optimization was reached, any organism that mutated could only be at a disadvantage.

I realized that the only fix for this would be to force the mutation rate to stay above 2 (it’s a peculiarity of the random-number-generation code I cobbled together for this simulation that, at a mutation rate less than 2, no mutations occur). I thought that all I’d get would be the simulation I started with, but I was pleasantly surprised to discover that there was actually quite a diversity of mutation rates, and that none of these rates was at a particularly huge advantage over any of the others. This is what a run of the fixed simulator produced:

Those numbers you see hovering over every agent are the mutation rate. It appears that there’s not really an advantage to having a mutation rate above the usual 2, but it does seem that there’s not a disadvantage, either. So I can finally call this simulation fixed.

This experience reminded me that there’s a reason genetic algorithms are so popular in AI research, and that brings us to the moral of this little story: Darwinian evolution is a lot smarter than us. When writing evolutionary simulations, if there’s a loophole or a workaround or an exploit to be found in your code, then evolution will find it. Plan accordingly.

NOTE: Someone requested an image with the organisms color-coded by “kill propensity.” Since you asked nicely, and since I agree that that would be a good image to have up here, here you go. The organisms that are the darkest have the lowest probability of killing their neighbors, and the ones that are closer to white are very likely to kill:

As you can see, the situation is as I described in the body of the post: the killers have too great a tendency to limit their own growth, and are easily out-competed by their more peaceful counterparts.


9 Responses to “Unexpected Consequences”

  1. John Nash Says:

    Great article. You may also be interested in my related project at http://www.simulatedevolution.com

  2. asymptote Says:

    Your program certainly looks interesting. I’ll be downloading it post haste!

    On another note, if you liked this article, check back in a few days. I just finished building a more comprehensive behavioral evolution simulator, and I’ll be writing an article about it as soon as debugging is finished.

  3. Derek Says:

    can you color code which ones have what differences/abilities by any chance? example: which ones are killers and which are pacifists?

  4. asymptote Says:

    Yes, I can certainly do that. It seemed like rather a good image to include, so I added it onto the post. Thanks for the suggestion!

    Also, a linguistic note: I used the terms “killer” and “pacifist,” because I liked the sound of them, but few of the organisms are true killers or pacifists: even the peaceful ones have a small but nonzero probability of killing their neighbors, and even the wild ones have a small (but nonzero) probability of letting them live.

  5. Michael Novak Says:

    Very impressive. I am itching to try to replicate your model in NetLogo. If time permits, I’d like to try to do that soon, and would be really interested in double checking your model rules to verify the same model conditions and results. Have you done any other evolutionary models in NetLogo?

  6. asymptote Says:

    Well, if you’re interested, I could perhaps upload the .nlogo file.

    As for the second question, yes, I’ve tried to code a number of other evolutionary models, with varying degrees of success. Actually, I’m planning to write a post about one such attempt in the very near future, so be on the lookout!

  7. Evolving Behavior « The Life of a Math Major Says:

    […] have to trouble with actually eating food) of the kind that I talked about in my previous post “Unexpected Consequences”. What, instead, I ended up with, was […]

  8. E-cosystem « The Life of a Math Major Says:

    […] I’ve mentioned in previous posts (namely, this one and this one), I’ve always been interested in simulated evolution. Unfortunately, the evolutionary models […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: