Starting with one cell

There is a small demo in Growing Neural Cellular Automata that grows an image from a single cell. Once it has finished, you can rub out part of the image. With a model trained for regeneration, the cells left behind begin filling in the hole.

The paper came out in 2020, written by Alexander Mordvintsev, Ettore Randazzo, Eyvind Niklasson, and Michael Levin. I like it because most of the individual steps are easy to follow, while the result remains a little peculiar. Every cell runs the same small neural network. None has been assigned a position in the finished picture, and none can look across the grid to check how things are coming along.

It has its own state and some information about its immediate neighbours. Repeating the same local calculation is enough to grow the pattern.

What a cell can see

Each cell stores 16 numbers. Four are the RGBA values that make it visible. The remaining twelve are hidden state, available for whatever the network learns to do with them.

It is tempting to give those channels names. Perhaps this one is memory, and that one tells the cell which way to grow. The model has made no such arrangement with us. Those interpretations would need testing; all we know from the training objective is that the values help produce the image.

To work out its next update, a cell looks at a 3×3 neighbourhood. Sobel filters estimate the horizontal and vertical gradients in each channel. The neural network receives these gradients together with the cell's own state, then produces a change to its 16 values.

Some cells skip each update, chosen by a random mask. This stops the learned rule from relying on the whole grid moving in perfect synchrony.

Plain text
perception → neural update → stochastic mask → next state

There is also a rule about which cells are allowed to remain alive. A cell needs enough alpha in itself or a neighbour; otherwise its state is cleared. This keeps empty parts of the grid from carrying hidden information independently of the growing pattern.

Training starts with a seed in the middle. The update runs repeatedly, and the resulting image is compared with the target. Adjust the network's weights and repeat. All the cells continue sharing one set of weights, even as their states become different.

The problem with stopping too soon

A model can learn to grow the right image and still be quite bad at keeping it. Some patterns fade away after the training window. Others carry on growing until they fall apart. There is a period in between when a screenshot would make the whole exercise look very successful.

The authors deal with this by keeping a pool of earlier states. A training run can pick up from one of those states, so the network has to practise continuing as well as starting. Fresh seeds are still introduced to keep it from forgetting how to grow the pattern in the first place.

This produces models that can maintain their shape for longer. Some also acquire a degree of regeneration without being explicitly trained for it.

For the regeneration experiment, the authors go further and damage some of the training samples. The network then has to produce the target from a state with part of it missing. That gives much stronger recovery, though how well it works depends on the model and the damage.

This is the experiment I find most interesting. The remaining cells have no separate repair procedure. They keep applying the same update rule to the situation they now find themselves in.

The aim is to make the target an attractor: nearby states should evolve back towards it. That is a useful property to get from local rules, although a grid trained against an image loss is still a long way from explaining how an animal regrows a limb.

In the browser

The demo uses a 96×96 grid and runs in WebGL. It stores the cell state in textures and applies the update network on the GPU. The weights and activations are quantized to 8-bit values for performance and compatibility with mobile hardware.

The different model types make the training differences visible. Leave a growing model running, then compare it with one trained for persistence or regeneration. Damage the pattern and see what survives. The finished image alone doesn't tell you much about what the rule has learned.

The learned demo stays on the original site. Below is Conway's Life (B3/S23), a rule-based automaton starting from a glider. It illustrates a shared local update rule, not a trained neural model.

Life B3/S23 · rule-based · 24×12 wrapping grid

Static seed; stepping requires JavaScript and Canvas 2D.

. # .
. . #
# # #
gen 0 · 5 alive