Active Inference InstituteSimulations

Chapters 4 and 7IntermediateNew edition

A trail is a belief written in the ground

Each ant here senses only the three cells in front of it, infers where the trail lies, and picks the move with the lowest expected free energy. Nobody plans the route. Because every ant that walks also marks the ground that the next ant senses, the colony as a whole finds food, commits to a path, and lets it go when the food is gone.

How firmly each ant picks its best move. A setting.
Rate at which pheromone fades, per second. A setting.
0 makes C flat over pheromone. A setting.

Over time

AII: EduActive · Watch, then do

Three short clips, three things to try

In 2021 the Institute gave two livestreams to the paper behind this page, Friedman et al. (2021), with its authors in the room. These are three short passages from them, each two to four minutes. Watch one, then press its button and look for the same thing on the stage above.

  1. Plays here, from 21:32. Nothing loads from YouTube until you press play.Open on YouTube at 21:32

    Before you start

    Marks that others can read

    An ant does not tell the others where the food is. It leaves a mark on the ground, and the mark does the telling. Working together through marks like this has a name: stigmergy.

    Listen for
    An agent’s actions leave signs in the environment, and signs that it and other agents can sense, which determine and incite their subsequent actions.
    Then try
    Guess where the first dark stain will appear, near the nest or near the food. Then watch the ground, not the ants.
    In the model equation 4

    The mark is one number per cell, the pheromone c. It is the only thing the ants share. No ant senses another ant: the likelihood A maps where the trail lies to the pheromone level in the three cells ahead, and nothing else about the colony enters an ant’s senses.

    The clip notes that earlier active inference models of navigation left no traces and took the environment as fixed. Here the environment is a state that the agents write to and read from. Constant et al. (2018) treat this as niche construction under the free energy principle.

    Equation 4, the ground

  2. Plays here, from 23:17. Nothing loads from YouTube until you press play.Open on YouTube at 23:17

    While it runs

    How a trail forms

    At first every ant wanders. One finds food and marks its way home. Ants that stumble on the mark are drawn along it and make it stronger. Soon there is a trail, and no ant planned it.

    Listen for
    No ant needed a bird’s eye view or a goal to even form a trail.
    Then try
    Follow one ant and read its panel. It senses three cells and nothing more. Ask what in those three cells could tell it that a trail exists.
    In the model equations 1 to 3

    The pull towards the mark is the risk term of expected free energy. The preferences C rise with pheromone level, so a move that is expected to bring stronger pheromone ahead has lower G. With no pheromone in range the three moves score alike and the walk is close to random, as the clip describes.

    The clip describes the T-maze of Friedman et al. (2021), where each ant takes the move with the least expected free energy. On this page the ground is open and the move is drawn from a softmax with precision γ. Experiment d repeats the paper’s comparison with a flat C: the stain remains, but recruitment falls away.

    Equation 2, expected free energy of a move · Experiment d

  3. Plays here, from 26:01. Nothing loads from YouTube until you press play.Open on YouTube at 26:01

    Afterwards

    Why a trail has to fade

    A mark that never faded would keep sending ants to food that has gone. Fading is how the colony forgets. Forgetting is what lets it find the new place.

    Listen for
    It is akin to forgetting, but what’s really interesting is it’s the colony forgetting, because the ant doesn’t have a direct memory.
    Then try
    A trail settles, then the food is moved. Predict how long ants will keep walking to the empty place. Then change the evaporation slider and run it again.
    In the model equations 4 and 5

    Forgetting is the evaporation rate λ. Over one internal step h the pheromone on a cell is multiplied by exp(−λh). A small λ gives a long-lived trail that tends to be slow to follow the food; a large λ gives a trail that never sharpens. The memory is in the ground: each ant starts every decision from the same prior D.

    The paper describes this decay as a drift that counteracts the reinforcing effect of stigmergic convergence. Experiment b measures it here: time to abandon the old trail at four evaporation rates. Trail entropy shows the moment the old trail lets go.

    Equation 4, the ground · Equation 5, commitment · Experiment b

The quoted lines are taken from the automatic captions, with punctuation added and hesitations removed. The speakers are discussing the T-maze model in the paper, not this page; where the two differ, the notes say so. Each clip stops at the end of the passage. The full recordings are listed under Sources.

Learn by doing

