Active Inference InstituteSimulations

Chapter 5AdvancedNew edition

The dopamine dial: confidence in what to do

In active inference, dopamine is proposed to report precision: how confident an animal is that what it is doing will bring what it prefers. Precision is not set by hand. The mouse on the left infers it at every step, and the simulated cell on the right fires when it changes.

Prior precision

γ₀ = 1/β₀, the level the mouse starts each trial with. Drag, or use the arrow keys.
How far the mouse trusts what it sees. Acetylcholine, in Parr & Friston (2017).
How far it trusts the world to stay as it was. Noradrenaline, in the same paper.

AII: EduActive · Watch, then do

Three short clips, three things to try

These three passages come from the Institute’s courses, where members work through the textbooks and a published tutorial. Each is about three minutes. Watch one, then press its button and look for the same thing in the mouse and the cell above.

  1. Plays here, from 61:20. Nothing loads from YouTube until you press play.Open on YouTube at 61:20

    Before you start

    Precision as a control knob

    Having a plan is one thing. Trusting it is another. In this model a single number, called precision, sets how much the animal’s planning counts when it chooses what to do. The speaker writes G for the score that planning gives each plan. Turn precision down and G counts for less.

    Listen for
    It’s kind of like a control knob. It’s kind of like, let me turn down the volume here. Let me just turn down the actual influence of G here.
    Then try
    Predict how the mouse will move when the knob is turned right down. Press the button, then watch how long it hesitates and which port it takes.
    In the model equation 2

    The knob is γ in equation 2: beliefs about policies are a softmax of −γG − F, so γ scales how much expected free energy G counts against the evidence F. On this page the dial does not set γ itself. It sets γ₀, the level each trial starts from, and the mouse then infers γ at every event.

    The speaker’s equation also has a habit term E, and says that with no confidence the agent falls back on habit. Here habits are flat and left out, so a mouse with low precision does not become habitual. Its choices become close to random.

    Equation 2, beliefs about policies

    Further viewing: γ as a trade between habit and planning, with a two-policy example, 32:26 · what is left when precision goes to zero, and the link to dopamine, 47:57 · the update equation for β, term by term, 55:36

  2. Plays here, from 60:19. Nothing loads from YouTube until you press play.Open on YouTube at 60:19

    While it runs

    A worked example: the dial goes up

    The mouse’s confidence is not fixed. Each time something happens, it compares how things are going with how it expected them to go. If the news supports the plan it already favoured, confidence rises. The speaker works one such case through with numbers.

    Listen for
    Gamma ends up equalling 1.28, which went up from one, which means that you’d have a predicted positive phasic dopamine response.
    Then try
    After 50 trials the mouse knows what the lamp’s colours mean. Predict the sign of the change in precision when it reaches the lamp. Press the button, then read “Change at this event” in the panel.
    In the model equation 3

    This is equation 3. The term (π − π₀)·G compares the policies the evidence supports with the policies the mouse favoured beforehand. In the speaker’s example the new evidence F agrees with G, so β falls and γ rises above 1. The page uses the same rule and repeats the step until γ settles.

    The example has two policies and numbers chosen by hand, with G = (10, 9) and F = (20, 1). The mouse has four policies, and its G and F are computed from its model of the lamp and the ports at each event. Its γ also starts from the dial’s setting, not always from 1.

    Equation 3, expected precision

  3. Plays here, from 69:25. Nothing loads from YouTube until you press play.Open on YouTube at 69:25

    Afterwards

    Not a reward prediction error

    The standard reading of these bursts is that the cell reports a reward that was better than predicted. The reading on this page is different. A cue makes the animal more sure of what to do, and the cell reports that rise in confidence. The two readings predict much the same recording.

    Listen for
    Instead of it being a reward prediction error, what would be happening is the cue is actually unexpectedly making the rat a lot more confident in what to do.
    Then try
    Now take the opposite case. The mouse follows a lamp it trusts and finds the port dry. Predict what happens to its confidence, and to the cell, at that moment. Then press the button.
    In the model equations 3 and 6

    On this page the burst and the pause are both changes in γ from equation 3, passed through the read-out of equation 6: a resting rate plus a gain times the rate of change of γ. The cell is an illustration added to the model. Its resting rate, gain and timing are settings.

    The speaker’s animal is a rat that sees a light and presses a lever; here it is a mouse that visits a lamp and picks a port. The speaker also says this is not offered as a complete account of dopamine. The page agrees: both readings predict the burst that moves to the cue and the pause at a withheld reward, and a recording like this one cannot tell them apart.

    Equation 3, expected precision · Equation 6, the model cell · Behaviour across the dial

