Chapters 4 & 8BeginnerNew
A murmuration, one expectation at a time
Dusk over a reed bed. Each starling watches its seven nearest neighbours and expects them to stay about two metres away. No bird is told to follow, to line up or to flee. Watch the flock first. Then build it from a single bird, in six small steps, underneath.
This sky needs WebGL 2, which this browser has switched off. The six steps, the clips and the mathematics below still work.
Free energy and flying together, the last minute
Free energy per bird (each gridline is ten times the one below)Flying together, 0 to 1Falcon sent, or action switched
Step by step
Build the flock from one bird
Each step below is a small flock seen from above, running the same model as the sky. Each adds one idea to the one before and comes back to the same short sum. Guess what will happen before you press anything. The numbers under each picture are read from that picture as it runs.
- 1A gap and an expectation
- 2A belief in between
- 3Acting on the error
- 4Why birds line up
- 5Seven neighbours
- 6Many birds
-
1One neighbour
A gap and an expectation
Two birds. The one in front flies straight on. The one behind senses how far ahead it is, and expects that distance to be a particular value. Everything else on this page grows from the difference between those two numbers.
The differencePredict firstStart the rear bird far behind, then very close. Where does it end up each time? Then change what it expects.New hereThe sensed distance y and the expected distance η. The rear bird settles where the two agree. Steps 2 and 3 open up how.
-
2Inside the bird
A belief in between
Hold the rear bird where it is, so it cannot move closer. It still has to settle what it thinks the distance is. Its belief μ is pulled one way by what it senses and the other way by what it expects. How hard each pulls is its precision.
Two errors and their sumPredict firstRaise trust in the senses. Which way does the belief move along the ruler? Now raise trust in the expectation instead.New hereA belief μ, two prediction errors, and free energy F: the errors squared, each weighted by its precision Π. The belief moves to make F small. That is perception. The middle term, about how fast the distance is changing, arrives in step 3.
-
3The other way out
Acting on the error
A belief can only meet the senses halfway. The bird has a second way to shrink the same free energy: move, so that what it senses changes. It cannot change the distance in an instant. It can change how fast the distance is closing, so that is the error its wings answer.
Action follows one errorPredict firstThe bird starts held, six metres back, with its free energy high. Release it. Which of the three parts of F falls first, and does any part rise on the way?New hereThe sensed rate of change y′, the belief about it μ′, and action. Too far away, the bird believes the gap should be closing; if it is not, the error pushes it along r̂, the direction of its neighbour. Too close, the same error has the opposite sign. No rule says “approach” or “keep away”.
-
4No rule for it
Why birds line up
Put the two birds side by side, already the expected distance apart. Turn one of them. At that instant the distance is still right, but it has started to change, and the other bird did not expect that. Cancelling the surprise means turning the same way.
What the rate of change containsPredict firstWhen the upper bird turns away, will the lower one follow at once, overshoot, or lag? Watch both headings in the numbers.New hereNothing in the sum. The rate of change y′ was already there in step 3. It holds the neighbour’s velocity vj as well as the bird’s own v, measured along the line between them, so matching it means matching the neighbour’s course. This works for a neighbour to the side. A neighbour straight ahead that turns changes y′ very little at first.
-
5The same sum, seven times
Seven neighbours
A starling attends to its six or seven nearest neighbours, however far away they are (Ballerini et al. 2008). Give the bird one belief and one set of errors for each. Each neighbour pushes along its own line. The bird feels the average.
Average over the neighboursPredict firstDrag the orange bird out of place, or press the button. Which arrows grow? Then lower the number of neighbours to one and try again.New hereOnly the average. The seven neighbours in this picture hold their course so that the arrows are easy to read. In the sky above, every neighbour is doing the same sum about its own seven.
-
6Everyone at once
Many birds
Ninety birds, each doing the sum of step 5 about its own seven neighbours, start out pointing up to 85 degrees either side of straight ahead. Nobody measures the flock. From outside, one number sums up how well they agree.
Flying together, as an observer measures itPredict firstHow long until they share a course: one second, five, or thirty? Then scatter them fully, in every direction, and see whether one flock or several comes out.New herePolarisation P: the length of the average heading, 1 when every bird points the same way. The birds do not compute it. Now go back up to the sky and send the falcon. To the birds it is one more neighbour, expected to be 18 metres away.
AII: EduActive · Watch, then do
Three short clips, three things to try
These passages come from three Institute recordings: an interview with Conor Heins, a guest stream on collective intelligence, and a lecture on collective behaviour. Each is between half a minute and a minute and a half. Watch one, then press its button and look for the same thing in the sky at the top of the page.
- The ideaA few plain sentences. Enough on its own.
- Listen for, then tryOne line from the clip, and one thing to do in the sky.
- In the modelWhich term carries the idea, and how this page differs from what is said.
-
Plays here, from 20:06. Nothing loads from YouTube until you press play.Open on YouTube at 20:06
1Before you start
Folded over on themselves
Many fish schools are close to flat. A starling flock fills the sky in three dimensions, and its shape folds and shimmers. Researchers film whole flocks to recover where every bird is. What the display is for is still an open question.
Listen forThen tryFine lines will join every bird to the neighbours it is attending to. Say whether you expect the lines to stay inside one sheet of the flock or to cross between sheets where it folds. Then look.In the model equation 1
The lines are the neighbour sets of equation 1: for each bird, the k birds nearest to it at that moment. They are recomputed as the birds move, and a bird keeps its belief about a neighbour only for as long as that bird stays in its set.
The shape of the flock on this page is not something the birds hold a belief about. It comes from the roost they circle, the height band they keep to and the moving air, which are plain steering terms here and are listed under “What this model leaves out”. The darkness of the cloud is the birds overlapping on the screen and showing more wing as they bank.
-
Plays here, from 2:08. Nothing loads from YouTube until you press play.Open on YouTube at 2:08
2While it runs
Simple rules, or something more
A murmuration is a classic example of a group doing something no member plans. The usual way to model it is to give every animal a few simple rules for reacting to its neighbours. The birds on this page are given no such rules. Each has an expectation, a belief and a body.
Listen forThen tryTake action away. The birds will still sense their neighbours and still update their beliefs, but will no longer steer by them. Say what you expect to happen to the flock and to the free energy line. Then switch action back on.In the model equations 3 and 4
With action off, equation 4 is multiplied by zero for the neighbour channels. Equation 3 keeps running, so beliefs still follow the senses, but nothing brings the senses back toward what is expected. The roost and height terms still steer the birds, which is why they keep circling.
The speaker is setting out two traditions, simple reactive agents and sophisticated social ones, before presenting a model of his own that is not the one on this page. The contrast drawn here, between writing rules in and letting them fall out of one quantity, follows Heins et al. (2024).
-
Plays here, from 33:22. Nothing loads from YouTube until you press play.Open on YouTube at 33:22
3Afterwards
How sure is each bird
In this kind of model an animal carries more than a guess. It also carries a sense of how far to trust its guess and how far to trust its eyes. The paper being read aloud found that these private settings change what the whole group does.
Listen forThen tryTrust in the senses will drop to a tenth of its usual value. Say whether you expect the flock to tighten, loosen or stay much the same. Then watch “Flying together” for half a minute.In the model equation 2
“Trust in the senses” is the sensory precision Πy of equation 2. It weights the two sensory errors in F, and so it sets both how fast a belief follows what is seen (equation 3) and how hard the same error pushes on the body (equation 4).
The speaker is reading the summary of the preprint that became Heins et al. (2024). The result he reads concerns how accurately a group chooses between options. This page does not test that. In our runs of 2,000 birds, lowering Πy from 2 to 0.2 lowered “Flying together” from 0.88 to 0.84, a small change.
The quoted lines are taken from the automatic captions, with punctuation added and hesitations removed. The speakers are discussing published work, 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 in the sky
- Take action away, then give it back. With action off, free energy per bird climbs from about 0.2 to above 10 within twenty seconds, and the birds drift apart. Switch it back on and the line falls again within about ten seconds. Perception alone cannot keep the flock; the birds have to move.
- Watch one neighbour only. With a single neighbour the birds pair off. They still circle the roost, because it steers each of them alike, but “In one flock” falls to a few per cent. With two neighbours most are linked again.
- Change what they expect. Slide “Expected distance” up to 4 metres and the cloud swells and thins. Nothing else was changed: the birds are making a different expectation come true. “Nearest neighbour” follows it.
- Send the falcon. A bird that senses the falcon inside 18 metres has one more channel, with a long expected distance and a neighbour closing at speed. Watch the free energy line jump twentyfold or more, and the flock open and close.
- Turn the sound on. The calls are synthesised, two voices to a bird as in the starling’s two-sided syrinx. They are not recordings. Calls come faster when the flock turns hard, and change when the falcon is near.
- Put it all back.
The mathematics
All of it in one place
Every bird runs the same small model, a reduced form of the one in Heins et al. (2024). The numbers under each equation are those of one bird in the sky at this moment and of the nearest of its neighbours: bird 1.
The bird is at r with velocity v; neighbour j is at rj with velocity vj, and r̂j is the unit vector pointing at it. The bird senses the distance y and how fast it is changing y′, each with a little random error z. Its neighbours are the k nearest birds, whatever their distance.
For each neighbour the bird holds a belief μ about the distance and μ′ about its rate of change. Its model of the world says that a distance relaxes toward the expected value η at rate α. The first two errors compare the senses with the beliefs. The third compares the beliefs with that model. Under Gaussian assumptions, variational free energy F is the sum of the squared errors, each weighted by a precision Π (an inverse variance). Terms that depend on neither belief nor action are left out, so only differences in F mean anything.
This is generalised filtering (Friston et al. 2010). Each belief moves down the gradient of F, and the belief about distance is also carried along by the belief about its rate of change.
The bird’s velocity enters F only through y′ in equation 1, and the derivative of y′ with respect to v is −r̂j. So each neighbour pushes along the line that joins it to the bird, by an amount set by one error. There is no term for attraction, repulsion or alignment. This is the push asked of the body. The body answers it with the limits listed below.
Polarisation P is the length of the average heading. F̄ is the free energy of equation 2 averaged over the birds; it is the line on the chart. The birds compute neither. “In one flock” is the share of birds in the largest set joined, directly or through others, by who is watching whom. “A change of course is shared across” is the distance at which two birds’ departures from the mean heading stop agreeing, as a share of the flock’s width (Cavagna et al. 2010).
Reading
Where this comes from
What is established
Starlings gather over their roost at dusk in flocks of hundreds to many thousands. Filming flocks over Rome in three dimensions showed that each bird interacts with a fixed number of nearest neighbours, six or seven, however near or far they happen to be, and not with everything inside a fixed distance (Ballerini et al. 2008; Bialek et al. 2012).
A small change in one bird’s course is correlated with changes across the whole flock, whatever the flock’s size (Cavagna et al. 2010). A turn starts with a few birds and crosses the rest as a wave that keeps its speed and hardly fades, which needs the birds’ turning to have inertia (Attanasi et al. 2014). When a falcon attacks, dark bands run through the flock away from it (Procaccini et al. 2011); a model suggests they are birds banking as they turn, so that more wing is seen (Hemelrijk et al. 2015).
Flocks have long been modelled by giving each animal rules: keep apart, stay close, line up (Reynolds 1987; Vicsek et al. 1995; Couzin et al. 2002; for starlings, Hildenbrandt et al. 2010). Heins et al. (2024) showed that such rules need not be written in. Agents that each minimise surprise about the distance to their neighbours, by updating beliefs and by moving, produce cohesion and coordinated motion, and the familiar social forces appear in the gradient of the free energy. This page follows that model in reduced form.
Is the flock itself an agent? Under the free energy principle a collective of inferring agents can, if it keeps a statistical boundary of its own (a Markov blanket), be treated as one larger agent with a generative model of its own. Waade et al. (2025) propose a way to estimate that group-level model from the behaviour of the individuals, and find, in a simple task that is not flocking, that it is not a plain copy or sum of the individuals’ models. This page stops one level down. Every belief on it belongs to a single bird, and polarisation and mean free energy are an observer’s summaries.
The free energy principle is a principle and a modelling framework. This page illustrates it. It is not evidence for it, and it does not show what real starlings compute.
What this model leaves out
Compared with Heins et al. (2024): that model is in two dimensions, was compared with fish, and has each agent sense the average distance to the others in four visual sectors. Here each of the k nearest neighbours is its own channel, in three dimensions, which is our choice and follows the starling finding. Beliefs are kept to two generalised orders, with one sensory precision for both. The birds do not learn or adjust their model as they fly.
Added here, and not derived from free energy: the pull back toward the roost, the height band, and a liking for level flight (after Hildenbrandt et al. 2010); a cruising speed that each bird returns to, with speed held between three quarters and one and a half times that; a turn rate that lags the turn asked for by about a fifth of a second and cannot exceed a limit; random jitter on turning; slow eddies in the air and the wind. The falcon is treated as one more channel of equation 2, with an expected distance of 18 metres, sensed only inside that range. The falcon itself is not an inferring agent: it flies at the middle of the flock twice and leaves.
A turn does not cross this flock as it crosses a real one. In a test, 160 birds flew as a flat sheet and the birds along one edge were held on a course 35 degrees off for four seconds. The far edge turned by less than 10 degrees, and the held birds separated from the rest. The reason is in equation 1: a bird senses only how fast each distance is changing, and a neighbour ahead or behind that turns changes that very little. In real flocks a turn crosses the whole flock with almost no loss (Attanasi et al. 2014). Heins et al. show that an explicit alignment term can be recovered by also giving agents a model of the angle between headings; that is not done here.
Also absent: what a bird can and cannot see through the others; the flattened shape of real flocks and the way neighbours sit to the side more than ahead; tiredness, hunger and differences between birds; the descent into the reeds. No boundary around the flock is computed and no model is fitted to the flock as a whole, so the page makes no claim that this flock is an agent. Without the roost to hold it, this flock would travel in a straight line. The birds are drawn about twice life size so that they can be seen. The reeds, the water, the banking and the sound are for appearance. The settings for speed, noise and rates were chosen to give a clear picture and were not fitted to data.
- Active Inference Institute (2024). Conor Heins ~ Active Inference Insights 019 ~ Collective Behaviour, Attention, Intelligence. Recording. youtube.com/watch?v=nf57wi3qLjk
- Active Inference Institute (2021). ActInf GuestStream #009.1 ~ “Collective intelligence and active inference”. Recording. youtube.com/watch?v=odkks5F9ZMM
- Active Inference Institute (2023). Collective Behavior (Lecture) ~ Daniel Friedman ~ Active Inference for the Social Sciences 2023. Recording. youtube.com/watch?v=ran1M2UmD80
- Heins, C., Millidge, B., Da Costa, L., Mann, R. P., Friston, K. J. & Couzin, I. D. (2024). Collective behavior from surprise minimization. Proceedings of the National Academy of Sciences 121(17), e2320239121. doi:10.1073/pnas.2320239121
- Ballerini, M., Cabibbo, N., Candelier, R., Cavagna, A., Cisbani, E., Giardina, I., Lecomte, V., Orlandi, A., Parisi, G., Procaccini, A., Viale, M. & Zdravkovic, V. (2008). Interaction ruling animal collective behavior depends on topological rather than metric distance: evidence from a field study. Proceedings of the National Academy of Sciences 105(4), 1232–1237. doi:10.1073/pnas.0711437105
- Cavagna, A., Cimarelli, A., Giardina, I., Parisi, G., Santagati, R., Stefanini, F. & Viale, M. (2010). Scale-free correlations in starling flocks. Proceedings of the National Academy of Sciences 107(26), 11865–11870. doi:10.1073/pnas.1005766107
- Bialek, W., Cavagna, A., Giardina, I., Mora, T., Silvestri, E., Viale, M. & Walczak, A. M. (2012). Statistical mechanics for natural flocks of birds. Proceedings of the National Academy of Sciences 109(13), 4786–4791. doi:10.1073/pnas.1118633109
- Attanasi, A., Cavagna, A., Del Castello, L., Giardina, I., Grigera, T. S., Jelić, A., Melillo, S., Parisi, L., Pohl, O., Shen, E. & Viale, M. (2014). Information transfer and behavioural inertia in starling flocks. Nature Physics 10, 691–696. doi:10.1038/nphys3035
- Procaccini, A., Orlandi, A., Cavagna, A., Giardina, I., Zoratto, F., Santucci, D., Chiarotti, F., Hemelrijk, C. K., Alleva, E., Parisi, G. & Carere, C. (2011). Propagating waves in starling, Sturnus vulgaris, flocks under predation. Animal Behaviour 82(4), 759–765. doi:10.1016/j.anbehav.2011.07.006
- Hemelrijk, C. K., van Zuidam, L. & Hildenbrandt, H. (2015). What underlies waves of agitation in starling flocks. Behavioral Ecology and Sociobiology 69(5), 755–764. doi:10.1007/s00265-015-1891-3
- Hildenbrandt, H., Carere, C. & Hemelrijk, C. K. (2010). Self-organized aerial displays of thousands of starlings: a model. Behavioral Ecology 21(6), 1349–1359. doi:10.1093/beheco/arq149
- Reynolds, C. W. (1987). Flocks, herds and schools: a distributed behavioral model. Proceedings of the 14th Annual Conference on Computer Graphics and Interactive Techniques, 25–34. doi:10.1145/37401.37406
- Vicsek, T., Czirók, A., Ben-Jacob, E., Cohen, I. & Shochet, O. (1995). Novel type of phase transition in a system of self-driven particles. Physical Review Letters 75(6), 1226–1229. doi:10.1103/PhysRevLett.75.1226
- Couzin, I. D., Krause, J., James, R., Ruxton, G. D. & Franks, N. R. (2002). Collective memory and spatial sorting in animal groups. Journal of Theoretical Biology 218, 1–11. doi:10.1006/jtbi.2002.3065
- Waade, P. T., Olesen, C. L., Laursen, J. E., Nehrer, S. W., Heins, C., Friston, K. & Mathys, C. (2025). As one and many: relating individual and emergent group-level generative models in active inference. Entropy 27(2), 143. doi:10.3390/e27020143
- Kaufmann, R., Gupta, P. & Taylor, J. (2021). An active inference model of collective intelligence. Entropy 23(7), 830. doi:10.3390/e23070830
- Friston, K., Stephan, K., Li, B. & Daunizeau, J. (2010). Generalised filtering. Mathematical Problems in Engineering 2010, 621670. doi:10.1155/2010/621670
- Friston, K. J., Daunizeau, J., Kilner, J. & Kiebel, S. J. (2010). Action and behavior: a free-energy formulation. Biological Cybernetics 102(3), 227–260. doi:10.1007/s00422-010-0364-z
- Buckley, C. L., Kim, C. S., McGregor, S. & Seth, A. K. (2017). The free energy principle for action and perception: a mathematical review. Journal of Mathematical Psychology 81, 55–79. doi:10.1016/j.jmp.2017.09.004
- Parr, T., Pezzulo, G. & Friston, K. J. (2022). Active Inference: The Free Energy Principle in Mind, Brain, and Behavior. MIT Press. Chapters 4 and 8. doi:10.7551/mitpress/12441.001.0001