Back to home

Evolving intelligent agents

Creatures on a grid evolve their own neural networks. My dissertation tested which settings evolve the fittest ones.

The simulation viewer: the generation, tick and selected creature's details on the left, the grid of creatures in the middle, and the selected creature's neural network on the right
The simulation viewer at generation 84. Most of the creatures (blue) have gathered in the top-right corner, which the fitness landscape rewards. On the right is one creature's brain, with positive weights in green and negative ones in red.

About

This was my final-year project for a BSc in Computer Science and Artificial Intelligence at Aberystwyth University, supervised by Dr Arina Buzdalova. It asks which settings help NEAT (NeuroEvolution of Augmenting Topologies) evolve the best agents for tasks they're never told about.

Creatures live on a 2D grid, as many as each experiment asks for, and each is controlled by its own small neural network. They're given the inputs they can sense, such as how far they are from each wall, and the actions they can take, such as moving a square or waiting, and every tick their network picks one. The map and the fitness landscape can both be changed too. Nobody tells the creatures the goal: the landscape quietly rewards certain places, like the centre or the corners in most of my tests, and at the end of each generation the fittest pass on mutated copies of their brains.

NEAT evolves each brain's structure as well as its weights, adding and removing connections and hidden neurons over the generations. Everything is plain Python, including the neural network, which doesn't use a library such as PyTorch, so every part of the algorithm could be changed and measured.

Experiments

Runs are scheduled from one configuration and repeated with fixed seeds, so every result can be reproduced exactly. Seven tests covered mutation, tournament size, elitism, crossover, a hard map with walls, five species competing for space, and starting from a ready-made network. The longest took up to 90 hours, and one ran for 10,000 generations.

Mutation settings

The first test tried 81 combinations of weight mutation strength, which is how far a weight can move when it mutates, and rate, which is how likely each weight is to mutate. Each combination ran for 250 generations, 20 times over.

Average fitness after 250 generations for each pair of settings, averaged over 20 runs. Hover a square to see its settings.
Weight mutation rate
0.50.550.60.650.70.750.80.850.9
Weight mutation strength0.2 70.3 72.0 74.6 70.1 71.0 70.6 68.6 69.3 67.9
0.14 72.5 72.4 74.0 72.1 69.7 72.1 74.0 73.0 72.7
0.1 70.1 74.3 72.6 74.2 76.2 75.4 72.4 72.6 74.1
0.07 75.6 76.5 76.4 74.2 75.9 72.7 75.5 74.3 74.8
0.05 74.8 74.6 73.6 77.9 79.4 73.8 77.4 77.3 75.6
0.04 77.9 77.5 77.8 76.1 73.9 74.9 78.1 75.0 76.1
0.03 77.0 77.8 78.2 76.7 75.5 74.8 79.5 75.5 75.7
0.02 76.7 76.1 74.4 74.7 75.6 78.5 76.2 76.4 77.1
0.01 74.4 76.7 77.5 73.8 76.7 77.2 78.6 76.2 77.8

Strengths from 0.01 to 0.05 all did about as well. From 0.1 up, fitness fell, and the drop was statistically significant (Kruskal–Wallis, p < 0.001): big mutations break brains that were nearly right. The rate barely mattered. The best and worst rates finished only about 1.2 apart, and no difference between them was significant.

Mean fitness for each value, averaged over the nine values of the other setting and 20 runs of each. Std is the standard deviation across those nine at generation 250.
ValueGen 50Gen 100Gen 250Std at 250
Weight mutation strength
0.0159.0467.1976.561.56
0.0258.6867.4776.181.25
0.0360.0467.5676.751.54
0.0458.1565.7876.361.54
0.0558.2966.6376.052.03
0.0758.1467.0475.111.23
0.157.9264.7773.551.84
0.1457.7765.1172.511.27
0.255.8962.3170.491.98
Weight mutation rate
0.558.7666.2674.362.84
0.5558.6366.7875.322.12
0.658.9366.1375.472.06
0.6558.3166.2174.422.37
0.758.1366.0774.892.96
0.7557.8465.3974.472.47
0.858.0666.6575.583.46
0.8557.6165.3474.412.45
0.957.6365.0274.652.97

What I found

  • Weight mutation strength is sensitive at the high end, from 0.1 up.
  • Tournament selection works best with a small group of 2.
  • Elitism can speed evolution up, but the effect was often not statistically significant.
  • Crossover hurt here: populations converged early, often on worse solutions.
  • How often weights mutate makes very little difference.
  • In simple fitness landscapes, starting from a ready-made network learned faster than NEAT's usual minimal start, probably because smooth landscapes need less structural evolution.