The quoted lines are taken from the automatic captions, with punctuation added and hesitations removed. The speakers are discussing the general equations and their own examples, 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.

Reading the picture

A mouse, a lamp and two ports

On each trial, water is behind one of two ports, left or right, chosen at random. The mouse has two moves. It can go straight to a port and guess. Or it can first visit a lamp, which lights blue or amber, and then choose a port. The lamp's colour tells where the water is on 95 trials in 100, but a new mouse does not know which colour means which side. It has to learn that from experience.

A policy is a plan: a sequence of moves. The pale paths on the floor are the four policies, and the brighter a path, the more the mouse believes it is the one it is following. When the mouse is unsure it pauses and looks about for longer; when it is confident it runs faster. Those two features of the drawing are set by the model's numbers: the pause by the entropy of its next move, the speed by the precision γ. The link between γ and running speed is a drawing convention here, not a result.

The right-hand view is drawn like a recording from a dopamine cell in the midbrain. Each row of ticks is one trial; each tick is one spike. Under the rows, the bars count spikes across trials, and the thin line is the firing rate the model asked for. The rows are lined up on three events: leaving the start box, reaching the lamp, and reaching the port.

The cell is a read-out, added for illustration. Its rate is a resting rate plus a gain times the rate of change of precision, and spikes are drawn at random from that rate. The resting rate, gain and timing are settings. What is computed by the theory is the size and sign of each change in precision.

Achieving a reward (or fulfilling our preferences) or encountering a cue indicative of a future reward enhances our confidence that we are pursuing a policy that minimizes expected free energy. This increase in confidence manifests as a spike in dopamine.Parr, Pezzulo & Friston (2022), Active Inference, chapter 5, p. 97

Measured, not drawn

Behaviour across the dial

Each point below is an average over 12 simulated mice with different random seeds. Every mouse starts naive, runs 40 trials (the last 20 are scored), and then the meaning of the lamp is reversed for 20 more. The measurement starts when this section comes into view and takes a few seconds.

Not yet measured.
Prior precision γ₀Hesitation at the lamp: entropy of the port choice (nats)Consults the lamp firstTrials with waterLearnt P(blue | water left)Errors after reversal, out of 20Water after reversal
Waiting for the measurement.

What the dial does here. With low prior precision the mouse's choices are close to random even when it has learnt what the lamp means: it knows, but does not act on what it knows. With high prior precision it commits to the port the lamp indicates and collects more water. The price appears when the lamp is reversed. A confident mouse keeps following the old meaning, so it makes more errors and collects less water until the new meaning has been learnt. An error after reversal is a trial on which the mouse saw the lamp and then went to the port that the old meaning pointed to.

What the mouse learns barely changes across the dial: see the column for the learnt meaning of blue. In this model dopamine sets how strongly beliefs drive action, and learning is done by a separate rule. FitzGerald, Dolan & Friston (2015) report the same dissociation in their simulations: lowering precision "impairs performance but spares learning".

What this may and may not say about people. Friston and colleagues (2012) simulated a loss of dopamine as a loss of precision, in a different, continuous-time model, and obtained behaviour "reminiscent of" Parkinson's disease. The textbook summarises the proposal for policies: "its depletion in severe Parkinson’s disease causes akinesia—a failure to enact specific policies—while exogenous dopamine agonists promote impulsive behaviors" (chapter 5, p. 94). The left and right ends of the dial are a toy version of that contrast: indecision at one end, rigid commitment at the other. The page makes no clinical claim beyond those papers, and this mouse cannot stay still, so it cannot show akinesia.

This is a hypothesis about dopamine, and it has a well-supported competitor. Schultz, Dayan & Montague (1997) explained the same recordings as a reward prediction error: the difference between the reward received and the reward predicted. Both accounts predict a burst to an unexpected reward, a burst that moves to the cue with learning, and a pause when a predicted reward is withheld. A picture like the one above cannot tell them apart.

The other two precisions

