Chapters 2, 4 and 7IntermediateNew edition
From beliefs to action: the complete loop
A fish looks for food it cannot see. In eight steps you build the whole loop of active inference on one small pond: a model, an observation, a belief, a plan, an action, and the next observation. Every number is computed as you watch.
AII: EduActive · Watch, then do
Three short clips, three things to try
These three passages come from a recorded tutorial and from the Institute’s study group on the textbook. Each is two to three minutes. Watch one, then press its button and look for the same tables in the pond 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 23:46. Nothing loads from YouTube until you press play.Open on YouTube at 23:46
1Before you start
The whole model in one pass
A model of this kind is a short list of parts. There are hidden states and the outcomes they produce. There are beliefs about where things start and how they change. There are preferences, and plans that are scored against them.
Listen forThen tryEach letter the speaker names has a table on this page. Predict which table the fish needs first when an outcome arrives. Then press the button and walk the eight steps, finding each letter as it comes.In the model A, B, C, D and G
The page has the same parts: A for outcomes given states, B with one table for each action, C for preferred outcomes, D for the first belief, and G for scoring policies. The speaker also names a habit prior E and a precision. Here E is flat, and the precision γ is a slider that is not updated by the model.
The tutorial this passage belongs to works through a different task: two slot machines and a hint that can be taken at a cost. This page uses a fish, three food patches and scent. The speaker describes the best policy as the one whose outcomes best match the preferences. On the page G also counts expected information, so a policy can score well by finding out.
Expected free energy of a policy · Policy selection
Further viewing: the model as a partially observable Markov decision process, 52:15 · the stages of policy selection, and what a softmax does, 64:05 · habit, present free energy and expected free energy in one policy equation, 67:03
-
Plays here, from 13:14. Nothing loads from YouTube until you press play.Open on YouTube at 13:14
2While it runs
States, A, B and D, step by step
Some things cannot be seen directly, such as the true temperature of a room. They are called hidden, or latent, states. At each moment a hidden state gives off something that can be seen, such as a thermometer reading. The state itself moves on from one moment to the next.
Listen forThen tryThe fish’s thermometer is scent. The button makes scent say nothing about where the food is. Predict what the fish can still learn from. Then press it, and use the step markers to return to step 1 and read the scent rows of table A.In the model tables A, B and D
On this page a hidden state is a pair: the zone the fish is in and the patch where the food lies, 18 states in all. A gives the probability of each outcome in each state. D is used once, at the first moment. After that the prior is B applied to the previous posterior, as the speaker says.
The speaker’s example is a room and a thermometer, with no action yet, so there is a single B. The pond has one B for each action from the start. With scent information at 0 a scent no longer depends on how far away the food is, so away from the patches it leaves the belief where it was. Eating, or failing to eat at a patch, still moves it.
-
Plays here, from 19:00. Nothing loads from YouTube until you press play.Open on YouTube at 19:00
3Afterwards
Actions as index cards
Each action has its own table that says how the world changes if that action is taken. Think of the tables as index cards of the same shape. Choosing an action is choosing which card to play next. A score called expected free energy guides the choice.
Listen forThen tryThe fish has three cards: stay, clockwise and anticlockwise. The button lets it plan only one card ahead. Predict whether it will set off from the Reeds. Then press it, and afterwards raise the planning horizon H to 2.In the model table B and policies
B on this page is three tables, one each for stay, clockwise and anticlockwise; step 1 shows them one at a time. A policy is a sequence of H actions, so there are 3H policies. Each is rolled forward through its B tables and then through A, and scored by G.
The speaker’s examples are the weather and a two-card file. The speaker also mentions a prior over policies that G then updates. Here that prior is flat, so Q(π) is a softmax of −γG alone, and the probability of an action is the sum of Q(π) over the policies that begin with it.
The quoted lines are taken from the automatic captions, with punctuation added and hesitations removed. The speakers use their own examples, not this pond; 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
The eight steps above are the main exercise. When you have walked them, these four experiments use free play. Each button sets the pond up; the settings it changes are listed.
- Walk the loop once, then let it run. Go from step 1 to step 8, predicting before you press each control. At step 8 press “Run the loop” and return to step 2: the same arithmetic now runs on a new moment.
- Shorten the horizon to one move. Predict: from the Reeds, no single move reaches a patch. Will the fish set off? With H = 1 it scores only the next moment: the Shallows cost it glare, the Silt offers nothing, so staying has the lowest G and it never eats. Then raise H to 2 and it plans round the Shallows, through the Silt.
- Flatten the preferences. Predict: with nothing preferred, will the fish stay still? Pragmatic value is now the same for every policy, so G is ordered by epistemic value alone. The fish goes where its beliefs are expected to change most. It crosses the Shallows without concern and patrols the patches, because that is where the information is.
- Make the scent uninformative. Predict: what can the fish still learn from? Go to step 2 after a scent arrives: likelihood is flat, so the posterior equals the prior. Only eating, or failing to eat at a patch, now moves its beliefs, so it must visit patches to find out. In a pond this small that costs it little.
- Turn precision down to zero, then recover. Predict: what does Q(π) look like at γ = 0? Every policy is equally probable and sampled actions are a random walk; meals become rare. Raise γ again and watch the count of meals pick up.
The mathematics
What is being computed
Hidden states are written s, outcomes o, actions u and policies π. P is the fish's generative model; Q is its current belief. Logarithms are natural, so quantities are in nats. The values under each equation are those of the moment now on the stage.
P(o | s) is a row of A. P(s) is D at the first moment and afterwards B(u) applied to the previous posterior. Code: AIF.bayes.
DKL is the Kullback–Leibler divergence, a measure of how far one distribution is from another; it is never negative. So F ≥ −ln P(o), with equality when Q is the exact posterior. Code: AIF.vfe.
τ runs over the future steps of the policy. Q(sτ | π) comes from applying B for each action in turn; Q(oτ | π) = A · Q(sτ | π); P(oτ) is C; H is Shannon entropy. Code: AIF.efe, summed in AIF.evaluatePolicies.
σ is the softmax. The textbook's general form is Q(π) = σ(ln E − γG − F), with E a prior over policies (habit) and F the free energy of past outcomes under each policy. Here E is flat, and every policy is re-evaluated from the current posterior at every step, so the F term is the same for all policies and drops out. Code: AIF.policyPosterior and sim.plan.
The four tables written out in full
Reading
Where this comes from
Interestingly, the expected free energy of a policy comprises two parts. The first quantifies the extent to which the policy is expected to resolve uncertainty (exploration) and the second how consistent the predicted outcomes are with an agent’s goals (exploitation).Parr, Pezzulo & Friston (2022), Active Inference, chapter 1, p. 10
What is established
The mathematics on this page is standard. Variational free energy is an upper bound on surprise, and its two decompositions are identities (Friston 2010; Parr, Pezzulo & Friston 2022, chapter 2). The discrete-state scheme, with tables A, B, C and D, expected free energy and a softmax over policies, is set out in the textbook (chapters 4 and 7), in Da Costa et al. (2020) and in the tutorial of Smith, Friston & Whyte (2022). The two readings of expected free energy, and the idea that the same quantity yields both information-seeking and goal-seeking, come from Friston et al. (2015, 2017).
The free energy principle is a principle and a modelling framework. This page illustrates how such a model works. It is not evidence about what fish, or brains, do.
What this model leaves out
The pond is invented for teaching: the probabilities in A and B are settings, not measurements of any fish. The fish always knows its own zone and its moves never fail. There is one kind of outcome, where published models usually have several.
Beliefs are updated by exact Bayes, so at the fish's own belief F equals surprise. Larger models use approximate, factorised beliefs found by gradient descent on F, and then F stays above surprise. The fish does not learn its tables (no Dirichlet counts), has no habits (E is flat), and its precision γ is a slider and is not itself inferred. Policies are re-planned in full at every step; with a horizon of 4 that is 81 policies, which is why the pond is small.
- Active Inference Institute. ActInf ModelStream #001.2: “A Step-by-Step Tutorial on Active Inference”. Recording. youtube.com/watch?v=bDJbEofbvyk
- Active Inference Institute (2025). ActInf Textbook Group, Cohort 8, Session 14 (Chapter 7). Recording. youtube.com/watch?v=TLAQxiO9whQ
- Parr, T., Pezzulo, G., & Friston, K. J. (2022). Active Inference: The Free Energy Principle in Mind, Brain, and Behavior. MIT Press. doi:10.7551/mitpress/12441.001.0001
- Da Costa, L., Parr, T., Sajid, N., Veselic, S., Neacsu, V., & Friston, K. (2020). Active inference on discrete state-spaces: a synthesis. Journal of Mathematical Psychology, 99, 102447. doi:10.1016/j.jmp.2020.102447
- Smith, R., Friston, K. J., & Whyte, C. J. (2022). A step-by-step tutorial on active inference and its application to empirical data. Journal of Mathematical Psychology, 107, 102632. doi:10.1016/j.jmp.2021.102632
- Friston, K., FitzGerald, T., Rigoli, F., Schwartenbeck, P., & Pezzulo, G. (2017). Active inference: a process theory. Neural Computation, 29(1), 1–49. doi:10.1162/NECO_a_00912
- Friston, K., Rigoli, F., Ognibene, D., Mathys, C., FitzGerald, T., & Pezzulo, G. (2015). Active inference and epistemic value. Cognitive Neuroscience, 6(4), 187–214. doi:10.1080/17588928.2015.1020053
- Friston, K. (2010). The free-energy principle: a unified brain theory? Nature Reviews Neuroscience, 11, 127–138. doi:10.1038/nrn2787