ES-HyperNEAT (Risi & Stanley, 2012) is a lovely trick for evolving neural networks. Most neuroevolution methods work on the network directly: start from random weights, or a bare-bones network, and mutate it connection by connection, adding neurons as they go. The network is just a tangle of links, and nothing in it has a place. ES-HyperNEAT gives every neuron a place. Its neurons live at points in a geometric space, the substrate, and evolution never touches a single weight. Instead it evolves a small function, built by composing simple pieces like sines, bumps and slopes, that takes the positions of any two neurons and returns the weight between them.

To picture it, fix one end of a connection at a sensor. Then every point in the space has a weight: the weight a neuron placed there would get from that sensor. The result is a landscape of weights spread across the substrate. Where the landscape is flat, neurons placed close together would get the same weights and compute the same thing, so one is enough. Where it varies, each neuron picks up something different, so that’s where neurons are worth adding. ES-HyperNEAT finds those places by splitting the space into quarters, and splitting again wherever the weights still vary. (The ES in its name stands for evolvable substrate.) The brain ends up growing neurons where its wiring needs detail, and its wiring is drawn rather than listed.

That only works if the brain’s space can hold the problem’s shape. A creature steering through 3D space needs wiring that varies with direction in three dimensions: up against down, left against right, and everything in between. In a 3D brain that pattern can sit where it naturally belongs. On a flat sheet, which is where ES-HyperNEAT’s brains usually live, it has to be squashed to fit, and squashing a sphere always puts something next to its opposite. The structure the creature needs gets crushed together, and the search for complexity ends up working on a distorted map of the problem. So does a 3D creature need a 3D brain?

Four neurons that won’t fit on a page

Here’s why the answer might be yes. Take the simplest wiring rule a geometric brain can have: neurons that are close together connect strongly, and neurons far apart don’t. Now try to build a tiny brain with it.

Three neurons that should all talk to each other equally are easy. Put them at the corners of an equilateral triangle. Now add a fourth that should talk to all three just as strongly as they talk to each other. On a flat sheet there’s nowhere to put it. The only point equally far from all three corners is the triangle’s centre, and that’s too close: about 0.58 of a side away, so it would be wired more strongly than the others are to each other. Give the brain a third dimension and the problem disappears. Lift the fourth neuron out of the page and the four make a tetrahedron, every pair the same distance apart.

That’s a general fact. In \(n\) dimensions, at most \(n + 1\) points can all be the same distance from each other, so the dimension of the space caps how many neurons can share an equal-strength clique. The cap shows up in looser forms too. Ask how many neurons can sit close to one central neuron without crowding each other, and you’re asking a question mathematicians call the kissing number: how many equal balls can touch one ball without overlapping. The answer is 6 on a flat sheet, 12 in three dimensions and 24 in four.

That number matters more than it sounds. In a brain wired by closeness, a neuron’s neighbours are what it listens to and what it drives. If two of those neighbours are also close to each other, they share everything else too: the same hidden neurons, the same outputs, the same influence. Their signals get mixed whether you want them mixed or not. A higher kissing number means a neuron can have more partners that are each close to it but far from one another, so it can bring many signals together while each one keeps its own separate wiring everywhere else. That’s what a lot of learning tasks need: many specific “this goes with that” relationships at once, without crosstalk between them. A flat brain runs out of room for them first.

So under a “connect what’s close” rule, the dimension of the brain isn’t a detail. It decides which patterns of near and far are even possible.

Why a 3D creature might care

The creature in this post is a single cell chasing a drifting speck of food through 3D space. It senses which way the food is with 14 sensors pointing in fixed directions (towards the faces and corners of a cube), and it moves with 6 thrusters, pushing up, down, left, right, forward and back.

A good controller is easy to describe. If a sensor fires, the food is roughly that way, so fire the thrusters that point the same way. Put every sensor and thruster in a 3D brain at the direction it points, and “points the same way” becomes “sits close by”. The one-line locality rule then is the controller.

A flat brain can’t do this, and there’s a theorem that says so. The Borsuk–Ulam theorem says that any continuous way of flattening a sphere onto a plane puts some pair of opposite points in the same place. Its most famous consequence is about the weather: right now, somewhere on Earth, two exactly opposite points have the same temperature and the same pressure. For our cell it means any smooth flat layout puts some direction on top of its opposite, so “food above” and “food below” become neighbours. The only way out is to tear the sphere somewhere, and the question becomes where you tear it.

So the test is simple. Give the same cell, the same task and the same evolutionary algorithm a 3D brain or one of several flat ones, and see what happens. Then try it on creatures that live in four and six dimensions.