Parr & Friston (2017) give the same treatment to two more distributions in the mouse's model: the likelihood, with precision ζ, which they relate to acetylcholine, and the transitions, with precision ω, which they relate to noradrenaline. Here both are sliders, with the same protocol as above and the dial at its current setting. The two columns of confidence separate them: ζ changes how sure the mouse is of the water's side while it looks at the lamp; ω changes how much of that confidence survives the walk to the port.

Not yet measured.
SettingConfidence in the water's side at the lampConfidence carried to the portBurst at the lamp, mean ΔγConsults the lamp firstTrials with waterLearnt P(blue | water left)Errors after reversal, out of 20
Press the button to measure.

Learn by doing

Try this

  1. Start with a naive mouse and watch ten trials. Predict first: will the cell fire at the lamp or at the water? A naive mouse learns nothing from the lamp's colour, so reaching the lamp leaves its confidence where it was. Water it could not count on raises its confidence, and the burst comes at the port.
  2. Let it learn for 50 trials, then look at the lower rows. Predict: once blue reliably means left, where should confidence rise? The burst should now come at the lamp, and the water, being expected, should add little. Compare the panel of early trials with the panel of late trials.
  3. Withhold the water once. Predict what the cell does at the moment the water should have arrived. The mouse followed a lamp it trusts and found a dry port, an outcome worse than it expected under its policy. Precision falls, and the cell falls silent for a moment.
  4. Turn the dial down, then up. Predict how the mouse will move at each setting. At γ₀ = 0.25 it dithers at the lamp and often takes the wrong port, though it has learnt what the colours mean. At γ₀ = 4 it runs straight to the port the lamp indicates. Then read the charts under "Behaviour across the dial".
  5. Reverse the lamp at each dial setting. Blue now means the other side. Predict which mouse suffers more. The confident mouse keeps obeying the old meaning and meets dry port after dry port, each with a pause in the cell, until its learnt mapping turns over. Then watch it recover.
  6. Now the other two precisions. Put the dial back to 1. Lower ζ and the lamp itself becomes hard to believe. Lower ω and the lamp is believed, but the belief fades before it can be used. Predict which one removes the burst at the lamp, then measure.

The mathematics

What is being computed

The mouse has a generative model of a trial. Hidden states s are its place (start box, lamp, left port, right port) and the context (water left or water right). Outcomes o are what it can observe: nothing, a blue lamp, an amber lamp, water or a dry port. The likelihood A = P(o | s) says what is seen where; the transitions B(u) = P(s′ | s, u) say where a move u leads; C = P(o) holds its preferences (ln C is +1 for water, −2 for a dry port and 0 otherwise, a setting); D is its belief at the start, with the two contexts equally likely. A policy π is a pair of moves. There are four. The live numbers below refer to the event shown most recently on the stage, and list the policies in the order: lamp then left, lamp then right, straight left, straight right.

1 · Expected free energy of a policy (model code: stepG, assess) G(π)=∑t≥τ[DKL[Q(ot|π)‖P(ot)]⏟risk+EQ(st|π)[H[P(ot|st)]]⏟ambiguity−W(π,t)⏟novelty] –

G is a cost: lower is better. Risk is how far the outcomes a policy is expected to bring differ from the preferred ones. Ambiguity is how uncertain outcomes would be even if the state were known. Novelty is the information the mouse expects to gain about A itself, here about what the lamp's colours mean (textbook, section 7.5). The sum runs over the present step τ and those still to come, using each policy's own beliefs.

2 · Beliefs about policies, before and after the evidence (AIF.precision) π0=σ(−γG),π=σ(−γG−F),F(π)=−lnP(o1,…,oτ|π) –

σ is the softmax function, which turns a list of numbers into probabilities. F(π) is the variational free energy of the outcomes so far under policy π; with exact inference, as here, it equals the surprise of those outcomes under that policy. A policy the mouse did not follow predicts the wrong place, so its F is about 16 nats higher and it drops out of π, though not out of π₀. Habits (the prior E over policies) are flat in this model and are omitted.

3 · Expected precision (AIF.precision; Friston et al. 2017) β=β0+(π−π0)·G,γ=1β –

