Chapters 1–4BeginnerNew edition
The fish that expects its water
This fish expects to be in water at 16 °C. When the water feels wrong it can close the gap in two ways: change its belief, or swim until the water feels right. You control the pond. Press and hold in the water to pour.
Press and hold in the water to pour. The dashed gold line is water at the fish’s preferred temperature.
The pond (yours to change)
The fish (switches for the experiment)
Learn by doing
Try this
Before each step, say what you think will happen. Then press the button and watch the pond, the gauge at its right, and the traces below it.
- Watch the fish at rest. A slow wave rocks the layer where warm water meets cold. The fish rides it, staying on the dashed gold line. Its error is small and wobbles with the noise in its sense.Predict: how far apart will free energy and surprise be?
- Pour cold water on the fish. Three things happen, in order. The sensation drops, so the error jumps. The belief moves towards the sensation. Then the fish swims, and the error goes.Predict: which way will it swim, and where will it stop?
- Switch action off and pour again. The fish can now only change its mind. Its belief shifts towards the cold, and free energy falls part of the way. The water is still not what it expects, so the error stays for as long as the water stays cold.Predict: will free energy return to its resting value?
- Switch perception off instead. The belief is now fixed at 16 °C. All of the error drives the swimming, and free energy sits far above surprise until the fish arrives.Predict: will the fish get back sooner or later than in step 2?
- Make the sense unreliable, then reliable. Precision sets how much an error counts. With low sensory precision the fish trusts its prior, barely revises its belief, and reacts late. With high precision it reacts at once.Predict: with a noisy sense, how long before the fish moves?
- Shade the surface. Under the lily pads the water cools slowly from the top. The fish drifts to keep itself in water at 16 °C, and no large error ever appears. Remove the shade and it drifts back.Predict: will the fish move up, down or sideways?
The mathematics
What is being computed
The fish cannot read the water temperature directly. It has a sensation, and a model of how sensations are caused. Every number below is the model’s current value.
T is the temperature of the water at the fish. g is the response of its temperature sense, which flattens out at the extremes, as receptors do. ω is noise whose variance is 1/Πy; the number Πy is the precision of the sense, the inverse of its variance. The constants r = 10, Tr = 15 °C and s = 8 °C are settings.
The fish’s model says two things. Sensations come from the water temperature through g, with precision Πy. And the water it is in should be at η = 16 °C, with precision Πμ. Its belief about the water is a bell curve centred on μ with precision Πq; this is the Laplace approximation. The sensory prediction error εy is the sensation minus the sensation the belief predicts. The prior error εμ is the belief minus the preferred temperature. Free energy F adds the two squared errors, each weighted by its precision, to terms that depend only on the precisions.
The belief slides downhill on F. The sensory error pulls it towards what is felt; the prior error pulls it back towards what is expected. Each pull is weighted by its precision. The derivative is taken of the two error terms, with Πq held at its current value, which is the usual scheme. The rate κμ = 0.4 is a setting.
Swimming cannot change the belief. It can only change what is sensed, so action sees free energy through the sensation alone. The fish’s velocity points down the slope of F: towards warmer water when it feels colder than it predicts, and the reverse. It stops when εy is zero. ∇T is the local slope of temperature across the pond, in °C per metre, measured over 5 cm. The gain κa = 0.0025 and a top speed of 0.5 m/s are settings.
Surprise is how improbable the sensation is under the fish’s whole model, whatever the water temperature v might be. Here it is found by adding up the integral numerically over 3,600 slices. Free energy is built to sit on or above surprise, and the gap between them measures how far the belief is from the best belief available. For a straight-line receptor that statement is exact. With the curved receptor used here, the Laplace form is an approximation: in the tests it fell below surprise by at most 0.05 nats while the fish was being disturbed and recovering, and by up to 0.17 nats at beliefs far from anything the fish reaches.
This is why the two switches do different things. Perception closes the gap between F and surprise. It cannot lower surprise itself, because it cannot change the sensation. Only action does that.
“perception can minimize variational free energy by reducing the discrepancy between approximate and true posterior but cannot go further in minimizing surprise. The next step of surprise minimization entails changing the sensations one gathers by acting, which is where inference goes beyond perception and becomes active.”Parr, Pezzulo & Friston (2022), Active Inference, chapter 3, p. 52
Reading
Where this comes from
What is established
The free energy principle describes a living thing as a system that keeps itself in the states it expects to occupy, which is the same as keeping the long-run surprise of its sensations low (Friston 2010). The equations here are the simplest continuous-time form of that idea: predictive coding under the Laplace approximation, as set out step by step by Bogacz (2017) and Buckley and colleagues (2017), and in chapter 4 of the textbook by Parr, Pezzulo and Friston (2022). Predictive coding as an account of perception goes back to Rao and Ballard (1999).
Letting action reduce the same prediction error, through a reflex that fulfils the predicted sensation, follows Friston and colleagues (2010) and Adams, Shipp and Friston (2013). Treating a preferred bodily state as a prior expectation that behaviour fulfils follows Pezzulo, Rigoli and Friston (2015).
Fish do choose their water temperature by swimming. Given a gradient, a fish settles in a narrow, species-typical band of temperature, its preferred temperature (Reynolds and Casterlin 1979).
The free energy principle is a principle and a modelling framework. This page illustrates it. It is not evidence for it.
What this model leaves out
- The published schemes use generalised coordinates of motion, hierarchies of causes, and beliefs about how states change. This fish has one hidden cause, one sensation and no model of dynamics. Precisions are fixed by you and are not learned.
- The fish is handed the local slope of its sensation, ∂y/∂x. A real fish has to find the slope by moving and comparing.
- The fish’s model is calibrated: the precision it assumes for its sense is the true one. Moving the Πy slider changes both the noise and the fish’s trust in the sense.
- Velocity follows the gradient directly, with a speed limit. There is no inertia, no energy cost and no other motive such as food or shelter. The swimming motion is drawn, not simulated.
- The water only conducts heat. There is no buoyancy and no flow, so cold water poured near the surface does not sink. The mixing rate is set far higher than in a real pond so that a pour spreads in seconds, and the standing layers and their slow wave are imposed, not computed.
- The preferred temperature of 16 °C and the receptor curve are settings, not measurements from a species. The faint colour of poured water is drawn so that you can see it; the temperature colours are a false-colour overlay.
- The earlier version of this page included a predator shadow and a narrator. Neither was computed from a stated model, so both have been left out.
- Friston, K. (2010). The free-energy principle: a unified brain theory? Nature Reviews Neuroscience, 11, 127–138. doi:10.1038/nrn2787
- Bogacz, R. (2017). A tutorial on the free-energy framework for modelling perception and learning. Journal of Mathematical Psychology, 76, 198–211. doi:10.1016/j.jmp.2015.11.003
- 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 1–4. doi:10.7551/mitpress/12441.001.0001
- Friston, K. J., Daunizeau, J., Kilner, J. & Kiebel, S. J. (2010). Action and behavior: a free-energy formulation. Biological Cybernetics, 102, 227–260. doi:10.1007/s00422-010-0364-z
- Adams, R. A., Shipp, S. & Friston, K. J. (2013). Predictions not commands: active inference in the motor system. Brain Structure and Function, 218, 611–643. doi:10.1007/s00429-012-0475-5
- Pezzulo, G., Rigoli, F. & Friston, K. (2015). Active Inference, homeostatic regulation and adaptive behavioural control. Progress in Neurobiology, 134, 17–35. doi:10.1016/j.pneurobio.2015.09.001
- Rao, R. P. N. & Ballard, D. H. (1999). Predictive coding in the visual cortex: a functional interpretation of some extra-classical receptive-field effects. Nature Neuroscience, 2, 79–87. doi:10.1038/4580
- Reynolds, W. W. & Casterlin, M. E. (1979). Behavioral thermoregulation and the “final preferendum” paradigm. American Zoologist, 19, 211–224. doi:10.1093/icb/19.1.211