Evolved cells chasing food. Each chase shows the next evolved run, so successes and failures turn up in their true proportions. The 3D brains always catch up, the best flat brain usually does, and the crudest one can never change height.

The short version: the 3D brain wins, but not in the way I expected. A carefully torn flat brain does surprisingly well for the 3D cell, and fails completely once the world has more dimensions to fold away.

Epistemic status: toy tasks, 8 evolutionary runs per setup (4 for the two crudest layouts of the 3D chase), and a simplified ES-HyperNEAT written from scratch rather than the reference code. The hand-set results are big and clear. The evolution results agree with them, but with 8 runs only large differences can be trusted. The ones in four and six dimensions are large.

1. The machinery

ES-HyperNEAT builds on HyperNEAT (Stanley, D’Ambrosio & Gauci, 2009). Every weight comes from the positions of the two neurons it connects:

\[w = f(\mathbf{p}, \mathbf{q})\]

The function \(f\) is itself a small network, a CPPN (compositional pattern-producing network): sines, Gaussians, sigmoids and straight lines feeding into each other. Composing them is what produces patterns, such as a sine of a Gaussian giving a repeating bump. Evolution only ever changes \(f\). The original method evolved it with NEAT, which grows networks one mutation at a time.

substrate (x₀, y₀) (x₁, y₁) w = ? ask the CPPN x₀y₀x₁y₁ CPPN sin · gaussian · tanh w
The CPPN turns two neurons' coordinates into the weight between them.

The designer only places the input and output neurons, to match the body: a sensor that looks left goes on the left, a thruster that pushes up goes near the top. That’s the only way the physical world gets into the network. Hidden neurons don’t stand for anything physical, so what matters is what they’re near. If \(f\) happens to say “connect what’s close”, a hidden neuron sitting between the left sensor and the left thruster listens to one and drives the other. Its position is its job.

The explorer below runs the splitting from the introduction on one weight landscape, \(f\) with one end fixed at a sensor. Each square is tested by sampling the weight at the centres of its four quarters. If those four weights vary by more than a threshold \(\tau\), the square is split and its quarters are tested in turn.

The quadtree on a random CPPN's weight landscape. Colour is the weight, lines are the final squares and dots are hidden neurons. Lower the threshold τ and the tree digs into the regions where the weights vary.

That splitting is a quadtree, built for a flat square. In three dimensions it becomes an octree, splitting cubes into eight, and in \(n\) dimensions a \(2^n\)-tree. Keep that \(2^n\) in mind; it comes back to bite at the end.

2. In 3D, the right brain is one line long

Put the cell’s sensors on a sphere of radius 1 at the directions they point, and its thrusters on a smaller sphere of radius 0.5. Then the distance between a sensor at \(\mathbf{p}\) and a thruster at \(\mathbf{q}\) satisfies

\[\lVert \mathbf{p} - \mathbf{q} \rVert^2 = \lVert \mathbf{p} \rVert^2 + \lVert \mathbf{q} \rVert^2 - 2\, \mathbf{p} \cdot \mathbf{q}\]

The two radii are fixed, so the distance shrinks exactly as the two directions line up. “Points the same way” really has become “sits close by”, and the locality rule

\[w = b - k \lVert \mathbf{p} - \mathbf{q} \rVert\]

with short connections positive and long ones negative, is the steering controller, routed through a grid of hidden neurons. In 3D it scores 0.748, slightly better than the hand-built controller (0.730). Doing nothing scores 0.225.

Flatten the same neurons onto a plane and the rule falls apart. Dropping the \(z\) coordinate is the obvious way to flatten, and the worst: up and down land on the same spot. Laying the sensors round a ring avoids collisions but gives up any sense of which directions are neighbours. The cleverest flat layout is a map projection, the kind on the United Nations flag, which keeps distances from its centre honest and smears the opposite point around the rim. I tilted its centre to sit between two sensors so that no sensor lands on the tear.

+z "target above" −z "target below" flatten (drop z) same point
Projecting along z puts +z and −z on the same spot.

Pick a brain and play with $$k$$ and $$b$$, or let the search find the best pair. Live scores are on 16 random chases. The table's best settings come from a grid search on the 16 test chases.

Brain Best score with \(w = b - k\lVert \mathbf{p} - \mathbf{q} \rVert\)
3D (true directions) 0.748
2D map projection, torn between sensors 0.525
2D, drop z 0.317
2D, sensors round a ring 0.232
reference: do nothing / hand-built controller 0.225 / 0.730

