Notes · artificial life and neuroevolution
NEAT0: Evolving Foraging Creatures
Small bilateral creatures forage for food in a 2D world. Each has a brain that evolves NEAT-style and can also learn during its lifetime. Nothing is hand-coded as a strategy: behaviour, brain wiring and body plan come from selection alone.
1Overview
NEAT0 is a two-dimensional artificial-life simulation. A population of simple creatures forages for a renewable food resource. Two mechanisms shape behaviour:
- Evolution across generations. A NEAT-style (NeuroEvolution of Augmenting Topologies) neural controller undergoes structural and parametric mutation at every reproduction.
- Learning within a lifetime. Reward-modulated Hebbian plasticity adjusts the inherited weights while a creature is alive.
Reproduction is asexual. NEAT's crossover, speciation and fitness-sharing machinery is not implemented, because it exists to make two-parent recombination safe and is not needed for clonal reproduction with mutation. There is no fitness function: a creature succeeds only by gaining enough energy to grow and divide.
The code has five parts:
- an evolvable brain genome with its mutation, activation and plasticity logic;
- a regrowing food field;
- the creature body, covering sensing, movement, metabolism, growth and fission;
- a world object that runs the tick loop and holds the single parameter dictionary;
- a GUI with live sliders for every parameter.
See Table 4 for the files.
2Movies
These are screen recordings of the simulation window. The top line of each frame shows the tick, the number of creatures alive, and the population means of size, limb count and brain node count. Green shading is the food field: darker means more food. Creatures are drawn as ovals with stick legs, and the red dots are their two food sensors (antennae).
Forage evolution
Ticks 4131 to 4934, 66 s. Two or three surviving creatures forage on a sparse patch map, with a mean brain size of 7 nodes.
ForageEvolution.mp4 · 0.6 MBSpinner, patroller, wanderer
Ticks 4857 to 5656, 59 s. Three creatures on the same map, each moving in a different way: the file name labels them spinner, patroller and wanderer.
SpinnerPatrollerWanderer.mp4 · 0.6 MBWigglers
Ticks 8784 to 8977, 27 s. A larger population (18 to 22 alive) on a map with many small patches, travelling as a tight group.
Wigglers.mp4 · 0.3 MBWeb versions of the screen recordings: H.264 MP4, 720 pixels wide, 30 frames per second. The full-resolution QuickTime originals are not on this site.
3World and body
Food field
The world is a toroidal grid of food density.
- Capacity map. Built once, as a sum of Gaussian patches at random locations. The patch count is the patch density times the sandbox area, so difficulty does not change silently when the sandbox is resized.
- Regrowth. Food regrows logistically toward the capacity \(C\):
with the rate \(r\) read every tick, so it can be changed while the simulation runs. Creatures sense food at continuous positions by bilinear interpolation, and eat from the nearest grid cell, up to a cap per tick.
Sensing and movement
The brain has five inputs:
- food at the left and right sensors, placed at \(\pm\)
sensor_angleoff the heading andsensor_distahead; - stored energy, normalized and clipped to \([0,2]\);
- the tick-over-tick change of each food sensor (delta_left, delta_right).
There is no long-range sensing and no perception of other creatures. The two outputs set turning and speed:
\[ \begin{equation} \dot\theta = 2(\text{turn}-0.5)\,\theta_{\max}, \qquad v = \text{speed}\cdot v_{\text{limb}}\cdot n_{\text{limbs}}, \tag{2}\label{eq:move} \end{equation} \]so a turn output of exactly 0.5 means straight ahead, and top speed grows with the evolved limb count.
Metabolism, growth and fission
Each tick a creature does the following:
- Eats.
- Pays a metabolic cost. The cost has five terms: a flat baseline, a term proportional to its current size, a term proportional to its limb count, a term proportional to its brain size (nodes plus enabled connections), and a movement term proportional to speed times size.
- Learns. The net energy change (intake minus cost) is the reward for its in-life learning.
- Dies if its energy reaches zero.
- Growth. Size is a dynamic state. It starts at half of the heritable
max_sizeand grows toward it. On a tick with an energy surplus, growth takes up tomax_growth_rateof the surplus first, and only the rest goes into the energy store. On a tick with a deficit, the creature does not grow; the store covers the shortfall. This follows how real single-celled organisms divide their energy, with growth drawing on current uptake and the store serving as a famine buffer. - Fission. When size reaches
max_size, the parent is replaced by two half-size offspring. Every creature reproduces exactly once, with exactly two offspring. The trigger is size alone, with no energy condition. The parent's remaining energy, minusfission_cost, is split evenly between the two offspring, so a better-fed parent produces better-provisioned offspring. - Inheritance. Each offspring gets a mutated copy of the brain, plus independently perturbed
max_size,limb_countandmax_growth_rate. - Population cap. Fission is suppressed at
max_population. This is the model's only hard density control.
4The evolvable brain
The genome holds two kinds of genes:
- Node genes: input, output or hidden. Every non-input node has an evolvable bias.
- Connection genes: \((\text{in}, \text{out}, w, \text{enabled}, p, w_0)\). Here \(w\) is the current weight, \(p\) an evolvable plasticity magnitude, and \(w_0\) the baseline weight set at birth or by the last weight mutation.
Every creature starts minimal: 5 inputs, 2 outputs, no hidden nodes, and all 10 input-to-output connections (Figure 4). The turn and speed weights start small, uniform in \(\pm0.05\), so newborn ancestors move nearly straight instead of locking into tight circles.
Forward pass
Mutation can create arbitrary depth and loops, so the network is evaluated by relaxation: every non-input node updates from its weighted input sum plus its bias, through a sigmoid, for brain_n_steps iterations. Hidden and output values persist from one tick to the next; only the inputs are overwritten. This matters because loops are common. In simulated lineages at the model's own mutation rates, 199 of 200 developed a real cycle within 500 generations, with a median of 42 generations.
Mutation operators
Seven operators act at each fission, each with its own probability:
- Weight perturbation. The new weight also becomes the new baseline \(w_0\).
- Bias perturbation on non-input nodes.
- Plasticity perturbation, clipped to \([0,2]\).
- Add-connection. No check against closing a loop.
- Add-node. A NEAT edge split: the new hidden node has bias 0, and the two new connections reproduce the old one almost exactly.
- Prune-connection and prune-node.
The operators do not favour safe targets. Selection judges the outcome.
Learning within a lifetime
Each connection with \(p > 0\) keeps an eligibility trace \(e\) of recent pre- and post-synaptic co-activity:
\[ \begin{align} e &\leftarrow \lambda\,e + (a_{\text{pre}} - 0.5)(a_{\text{post}} - 0.5), \tag{3}\label{eq:trace} \\ \Delta w &= p\,R\,e - d\,(w - w_0), \tag{4}\label{eq:dw} \end{align} \]where \(R\) is the tick's reward (net energy change), \(\lambda\) = trace_decay and \(d\) = plasticity_decay_rate. Each of the three ingredients fixes a failure that was observed:
- Centering (the \(-0.5\)). Sigmoid outputs are positive, so without centering every plastic weight moves in the same direction under sustained reward. This was seen to drive all of them to the clip bound.
- Homeostatic decay toward \(w_0\). It limits how far learning alone can move a weight, however long a reward of one sign lasts.
- The eligibility trace. It handles the distal-reward problem: food from a good turn arrives several ticks later. With \(\lambda = 0.9\) the trace remembers about 9 ticks. Traces are not inherited.
The brain cost term (nodes plus enabled connections) is the only force against unbounded growth of the network.
5Parameters
Every tunable value lives in DEFAULT_PARAMS in world.py, and every one appears as a live slider in the GUI. None has been tuned to a target regime: the values are chosen to be plausible and to run.
| Parameter | Default | Role |
|---|---|---|
| energy_ref | 10.0 | Scale that normalizes the energy input |
| eat_rate | 0.15 | Max food eaten from one cell per tick |
| base_cost | 0.02 | Flat cost per tick |
| size_coef | 0.01 | Cost per unit of current size |
| limb_coef | 0.005 | Cost per limb |
| brain_coef | 0.001 | Cost per node or enabled connection |
| move_cost_coef | 0.02 | Movement cost = this × speed × size |
| energy_capacity_coef | 25.0 | Energy cap = this × size |
| background_hazard | 0.0 | Random death probability per tick (off) |
| max_growth_rate | 0.001 | Heritable. Cap on energy per tick that growth can absorb |
| growth_cost_coef | 1.0 | Energy per unit of size gained |
| fission_cost | 0.0 | One-time energy cost at fission |
| mut_weight_rate / _scale | 0.3 / 0.4 | Weight mutation: probability per connection / std. dev. |
| mut_bias_rate / _scale | 0.3 / 0.4 | Bias mutation: probability per node / std. dev. |
| mut_plasticity_rate / _scale | 0.1 / 0.2 | Plasticity mutation: probability per connection / std. dev. |
| plasticity_decay_rate | 0.5 | \(d\) in Eq. \eqref{eq:dw} |
| trace_decay | 0.9 | \(\lambda\) in Eq. \eqref{eq:trace} |
| mut_add_conn_rate | 0.05 | Add-connection probability |
| mut_add_node_rate | 0.03 | Add-node probability |
| mut_prune_conn_rate | 0.05 | Prune-connection probability |
| mut_prune_node_rate | 0.03 | Prune-node probability |
| mut_body_scale | 0.15 | Std. dev. of max_size and limb_count mutation |
| mut_growth_rate_scale | 0.0005 | Std. dev. of max_growth_rate mutation |
| turn_init_scale / speed_init_scale | 0.05 / 0.05 | Ancestors only: range of the initial output weights and biases |
| max_turn_rate | 0.5 | \(\theta_{\max}\) in Eq. \eqref{eq:move}, rad per tick |
| speed_per_limb | 0.15 | \(v_{\text{limb}}\) in Eq. \eqref{eq:move} |
| sensor_angle | π/4 | Sensor offset from the heading |
| sensor_dist | 3.0 | Sensor distance ahead |
| brain_n_steps | 3 | Relaxation iterations per forward pass |
| max_population | 500 | Hard population cap |
| regrow_rate | 0.05 | \(r\) in Eq. \eqref{eq:regrow} |
| patch_density | 1/150 | Patches per unit area (set at Reset) |
| patch_radius | 2.0 | Radius of each food patch (set at Reset) |
| capacity_peak | 5.0 | Peak capacity at a patch centre (set at Reset) |
6Findings: two foraging strategies
One run produced two distinct evolved foraging strategies. Both survived a severe bottleneck, and both went on to fill the population together. Run settings:
- 40 ancestors, seed 901891, a 120 × 120 sandbox;
- a population cap of 300, which was the GUI's default at the time (see the bug note below);
- every other parameter at its default.