Try this

  1. Watch a trail form. Before you press the button, guess: will the first dark stain appear near the nest, or near the food? Then watch. An ant that finds food walks home and marks the ground as it goes. Each ant after it prefers to sense pheromone ahead, so it follows the mark and thickens it.
  2. The double bridge. Two paths lead from the nest to the food. One is about a third longer. Decide now which one the colony will end up using, and how sure you are. Then run it, and read the share of traffic on each branch. Run it several times: the answer is not always the same.
  3. Move the food. Let a trail settle, then move the food. Predict how long ants will keep walking to the empty place. The old trail is a belief that is no longer true; it lasts until it evaporates.
  4. Turn precision both ways. Low precision (γ = 0.5) makes every ant pick its moves almost at random. High precision (γ = 32) makes every ant take its best move every time. Predict which gives the sharper trail, and which is more likely to lock on to the longer branch.
  5. Remove the preference. Make the preferences flat over pheromone. The ants still lay it, and still sense it, but no longer prefer it. Predict what happens to the stain, to the ants that are not carrying food, and to the food delivered per minute.
  6. Inspect one ant. Tap an ant on the stage, or use the button. The panel shows what it sensed, what it inferred, the expected free energy of its three moves and the one it took. Check the sums by eye against the equations below.

Measured, not asserted

Four experiments

Each button runs fresh colonies in the background, with the settings stated, and reports what came out. Different seeds give different colonies. The runs take up to a minute.

a. Which branch wins

Double bridge, 8 colonies (seeds 1 to 8), 300 s each, with the settings now on the sliders. The bar is the share of crossings on the short branch in the last 60 s.

b. Time to switch

One food source. After 150 s it is moved. For four evaporation rates, 3 colonies each: how long until the old trail has faded to a tenth, and until deliveries from the new place reach half the old rate.

c. Precision

Double bridge at γ = 0.5, 4 and 32, 6 colonies each, 300 s. Commitment is |2 × share − 1|: 0 means even traffic, 1 means one branch only.

d. No preference, no recruitment

One food source, 240 s, 4 colonies with cφ = 4 and 4 with cφ = 0 (flat C over pheromone). "On trail" is the share of ants without food that stand on marked ground.

The mathematics

What is being computed

The numbers under each equation are those of the ant now selected, at its last decision point. A decision point is the moment an ant arrives on a new cell. Hidden states s are things the ant cannot see directly; outcomes o are what its senses report; a move u is turn left, forward or turn right.

The ant has three hidden-state factors, each with its own sense. Trail: the trail lies left, ahead, right, or nowhere near; sensed as a pheromone level from 0 to in each of three forward cells. Food: left, ahead, right or none; sensed directly at short range. Home: the bearing of the nest in steps of 45°; sensed with some noise.

1 · Perception: where is the trail Q(s)=P(o|s)P(s)∑s′P(o|s′)P(s′),P(o|s)=A,P(s)=D

This is exact Bayes, so the variational free energy F equals the surprise −ln P(o). A says that a cell on the trail tends to read high and a cell off it tends to read low. D is the same at every decision point: this ant does not carry a belief from one step to the next.

2 · Expected free energy of a move G(u)=∑factors[DKL[Q(o|u)‖C]⏟risk+𝔼Q(s|u)[H[P(o|s)]]⏟ambiguity]

Q(s | u) = B(u) Q(s) is where the trail will lie after the move: turning towards it brings it straight ahead. Q(o | u) = A Q(s | u) is what the ant then expects to sense. C is what it prefers to sense. Risk is the gap between the two. Ambiguity is how uninformative the expected senses are. The three factors are independent, so their terms add exactly. Lower G is better.

C is where the task lives. Every ant prefers strong pheromone, most of all straight ahead. An ant without food also prefers to sense food; on the bridge it prefers, in addition, to have the nest behind it. When it picks food up, C switches: it no longer cares about food and prefers the nest straight ahead. Nothing else in the ant changes.

3 · Choosing Q(u)=σ(lnE−γG)

σ is the softmax. E is a habit that favours going forward. γ is the precision of the ant's beliefs about what to do. The move is drawn from Q(u). A move into a wall is not offered. The free energy F of the present outcome is the same for all three moves, so it cancels here.

4 · The ground ∂c∂t=−λc+D∇2c+ρ·(ants on the cell)

