Chapter 7AdvancedNew edition
The T-maze: looking before choosing
A rat must pick one of two arms. One holds food, the other a mild shock, and it does not know which. Nobody tells it to explore. It scores each plan by one quantity, expected free energy, and that quantity already contains the value of finding out. Watch it visit the cue light first, then go for the food.
AII: EduActive · Watch, then do
Three short clips, three things to try
These three passages come from a research talk and from the Institute’s study group on a textbook. Each is one to two and a half minutes. Watch one, then press its button and look for the same thing in the maze 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 9:41. Nothing loads from YouTube until you press play.Open on YouTube at 9:41
1Before you start
The classic maze
An animal sits in a maze shaped like a T. One arm holds a reward and the other a punishment, and a cue elsewhere in the maze says which is which. The animal can gamble on an arm at once, or it can read the cue first.
Listen forThen tryThe rat starts at the junction with no idea where the food is. Decide whether it will go left, right, or down to the cue light. Then press the button and watch its first move.In the model equations 1 and 4
The page scores each policy, a short sequence of moves, by its expected free energy G, and turns the scores into probabilities Q(π). Policies that begin at the cue have the lowest G at the opening settings, because G contains the information the cue is expected to give.
The speaker describes a mouse and goes on to replace the maze with an ambiguous word; only the maze is used here. This page has a rat, the textbook’s values, and arms that cannot be left. The speaker says active inference has resolved the dilemma of exploring or exploiting. The page claims less: both values are parts of one quantity, so no separate rule for exploring is needed. It is an illustration, not evidence about animals.
Equation 1, expected free energy · Equation 4, beliefs about policies
-
Plays here, from 21:33. Nothing loads from YouTube until you press play.Open on YouTube at 21:33
2While it runs
Will I see what I want to see
Expected free energy is the score a plan gets, and lower is better. One part of it is called risk. Risk is the gap between what the animal expects to sense if it follows a plan and what it would like to sense.
Listen forThen tryMake the rat nearly sure that the food is on the left. Predict which plan now carries the least risk, and whether the rat will still visit the cue. Then press the button and read the risk bars in the policy panel.In the model equation 1
Risk is the first term of equation 1: the divergence between Q(o | π), the outcomes expected under a policy, and P(o), the preferred outcomes. On this page P(o) is the vector C, set by the preference strength c: +c for food and −c for shock. The policy panel shows risk and ambiguity as separate parts of each bar when “Risk + ambiguity” is selected.
The speaker is working through a textbook’s general formula and does not have a maze in mind. The second term, ambiguity, comes just after this passage ends. On the page it is the expected entropy of the outcomes in the places a policy leads to.
Equation 1, expected free energy
Further viewing: the two terms again, as the gap between wanted and expected outcomes and as how informative a state is, 83:32
-
Plays here, from 31:14. Nothing loads from YouTube until you press play.Open on YouTube at 31:14
3Afterwards
Explore first, then exploit
When it is unclear how to reach a goal, the best plan is often to find out first. Turn on the light before you search the room. Once the uncertainty is gone, what remains is to go for the reward.
Listen forThen tryNow take the value of finding out away, so that only preferences count. Predict how often this rat will reach the food in 100 trials. Then press the button and compare the rows of the tally.In the model equations 1 and 2
On this page the order of exploring and then exploiting appears inside a single trial: cue first, then an arm. The term that produces it is the epistemic value in the second line of equation 1. At the cue it has the closed form of equation 2, worth 0.693 nats at the opening settings. “No epistemic value” removes that term and leaves the pragmatic value.
The speaker counts three terms: risk, ambiguity and novelty. Novelty is the value of learning the model’s parameters over many trials. This page has no novelty term and no learning across trials; the rat starts every trial with the same prior. The speaker’s examples are a map and a light switch, not a maze.
Equation 1, expected free energy · Equation 2, what the cue is worth
The quoted lines are taken from the automatic captions, with punctuation added and hesitations removed. None of the speakers is describing this page; where their examples differ from it, 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
- Predict the first move, then watch.
The rat starts at the junction with no idea where the food is. Will it go left, right, or down to the cue light? Decide, then run a trial. Look at the policy rows before it moves: the lowest bars and the tallest Q(π) belong to plans that begin at the cue.
- Watch the belief change at the cue.
When the rat reaches the light, the tint on the two arms changes. Predict how many nats it gains. A flat belief over two contexts holds ln 2 = 0.693 nats of uncertainty, and a perfect cue removes all of it. Then see every policy scored again: the plan that ends in the indicated arm takes nearly all the probability, and precision rises.
- Make the rat confident.
Set the prior that reward is on the left to 0.95. Will it still check? It goes straight to the left arm. Now lower the prior slowly. The sentence beside the maze reports the prior at which the rat stops checking the cue.
- Make the cue unreliable.
With one-move policies, each move is judged on its own. Drag cue validity down from 1. The information the cue offers is computed, not assumed: it falls, and once it is below what an arm itself would reveal, the rat stops visiting. Predict the validity at which that happens.
- Remove the epistemic value.
Now only preferences count. Predict what the cue is worth to this rat. Run 100 trials and compare the rows of the tally. Then put the epistemic value back and remove the preferences instead: the rat looks, and then has no reason to go anywhere.
- Lower the precision, then restore it.
Raise β to 4 and let the move be sampled. The same expected free energies now give a flatter Q(π), and the rat wanders. Then return to the opening settings and watch the orderly pattern come back: cue first, then food.
The mathematics
What is being computed
The rat has a generative model: a set of probabilities that says how hidden states produce outcomes. The hidden states s are where the rat is (centre, left arm, right arm, cue) and the context (reward on the left, or on the right). The outcomes o are what it can sense: the place it is in, the food or shock in an arm, and which way the cue points. A policy π is a sequence of moves. All logarithms are natural, so information is in nats (1 nat = 1.44 bits).
Q(oτ | π) is what the rat expects to sense if it follows the policy. P(oτ) is the vector C: the outcomes it prefers, written as probabilities. Risk is how far the expected outcomes are from the preferred ones. Ambiguity is how noisy the outcomes are in the places the policy leads to. The second line is the same number split another way. Epistemic value is the information the rat expects to gain about hidden states. Pragmatic value is the expected log-preference. G for a whole policy is the sum over its remaining steps. G is a cost: lower is better. In code: AIF.efe, summed in AIF.evaluatePolicies.
Epistemic value is the mutual information between outcomes and hidden states (textbook equation 7.8). At the cue it has a closed form. Here p is the current belief that reward is on the left, v is the cue validity, and H2(x) = −x ln x − (1−x) ln(1−x) is the entropy of a coin with bias x. A perfect cue (v = 1) is worth the whole uncertainty about context, H2(p). An arm is informative too, because food or shock also tells the rat the context: replace v by a. In code: MODEL.cueInformation, tested against the general formula and a direct sum.
The rat senses nothing new until it arrives. On arrival the outcome is drawn from the maze, and the belief Q(s) is replaced by the exact posterior. The denominator is the probability the rat gave to that outcome; minus its logarithm is the surprise. Because the posterior is exact, the variational free energy of this update equals the surprise. The information actually gained on one trial can differ from the information expected in equation 2, which is an average over the outcomes that might have occurred. In code: AIF.bayes, called in arrive().
σ is the softmax function, which turns scores into probabilities. E is a prior over policies (a habit); here it is flat, so ln E is the same for every policy and cancels. γ is the expected precision: how much the rat trusts its own scoring. F is the free energy of the outcomes so far under each policy. A policy that predicted the rat would be somewhere else gives the observed outcomes zero probability; with a floor of e−16 its F is 16 nats, so it is all but ruled out. F is computed under every policy; none is deleted. The move u is then drawn with action precision α: at α = 512 the most probable next move is taken, and at α = 1 the move is sampled. In code: MODEL.plan.
π0 is what the rat would believe about its policies from G alone; π also counts the evidence F. If the policies that survive the evidence have a lower G than the rat expected on average, β falls and precision γ rises: things are going better than expected. If they have a higher G, precision falls. The panel plots γ as this equation is iterated to its fixed point, and the change in γ from one iteration to the next. In the process theory that rate of change is the model's simulated phasic dopamine response (Schwartenbeck et al. 2015; Friston et al. 2017). In code: AIF.precision.
The fact that utility and the value of information emerge as two components of the expected free energy means that we do not need to worry about balancing exploration and exploitation. Both are in service of optimizing the same function.Parr, Pezzulo & Friston (2022), Active Inference, chapter 7, p. 131
Reading
Where this comes from
What is established
This is the T-maze of Friston and colleagues (2015, 2017), as specified in chapter 7 of the textbook (figures 7.4 to 7.7): four locations, two contexts, arms that cannot be left, food with probability 0.98 in the correct arm, log-preferences of +6 and −6, a slight aversion (−1) to the start, and a flat prior over context. The page uses those values at its opening settings.
It is a mathematical fact, checked in this page's tests, that risk plus ambiguity equals minus epistemic value minus pragmatic value, and that epistemic value is the mutual information between outcomes and hidden states. So an agent that selects policies by expected free energy is drawn to informative places without a separate rule for exploring.
The link between changes in expected precision and dopamine is a hypothesis of the process theory. Schwartenbeck and colleagues (2015) report midbrain activity in humans that follows the model's precision in a different task. The trace on this page is the model's quantity, not a recording.
The free energy principle is a modelling framework. This page illustrates it. It is not evidence that rats, or brains, work this way.
What this model leaves out
Looking ahead through its own future beliefs. When this rat scores “cue, then left”, it does not imagine what it will know after seeing the cue. The second step is scored with today's belief. That is why “cue, then stay at the cue” can score as well as “cue, then an arm” before the cue is seen, and why the scores are computed again after every outcome. An agent that does update its expected beliefs within a plan uses sophisticated inference (Friston, Da Costa, Hafner, Hesp & Parr 2021). For the same reason the cue's lead here is slim: at the opening settings it is worth 0.693 nats, and an arm, whose food or shock also reveals the context, is worth 0.595.
How policies are counted. The probability of a move is the sum over the policies that begin with it. Four distinct two-move policies begin at the cue and only one in each arm, so with two-move policies the cue gains from that sum as well as from its lower G. With the epistemic value removed, every policy that avoids the centre has exactly the same G, and the cue is still the most probable first move for that reason alone. One-move policies have no such effect, which is why steps 4 and 5 use them.
Message passing. The published scheme infers states by iterative message passing under each policy and has two outcome modalities. Here beliefs are exact (Bayes' rule), and the two modalities are merged into seven joint outcomes, which is the same model. A policy that has been contradicted keeps its own earlier predictions when its G is computed; the published scheme would give it a compromise belief.
The rest of the trial. Precision is updated at the two decision points only, so the trace shows no response to the final outcome of a two-move trial. There is no learning across trials: the rat starts each one with the same prior, and the world is drawn from that prior. The moving animal is an illustration; its path and pauses are not part of the model.
- Active Inference Institute. Ahmad Nazzal: “A Lexical T-Maze for Active Inference”. Recording. youtube.com/watch?v=GAmQEsobfPw
- Active Inference Institute (2026). Fundamentals of Active Inference (Ch. 9: Active Inference in POMDPs, Session 43). Recording. youtube.com/watch?v=GdnjIgX0ZN8
- Active Inference Institute (2026). Fundamentals of Active Inference (Ch. 10: Learning in Discrete Models, Session 47). Recording. youtube.com/watch?v=GQYh03SoJ88
- Parr, T., Pezzulo, G. & Friston, K. J. (2022). Active Inference: The Free Energy Principle in Mind, Brain, and Behavior. MIT Press. Chapter 7. doi:10.7551/mitpress/12441.001.0001
- 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., 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
- Schwartenbeck, P., FitzGerald, T. H. B., Mathys, C., Dolan, R. & Friston, K. (2015). The dopaminergic midbrain encodes the expected certainty about desired outcomes. Cerebral Cortex, 25(10), 3434–3445. doi:10.1093/cercor/bhu159
- Friston, K., Da Costa, L., Hafner, D., Hesp, C. & Parr, T. (2021). Sophisticated inference. Neural Computation, 33(3), 713–763. doi:10.1162/neco_a_01351
- 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