The best flat brain gets about halfway from doing nothing to the hand-built controller. A cleverer CPPN could encode exceptions to locality, but evolution would have to stumble on every one of them.

3. Letting evolution loose

A hand-set rule on a fixed grid is a thought experiment. The real test is to let ES-HyperNEAT do the whole job: start from a random CPPN, let its quadtree place the hidden neurons, and evolve.

How the experiment works
  • Task. The cell integrates its net thrust with damping, \(\mathbf{v} \leftarrow 0.8\,\mathbf{v} + 0.3\,\mathbf{F}\) and \(\mathbf{x} \leftarrow \mathbf{x} + 0.25\,\mathbf{v}\), so it overshoots if it thrusts too hard. A chase lasts 60 steps and scores \(1/(1 + \bar{d})\), where \(\bar{d}\) is the mean distance to the food.
  • Learning. The CPPN has a fixed shape and is trained with an evolution strategy (Salimans et al., 2017) rather than NEAT: every generation tries 32 random nudges to its parameters and steps towards the ones that did well. A run lasts 120 generations.
  • Scoring. Every 5 generations the current brain is tested on 16 chases it never trains on. That’s what the charts show.
  • Code. About 1,500 lines of NumPy, in /experiments/es-hyperneat/. python run_all.py reruns everything, and results/ holds every run’s raw output.

Top: mean test score, ±1 standard error. Bottom: every run's final score.

Every one of the eight 3D runs ended level with the hand-built controller, the fastest within 30 generations. The map projection did better than its hand-set score suggested: six of its eight runs got there too, finishing just as well, but later (70 to 115 generations). The other two stalled at 0.44 and 0.66.

The crude flattenings never got going. The ring topped out at 0.35, and the drop-z brain is my favourite failure: all four runs finished at exactly the same score, 0.319. Dropping \(z\) puts the up and down thrusters on the same spot, so they always get identical weights, always fire together and always cancel. Whatever evolution does, the cell can’t change height.

Brain Runs within 5% of the hand-built score Mean final score First got there
3D 8 / 8 0.737 generation 30–100
2D map projection 6 / 8 0.688 generation 70–115
2D, drop z 0 / 4 0.319 never
2D ring 0 / 4 0.314 never

One accident made the point about tearing better than I could have planned. My first version of the map shrank the thrusters onto an inner ring, which on a map like this changes which direction a point stands for. That left one sensor sitting exactly on the wrong thruster. Fixing that, and tilting the map so no sensor sat on its tear, doubled the map’s success rate, from three runs in eight to six. Every flat brain has to tear the sphere, and for a 3D creature a careful tear costs a little reliability while a careless one is fatal.

4. Creatures in four and six dimensions

The 3D cell might be a mild case. A sphere has only one tear to hide, and a careful map hides it well. So I ran the same code on more worlds, where the brain can have too few dimensions by more than one.

The simplest is the same chase in other dimensions: a flat creature in a 2D world, and a creature in a 4D world whose 24 sensors sit on the corners and faces of a tesseract. The most interesting is a spacecraft that has to reach a dock and match its slow tumble. It needs to know where the dock is (three dimensions) and which way to turn to line up with it (three more), and it has thrusters for moving and torquers for turning. A 6D brain can keep “the dock is to my left” next to “thrust left”, and “I need to turn about my left axis” next to “torque about the left axis”, with the two families at right angles to each other. In 3D, something has to give. Either the two families sit side by side, or one nests inside the other, so that the left-thrust neuron sits next to the left-turn neuron and the two kinds of signal bleed into each other. This is the kissing-number problem from the four-neuron puzzle in action. Every thruster and every torquer needs its own partners close by and everyone else’s at a distance, and three dimensions don’t have room for all of those relationships at once.

Every evolved docking run, one per approach. The dashed box is the dock and the solid one the spacecraft. Their coloured axes line up when the craft faces the right way.

The results are much starker than for the 3D cell. In four and six dimensions only the brain with matching dimensions worked: 5 of 8 runs in the 4D chase and 7 of 8 in docking, against 0 of 40 runs across every layout with too few dimensions. The hand-set rule tells the same story, around 0.72 for the matched brains and under 0.34 for every other.

The 4D chase, drawn in 3D. The gauge on the right shows the fourth coordinate, w, of the food (gold) and the cell (green). The 3D brain chases well in the three dimensions you can see and loses the food in the one you can't.

