Info
This post was imported from a personal note. It may contain inside jokes, streams of consciousness, errors, and other nonsense.
I know I was gonna use the command line to perform these but I ended up using a single key press instead. I have to recompile when I change the parameters, sure, but it gives me a very tight feedback loop and I’m already recompiling every few minutes anyway.
It’s kinda janky but it works!
Here’s the first generation:
There’s a lot of sitting around doing nothing. Guy in the top right is just rotating without moving. One in the bottom left isn’t even doing that much.
Here’s three generations later:
Some of them are moving towards food. Some of them are still moving away from them but they’re all moving.
The current code just counts the number of food sources each boid ate, grabs the top four, and repopulates with mutations of them. The top two boids will get two extra offspring in the new world. Mutations are limited to ±0.1 for weights in the range ±1.
I think this is fifth gen.
And here’s gen twelve.
Now gen thirteen.
I don’t see it in these animations but I saw a good trick where the boid will slow down as it gets close to the food source, allowing it to turn toward it and consume it instead of going in circles around it like a planet around its star.
They don’t default to traveling in a straight line but a large-ish circle, when no food is around.
By now the weights have mostly converged:
id, generation, numFoodsEaten, w0, w1, w2, w3, w4, w5
1, 13, 0, 0.571895, -0.427354, -0.958601, 0.384091, -0.676696, 0.862017
2, 13, 0, 0.711493, -0.42324, -0.72439, 0.196152, -0.419754, 0.500568
3, 13, 5, 0.77914, -0.384487, -0.796737, 0.374618, -0.318946, 0.727973
4, 13, 0, 0.465013, -0.404331, -0.811887, 0.328126, -0.755604, 0.722169
5, 13, 8, 0.584432, -0.306519, -1, 0.411557, -0.501489, 0.828471
6, 13, 1, 0.741425, -0.517316, -0.780092, 0.22938, -0.474822, 0.603037
7, 13, 2, 0.846696, -0.472179, -0.598141, 0.330885, -0.319629, 0.553053
8, 13, 0, 0.438651, -0.42581, -0.98406, 0.369253, -0.697387, 0.73636
9, 13, 7, 0.574593, -0.372842, -0.948933, 0.352718, -0.527027, 0.701074
10, 13, 3, 0.766115, -0.410288, -0.770217, 0.384262, -0.425003, 0.506281
I need to recap for myself what these actually do. w0 (bias to speed) - positive, 0.3 to 0.8 w1 (bias to turn) - negative, -0.3 to -0.4 w2 (food detect to speed) - very negative, -0.6 to -1.0 w3 (food detect to turn) - positive, around 0.3 to 0.4 w4 (food direction to speed) - negative, -0.3 to -0.8 w5 (food direction to turn) - positive, 0.5 to 0.9
Interpretation.
- w0 Always move forward but not necessarily as fast as possible.
- w1 Always turn to the left.
- w2 The closer you get to food the slower you should go.
- w3 Turn to the right to counter the effect of the bias on the turn, looks like.
- w4 If the food is on the left the speed up but on the right slow down. What? Weird.
- w5 Turn in the same direction as the food. That makes sense.
Should try with different random initializations and see what happens. Should also make it so I can run the sim faster than real-time.
It’s weird how the behaviour of turning away from food is so persistent.
Running the Sim Faster than Real-Time #
Maybe start by pressing a key to do a bunch of steps real quick? Or press a key to run until 80% of the food sources are consumed then select, mutate, repopulate.
On my system the elapsed seconds per step seems to hover around 0.016-0.017.