c is the pheromone on a cell. It evaporates at rate λ, spreads a little, and is laid at rate ρ by each ant standing on the cell. These are rates per second of simulated time. The decay over one internal step h is exp(−λh), so the picture does not depend on how fast your screen redraws.

5 · How committed the colony is H=−∑ipilnpi,pi=ci∑jcj

The trail entropy treats the pheromone field as a probability distribution over cells. It is low when the pheromone sits on few cells and reaches ln N when it is spread evenly over all N walkable cells. On the bridge it falls when the colony drops one branch.

Reading

Where this comes from

“We actively carve our ecological niches to render them more predictable and less surprising.”Parr, Pezzulo & Friston (2022), Active Inference, chapter 3, box 3.3, p. 60

What is established

Many ants lay chemical trails and follow them, and a trail that is not renewed fades (Hölldobler & Wilson 1990). Argentine ants mark the ground while they explore as well as on the way home, and a colony offered two equal branches ends up using mostly one of them (Deneubourg et al. 1990). Offered a short and a long branch, colonies mostly choose the short one (Goss et al. 1989). The explanation given there is timing: ants that take the short branch reach the far end and come back first, so that branch is marked first. A bridge here has branches of 68 and 88 cells.

Coordination through marks left in a shared environment is called stigmergy (Grassé 1959). Changing your surroundings in ways that change what you and others later sense is niche construction; Constant et al. (2018) give an account of it under the free energy principle, in which the environment comes to carry information that agents would otherwise have to hold themselves.

Friedman et al. (2021) built a colony of active inference ants that forage in a T-maze, lay pheromone on the way home and find the food again when it changes arm. They compared a preference that rises with pheromone level with a flat one. This page is a reconstruction in that spirit, not a copy.

How this differs from Friedman et al. (2021)

  • The ant. Theirs has nine hidden states (its own cell and the eight around it), senses pheromone at ten levels, has nine one-step policies (stay, or step to a neighbour) and takes the one with the least expected free energy. Ours has three factors (trail, food and nest bearing), senses seven levels in three forward cells, has three turning moves, and draws its move from a softmax with precision γ.
  • Preferences. In both, C rises with pheromone level; experiment d repeats their comparison with a flat C. Their homeward ant walks at random with a bias towards the nest. Here the homeward drive is put into C: picking up food switches the preferred outcomes from food to "nest ahead", read from a noisy compass that stands in for path integration (Müller & Wehner 1988).
  • The ground. Their pheromone is laid only on the way home and decays with a small probability per step. Ours evaporates and spreads at stated rates per second. On the bridge only, ants also lay it on the way out, as Argentine ants do, and outbound ants prefer the nest behind them; the tick box turns outbound laying off.
  • The arenas. Their T-maze is replaced by open ground, a double bridge and a movable source. The measurements and all parameter values are ours.

What this model leaves out

  • Memory and learning. The ant's A, B and D are fixed, each decision starts from the same prior, and it plans one step ahead.
  • Bodies. Ants pass through one another; there is no crowding, no contact, and no recruitment inside the nest. Walls are handled outside inference: a blocked move is simply not offered, and an ant with no free move turns on the spot.
  • Chemistry. Real colonies use several pheromones with different lifetimes, and trail lifetimes of many minutes. Here there is one, and it fades in seconds so that you can watch.
  • Navigation. The compass always points straight at the nest. On the bridge this limits how much longer the long branch can be: every stretch must lead towards the nest.
  • The grid. Eight headings and square cells. Diagonal steps take longer, but a trail is still made of squares.
  • The colony has no model of its own. "The colony believes" is shorthand for a pattern in the ground that changes what each ant senses.

What the test runs found

From the test file that ships with this page (300 s per colony on the bridge). With trail laid both ways and γ = 4, the short branch won in 10 of 12 colonies. With trail laid only on the way home, it won in 7 of 10; we had bet on 8. At γ = 32 every colony locked on to one branch, and in 5 of 12 it was the long one. At γ = 0.5 none committed. Without the preference for pheromone, deliveries fell from about 670 to about 115 a minute; homing ants still left a stain, so the trail entropy barely moved, which we had not expected. After the food was moved, the old trail faded in about ln 10/λ seconds, but the switch was quickest at a middling evaporation rate: medians of 95, 70, 58 and 75 s for λ = 0.025, 0.05, 0.1 and 0.2 per second.

This page illustrates how the framework can be applied. It is not evidence that ants, or colonies, perform these calculations.