There’s an obvious objection: maybe a higher-dimensional brain just has more room, so it grows more neurons. In the main experiment it did, about six times as many. But in docking every layout could place the same 64 hidden neurons, and the matched brain still won 7 to 0. In the 4D chase the losing 3D brain grew more neurons than the winning 4D one. And going the other way, giving the flat creature a 3D brain with an extra dimension it had no use for, grew seven times as many neurons and gained nothing. Extra dimensions help when they match the world. What they add isn’t room for more neurons, but room for the right relationships between them.

The flat creature also shows that a missing dimension isn’t always a problem. A circle cut open into a line is torn at just one point, and its 1D brain did as well as its 2D one. One dimension short was harmless for the flat creature, cost some reliability for the 3D cell, and was fatal in four and six dimensions. That’s three tasks with different sensors and difficulties, so treat it as a pattern rather than a law. It’s the pattern the geometry predicts.

World Matched brain: hand-set rule Matched brain: evolved runs that got there Brains with fewer dimensions
Flat chase (2D) 0.783 8 / 8 1D line: 0.760, 8 / 8
3D chase 0.748 8 / 8 best 2D: 0.525, 6 / 8
4D chase 0.716 5 / 8 3D: 0.29–0.33, 0 / 16
6-DOF docking 0.725 7 / 8 3D and 2D: 0.25–0.29, 0 / 24
All the results, including a 3D retina

Hand-set: best score of \(w = b - k\lVert \mathbf{p} - \mathbf{q} \rVert\) on a fixed grid of hidden neurons. Evolved: mean final score over 8 runs, and how many got within 5% of the hand-built controller. These runs use the gradient test from Part 2, which finds equally good networks for much less search.

World Brain Hand-set Evolved mean Got there Hidden neurons
Flat chase (hand-built 0.769, nothing 0.270) 2D 0.783 0.778 8 / 8 ~60
  3D, extra axis unused 0.785 0.771 8 / 8 ~418
  1D angle line 0.760 0.780 8 / 8 ~13
4D chase (hand-built 0.706, nothing 0.197) 4D 0.716 0.605 5 / 8 ~256
  3D map 0.291 0.276 0 / 8 ~139
  3D, drop w 0.334 0.340 0 / 8 ~324
6-DOF docking (hand-built 0.724, nothing 0.197) 6D 0.725 0.648 7 / 8 64
  3D, side by side 0.261 0.266 0 / 8 64
  3D, nested 0.286 0.275 0 / 8 64
  two 2D maps 0.250 0.245 0 / 8 ~31
3D retina (hand-built 0.969, chance 0.125) 3D 1.000 0.590 0 / 8 64
  2D, slices side by side 0.375 0.336 0 / 8 ~26
  2D, drop z 0.391 0.361 0 / 8 ~42

The retina is a 4×4×4 block of light sensors containing two objects, a 2×2×2 cube and a 2×2×1 pancake, and the brain has to point at the cube. Seen as flat slices, a cube is a square in two slices and a pancake lying flat is a square in one, so a flat brain can’t tell them apart locally. The geometry was decisive for the hand-set rule (a perfect 1.000 in 3D), and evolution in 3D clearly beat 2D, but no run fully solved it in 120 generations.

The retina and docking tasks are ports of experiments from an earlier draft of this post, rebuilt on the same code with seeds and saved results.

5. Beyond bodies

The creatures here wear their dimensions on their sleeves. A cell in space has three directions to move in, a spacecraft has six degrees of freedom, and a seven-joint robot arm has seven. For tasks like these, the right number of dimensions is the number of ways the body can move, and the results above suggest the brain should have at least that many.

Plenty of problems have a geometry that’s less obvious but just as real. Musical pitch is a nice one. Notes an octave apart sound alike, so pitch isn’t a line but a spiral: round and round the twelve notes, climbing an octave each turn. Psychologists have long modelled it as a helix in three dimensions (Shepard, 1982). A piano keyboard is the flat version, a line that has torn the circle of notes open. A brain for music laid out along a keyboard would face the same problem as the cell’s flat brain.

Language goes much further. The word embeddings behind modern translation and search place every word at a point in a space of hundreds of dimensions, where directions carry meaning: the step from “man” to “woman” is roughly the step from “king” to “queen” (Mikolov et al., 2013). Nobody knows the “right” dimension of meaning, and it almost certainly isn’t three. If brains like ES-HyperNEAT’s are to work on problems like that, their substrates will need far more dimensions than a sheet, and the dimension itself may have to be learned rather than chosen. That’s a long way from a cell chasing food, but it’s the same question.