This is the centre of the page. (π − π₀)·G is the expected free energy of the policies the evidence supports, minus the expected free energy the mouse anticipated before the evidence. If the mouse finds itself on a better course than it anticipated, the term is negative, β falls and precision γ rises. If things have gone worse than anticipated, γ falls. Because π and π₀ themselves depend on γ, the equation is solved by iteration to its fixed point. The dial sets β₀ = 1/γ₀. In the start box nothing yet separates the policies, so π = π₀ and γ = γ₀ exactly.

4 · Learning what the lamp means (AIF.learnA, smooth) a←a+∑tot⊗Q(st|o1,…,o3),A=a∑oa –

The mouse keeps Dirichlet counts a: a tally of how often each outcome has gone with each state. After every trial it adds what it saw, weighted by its belief, looking back from the end of the trial, about which state it was in. Each lamp cell starts at 2, which means the colours carry no meaning at first.

5 · The other precisions (gibbs; Parr & Friston 2017; textbook Box 7.1) Aζ=σ(ζlnA),Bω=σ(ωlnB) –

Each column of the matrix is raised to a power and rescaled to sum to one. Below 1 the distribution is flattened: the mouse trusts it less. Above 1 it is sharpened. Zeros stay zero, so the mouse never doubts which place it is in.

6 · The model cell: an illustrative read-out (rateAt, spikes) r(t)=max(0,r0+gdγdt),dγdt=∑kΔγkTre−(t−tk)/Tr –

After each event at time tk, γ is taken to relax to its new value with time constant Tr; the sum runs over the events that have already happened. Spikes are drawn at random (a Poisson process) from the rate r(t). A cell cannot fire at less than zero, so a pause can only be as deep as the resting rate allows. Friston and colleagues (2017) plot the rate of change of precision in the same way; the resting rate r₀, the gain g, the time constant and the one-second spacing of events are settings chosen so that the picture is legible.

Four bets, and how they came out

Four results from the recordings were written down as bets before the model was built. Each is recomputed in your browser from the equations above, with the dial at 1 and ζ = ω = 1. The preferences and the starting counts are settings, and they were chosen with these bets in view; the two checks at the foot of the table show where the model still departs from the recordings.

BetComputedResult

Reading

Where this comes from

What is established

Schultz, Dayan & Montague (1997) reviewed recordings from midbrain dopamine cells in monkeys: a burst to an unexpected reward, a burst to a cue that predicts reward once the animal has learnt it, and a pause when a predicted reward does not arrive. Those are observations.

The reading of them shown here is a proposal. Friston and colleagues (2012) suggested that dopamine reports precision. Friston and colleagues (2014) made that the precision of beliefs about policies in a discrete model and noted that its changes resemble dopamine responses. Schwartenbeck and colleagues (2015) found that activity in the human dopaminergic midbrain, measured with functional imaging, followed trial-by-trial estimates of precision from such a model. FitzGerald, Dolan & Friston (2015) added learning and simulated the transfer of responses from reward to cue. Friston and colleagues (2017) set out the update rule used here. Parr & Friston (2017) proposed the roles for acetylcholine and noradrenaline. The textbook summarises all of this in chapter 5, and adds that the role of serotonin "seems less clear" (p. 97); it is not modelled here.

The free energy principle is a modelling framework. This page illustrates one model built within it. It is not evidence that the brain works this way.

What this model leaves out

  • The published simulations use approximate (variational) message passing in a T-maze with more policies, including staying put. This page uses exact inference in a smaller task, with four policies and no option to stay.
  • The published equations sum expected free energy over all time steps of a policy. Here the sum runs over the present and remaining steps.
  • With the dial above 1 the model departs from the recordings in two ways that the bets table reports: a fully expected reward produces a small dip instead of no response, and the burst at the lamp stops growing with the lamp's reliability.
  • ζ and ω are fixed by sliders. In Parr & Friston (2017) they are inferred, as γ is, and their task allowed the animal to look again; this one does not. Here ζ applies to every observation at once.
  • The mouse's model allows the water to change side with probability 0.02 per step. In the simulated world it never does within a trial.
  • The spikes, their timing, the running speed and the pauses are illustrations. Real dopamine cells are diverse, and their activity is also discussed in terms of salience, movement and effort, none of which is modelled.
  • The original version of this page gave serotonin a role and showed a dopamine-to-serotonin ratio. No active inference paper supplies that mechanism, so it is not carried over.