- By tick ~2,000 the 40 ancestors have collapsed to 2 survivors.
- Two recovery attempts near ticks 25,000–27,000 fall back to one survivor.
- A partial recovery starts near tick 48,000.
- A lasting breakout starts near tick 70,000 and reaches the cap of 300 by about tick 85,000.

- Orbit (creature 47).
- Circles one patch with a period of about 90–100 ticks, keeping its energy between 25 and 28.
- Its strongest weight is left food → speed (−0.57): more food ahead means slower, which turns gradient-following into staying put.
- Patrol (creature 45).
- Runs a circuit of about 550 ticks.
- Its turning is dominated by delta_left (−0.31), several times larger than either raw food weight. It steers on whether food is rising or falling, not on the food level itself.
- Its energy peaks higher than the orbiter's (35.7 against 27.7) but swings more, down to 14.5.
Neither strategy displaced the other. At tick 91,500 the population was full (\(n = 300\)). Classified by which turn weights dominate:
- 137 creatures (45.7%) were delta-dominated;
- 79 (26.3%) were raw-food-dominated;
- 84 (28.0%) were mixed.
Each strategy began with one mutation
While the simulation was running, a parent was seen producing one daughter that kept its strategy and one that did not. To find out why, every fission was instrumented to record the parent's and both daughters' turn weights at the moment of birth. Both strategies trace back to the same ancestor, creature 31 (Figure 7).
| left food | right food | energy | Δ left | Δ right | |
|---|---|---|---|---|---|
| Parent 31 | 0.0279 | −0.0224 | 0.0347 | −0.0048 | −0.0099 |
| Daughter 40 | 0.0279 | −0.0224 | 0.0347 | −0.0048 | −0.0099 |
| Daughter 41 | 0.0279 | −0.0224 | 0.0347 | −0.3056 | −0.0099 |
| left food | right food | energy | Δ left | Δ right | |
|---|---|---|---|---|---|
| Parent 40 | 0.0279 | −0.0224 | 0.0347 | −0.0048 | −0.0099 |
| Daughter 46 | 0.0236 | −0.8495 | −0.6202 | −0.0048 | −0.0099 |
| Daughter 47 (orbit) | −0.1462 | 0.0519 | 0.0457 | 0.0902 | −0.0099 |
Both strategies are therefore founding mutations, not learned behaviour.
- Patrol. One Gaussian draw moved delta_left → turn from −0.0048 to −0.3056.
- Orbit. It appeared one generation later on the unmutated branch.
- No learning. Creature 47's weights at tick 4,800 were bit-for-bit identical to its weights at birth, so plasticity played no part in these two lineages.
7Related work and code
No single mechanism here is new. What defines NEAT0 is the combination, and what it leaves out:
- NEAT-style structural mutation, asexual only (Stanley & Miikkulainen 2002);
- evolvable per-connection plasticity with decay toward an inherited baseline (Floreano & Urzelai 2000; Soltoggio, Stanley & Risi 2018);
- implicit fitness through energy alone;
- a two-point food sensorium, with no vision, mating or predation.
The closest ecological precedent is Yaeger's PolyWorld (1994): evolved Hebbian brains in a 2D world with shared food. It differs in having sexual reproduction, vision and predation. Other related work:
- Risi & Stanley (2010) pair NEAT-style evolution with evolved plasticity, but use an explicit fitness function.
- Izhikevich (2007) frames the distal-reward problem that the eligibility trace addresses.
- Cylke, Serbanescu & Banerjee (2024) give the energy-allocation picture behind the growth rule.
Running it
python3 creature_gui.py --n-orgs 1
This opens two windows:
- Simulation window. The world, a scrolling graph of one of 15 metrics, and Run / Step / Reset / Fast-forward controls.
- Parameters window. A live slider for every parameter, and a read-only list of all values.
Other flags: --width, --height, --max-population, --seed.
| File | Version | Role |
|---|---|---|
| neat_brain.py | 1.6d0 | Genome, forward pass, seven mutation operators, eligibility-trace learning |
| environment.py | — | Patchy, regrowing food field; bilinear sensing and eating |
| creature.py | 1.8 | Body, sensing, metabolism, growth and fission; heritable antenna length with a breakage risk |
| world.py | 1.9 | Tick loop; DEFAULT_PARAMS, the single source of every parameter |
| draw_creature.py | 1.1 | Rendering: oval body, stick legs, red antenna dots |
| creature_gui.py | 1.14 | The two-window GUI |