It’s also where the kissing-number intuition has a famous big sibling. In high dimensions you can fit astronomically many directions that are all almost at right angles to each other, far more than the number of dimensions. That’s how a few hundred dimensions can hold the meanings of millions of words, each related to its neighbours without being tangled up with everything else. It’s also thought to be how ordinary neural networks store more features than they have neurons, a phenomenon called superposition (Elhage et al., 2022). More dimensions, more room for things to be related to one thing without being related to each other.

6. The price of extra dimensions

There’s a catch, and it’s that \(2^n\). The quadtree that places hidden neurons splits a square into 4, a cube into 8, and an \(n\)-dimensional cell into \(2^n\) pieces. Worse, deciding whether to split a cell means sampling the weight landscape at the centre of every piece. Both the number of cells and the cost of testing each one multiply with every dimension you add.

Cost of one search on random CPPNs in 2 to 7 dimensions, median over 10, log scale.

Show the numbers
n cells tested CPPN evaluations time per search evaluations if every cell splits
2 13 416 1.1 ms 672
3 49 3,136 3.9 ms 4,672
4 193 24,704 27 ms 34,944
5 97 24,832 27 ms 270,592
6 1,537 786,944 0.87 s 2,130,432
7 6,209 6,358,016 8.8 s 16,909,312

Depth-2 trees, each measured from 8 neurons. Real trees only split where the weights vary, so their sizes vary too, which is why 5D comes out no dearer than 4D. Timings from an AMD Ryzen 7 7840HS.

Going from 2 to 7 dimensions makes one search about 15,000 times more work, and evolution runs a search for every candidate brain in every generation. Even the step from 2D to 3D stretched a training run on the cell from under a minute to almost six.

7. What could be wrong

  • These are toy tasks with 8 runs each. Only big differences mean much. The ones in four and six dimensions are big; the one for the 3D cell is moderate.
  • My ES-HyperNEAT is simplified. It was written from scratch, with a fixed-shape CPPN trained by an evolution strategy instead of NEAT, one hidden layer and simplified pruning. The CPPN is also handed the distance between two neurons as an input, which gives “connect what’s close” a head start on every brain alike.
  • The kissing number is an intuition, not a measurement. None of the experiments measure it directly. The rigorous part is narrower: the dimension limits which patterns of near and far a brain can have, as the four neurons show. The docking results are consistent with the crosstalk story, but they don’t prove it.
  • I couldn’t fix the neuron count directly. Forcing 3D and 2D brains to exactly 75 or 480 hidden neurons broke learning for both, so that test said nothing about dimensions. The equal-capacity docking and retina tasks are the better evidence.

8. The dilemma

Matching the world’s geometry argues for as many dimensions as the world has. The search that places neurons argues for as few as possible, because every dimension multiplies its cost.

There may be a way out. The quadtree’s test is really asking how fast the weight landscape changes across a cell, which is a question about its gradient, and the CPPN is built from differentiable pieces. Part 2: A gradient test for ES-HyperNEAT’s quadtree swaps the \(2^n\) samples for a single gradient, and checks whether that finds equally good brains for much less work.

References

  • Elhage, N., Hume, T., Olsson, C., Schiefer, N., Henighan, T., Kravec, S., Hatfield-Dodds, Z., Lasenby, R., Drain, D., Chen, C., et al. (2022). Toy models of superposition. Transformer Circuits Thread. arXiv:2209.10652
  • Mikolov, T., Chen, K., Corrado, G. & Dean, J. (2013). Efficient estimation of word representations in vector space. arXiv:1301.3781
  • Risi, S. & Stanley, K. O. (2012). An enhanced hypercube-based encoding for evolving the placement, density, and connectivity of neurons. Artificial Life, 18(4), 331–363. doi:10.1162/artl_a_00071
  • Salimans, T., Ho, J., Chen, X., Sidor, S. & Sutskever, I. (2017). Evolution strategies as a scalable alternative to reinforcement learning. arXiv:1703.03864
  • Shepard, R. N. (1982). Geometrical approximations to the structure of musical pitch. Psychological Review, 89(4), 305–333. doi:10.1037/0033-295X.89.4.305
  • Stanley, K. O., D’Ambrosio, D. B. & Gauci, J. (2009). A hypercube-based encoding for evolving large-scale neural networks. Artificial Life, 15(2), 185–212. doi:10.1162/artl.2009.15.2.15202
  • Stanley, K. O. & Miikkulainen, R. (2002). Evolving neural networks through augmenting topologies. Evolutionary Computation, 10(2), 99–127. doi:10.1162/106365602320169811