Chapters 3 & 7BeginnerNew edition
A school with no leader
No fish here is told to school, and none is told how to flee. Each one only predicts how far away its neighbours and a predator should be, and moves to make those predictions come true. Watch the school meet a hunter, then take the hunter's place.
To hunt, press on the water: the predator swims after your pointer or finger, and each press (or tap) is a strike. With the keyboard, focus the water: ← → turn, ↑ ↓ faster and slower, Space strikes.
The encounter
- School
- Strikes, and fish caught
- Fish that sense the predator now
- Vacuole no fish within 2.5 body lengths of its body, fish on at least 9 of 12 sides
Last strike
- Free energy per fish the second before → peak within 2 s
- Fastest fish within 1 s
- Flash expansion fish within 8 body lengths: their spread reaches 1.5 × within 1 s
- Fountain fish ahead part, pass both sides, and join behind the tail within 8 s
- Split two or more groups, the largest under 80%, within 5 s
- Time to re-form one group again, holding over 95%
- Area occupied before → peak within 3 s
AII: EduActive · Watch, then do
Three short clips, three things to try
These three passages come from an Institute interview and an Institute lecture. Both discuss the paper whose model this page follows in reduced form, Heins et al. (2024). Each is one to two and a half minutes. Watch one, then press its button and look for the same thing in the water above.
- The ideaA few plain sentences. Enough on its own.
- Listen for, then tryOne line from the clip, and one thing to do on the stage.
- In the modelWhich matrix, term or rate carries the idea, and how this page differs from what is said.
-
Plays here, from 18:40. Nothing loads from YouTube until you press play.Open on YouTube at 18:40
1Before you start
Roles in a school keep changing
In a school of fish nobody holds a fixed job. A fish at the edge sees danger first. A moment later it may be in the middle and another fish is at the edge. What a fish does depends on where it happens to be.
Listen forThen tryOne fish will be marked, with the distances it senses on each side. Say which fish you expect to carry the largest errors, those in the middle or those at the edge. Then press Another fish a few times and compare.In the model equations 1 and 2
On this page every fish runs the same model with the same numbers. Differences between fish come only from position: which of the four sectors hold neighbours, and how far the sensed distances y are from the preferred distance η. A fish at the edge may have sectors with no neighbour in them, and those sectors drop out of its free energy. When it moves inward that changes.
The speaker’s wider point is about where to draw the boundary of a group treated as one agent, when its members keep changing places. The page does not attempt this. The outline round each group is a convex hull, and no statistical boundary (Markov blanket) is computed.
Equation 1, prediction errors · Equation 2, free energy of one fish
-
Plays here, from 47:36. Nothing loads from YouTube until you press play.Open on YouTube at 47:36
2While it runs
Each fish reduces its own error
A fish in this kind of model does not need to know where it is, or to think about itself at all. It expects its neighbours to be a certain distance away. When they are not, it changes its own speed and direction until the mismatch shrinks.
Listen forThen tryTake that one ability away. With action off, the fish still sense and still update their beliefs, but cannot turn or change speed in response. Say whether you think the school will hold together. Then watch the free energy per fish.In the model equation 4
In equation 4 the heading θ and speed s of a fish descend its own free energy F. Action enters only through its effect on what the fish senses: turning or changing speed alters how fast each sector’s distance is changing. No fish has access to another’s errors, and none holds a belief about its own position.
The page departs from the published model in ways that touch this passage. It adds a prior on the fish’s own cruising speed, limits on turning and speed, and random noise on heading, so behaviour here is not quite a fixed function of what is sensed. The small memory the speaker mentions is the belief μ carried from one step to the next.
-
Plays here, from 30:49. Nothing loads from YouTube until you press play.Open on YouTube at 30:49
3Afterwards
The paper’s summary, read aloud
Older models of schooling give each fish rules: move away from close neighbours, move towards distant ones, line up. The paper behind this page writes in no such rules. Each fish only tries to keep its surprise low, and the familiar group patterns appear.
Listen forThen tryThe fish will start scattered, each heading its own way, with no predator. Say which of the three you expect to see: a group that holds together, a group that circles, a group that travels one way. Then watch polarisation and rotation.In the model equations 4 and 6
The speaker is reading the summary of the preprint that became Heins et al. (2024). The “social forces” it mentions are not written into equation 4. They appear in the gradient of F: a neighbour that is too far or receding produces an error that turns the fish towards it, and one that is too close or approaching turns it away. Cohesion, milling and directed motion are read off the group with polarisation P and rotation M, which the fish do not compute.
This page is a reduced form of that model. Beliefs are kept to two orders, each fish attends to at most eight neighbours per sector, and the fish do not learn while swimming. The predator and the looming term are additions made for this page.
The quoted lines are taken from the automatic captions, with punctuation added and hesitations removed. The speakers are discussing the published model, 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
- Watch a school form. The fish start scattered, each heading its own way, with no predator. Nothing in the model mentions a school. Predict whether they will stay scattered. Then watch the groups merge, the spacing tighten and polarisation rise. Sometimes the group circles as a mill on the way, and now and then it stays one.
- Inspect one fish. A fish divides the water around it into four sectors. In each it senses the mean distance to its nearest neighbours, holds a belief about that distance, and compares both with the distance η it expects. Predict which fish carry the largest errors: those in the middle or those at the edge. Pick several and compare. Then move the preferred distance η and watch the measured spacing follow.
- Take away its trust in its senses. Sensory precision is the weight a fish gives to what it sees of its neighbours. Predict what the school does when that weight is zero. The fish still swim, but those prediction errors no longer move them, and polarisation and spacing drift to the values for fish that ignore each other.
- Switch action off. Now the fish still sense and still update their beliefs, but cannot turn or change speed in response. Predict whether believing alone can hold a school together. Watch the free energy per fish: it has only one of its two ways down.
- Watch a strike. A predator is one more thing a fish expects to be far away, and a thing that looms is one more prediction error. The predator circles, turns in and lunges at about eight times the fish's cruising speed. Predict what the nearest fish will do, what the far ones will do, and what the trace of free energy will do. A manoeuvre is named on the water only when its measurement is met. In our seeded tests of 20 strikes by the autopilot, flash expansion was named in 19, a split in 18, a fountain in 6 and a vacuole in 3. Free energy per fish peaked at a median of 4.9 times its value in the second before, and the fastest fish reached a median of 8.6 body lengths a second. Of 14 splits that could be followed, 7 were one group again, after a median of 11 seconds.
- Hunt, and bet first. Now you are the predator. Before you start, make two bets. How many of ten strikes will catch a fish? And will it be easier once the fish stop attending to each other? Strike ten times and note the count. Then turn sensory precision down, restock, and strike ten more. We bet that a strike on fish that hardly attend to each other (precision 0.05) would catch at least one and a half times as often. We lost. The autopilot caught a fish in 7 of 33 strikes on the coordinated school and in 7 of 32 with precision turned down. In this model each fish still senses the predator for itself, so its escape owes little to its neighbours.
The mathematics
What is being computed
Every fish 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 fish at this moment: . Choose another with “Inspect one fish”.
In each sector, y is the sensed mean distance to the nearest neighbours and y′ its sensed rate of change. μ and μ′ are the fish's beliefs about that distance and its rate of change. The fish expects any distance to relax towards its preferred value η at rate α. A prediction error is the gap between what is sensed and what is believed (the first two), or between a belief and what the fish's own model expects of it (the third).
Variational free energy F is, under Gaussian assumptions, the sum of squared prediction errors, each weighted by its precision Π (an inverse variance: how much that error is trusted). The sum runs over the sectors that contain a neighbour, and over the predator when it is sensed (with the looming term of equation 5). The last term is the fish's expectation of its own cruising speed s0. Terms that depend on neither belief nor action are left out, so only differences in F are meaningful.
This is generalised filtering: 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.
A fish cannot change its beliefs' targets, but it can change what it senses. Turning (heading θ) or changing speed s alters how fast each sector's distance is changing: moving towards a sector's neighbours makes that distance shrink faster. The unit vector r̂l points from the fish towards the neighbours in sector l; t̂ points along the fish's heading and n̂ to its left. Action enters only through this effect on sensation, weighted by the same precision and the same error as in equation 2. There is no rule here for attraction, repulsion or alignment. A neighbour that is too far, or receding, produces an error that turns the fish towards it; one that is too close, or approaching, turns it away.
The predator is a fifth channel, treated like a sector: a sensed distance yp to the nearest part of its body, with its own large preferred distance. On top of that the fish senses how fast the predator is closing relative to how far away it is. This ratio λ is the rate at which the predator's image grows, and it equals one over the time to collision τ at the present closing speed (Lee 1976). The fish's model of calm water predicts λ = 0, with precision Πλ, so λ itself is the prediction error. It is small for a predator cruising at a distance and grows steeply in the last moments of a lunge. It moves the fish by the same rule as equation 4: turning or speeding up changes yp′, and so changes λ. A fish answering it may swim far above cruising speed for a moment, a fast start, until a reserve that takes three seconds to refill is spent. That reserve is a limit on the body, not a rule of behaviour. This term and that limit are ours; they are not in Heins et al. (2024).
Polarisation P is the length of the average heading: 1 when all fish point the same way. Rotation M is the average turning of headings about the group's centre: 1 for a perfect mill. Here v̂i is the unit heading of fish i and r̂ic the unit vector from the centre of the group to that fish (Couzin et al. 2002). The fish do not compute these; they are an observer's summary.
Reading
Where this comes from
What is established
Fish schools, bird flocks and insect swarms move between a few collective states: a disordered swarm, a rotating mill and a polarised group. Couzin et al. (2002) showed these states in a model of local attraction, repulsion and alignment, and gave the order parameters used here. Tunstrøm et al. (2013) found the same three states in real golden shiners.
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; the familiar social forces appear in the gradient of the free energy. This page follows that model in reduced form.
Schools of real fish answer an attack with a small repertoire of collective manoeuvres. Magurran & Pitcher (1987) and Pitcher & Parrish (1993) describe, among others, flash expansion, in which fish burst outward from the point of attack; the fountain effect, in which the school parts in front of the predator, passes it on both sides and joins again behind it; and the vacuole, a clear space that opens round a predator inside the school. A single fish answers a sudden threat with a fast start, a brief burst far above cruising speed (Domenici & Blake 1997). The image of an approaching object grows at a relative rate equal to one over the time to collision (Lee 1976).
Under the free energy principle, groups of this kind have also been modelled as agents in their own right, with the individuals in the role of the group's states (Friston & Frith 2015; Palacios et al. 2020; Heins et al. 2024). That is a modelling proposal. The outline drawn round each group on this page is only the convex hull of its fish. No statistical boundary (Markov blanket) is computed here, and whether such boundaries exist in loosely coupled systems is debated (Aguilera et al. 2022; Biehl et al. 2021).
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 fish compute.
What this model leaves out
Compared with Heins et al. (2024): each fish attends to at most its eight nearest neighbours in each of four quarter-circle sectors within a sensing range of 8 body lengths, where the published observation is an average over the neighbours in a sector. Beliefs are kept to two generalised orders (distance and its rate), with one sensory precision for both; the paper's separate smoothness parameters are not modelled. The fish here do not learn or adjust their model's parameters while swimming.
Added here, and not taken from that paper: the prior on a fish's own speed; limits on turning rate and on speed, and the fast-start reserve that lifts them for a moment; random noise on heading; the predator, treated as one more sensed distance with a large preferred value; and the looming term. These choices are ours.
The predator is not an active inference agent. It is a body with limits on turning, speed and acceleration, steered by you or by a short autopilot that circles the densest part of the school and lunges into it. The fish sense the nearest point of a line from its snout to its tail, not its outline. A fish within 0.8 body lengths of the snout as a lunge ends counts as caught. The predator is never confused by numbers, and no fish hides behind another, so two of the benefits claimed for real schools are absent. In our test a school whose fish hardly attended to each other was no easier to catch from (7 of 32 strikes against 7 of 33), although we had bet that it would be.
The names of the manoeuvres come from descriptions of real fish, which are in words. The criteria used here to decide when to show a name are ours: the distances, fractions and time limits beside each measurement. One threshold of the fountain test was set after looking at trial runs. A predator that the fish cannot sense was run as a control and earned none of the names.
Real schools can pass a turn from fish to fish as a wave that outruns the fish themselves (Herbert-Read et al. 2015). This model does not reliably do so. In a test with a predator held still in front of the school, the fish that sensed it turned sharply, but among fish that never sensed it the time of turning was only weakly tied to distance from the predator: a clear front appeared in one run of four. So nothing on this page is called a wave. In a strike most of the nearby fish sense the predator directly.
The water is flat and wraps round at its edges; fish have no bodies to collide and cannot hide one another from view. The picture is drawn as if seen from the side, and the view stays with the predator when there is one. Fish and predator are drawn larger than life so that they can be seen. The differences in depth and size, the roll of a turning fish and the flash of its flank, the bubbles and the pale wake of a lunge, the screen shake and the sound are for appearance only. Slow motion changes the speed of the model's clock and nothing else. The settings for speed, noise and rates were chosen to give a clear picture, not fitted to data.
- Active Inference Institute. Conor Heins ~ Active Inference Insights 019 ~ Collective Behaviour, Attention, Intelligence. Recording. youtube.com/watch?v=nf57wi3qLjk
- 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
- 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
- Tunstrøm, K., Katz, Y., Ioannou, C. C., Huepe, C., Lutz, M. J. & Couzin, I. D. (2013). Collective states, multistability and transitional behavior in schooling fish. PLoS Computational Biology 9(2), e1002915. doi:10.1371/journal.pcbi.1002915
- Herbert-Read, J. E., Buhl, J., Hu, F., Ward, A. J. W. & Sumpter, D. J. T. (2015). Initiation and spread of escape waves within animal groups. Royal Society Open Science 2, 140355. doi:10.1098/rsos.140355
- Magurran, A. E. & Pitcher, T. J. (1987). Provenance, shoal size and the sociobiology of predator-evasion behaviour in minnow shoals. Proceedings of the Royal Society of London B 229, 439–465. doi:10.1098/rspb.1987.0004
- Pitcher, T. J. & Parrish, J. K. (1993). Functions of shoaling behaviour in teleosts. In T. J. Pitcher (ed.), Behaviour of Teleost Fishes, 2nd edn, pp. 363–439. Chapman & Hall, London.
- Domenici, P. & Blake, R. W. (1997). The kinematics and performance of fish fast-start swimming. Journal of Experimental Biology 200, 1165–1178. doi:10.1242/jeb.200.8.1165
- Lee, D. N. (1976). A theory of visual control of braking based on information about time-to-collision. Perception 5, 437–459. doi:10.1068/p050437
- Friston, K., Stephan, K., Li, B. & Daunizeau, J. (2010). Generalised filtering. Mathematical Problems in Engineering 2010, 621670. doi:10.1155/2010/621670
- Friston, K. (2010). The free-energy principle: a unified brain theory? Nature Reviews Neuroscience 11, 127–138. doi:10.1038/nrn2787
- 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 3, 4 and 8. doi:10.7551/mitpress/12441.001.0001
- Friston, K. & Frith, C. (2015). A Duet for one. Consciousness and Cognition 36, 390–405. doi:10.1016/j.concog.2014.12.003
- Palacios, E. R., Razi, A., Parr, T., Kirchhoff, M. & Friston, K. (2020). On Markov blankets and hierarchical self-organisation. Journal of Theoretical Biology 486, 110089. doi:10.1016/j.jtbi.2019.110089
- Aguilera, M., Millidge, B., Tschantz, A. & Buckley, C. L. (2022). How particular is the physics of the free energy principle? Physics of Life Reviews 40, 24–50. doi:10.1016/j.plrev.2021.11.001
- Biehl, M., Pollock, F. A. & Kanai, R. (2021). A technical critique of some parts of the free energy principle. Entropy 23(3), 293. doi:10.3390/e23030293