Chapter 14

Psychology and Neuroscience

Temporal-difference learning was invented to solve a computational problem, and only afterwards did it turn out to describe, with uncomfortable precision, what rabbits learn about tones and air puffs and what dopamine neurons in a monkey’s midbrain do when juice arrives. Part II ended with actor–critic methods (Chapter 13), in which one TD error trains both a critic and an actor; Part III opens by finding that architecture, and that error, in animals. This chapter condenses Sutton and Barto’s two chapters on psychology and neuroscience into one argument.Richard S. Sutton and Andrew G. Barto. Reinforcement Learning: An Introduction. Adaptive Computation and Machine Learning. MIT Press, Cambridge, MA, second edition, 2018. ISBN 978-0-262-03924-6. URL http://incompleteideas.net/book/the-book-2nd.html Its thread is a single equation, the TD error (6.2), read three times: as a theory of classical conditioning that generalizes the Rescorla–Wagner model, as a theory of the phasic activity of dopamine neurons, and as the reinforcement signal of an actor–critic architecture spread over the striatum. Around this thread we place the rest of the correspondences: instrumental conditioning and the law of effect, eligibility traces and delayed reinforcement, cognitive maps and the split between habitual and goal-directed behavior, and a TD model of addiction. Our aim is to derive what the book shows by simulation: blocking, second-order conditioning, the backward migration of the TD error, and the unbounded values of Redish’s addiction model all follow from short exact calculations.

The correspondences are not perfect, and both of the book’s chapters insist on it. Reinforcement learning is an engineering theory of idealized agents, not a model of rats. Where the brain departs from the theory we say so, and the last section reports what has been learned since 2018, cautiously, because several of those questions are still open.

14.1Prediction and Control in Animal Learning

Psychologists distinguish two families of laboratory experiments, and they line up with the two halves of every reinforcement learning algorithm. In classical (or Pavlovian) conditioning the experimenter delivers a biologically significant stimulus whatever the animal does: Pavlov’s dog hears a metronome, and food follows. The innate trigger (food) is the unconditioned stimulus (US) and the innate response (salivation) the unconditioned response (UR); after a few pairings the formerly neutral metronome becomes a conditioned stimulus (CS) that elicits a conditioned response (CR) of its own. Nothing the animal does changes what happens next, so what it learns is a prediction: classical conditioning is policy evaluation. In instrumental (or operant) conditioning the reinforcing stimulus is contingent on behavior: a cat escapes from a puzzle box by pulling a loop and gets the food outside. What the animal learns is a policy; instrumental conditioning is control.

The two experimental designs differ in timing as well. In delay conditioning the CS lasts until the US; in trace conditioning the CS ends and an empty trace interval separates it from the US. The interval from CS onset to US onset is the interstimulus interval (ISI). Learning depends strongly on the ISI: it is negligible when the US comes first or simultaneously, peaks at a short positive ISI, and decays for long ones. A model of conditioning that ignores time inside a trial cannot say anything about this.

The words need care.The book’s comments on terminology (end of its Chapter 14) are worth reading in full. Three warnings matter here. Reinforcement in psychology means strengthening (and, by extension, weakening) of behavior, whatever caused it; control in psychology usually means control of the animal by the stimuli, the reverse of the engineer’s sense; and Skinner’s negative reinforcement (removal of an aversive stimulus that increases behavior) is not a negative reinforcement signal in our sense. The split between prediction and control is a first approximation: Pavlovian responses are themselves actions (an eyeblink is a well-timed protective act, sometimes called Pavlovian control), and in most real experiments classical and instrumental learning run at once.

14.2Classical Conditioning and the Rescorla–Wagner Model

Two experimental facts shaped every modern model of classical conditioning.

Blocking (Kamin, 1968–1969).Leon J. Kamin. Predictability, Surprise, Attention, and Conditioning. In Byron A. Campbell and Russell M. Church, editors, Punishment and Aversive Behavior, pages 279–296. Appleton-Century-Crofts, New York, 1969 First train a tone A until it reliably predicts an air puff to a rabbit’s eye. Then present a compound of the tone and a light, AX, followed by the same puff. Finally test the light X alone: the rabbit barely responds. A control group that sees only the AX phase learns about X normally. Pairing X with the US was not enough; the prior learning about A blocked learning about X. Temporal contiguity of CS and US is therefore not sufficient for conditioning.

Higher-order conditioning. After the metronome predicts food, Pavlov’s assistant showed a black square followed by the metronome, never by food; within ten trials the dog salivated to the square. The metronome acted as a US for the square: second-order conditioning. In instrumental settings the same phenomenon makes a stimulus that predicts reward a conditioned reinforcer (money is the human example). A conditioned reinforcer slowly loses its power during second-order trials, because those trials are also extinction trials for it; this is why higher-order conditioning is hard to demonstrate.

14.2.1The Rescorla–Wagner Model as an LMS Rule

Rescorla and Wagner proposed that animals learn only when they are surprised.Robert A. Rescorla and Allan R. Wagner. A Theory of Pavlovian Conditioning: Variations in the Effectiveness of Reinforcement and Nonreinforcement. In Abraham H. Black and William F. Prokasy, editors, Classical Conditioning II: Current Research and Theory, pages 64–99. Appleton-Century-Crofts, New York, 1972 Each component CSi_i of a compound has an associative strength, the compound’s aggregate strength is the sum of the components’, and every present component moves by the same error: the asymptote the US can support minus the aggregate prediction. In the language of Chapter 9, let a trial type ss be described by the binary feature vector 𝐱(s)∈{0,1}d\mathbf{x}(s) \in \{0,1\}^d, with xi(s)=1x_i(s) = 1 if CSi_i is present.

Definition 14.1 (Rescorla–Wagner Model). With associative strengths 𝐰∈ℝd\mathbf{w} \in \mathbb{R}^d, the US prediction of trial type ss is v^(s,𝐰)=𝐰⊤𝐱(s)\hat v(s, \mathbf{w}) = \mathbf{w}^\top\mathbf{x}(s). On trial tt (here tt counts trials, not time steps), with trial type StS_t and US magnitude RtR_t,

δt=Rt−𝐰t⊤𝐱(St),𝐰t+1=𝐰t+α δt 𝐱(St). \delta_t = R_t - \mathbf{w}_t^\top\mathbf{x}(S_t), \qquad \mathbf{w}_{t+1} = \mathbf{w}_t + \alpha\,\delta_t\,\mathbf{x}(S_t). (14.1)

This is the Rescorla–Wagner model, and it is exactly the least-mean-square (LMS) or Widrow–Hoff ruleBernard Widrow and Marcian E. Hoff. Adaptive Switching Circuits. In 1960 IRE WESCON Convention Record, Part 4, pages 96–104, 1960 restricted to binary inputs, an identity first pointed out by Sutton and Barto in 1981.Richard S. Sutton and Andrew G. Barto. Toward a Modern Theory of Adaptive Networks: Expectation and Prediction. Psychological Review, 88(2):135–170, 1981. doi: 10.1037/0033-295X.88.2.135 (Rescorla and Wagner allowed a separate step size αiβ\alpha_i\beta for each CS and US; we take a common α\alpha until it matters.) Only the strengths of components present on a trial change, because of the factor 𝐱(St)\mathbf{x}(S_t). Being an LMS rule, its long-run behavior is governed by a linear system.

Proposition 14.2 (Expected Rescorla–Wagner Dynamics). Let trial types be drawn independently from a fixed distribution, and write 𝐀=𝔼[𝐱(S)𝐱(S)⊤]\mathbf{A} = \mathbb{E}[\mathbf{x}(S)\mathbf{x}(S)^\top], 𝐛=𝔼[R 𝐱(S)]\mathbf{b} = \mathbb{E}[R\,\mathbf{x}(S)]. The expected update is 𝔼[𝐰t+1−𝐰t∣𝐰t]=α(𝐛−𝐀𝐰t)\mathbb{E}[\mathbf{w}_{t+1} - \mathbf{w}_t \mid \mathbf{w}_t] = \alpha(\mathbf{b} - \mathbf{A}\mathbf{w}_t), whose fixed points are the solutions of the normal equations 𝐀𝐰=𝐛\mathbf{A}\mathbf{w} = \mathbf{b}, that is, the minimizers of 𝔼[(R−𝐰⊤𝐱(S))2]\mathbb{E}[(R - \mathbf{w}^\top\mathbf{x}(S))^2]. If 𝐀≻0\mathbf{A} \succ 0 and 0<α<2/λmax⁡(𝐀)0 < \alpha < 2/\lambda_{\max}(\mathbf{A}), the mean iteration converges to 𝐰∗=𝐀−1𝐛\mathbf{w}^* = \mathbf{A}^{-1}\mathbf{b}.

Proof. Take expectations of (14.1): 𝔼[δt𝐱(St)∣𝐰t]=𝔼[R𝐱]−𝔼[𝐱𝐱⊤]𝐰t\mathbb{E}[\delta_t\mathbf{x}(S_t) \mid \mathbf{w}_t] = \mathbb{E}[R\mathbf{x}] - \mathbb{E}[\mathbf{x}\mathbf{x}^\top]\mathbf{w}_t. The gradient of 12𝔼[(R−𝐰⊤𝐱)2]\frac{1}{2}\mathbb{E}[(R - \mathbf{w}^\top\mathbf{x})^2] is 𝐀𝐰−𝐛\mathbf{A}\mathbf{w} - \mathbf{b}, so the fixed points are its stationary points, minimizers because 𝐀⪰0\mathbf{A} \succeq 0. The mean iteration is 𝐰↦(𝐈−α𝐀)𝐰+α𝐛\mathbf{w} \mapsto (\mathbf{I} - \alpha\mathbf{A})\mathbf{w} + \alpha\mathbf{b}, a contraction in the eigenbasis of 𝐀\mathbf{A} when every eigenvalue of 𝐈−α𝐀\mathbf{I} - \alpha\mathbf{A} lies in (−1,1)(-1, 1). □

The animal, in this reading, is doing regression: it assigns to each cue the weight that best predicts the US jointly with the other cues present. Blocking is the regression fact that a redundant predictor receives no weight once the first one fits. The dynamics show exactly how this happens.

Proposition 14.3 (Blocking in the Rescorla–Wagner Model). Phase 1: mm trials with A alone, 𝐱=(1,0)⊤\mathbf{x} = (1, 0)^\top, starting from 𝐰=𝟎\mathbf{w} = \mathbf{0}. Phase 2: trials with the compound AX, 𝐱=(1,1)⊤\mathbf{x} = (1, 1)^\top, both with US magnitude RR and 0<α<10 < \alpha < 1. Then (i) after phase 1, wA=R(1−(1−α)m)w_A = R\bigl(1 - (1-\alpha)^m\bigr) and wX=0w_X = 0; (ii) during phase 2 the difference wA−wXw_A - w_X is invariant and the sum satisfies (wA+wX)−R↦(1−2α)((wA+wX)−R)(w_A + w_X) - R \mapsto (1 - 2\alpha)\bigl((w_A + w_X) - R\bigr); (iii) consequently

wX→R2 (1−α)m,wA→R−R2 (1−α)m. w_X \to \frac{R}{2}\,(1 - \alpha)^m, \qquad w_A \to R - \frac{R}{2}\,(1-\alpha)^m. (14.2)

Without pretraining (m=0m = 0) the two cues share the prediction equally (overshadowing); with long pretraining (m→∞m \to \infty) X learns nothing (blocking).

Proof. (i) In phase 1, wA↦wA+α(R−wA)w_A \mapsto w_A + \alpha(R - w_A), so R−wAR - w_A shrinks by 1−α1-\alpha per trial. (ii) In phase 2 both components receive the same increment αδ\alpha\delta, so their difference is unchanged, and the sum receives 2αδ=2α(R−wA−wX)2\alpha\delta = 2\alpha(R - w_A - w_X). (iii) The sum converges to RR since ∣1−2α∣<1\lvert 1 - 2\alpha\rvert < 1; solving wA+wX=Rw_A + w_X = R, wA−wX=R(1−(1−α)m)w_A - w_X = R(1 - (1-\alpha)^m) gives (14.2). □

With unequal saliences αA≠αX\alpha_A \neq \alpha_X the invariant becomes wA/αA−wX/αXw_A/\alpha_A - w_X/\alpha_X, and the more salient cue takes the larger share, which is the Rescorla–Wagner account of overshadowing by a salient stimulus. The same arithmetic predicts overexpectation and conditioned inhibition (Exercise 14.12), both observed in animals, which is why the model was so influential: a simple, mechanical error-correction rule accounted for results that seemed to require the animal to reason about redundancy.

14.2.2In Wolfram Language: Blocking

We verify the two phases symbolically: the single-cue learning curve, the invariant of phase 2, and the limit (14.2).

Phase 1 is a scalar linear recursion for wAw_A; RSolve returns the acquisition curve R(1−(1−α)n)R(1-(1-\alpha)^n).
const acq = await show`RSolve[{v[n + 1] == v[n] + \[Alpha] (R - v[n]), v[0] == 0}, v[n], n][[1, 1, 2]] // Simplify`
wA(n)=R−R(1−α)n w_A(n) = R-R (1-\alpha )^n One Rescorla–Wagner step on the compound AX, applied to symbolic strengths: the difference wA−wXw_A - w_X changes by 00, and the sum’s distance from RR is multiplied by 1−2α1 - 2\alpha (both residuals vanish).
const rw = await wl`Function[{w, x, r}, w + \[Alpha] (r - w . x) x]`
const blockInv = await show`Simplify[{${rw}[{Subscript[w, A], Subscript[w, X]}, {1, 1}, R] . {1, -1} - (Subscript[w, A] - Subscript[w, X]), ${rw}[{Subscript[w, A], Subscript[w, X]}, {1, 1}, R] . {1, 1} - R - (1 - 2 \[Alpha]) (Subscript[w, A] + Subscript[w, X] - R)}]`
(Δ(wA−wX),  (wA′+wX′−R)−(1−2α)(wA+wX−R))={0,0} \bigl(\Delta(w_A - w_X),\; (w_A' + w_X' - R) - (1-2\alpha)(w_A + w_X - R)\bigr) = \{0,0\} At the end of phase 2 the sum is RR and the difference is what phase 1 left after mm trials; solving gives the blocked strength of X.
const blockLim = await show`Solve[{Subscript[w, A] + Subscript[w, X] == R, Subscript[w, A] - Subscript[w, X] == (${acq} /. n -> m)}, {Subscript[w, A], Subscript[w, X]}] // Simplify`
{{wA→R−12R(1−α)m,wX→12R(1−α)m}} \left\{\left\{w_A\to R-\frac{1}{2} R (1-\alpha )^m,w_X\to \frac{1}{2} R (1-\alpha )^m\right\}\right\}

14.3The TD Model of Classical Conditioning

The Rescorla–Wagner model is a trial-level model: one step is one whole trial, so it cannot represent the ISI, the shape of the CR within a trial, or a CS that predicts another CS. Sutton and Barto’s TD model makes the model real-time:Richard S. Sutton and Andrew G. Barto. Toward a Modern Theory of Adaptive Networks: Expectation and Prediction. Psychological Review, 88(2):135–170, 1981. doi: 10.1037/0033-295X.88.2.135; and Richard S. Sutton and Andrew G. Barto. Time-Derivative Models of Pavlovian Reinforcement. In Michael Gabriel and John Moore, editors, Learning and Computational Neuroscience: Foundations of Adaptive Networks, pages 497–537. MIT Press, Cambridge, MA, 1990 tt now counts small time steps (say 1010 ms), each moment has a state StS_t with features 𝐱(St)\mathbf{x}(S_t) describing how the stimuli are currently represented inside the animal, and the target of the prediction is no longer the US on this trial but the discounted sum of all future USs. Trials disappear from the theory; they are just fragments of a continuing stream of experience.

Algorithm 14.4 (TD Model of Classical Conditioning). Parameters: step size α>0\alpha > 0, discount γ∈[0,1)\gamma \in [0, 1), trace decay λ∈[0,1]\lambda \in [0, 1]; a stimulus representation s↦𝐱(s)∈ℝds \mapsto \mathbf{x}(s) \in \mathbb{R}^d. Initialize: 𝐰=𝟎\mathbf{w} = \mathbf{0}, 𝐳=𝟎\mathbf{z} = \mathbf{0}. At every time step tt, observe 𝐱(St)\mathbf{x}(S_t), the US intensity Rt+1R_{t+1} and 𝐱(St+1)\mathbf{x}(S_{t+1}):

  1. 𝐳←γλ 𝐳+𝐱(St)\mathbf{z} \leftarrow \gamma\lambda\,\mathbf{z} + \mathbf{x}(S_t) (stimulus trace).
  2. δt←Rt+1+γ 𝐰⊤𝐱(St+1)−𝐰⊤𝐱(St)\delta_t \leftarrow R_{t+1} + \gamma\,\mathbf{w}^\top\mathbf{x}(S_{t+1}) - \mathbf{w}^\top\mathbf{x}(S_t) (TD error).
  3. 𝐰←𝐰+α δt 𝐳\mathbf{w} \leftarrow \mathbf{w} + \alpha\,\delta_t\,\mathbf{z}.

The US prediction v^(St,𝐰)=𝐰⊤𝐱(St)\hat v(S_t, \mathbf{w}) = \mathbf{w}^\top\mathbf{x}(S_t) is taken as the strength of the CR at time tt.

This is linear semi-gradient TD(λ\lambda) with accumulating traces, Algorithm 12.2, except that RR is the intensity of a US that need not be rewarding: the model predicts air puffs as readily as food. One special case connects it with the past. With γ=0\gamma = 0 the trace collapses to 𝐳=𝐱(St)\mathbf{z} = \mathbf{x}(S_t) (because γλ=0\gamma\lambda = 0) and the error to Rt+1−v^(St,𝐰)R_{t+1} - \hat v(S_t, \mathbf{w}): the Rescorla–Wagner rule, applied at every time step instead of once per trial, with the target one step ahead. Eligibility traces in the model are Pavlov’s stimulus traces, the persisting after-effect of a stimulus that lets a CS that has ended still be associated with a later US.

14.3.1Stimulus Representations

The TD model deliberately leaves 𝐱\mathbf{x} open, because how the brain represents elapsed time since a stimulus is an empirical question. Three choices have been studied in depth.Elliot A. Ludvig, Richard S. Sutton, and E. James Kehoe. Stimulus Representation and the Timing of Reward-Prediction Errors in Models of the Dopamine System. Neural Computation, 20(12):3034–3054, 2008. doi: 10.1162/neco.2008.11-07-654; and Elliot A. Ludvig, Richard S. Sutton, and E. James Kehoe. Evaluating the TD Model of Classical Conditioning. Learning & Behavior, 40(3):305–319, 2012. doi: 10.3758/s13420-012-0082-6

  • The complete serial compound (CSC): the onset of a CS starts a cascade of non-overlapping internal signals, one feature for each time step since onset, a tapped delay line. Every moment after the CS is a separate state, so with the CSC the TD model is tabular TD in time. Ludvig, Sutton and Kehoe call it a “useful fiction”: unrealistic as neural hypothesis, but the cleanest view of what TD does.
  • The presence representation: one feature per CS, equal to 11 while the CS is on. No timing information at all.
  • Microstimuli: each stimulus starts a slowly decaying memory trace and a family of overlapping bumps on that trace, later ones wider and lower. This sits between the two extremes in temporal generalization and is the most plausible of the three.

What the representation can express limits what can be predicted. With the CSC the asymptotic prediction rises exponentially, v^=γkR\hat v = \gamma^{k}R at kk steps before the US (Theorem 14.7 below), peaking exactly at the US, like the well-timed eyeblink of a trained rabbit. With the presence representation one weight must serve the whole CS, and the compromise is a flat prediction whose level depends on the ISI.

Proposition 14.5 (The Presence Representation Cannot Time the US). A single CS is on for T≥1T \ge 1 steps (times 0,…,T−10, \dots, T-1) and the US of intensity RR arrives at its offset, at the step into time TT; nothing else predicts anything, so the CS feature is xt=1x_t = 1 for 0≤t<T0 \le t < T and 00 otherwise, and traces start at zero each trial. The TD(λ\lambda) fixed point, the weight at which the update ∑tδtzt\sum_t \delta_t z_t summed over a trial vanishes, is, with μ=γλ\mu = \gamma\lambda and Zt=∑j=0tμjZ_t = \sum_{j=0}^{t}\mu^j,

w∗=R ZT−1ZT−1+(1−γ)∑t=0T−2Zt. w^* = \frac{R\,Z_{T-1}}{Z_{T-1} + (1-\gamma)\sum_{t=0}^{T-2} Z_t}. (14.3)

For λ=0\lambda = 0 it is w=R/(1+(T−1)(1−γ))w = R/\bigl(1 + (T-1)(1-\gamma)\bigr): the CR is flat during the CS, and it is weaker for longer ISIs. At the fixed point δ=(γ−1)w<0\delta = (\gamma - 1)w < 0 during the CS and δ=R−w>0\delta = R - w > 0 at the US. For λ=1\lambda = 1 it is R(1−γT)/(T(1−γ))R(1-\gamma^T)/\bigl(T(1-\gamma)\bigr), the average of the Monte Carlo returns over the CS.

Proof. Within a trial, δt=γw−w\delta_t = \gamma w - w for 0≤t≤T−20 \le t \le T-2, δT−1=R−w\delta_{T-1} = R - w, and the trace is zt=∑j=0t(γλ)t−jz_t = \sum_{j=0}^{t}(\gamma\lambda)^{t-j}. So zt=Ztz_t = Z_t, and ∑t=0T−1δtzt=(γ−1)w∑t=0T−2Zt+(R−w)ZT−1=0\sum_{t=0}^{T-1}\delta_t z_t = (\gamma - 1)w\sum_{t=0}^{T-2}Z_t + (R - w)Z_{T-1} = 0 is one linear equation for ww, with solution (14.3). At λ=0\lambda = 0 every Zt=1Z_t = 1; at λ=1\lambda = 1, (1−γ)Zt=1−γt+1(1-\gamma)Z_t = 1 - \gamma^{t+1}, the denominator telescopes to TT, and w∗=R ZT−1/Tw^* = R\,Z_{T-1}/T, as the check below confirms. □

Even with this crude representation, the TD model reproduces everything the Rescorla–Wagner model does (it is error-correcting) and more. Its predictions about timing within a trial follow from bootstrapping, and several were confirmed after the model made them.The book reproduces Sutton and Barto’s 1990 simulations of four such effects. Facilitation of remote associations: filling the gap between a CS A and the US with a second CS B speeds and strengthens conditioning to A (Kehoe, 1982). The Egger–Miller effect: an earlier, overlapping CS A reduces conditioning to a CS B that is better placed in time. Temporal primacy overrides blocking: if the added CS starts before the pretrained one, it is not blocked and the pretrained CS loses strength, a prediction of the model confirmed by Kehoe, Schreurs and Graham (1987). Second-order conditioning, below.E. James Kehoe, Bernard G. Schreurs, and P. Graham. Temporal Primacy Overrides Prior Training in Serial Compound Conditioning of the Rabbit’s Nictitating Membrane Response. Animal Learning & Behavior, 15(4):455–464, 1987 The mechanism is visible in the TD error: γv^(St+1)−v^(St)\gamma\hat v(S_{t+1}) - \hat v(S_t) enters δt\delta_t on exactly the same footing as Rt+1R_{t+1}. As far as learning is concerned, a rise in prediction is indistinguishable from the arrival of a US. An earlier stimulus is trained by the prediction of a later one, which is why temporal primacy wins and why second-order conditioning happens.

Proposition 14.6 (Second-Order Conditioning and Its Extinction). Let CS B have strength b0b_0 after first-order training, and run second-order trials: a brief A, then a brief B one step later, no US. Let each brief stimulus be one state with its own feature, so A and B have weights aa and bb, and let the step out of B lead to an empty state; take λ=0\lambda = 0. With a0=0a_0 = 0, after nn trials

bn=b0(1−α)n,an=γ b0 α n (1−α)n−1. b_n = b_0(1-\alpha)^n, \qquad a_n = \gamma\,b_0\,\alpha\, n\,(1-\alpha)^{n-1}. (14.4)

The second-order strength ana_n rises, peaks near n∗=−1/log⁡(1−α)n^* = -1/\log(1-\alpha) (for small α\alpha at about γb0/e\gamma b_0/e), and then decays to zero together with bnb_n.

Proof. On each trial, A is updated first with δ=γbn−an\delta = \gamma b_n - a_n and then B with δ=0−bn\delta = 0 - b_n. So bn+1=(1−α)bnb_{n+1} = (1-\alpha)b_n and an+1=(1−α)an+αγb0(1−α)na_{n+1} = (1-\alpha)a_n + \alpha\gamma b_0(1-\alpha)^n; the second recursion is solved by (14.4), as the check below confirms. Maximizing n(1−α)n−1n(1-\alpha)^{n-1} over real nn gives n∗n^*, and as α→0\alpha \to 0, αn∗→1\alpha n^* \to 1 and (1−α)n∗→e−1(1-\alpha)^{n^*} \to e^{-1}. □

Two curves over 60 trials: the strength of the first-order cue B decays geometrically from 1 while the strength of the second-order cue A rises from zero to a peak near trial 10 and then decaysFigure 14.1: Exact second-order learning curves (14.4) with b0=1b_0 = 1, γ=0.95\gamma = 0.95, α=0.1\alpha = 0.1: the secondary reinforcer B (gray) extinguishes while it trains A (color), so A’s strength peaks and then fades.

This rise and fall is what animal experiments show, and it is why higher-order conditioning needs occasional first-order “refresher” trials (Figure 14.1). The Rescorla–Wagner model has no such mechanism: a cue never followed by a US can only lose strength.

14.3.2In Wolfram Language: Timing and Second-Order Conditioning

Both propositions reduce to one linear equation and one linear recursion, solved here in closed form.

The presence-representation fixed point: the trial sum of δtzt\delta_t z_t, with zt=Zt=(1−μt+1)/(1−μ)z_t = Z_t = (1-\mu^{t+1})/(1-\mu) and μ=γλ\mu = \gamma\lambda, set to zero and solved for the single weight ww.
const presence = await show`Simplify[Solve[(\[Gamma] - 1) w Sum[(1 - \[Mu]^(t + 1))/(1 - \[Mu]), {t, 0, T - 2}] + (R - w) (1 - \[Mu]^T)/(1 - \[Mu]) == 0, w][[1, 1, 2]]]`
w∗=R(−1+μ)(−1+μT)T(−1+γ)(−1+μ)−(γ−μ)(−1+μT) w^* = \frac{R (-1+\mu ) \left(-1+\mu ^T\right)}{T (-1+\gamma ) (-1+\mu )-(\gamma -\mu ) \left(-1+\mu ^T\right)} The two ends of the λ\lambda range, μ=0\mu = 0 and μ=γ\mu = \gamma: TD(0) gives R/(1+(T−1)(1−γ))R/(1+(T-1)(1-\gamma)); TD(1) gives the average of the Monte Carlo returns γT−1−tR\gamma^{T-1-t}R over the CS.
const presenceEnds = await show`Simplify[{${presence} /. \[Mu] -> 0, ${presence} /. \[Mu] -> \[Gamma]}, T > 1]`
(wλ=0∗, wλ=1∗)={RT+γ−Tγ,R(−1+γT)T(−1+γ)} \bigl(w^*_{\lambda=0},\ w^*_{\lambda=1}\bigr) = \left\{\frac{R}{T+\gamma -T \gamma },\frac{R \left(-1+\gamma ^T\right)}{T (-1+\gamma )}\right\} Second-order conditioning as a pair of coupled recursions for an=wA(n)a_n = w_A(n) and bn=wB(n)b_n = w_B(n), solved exactly: B extinguishes geometrically while it drives A.
const second = await show`RSolve[{Subscript[w, A][n + 1] == Subscript[w, A][n] + \[Alpha] (\[Gamma] Subscript[w, B][n] - Subscript[w, A][n]), Subscript[w, B][n + 1] == (1 - \[Alpha]) Subscript[w, B][n], Subscript[w, A][0] == 0, Subscript[w, B][0] == Subscript[b, 0]}, {Subscript[w, A][n], Subscript[w, B][n]}, n] // FullSimplify`
{{wA(n)→n(1−α)−1+nαγb0,wB(n)→(1−α)nb0}} \left\{\left\{w_A(n)\to n (1-\alpha )^{-1+n} \alpha \gamma b_0,w_B(n)\to (1-\alpha )^n b_0\right\}\right\}

14.4Instrumental Conditioning, Delay, and Cognitive Maps

Thorndike placed hungry cats in puzzle boxes and timed their escapes, which fell over successive trials from minutes to seconds. He summarized such data in the law of effect: responses followed by satisfaction are “stamped in”, responses followed by discomfort “stamped out”.Edward L. Thorndike. Animal Intelligence: Experimental Studies. Macmillan, New York, 1911 In computational terms the law describes learning that is selectional (try alternatives, keep what works, unlike supervised learning) and associative (what works is tied to the situation, unlike natural selection), the two ingredients of every reinforcement learning algorithm since Chapter 2. It combines search with memory. Several features of the book’s formalism have direct counterparts. The cats explored only among their “instinctual impulses”, like a state-dependent action set 𝒜(s)\mathcal{A}(s); Skinner’s shaping, reinforcing successive approximations of a target behavior, is the curriculum strategy that makes sparse-reward problems learnable; and an animal’s motivational state (hunger, satiety) is part of the state on which the reward signal depends.

14.4.1Delayed Reinforcement

The law of effect requires the present to act on the past: how can a reward strengthen a response emitted seconds or minutes before? This is Minsky’s credit-assignment problem, and the theory of animal learning proposed the same two remedies reinforcement learning uses. The first is a trace. Hull postulated that every action leaves a decaying internal “molar stimulus trace” and derived from it a goal gradient, the decline of learning with the delay of reinforcement;Clark L. Hull. Principles of Behavior: An Introduction to Behavior Theory. Appleton-Century, New York, 1943 eligibility traces (Chapter 12) are such traces. The second is conditioned reinforcement. Hull also argued that longer gradients arise because stimuli present during the delay become secondary reinforcers, passing reinforcement backwards step by step; experiments confirmed that learning tolerates long delays much better when the delay is filled with regular stimuli. A learned value function does exactly this: the critic of an actor–critic method (Algorithm 13.7) delivers at every step a TD error that evaluates the last action long before primary reward arrives. Traces bridge short gaps, values bridge long ones, and both are needed.

14.4.2Cognitive Maps and Latent Learning

In Blodgett’s 1929 latent learning experiment, rats explored a maze for several days with no food in it and showed little sign of learning; when food was then placed in the goal box they caught up almost at once with rats that had been rewarded all along.Hugh C. Blodgett. The Effect of the Introduction of Reward upon the Maze Performance of Rats. University of California Publications in Psychology, 4:113–134, 1929 Tolman concluded that the unrewarded rats had built a cognitive map and used it as soon as there was a reason to.Edward C. Tolman. Cognitive Maps in Rats and Men. Psychological Review, 55(4):189–208, 1948. doi: 10.1037/h0061626 In our terms, they learned an environment model without reward, by learning stimulus–stimulus (S–S′) and situation–action–situation (SA–S′) associations, which is supervised learning, and they planned with it when a reward model appeared. This is the model-based architecture of Chapter 8: model learning needs no reward, and planning converts a change in the reward model into a change of policy without new experience on the affected paths.

14.4.3Habitual and Goal-Directed Behavior

Psychologists distinguish habits, controlled by antecedent stimuli and executed more or less automatically, from goal-directed behavior, controlled by knowledge of action–outcome relations and of the current value of outcomes. Daw, Niv and Dayan proposed that this is the distinction between model-free and model-based reinforcement learning.Nathaniel D. Daw, Yael Niv, and Peter Dayan. Uncertainty-Based Competition between Prefrontal and Dorsolateral Striatal Systems for Behavioral Control. Nature Neuroscience, 8(12):1704–1711, 2005. doi: 10.1038/nn1560 A model-free agent caches values Q(s,a)Q(s, a) or a policy, and to change them it must revisit the states and experience the consequences again. A model-based agent recomputes values from its model at decision time, so a changed reward propagates immediately.

Outcome devaluation is the decisive experiment. Adams and Dickinson trained rats to press a lever for sucrose pellets, then, with the lever removed, paired free pellets with nausea induced by lithium chloride.Christopher D. Adams and Anthony Dickinson. Instrumental Responding Following Reinforcer Devaluation. The Quarterly Journal of Experimental Psychology Section B, 33(2):109–121, 1981. doi: 10.1080/14640748108400816 Back in the chamber, under extinction (lever present, no pellets), the poisoned rats pressed less from the first minute, although they had never experienced pressing followed by sickness. They must have chained “press → pellet” with “pellet → bad”, a two-step model lookup. Adams then showed that rats overtrained on the lever (500 rewarded presses instead of 100) were insensitive to devaluation: extended practice turns goal-directed behavior into habit.Christopher D. Adams. Variations in the Sensitivity of Instrumental Responding to Reinforcer Devaluation. The Quarterly Journal of Experimental Psychology Section B, 34(2b):77–98, 1982. doi: 10.1080/14640748208400878 Daw, Niv and Dayan explained the shift normatively: each system’s recommendation comes with an uncertainty, and control goes to the more reliable one. Early on, the model chains short, quickly learned predictions and wins; with experience the cached values become accurate while planning keeps paying for model errors and for the pruning that makes it tractable, so the habit takes over.

14.5Reward, Reinforcement, Value, and Prediction Error

Before looking for these quantities in the brain we must say precisely what each one is, because neural signals related to reward are found almost everywhere and are strongly correlated with one another.

  • The reward signal RtR_t defines the problem. It is a number inside the agent, not an object in the world, and there is probably no single neural “master” reward signal; RtR_t abstracts the net effect of many systems that evaluate sensations and states.
  • A reinforcement signal is the scalar that multiplies a vector in a learning rule to produce a parameter update: in 𝐰←𝐰+α δt 𝐳t\mathbf{w} \leftarrow \mathbf{w} + \alpha\,\delta_t\,\mathbf{z}_t it is δt\delta_t. For REINFORCE without baseline it is the return itself; for most algorithms in this companion it is a TD error.
  • A value signal is a prediction of future reward, V(s)V(s) or Q(s,a)Q(s, a).
  • A reward prediction error (RPE) is a difference between received and expected reward. The TD error is a particular RPE, between successive long-term predictions.

The TD error carries both kinds of reinforcement at once,

δt=Rt+1⏟primary+γV(St+1)−V(St)⏟conditioned, \delta_t = \underbrace{R_{t+1}}_{\text{primary}} + \underbrace{\gamma V(S_{t+1}) - V(S_t)}_{\text{conditioned}}, (14.5)

and it is “pure” conditioned reinforcement when Rt+1=0R_{t+1} = 0, as in second-order conditioning. One indexing remark avoids confusion. The book’s δt\delta_t becomes available only at time t+1t+1; in the neuroscience literature the signal emitted at time tt is our δt−1=Rt+γV(St)−V(St−1)\delta_{t-1} = R_t + \gamma V(S_t) - V(S_{t-1}). With time steps of a few milliseconds the shift is immaterial, and below we simply attach each TD error to the moment it is computed.

14.6Dopamine and the Reward Prediction Error Hypothesis

Only a little neuroscience is needed. Neurons communicate through synapses: an action potential (spike) of the presynaptic neuron releases a neurotransmitter that excites or inhibits the postsynaptic neuron, with a strength, the synaptic efficacy, that can change with experience; synaptic efficacies play the role of weights. A neuromodulator is a transmitter with slower, broader effects, often altering plasticity rather than firing. A neuron’s phasic activity is a brief burst or pause, its tonic activity a slowly varying level. Dopamine is a neuromodulator made by neurons in two midbrain nuclei, the substantia nigra pars compacta (SNpc) and the ventral tegmental area (VTA). Their axons branch enormously, each making on the order of hundreds of thousands of synaptic contacts, many on the medium spiny neurons of the striatum, the input structure of the basal ganglia, which receives input from almost the whole cortex. There, a cortical axon contacts the tip of a dendritic spine while dopamine is released at its stem: presynaptic activity, postsynaptic activity and dopamine meet at one place. A system built this way can broadcast something like a scalar signal to a large part of the brain.

The traditional view, going back to Olds and Milner’s discovery in 1954 that rats work relentlessly for electrical stimulation of certain brain sites, was that dopamine signals reward. Recordings by Wolfram Schultz’s group in the late 1980s and 1990s told a different story. Monkeys received juice after a cue; dopamine neurons in SNpc and VTA showed three regularities.

  1. Early in training, they burst when the juice arrived unpredicted.
  2. As the cue came to predict the juice, the burst moved to the cue and disappeared from the fully predicted juice. When an instruction cue was added one second before the trigger cue, the response moved again, to the earliest reliable predictor.
  3. When a predicted reward was withheld (the monkey pressed the wrong lever), firing dropped below baseline shortly after the time the reward was due, without any external event to mark that time.

Montague, Dayan and Sejnowski recognized the TD error in these data and stated the reward prediction error hypothesis: the phasic activity of dopamine neurons conveys TD errors to their targets.P. Read Montague, Peter Dayan, and Terrence J. Sejnowski. A Framework for Mesencephalic Dopamine Systems Based on Predictive Hebbian Learning. Journal of Neuroscience, 16(5):1936–1947, 1996. doi: 10.1523/JNEUROSCI.16-05-01936.1996; and Wolfram Schultz, Peter Dayan, and P. Read Montague. A Neural Substrate of Prediction and Reward. Science, 275(5306):1593–1599, 1997. doi: 10.1126/science.275.5306.1593 Because firing rates cannot be negative, the dopamine signal is modeled as bt+δt−1b_t + \delta_{t-1} with a background rate btb_t, which leaves less room for negative errors (pauses) than for positive ones (bursts). Montague and colleagues used the CSC representation and an essentially tabular TD learner, and with these choices the correspondence can be derived exactly, for every trial, not only at the start and the end of learning.

14.6.1The TD Error Along a Trial, Exactly

Idealize the monkey task as a prediction problem. The policy is fixed, a trial is an episode, and the CSC turns the time steps after the cue into a chain of states s0,s1,…,sKs_0, s_1, \dots, s_K visited at times 0,…,K0, \dots, K; from sKs_K the transition at time K+1K+1 delivers reward RR and ends the trial. Before the cue the animal is in an inter-trial state whose value we fix at 00, because the moment the cue appears is unpredictable (the earliest reward-predicting state is an unpredicted predictor). Index the states by their distance to the reward, k=K−jk = K - j for sjs_j, write Vn(k)V_n(k) for the value after nn trials of tabular TD(0) (Algorithm 6.1) from V0≡0V_0 \equiv 0, and let Bn∼Binomial⁡(n,α)B_n \sim \operatorname{Binomial}(n, \alpha).

Theorem 14.7 (TD Errors under the Complete Serial Compound). For 0<α≤10 < \alpha \le 1, 0<γ≤10 < \gamma \le 1, every n≥0n \ge 0 and 0≤k≤K0 \le k \le K,

Vn(k)=γkR Pr⁡{Bn≥k+1}. V_n(k) = \gamma^{k}R\,\Pr\{B_n \ge k+1\}. (14.6)

In trial n≥1n \ge 1 the TD errors are: at the cue (entering s0s_0 from the inter-trial state), and on leaving the state at distance kk,

δncue=γK+1R Pr⁡{Bn−1≥K+1},δn(k)=γkR Pr⁡{Bn−1=k}. \delta^{\text{cue}}_n = \gamma^{K+1}R\,\Pr\{B_{n-1} \ge K+1\}, \qquad \delta_n(k) = \gamma^{k}R\,\Pr\{B_{n-1} = k\}. (14.7)

Hence: (i) in the first trial δ=R\delta = R at the reward and 00 elsewhere; (ii) as n→∞n \to \infty, V(k)→γkRV(k) \to \gamma^k R, the error vanishes at the reward and everywhere inside the interval, and only δcue→γK+1R\delta^{\text{cue}} \to \gamma^{K+1}R remains; (iii) if the reward is omitted after learning, the error at the usual reward time is −V(0)=−R-V(0) = -R; (iv) during learning, the error is a bump located around distance k≈(n−1)αk \approx (n-1)\alpha from the reward, traveling back towards the cue at α\alpha states per trial.

Proof. In a trial the states are visited forward in time, and the update of sjs_j uses the value of sj+1s_{j+1}, which has not yet been updated in that trial. So every TD error of trial nn uses the values Vn−1V_{n-1}. With the convention γVn−1(−1):=R\gamma V_{n-1}(-1) := R (the “next value” of the last state is the reward),

δn(k)=γVn−1(k−1)−Vn−1(k),Vn(k)=(1−α)Vn−1(k)+αγVn−1(k−1). \begin{aligned} \delta_n(k) &= \gamma V_{n-1}(k-1) - V_{n-1}(k), \\ V_n(k) &= (1-\alpha)V_{n-1}(k) + \alpha\gamma V_{n-1}(k-1). \end{aligned}

We prove (14.6) by induction on nn; it holds at n=0n = 0, since Pr⁡{B0≥1}=0\Pr\{B_0 \ge 1\} = 0. Writing Bn=Bn−1+ξnB_n = B_{n-1} + \xi_n with an independent ξn∼Bernoulli⁡(α)\xi_n \sim \operatorname{Bernoulli}(\alpha), we have Pr⁡{Bn≥k+1}=(1−α)Pr⁡{Bn−1≥k+1}+αPr⁡{Bn−1≥k}\Pr\{B_n \ge k+1\} = (1-\alpha)\Pr\{B_{n-1} \ge k+1\} + \alpha\Pr\{B_{n-1} \ge k\}. Multiplying by γkR\gamma^k R, the right side becomes (1−α)Vn−1(k)+αγVn−1(k−1)(1-\alpha)V_{n-1}(k) + \alpha\gamma V_{n-1}(k-1) by the induction hypothesis (for k=0k = 0, Pr⁡{Bn−1≥0}=1\Pr\{B_{n-1} \ge 0\} = 1 and the convention gives αR\alpha R), which is the update. For the errors, γVn−1(k−1)−Vn−1(k)=γkR(Pr⁡{Bn−1≥k}−Pr⁡{Bn−1≥k+1})=γkRPr⁡{Bn−1=k}\gamma V_{n-1}(k-1) - V_{n-1}(k) = \gamma^{k}R\bigl(\Pr\{B_{n-1} \ge k\} - \Pr\{B_{n-1} \ge k+1\}\bigr) = \gamma^k R\Pr\{B_{n-1} = k\}, and at the cue the error is γVn−1(K)−0\gamma V_{n-1}(K) - 0. Claims (i)–(iii) follow by letting n=1n = 1 and n→∞n \to \infty; (iv) is the location of the mode of the binomial. □

The four regularities of Schultz’s recordings are (i)–(iii) and the transfer from the later to the earlier cue, which is (ii) applied to a chain that starts earlier (Figure 14.2). The theorem also says something less often stated: the discounted mass of the error is conserved,

γ−(K+1)δncue+∑k=0Kγ−kδn(k)=R(Pr⁡{Bn−1≥K+1}+Pr⁡{Bn−1≤K})=R, \gamma^{-(K+1)}\delta^{\text{cue}}_n + \sum_{k=0}^{K}\gamma^{-k}\delta_n(k) = R\Bigl(\Pr\{B_{n-1} \ge K+1\} + \Pr\{B_{n-1} \le K\}\Bigr) = R,

so learning does not destroy the burst, it moves it. The gradual migration in (iv), however, is a prediction of TD(0) with the CSC that dopamine recordings do not show: responses to the cue grow while responses to the reward shrink, with no wave traveling through the delay. Pan, Schmidt, Wickens and Hyland pointed out that eligibility traces remove the wave: with λ=1\lambda = 1 every state is updated directly towards the return, and the intermediate errors are zero throughout learning (Exercise 14.13).Wei-Xing Pan, Robert Schmidt, Jeffery R. Wickens, and Brian I. Hyland. Dopamine Cells Respond to Predicted Events during Classical Conditioning: Evidence for Eligibility Traces in the Reward-Learning Network. Journal of Neuroscience, 25(26):6235–6242, 2005. doi: 10.1523/JNEUROSCI.1478-05.2005 The data thus favor TD(λ\lambda) with long traces over TD(0), one of several places where neural data constrain the algorithm.

Four stem plots of the TD error against time in a trial with the cue at time 0 and the reward at time 10. First trial: a single spike of height 1 at the reward. Trial 25: a low bump spread over the middle of the interval. After learning: a single spike of height about 0.82 at the cue. Reward omitted: a spike at the cue and a negative spike of minus 1 at the reward time
Figure 14.2: The TD error along a trial of the CSC model, computed from the exact formulas (14.7) with K+1=10K + 1 = 10 cue states, R=1R = 1, γ=0.98\gamma = 0.98, α=0.2\alpha = 0.2; the cue (CS) appears at time 00 and the reward (US) at time 1010 (dashed lines). (a) First trial: the error is the unpredicted reward. (b) Trial 25: a binomial bump, centered about 24α≈524\alpha \approx 5 steps before the reward, travels backwards through the delay. (c) After learning: the error has moved to the cue, γ10R≈0.82\gamma^{10}R \approx 0.82, and the fully predicted reward produces none. (d) Reward omitted after learning: the burst at the cue remains and a dip of −R-R appears at the time the reward was due.

14.6.2In Wolfram Language: the TD Error/Dopamine Correspondence

We reproduce the theorem in two steps on a short trial with four cue states (K=3K = 3): first the asymptotic values and the three iconic error profiles, then the exact intermediate trials against the binomial formula.

delta maps a list of values (earliest state first) and the reward delivered at the end to the TD errors along the trial: cue onset, the three inner transitions, the reward. The asymptotic values solve the CSC Bellman equations V(0)=RV(0) = R, V(k)=γV(k−1)V(k) = \gamma V(k-1).
const delta = await wl`Function[{v, r}, Join[{\[Gamma] v[[1]]}, Table[\[Gamma] v[[k + 1]] - v[[k]], {k, Length[v] - 1}], {r - v[[-1]]}]]`
const vstar = await wl`Table[Subscript[v, k], {k, 3, 0, -1}] /. First[Solve[{Subscript[v, 0] == R, Subscript[v, 1] == \[Gamma] Subscript[v, 0], Subscript[v, 2] == \[Gamma] Subscript[v, 1], Subscript[v, 3] == \[Gamma] Subscript[v, 2]}, Table[Subscript[v, k], {k, 0, 3}]]]`
const cscTable = await show`{${vstar}, ${delta}[{0, 0, 0, 0}, R], ${delta}[${vstar}, R], ${delta}[${vstar}, 0]}`
(V∗, δfirst trial, δlearned, δomitted)={{Rγ3,Rγ2,Rγ,R},{0,0,0,0,R},{Rγ4,0,0,0,0},{Rγ4,0,0,0,−R}} \begin{aligned} &\bigl(V^*,\ \delta_{\text{first trial}},\ \delta_{\text{learned}},\ \delta_{\text{omitted}}\bigr) \\ &= \left\{\left\{R \gamma ^3,R \gamma ^2,R \gamma ,R\right\},\{0,0,0,0,R\},\left\{R \gamma ^4,0,0,0,0\right\},\left\{R \gamma ^4,0,0,0,-R\right\}\right\} \end{aligned} One trial of tabular TD(0), written as a pure function that returns the new values and the errors it produced; three trials from zero give the errors of trial 3: binomial weights (1−α)2(1-\alpha)^2, 2α(1−α)2\alpha(1-\alpha), α2\alpha^2 times γkR\gamma^k R.
const trial = await wl`Function[{v}, Module[{w = v, d}, d = {\[Gamma] w[[1]]}; Do[d = Append[d, \[Gamma] w[[t + 1]] - w[[t]]]; w[[t]] = w[[t]] + \[Alpha] (\[Gamma] w[[t + 1]] - w[[t]]), {t, Length[w] - 1}]; d = Append[d, R - w[[-1]]]; w[[-1]] = w[[-1]] + \[Alpha] (R - w[[-1]]); {w, d}]]`
const third = await show`Factor[Last[${trial}[First[${trial}[First[${trial}[{0, 0, 0, 0}]]]]]]]`
δtrial 3={0,0,Rα2γ2,−2R(−1+α)αγ,R(−1+α)2} \delta_{\text{trial }3} = \left\{0,0,R \alpha ^2 \gamma ^2,-2 R (-1+\alpha ) \alpha \gamma ,R (-1+\alpha )^2\right\} The simulated errors of trials 11 to 88, minus the closed form (14.7), for symbolic α\alpha, γ\gamma, RR: every difference expands to 00.
const wave = await wl`Function[{n, kk}, Join[{R \[Gamma]^(kk + 1) Sum[Binomial[n - 1, j] \[Alpha]^j (1 - \[Alpha])^(n - 1 - j), {j, kk + 1, n - 1}]}, Table[R \[Gamma]^k Binomial[n - 1, k] \[Alpha]^k (1 - \[Alpha])^(n - 1 - k), {k, kk, 0, -1}]]]`
const waveCheck = await show`Union[Flatten[Table[Expand[Last[${trial}[Nest[First[${trial}[#]] &, {0, 0, 0, 0}, n - 1]]] - ${wave}[n, 3]], {n, 1, 8}]]]`
{δnsimulated−δnbinomial}n=18={0} \Bigl\{\delta^{\text{simulated}}_n - \delta^{\text{binomial}}_n\Bigr\}_{n=1}^{8} = \{0\}

14.6.3Where the Hypothesis Strains, and How It Was Tested

Not every dopamine neuron behaves like this, and the fit depends on the representation. The best-known discrepancy concerns a reward delivered earlier than expected: dopamine neurons burst at the early reward, as TD predicts, but do not pause at the usual time, whereas TD with the CSC predicts a dip there, because the clock started by the cue keeps running (Exercise 14.14).Jeffrey R. Hollerman and Wolfram Schultz. Dopamine Neurons Report an Error in the Temporal Prediction of Reward during Learning. Nature Neuroscience, 1(4):304–309, 1998. doi: 10.1038/1124 Representations in which a reward resets the cascade, microstimuli, or belief states over hidden task states computed by sensory cortex repair this and other timing details.Elliot A. Ludvig, Richard S. Sutton, and E. James Kehoe. Stimulus Representation and the Timing of Reward-Prediction Errors in Models of the Dopamine System. Neural Computation, 20(12):3034–3054, 2008. doi: 10.1162/neco.2008.11-07-654; and Nathaniel D. Daw, Aaron C. Courville, and David S. Touretzky. Representation and Timing in Theories of the Dopamine System. Neural Computation, 18(7):1637–1677, 2006. doi: 10.1162/neco.2006.18.7.1637 None of these refinements touches the core claim that phasic dopamine activity behaves like a TD error. A more radical alternative should be mentioned as well: it has been argued that dopamine signals RPEs but not specifically TD errors, citing, among other things, how rarely conditioning beyond the second order is observed.

Correlation is not causation, and the decisive tests are recent. Optogenetics makes it possible to excite or silence genetically identified neurons with light on a millisecond scale. Phasic (but not tonic) optogenetic activation of dopamine neurons suffices to condition a place preference in mice.Hsing-Chen Tsai, Feng Zhang, Antoine Adamantidis, Garret D. Stuber, Antonello Bonci, Luis de Lecea, and Karl Deisseroth. Phasic Firing in Dopaminergic Neurons Is Sufficient for Behavioral Conditioning. Science, 324(5930):1080–1084, 2009. doi: 10.1126/science.1168878 Steinberg and colleagues then used the two paradigms where the theory says learning requires a prediction error.Elizabeth E. Steinberg, Ronald Keiflin, Josiah R. Boivin, Ilana B. Witten, Karl Deisseroth, and Patricia H. Janak. A Causal Link between Prediction Errors, Dopamine Neurons and Learning. Nature Neuroscience, 16(7):966–973, 2013. doi: 10.1038/nn.3413 In a blocking design, they activated dopamine neurons at the moment of the fully predicted reward on compound trials; the added cue, normally blocked, was learned. In extinction, they activated the neurons when the expected reward was omitted, replacing the natural pause by a burst, and reward seeking declined more slowly. An artificial positive δ\delta produced exactly the learning a real one would. These experiments show that phasic dopamine acts as a reinforcement signal; they do not by themselves show that it is computed as a TD error.

14.7Actor and Critic in the Striatum

If dopamine broadcasts δ\delta, which algorithm uses it? Actor–critic methods (Chapter 13) are attractive candidates for two reasons. They have two components, and the striatum has two major divisions: the ventral striatum, implicated in assigning value, and the dorsal striatum, implicated in action selection. And in actor–critic methods the same δ\delta trains both components, while dopamine axons reach both divisions. The hypothesis, made precise by Takahashi, Schoenbaum and Niv, places the critic’s value learning in the ventral striatum and the actor in the dorsal striatum; the ventral striatum sends value information to VTA and SNpc, where dopamine neurons combine it with reward information into δ\delta.Yuji Takahashi, Geoffrey Schoenbaum, and Yael Niv. Silencing the Critics: Understanding the Effects of Cocaine Sensitization on Dorsolateral and Ventral Striatum in the Context of an Actor/Critic Model. Frontiers in Neuroscience, 2(1):86–99, 2008. doi: 10.3389/neuro.01.014.2008 Imaging in humans pointed the same way: in an instrumental task the dorsal striatum showed prediction-error activity linked to action selection, while the ventral striatum showed it in both instrumental and Pavlovian versions.John O’Doherty, Peter Dayan, Johannes Schultz, Ralf Deichmann, Karl Friston, and Raymond J. Dolan. Dissociable Roles of Ventral and Dorsal Striatum in Instrumental Conditioning. Science, 304(5669):452–454, 2004. doi: 10.1126/science.1094285 A consequence of this picture is that RtR_t is not any single neural signal: it is the net reward information converging on dopamine neurons from many areas.

The neural reading is cleanest for the network actor–critic of Barto, Sutton and Anderson,Andrew G. Barto, Richard S. Sutton, and Charles W. Anderson. Neuronlike Adaptive Elements That Can Solve Difficult Learning Control Problems. IEEE Transactions on Systems, Man, and Cybernetics, SMC-13(5):834–846, 1983. doi: 10.1109/TSMC.1983.6313077 which we write in the notation of Algorithm 13.7. Cortical features 𝐱(St)\mathbf{x}(S_t) reach a single linear critic unit and kk stochastic actor units through modifiable synapses.

Algorithm 14.8 (Neural Actor–Critic with Two- and Three-Factor Rules). Parameters: α𝐰,α𝜽>0\alpha^{\mathbf{w}}, \alpha^{\boldsymbol\theta} > 0, γ∈[0,1)\gamma \in [0,1), λ𝐰,λ𝜽∈[0,1]\lambda^{\mathbf{w}}, \lambda^{\boldsymbol\theta} \in [0,1]. Units: critic v^(s,𝐰)=𝐰⊤𝐱(s)\hat v(s, \mathbf{w}) = \mathbf{w}^\top\mathbf{x}(s); actor units j=1,…,kj = 1, \dots, k, each a Bernoulli-logistic unit that fires (Aj=1A_{j} = 1) with probability πj(1∣s)=σ(𝜽j⊤𝐱(s))\pi_j(1 \mid s) = \sigma(\boldsymbol\theta_j^\top\mathbf{x}(s)), σ(u)=1/(1+e−u)\sigma(u) = 1/(1 + e^{-u}). Initialize 𝐰,𝜽j\mathbf{w}, \boldsymbol\theta_j, and traces 𝐳𝐰=𝐳j𝜽=𝟎\mathbf{z}^{\mathbf{w}} = \mathbf{z}^{\boldsymbol\theta}_j = \mathbf{0}. Each step, in state StS_t:

  1. Each actor unit fires, Aj,t∼Bernoulli⁡(σ(𝜽j⊤𝐱(St)))A_{j,t} \sim \operatorname{Bernoulli}\bigl(\sigma(\boldsymbol\theta_j^\top\mathbf{x}(S_t))\bigr); the collective action is executed, and Rt+1,St+1R_{t+1}, S_{t+1} are observed.
  2. Dopamine: δt=Rt+1+γv^(St+1,𝐰)−v^(St,𝐰)\delta_t = R_{t+1} + \gamma\hat v(S_{t+1}, \mathbf{w}) - \hat v(S_t, \mathbf{w}).
  3. Critic synapses (non-contingent trace): 𝐳𝐰←γλ𝐰𝐳𝐰+𝐱(St)\mathbf{z}^{\mathbf{w}} \leftarrow \gamma\lambda^{\mathbf{w}}\mathbf{z}^{\mathbf{w}} + \mathbf{x}(S_t), then 𝐰←𝐰+α𝐰δt 𝐳𝐰\mathbf{w} \leftarrow \mathbf{w} + \alpha^{\mathbf{w}}\delta_t\,\mathbf{z}^{\mathbf{w}}.
  4. Actor synapses (contingent trace): 𝐳j𝜽←γλ𝜽𝐳j𝜽+(Aj,t−σ(𝜽j⊤𝐱(St)))𝐱(St)\mathbf{z}^{\boldsymbol\theta}_j \leftarrow \gamma\lambda^{\boldsymbol\theta}\mathbf{z}^{\boldsymbol\theta}_j + \bigl(A_{j,t} - \sigma(\boldsymbol\theta_j^\top\mathbf{x}(S_t))\bigr)\mathbf{x}(S_t), then 𝜽j←𝜽j+α𝜽δt 𝐳j𝜽\boldsymbol\theta_j \leftarrow \boldsymbol\theta_j + \alpha^{\boldsymbol\theta}\delta_t\,\mathbf{z}^{\boldsymbol\theta}_j.

The actor’s trace is a trace of ∇ln⁡πj(Aj,t∣St)\nabla\ln\pi_j(A_{j,t} \mid S_t), which for a logistic unit is (Aj,t−πj(1∣St)) 𝐱(St)(A_{j,t} - \pi_j(1 \mid S_t))\,\mathbf{x}(S_t) (checked below). The only difference between the two learning rules is in the eligibility traces, and it is the difference between prediction and control.

  • The critic’s trace depends only on presynaptic activity xix_i: a non-contingent eligibility trace. Its update is a two-factor rule (presynaptic activity × dopamine), the TD model of classical conditioning in neural form. The critic works to drive δ\delta to zero.
  • The actor’s trace depends on presynaptic activity and on whether the postsynaptic unit fired: a contingent eligibility trace. Its update is a three-factor learning rule (presynaptic × postsynaptic × dopamine), a law of effect for a single synapse. The actor works to make δ\delta large.

Is there such plasticity in the striatum? Hebb’s postulate is two-factor (pre × post). Spike-timing-dependent plasticity (STDP) makes it causal: a synapse strengthens when its input spike shortly precedes a postsynaptic spike, and weakens in the reverse order, which is the “presynaptic activity contributed to the output” condition of a contingent trace. In reward-modulated STDP the change also needs a neuromodulator to arrive within a window after the pairing. At corticostriatal synapses, Yagishita and colleagues found that dopamine enlarged dendritic spines of striatal neurons only when it arrived within a window of roughly 0.30.3 to 22 seconds after the glutamatergic (cortical) input, and identified a molecular mechanism for the window.Sho Yagishita, Akiko Hayashi-Takagi, Graham C. R. Ellis-Davies, Hidetoshi Urakubo, Shin Ishii, and Haruo Kasai. A Critical Time Window for Dopamine Actions on the Structural Plasticity of Dendritic Spines. Science, 345(6204):1616–1620, 2014. doi: 10.1126/science.1255514 That is a contingent eligibility trace with a lifetime of about a second.Beyond Sutton and Barto (2018). Gerstner, Lehmann, Liakoni, Corneil and Brea (2018) review four experiments, in striatum, cortex and hippocampus, that support synaptic eligibility traces lasting seconds combined with a third factor (reward, surprise or novelty, carried by a neuromodulator), and they connect them with the “neoHebbian” three-factor rules of theory. They also stress the time-scale problem the traces solve: spikes take milliseconds, behavior takes seconds.Wulfram Gerstner, Marco Lehmann, Vasiliki Liakoni, Dane Corneil, and Johanni Brea. Eligibility Traces and Plasticity on Behavioral Time Scales: Experimental Support of NeoHebbian Three-Factor Learning Rules. Frontiers in Neural Circuits, 12:53, 2018. doi: 10.3389/fncir.2018.00053

14.7.1In Wolfram Language: the Contingent Trace

Gradient of ln⁡π\ln\pi for a logistic unit, for both outputs: (1−σ)𝐱(1-\sigma)\mathbf{x} if it fired and −σ𝐱-\sigma\mathbf{x} if it did not, that is, (a−σ)𝐱(a - \sigma)\mathbf{x}.
const elig = await show`Simplify[{D[Log[LogisticSigmoid[\[Theta] x]], \[Theta]], D[Log[1 - LogisticSigmoid[\[Theta] x]], \[Theta]]} - {(1 - LogisticSigmoid[\[Theta] x]) x, (0 - LogisticSigmoid[\[Theta] x]) x}]`
∇θln⁡π(a∣x)−(a−σ(θx)) x for a=1,0:{0,0} \nabla_\theta\ln\pi(a \mid x) - (a - \sigma(\theta x))\,x\ \text{for } a = 1, 0: \quad \{0,0\}

14.8Hedonistic Neurons and Collective Reinforcement Learning

The term eligibility and the actor’s learning rule come from Klopf’s hedonistic neuron hypothesis: each neuron is itself a reinforcement learning agent, which adjusts its synapses to increase rewarding input and decrease punishing input that follow its own spikes.A. Harry Klopf. The Hedonistic Neuron: A Theory of Memory, Learning, and Intelligence. Hemisphere, Washington, DC, 1982 A synapse that contributed to a spike becomes eligible, and a later reinforcing signal changes it only while it remains eligible. Klopf imagined the trace as a histogram of the delays of the feedback loops a neuron is embedded in; the geometric traces of Chapter 12 are a simplified placeholder for that idea. The hypothesis is less strange than it sounds. E. coli finds food by run and twiddle: keep swimming while things improve, tumble into a random new direction when they get worse, a trial-and-error strategy of a single cell with a short memory.

If dopamine reaches the synapses of millions of actor-like striatal neurons with the same δ\delta, the striatum is a team: many agents, one common reinforcement signal that evaluates their collective action. Each unit sees the others only as part of its environment, cannot observe their actions, and finds its own influence on the reward buried in their noise. That such a team can learn at all rests on a short theorem of Williams.Ronald J. Williams. Simple Statistical Gradient-Following Algorithms for Connectionist Reinforcement Learning. Machine Learning, 8(3–4):229–256, Springer, 1992. doi: 10.1007/BF00992696

Proposition 14.9 (A Team of REINFORCE Units Follows the Team Gradient). Let units j=1,…,kj = 1, \dots, k fire independently given the input 𝐱\mathbf{x}, unit jj with probability σ(𝜽j⊤𝐱)\sigma(\boldsymbol\theta_j^\top\mathbf{x}), and let the common reward RR depend on the joint action 𝐀\mathbf{A} (and possibly on 𝐱\mathbf{x} and noise). Then for each jj

𝔼[R (Aj−σ(𝜽j⊤𝐱)) 𝐱∣𝐱]=∇𝜽j 𝔼[R∣𝐱], \mathbb{E}\bigl[R\,(A_j - \sigma(\boldsymbol\theta_j^\top\mathbf{x}))\,\mathbf{x} \bigm| \mathbf{x}\bigr] = \nabla_{\boldsymbol\theta_j}\,\mathbb{E}[R \mid \mathbf{x}], (14.8)

so the local, contingent updates of all units together form an unbiased estimate of the gradient of the team’s expected reward. A non-contingent rule Δ𝜽j∝R 𝐱\Delta\boldsymbol\theta_j \propto R\,\mathbf{x} has expectation 𝔼[R∣𝐱] 𝐱\mathbb{E}[R \mid \mathbf{x}]\,\mathbf{x}, which carries no information about how unit jj affects RR.

Proof. The joint policy factorizes, π(𝐚∣𝐱)=∏iπi(ai∣𝐱)\pi(\mathbf{a} \mid \mathbf{x}) = \prod_i \pi_i(a_i \mid \mathbf{x}), so ∇𝜽jln⁡π(𝐚∣𝐱)=∇𝜽jln⁡πj(aj∣𝐱)=(aj−σ(𝜽j⊤𝐱))𝐱\nabla_{\boldsymbol\theta_j}\ln\pi(\mathbf{a} \mid \mathbf{x}) = \nabla_{\boldsymbol\theta_j}\ln\pi_j(a_j \mid \mathbf{x}) = (a_j - \sigma(\boldsymbol\theta_j^\top\mathbf{x}))\mathbf{x}. The score-function identity of Algorithm 13.4, ∇𝔼[R]=𝔼[R ∇ln⁡π(𝐀)]\nabla\mathbb{E}[R] = \mathbb{E}[R\,\nabla\ln\pi(\mathbf{A})], gives (14.8). In the non-contingent rule 𝐱\mathbf{x} is constant under the conditioning, so its expectation is 𝔼[R∣𝐱] 𝐱\mathbb{E}[R \mid \mathbf{x}]\,\mathbf{x}. □

Two requirements emerge, matching the book’s discussion: the units must use contingent traces, which remember their own action, and they must vary their actions, since a deterministic team cannot explore its collective action space. Williams also showed that the result extends to multilayer networks of such units with the reward broadcast to all of them; the team then performs gradient ascent like backpropagation but without a backward pass, far slower in practice but much easier to imagine in neural tissue. A population of critic-like units, by contrast, is not a team at all: with non-contingent traces they would all learn to predict the same quantity.

A two-unit team with logistic units (x=1x = 1) and an arbitrary reward table ra1a2r_{a_1a_2}: the expected contingent update of unit 1 minus ∂J/∂θ1\partial J/\partial\theta_1 is 00, while the expected non-contingent update is JJ itself.
const team = await show`Module[{p1 = LogisticSigmoid[Subscript[\[Theta], 1]], p2 = LogisticSigmoid[Subscript[\[Theta], 2]], pr, J}, pr = Function[{a1, a2}, If[a1 == 1, p1, 1 - p1] If[a2 == 1, p2, 1 - p2]]; J = Sum[pr[a1, a2] Subscript[r, a1, a2], {a1, 0, 1}, {a2, 0, 1}]; {Simplify[Sum[pr[a1, a2] Subscript[r, a1, a2] (a1 - p1), {a1, 0, 1}, {a2, 0, 1}] - D[J, Subscript[\[Theta], 1]]], Simplify[Sum[pr[a1, a2] Subscript[r, a1, a2], {a1, 0, 1}, {a2, 0, 1}] - J]}]`
(𝔼[R(A1−σ(θ1))]−∂J∂θ1, 𝔼[R]−J)={0,0} \Bigl(\mathbb{E}[R(A_1 - \sigma(\theta_1))] - \tfrac{\partial J}{\partial\theta_1},\ \mathbb{E}[R] - J\Bigr) = \{0,0\}

14.9Model-Based Control in the Brain

Basic actor–critic is model-free, so the hypothesis above concerns habits. Lesion and inactivation studies in rats refine it: inactivating the dorsolateral striatum impairs habits and leaves behavior goal-directed, while inactivating the dorsomedial striatum does the opposite, so the dorsal striatum is not one actor but at least two systems. The orbitofrontal cortex carries signals of the subjective value of outcomes and may hold the reward part of a model. The hippocampus, long known as necessary for flexible spatial navigation (Tolman’s maps), provides the most direct evidence of planning: when a rat pauses at a choice point, decoded hippocampal activity sweeps forward along the possible paths,Adam Johnson and A. David Redish. Neural Ensembles in CA3 Transiently Encode Paths Forward of the Animal at a Decision Point. Journal of Neuroscience, 27(45):12176–12189, 2007. doi: 10.1523/JNEUROSCI.3761-07.2007 and sequences generated before a run depict the path the rat then takes to a remembered goal.Brad E. Pfeiffer and David J. Foster. Hippocampal Place-Cell Sequences Depict Future Paths to Remembered Goals. Nature, 497(7447):74–79, 2013. doi: 10.1038/nature12112 This looks like decision-time planning with a transition model, a rollout, rather than background planning in the style of Dyna (Algorithm 8.2), although nothing rules out both.

The clean separation suggested by these results does not survive closer inspection. In a two-step task designed to separate the two systems, human choices and striatal prediction-error signals reflected a mixture of model-free and model-based evaluation.Nathaniel D. Daw, Samuel J. Gershman, Ben Seymour, Peter Dayan, and Raymond J. Dolan. Model-Based Influences on Humans’ Choices and Striatal Prediction Errors. Neuron, 69(6):1204–1215, 2011. doi: 10.1016/j.neuron.2011.02.027 As Doll, Simon and Daw put it, “model-based influences appear ubiquitous more or less wherever the brain processes reward information,” including the dopamine signal itself.Bradley B. Doll, Dylan A. Simon, and Nathaniel D. Daw. The Ubiquity of Model-Based Reinforcement Learning. Current Opinion in Neurobiology, 22(6):1075–1081, 2012. doi: 10.1016/j.conb.2012.08.003 Intermediate algorithms, cached in some respects and computed in others, are therefore of special interest; the successor representation in Section 14.11 is the leading example.

14.10Addiction as TD Learning Gone Awry

Many drugs of abuse, cocaine among them, raise dopamine levels pharmacologically. If dopamine is δ\delta, a drug injects an error that the value function cannot predict away. Redish turned this into a model:A. David Redish. Addiction as a Computational Process Gone Awry. Science, 306(5703):1944–1947, 2004. doi: 10.1126/science.1102384 on transitions into a state s′s' where the drug acts, with a pharmacological surge D(s′)>0D(s') > 0,

δt=max⁡{Rt+1+γV(St+1)−V(St)+D(St+1),  D(St+1)}, \delta_t = \max\bigl\{R_{t+1} + \gamma V(S_{t+1}) - V(S_t) + D(S_{t+1}),\; D(S_{t+1})\bigr\}, (14.9)

and the ordinary TD error elsewhere. For a natural reward the error is driven to zero by learning; for the drug it never falls below DD.Redish’s equation is written in a semi-Markov form with a delay-dependent discount γd\gamma^{d}; the one-step form (14.9) keeps its essential feature, the floor DD. He notes himself that biological compensation would bound values in reality.

Proposition 14.10 (No Finite Values for Drug-Predicting States). In tabular TD(0) with constant α>0\alpha > 0, let ss be a state visited infinitely often from which every transition leads to a state s′s' with D(s′)≥D>0D(s') \ge D > 0 (the state in which the drug is taken). Then V(s)→∞V(s) \to \infty. Equivalently, the fixed-point condition δ=0\delta = 0 has no solution in V(s)V(s), while for a natural reward (D≡0D \equiv 0, ordinary δ\delta) it has the unique solution V(s)=R+γV(s′)V(s) = R + \gamma V(s').

Proof. By (14.9), δ≥D(s′)≥D>0\delta \ge D(s') \ge D > 0 whatever the values, so every visit increases V(s)V(s) by at least αD\alpha D, and V(s)V(s) changes only on visits to ss; after nn visits V(s)≥V0(s)+nαDV(s) \ge V_0(s) + n\alpha D. A fixed point would need δ=0<D\delta = 0 < D. □

The hypothesis that every transition out of ss carries the drug matters. If the drug follows ss only with probability p<1p < 1, and otherwise the agent receives RR and moves to s′′s'', then once V(s)V(s) is large the drug transitions contribute an error of exactly DD, while the others contribute R+γV(s′′)−V(s)R + \gamma V(s'') - V(s), more and more negative. The expected update pD+(1−p)(R+γV(s′′)−V(s))pD + (1-p)\bigl(R + \gamma V(s'') - V(s)\bigr) vanishes at the finite value V(s)=R+γV(s′′)+pD/(1−p)V(s) = R + \gamma V(s'') + pD/(1-p): the drug inflates the value without making it infinite.

Bootstrapping then propagates the unbounded value backwards to every cue and action leading to the drug, and the drug option comes to dominate a fixed natural alternative, at a rate that depends on how large the alternative is, as in choice experiments; the model also predicts that drug seeking becomes less sensitive to cost with experience. It made a sharp prediction as well: since the drug always produces a positive error, cues added to a drug-predicting cue should not be blocked. The prediction failed: in rats self-administering cocaine, pretraining with a tone blocked conditioning to an added light.Leigh V. Panlilio, Eric B. Thorndike, and Charles W. Schindler. Blocking of Conditioning to a Cocaine-Paired Stimulus: Testing the Hypothesis That Cocaine Perpetually Produces a Signal of Larger-Than-Expected Reward. Pharmacology Biochemistry and Behavior, 86(4):774–777, 2007. doi: 10.1016/j.pbb.2007.03.005Beyond Sutton and Barto (2018). The book presents Redish’s model without this test. Panlilio, Thorndike and Schindler (2007) ran the blocking experiment with cocaine as reinforcer and found ordinary blocking, contrary to the model; drug reinforcers seem to obey most of the standard laws of conditioning. The model is best read as Sutton and Barto present it: one possible piece of a complex disorder, and an illustration of how RL theory feeds the young field of computational psychiatry.

The fixed-point equations side by side: for a natural reward δ=0\delta = 0 has the unique solution V(s)=R+γV(s′)V(s) = R + \gamma V(s'); with a drug surge D>0D > 0, δ=0\delta = 0 has no real solution at all.
const redish = await show`{Solve[R + \[Gamma] Subscript[v, 2] - Subscript[v, 1] == 0, Subscript[v, 1]], Reduce[Max[R + \[Gamma] Subscript[v, 2] - Subscript[v, 1] + d, d] == 0 && d > 0, Subscript[v, 1], Reals]}`
(δ=0 without drug, δ=0 with D>0):{{{v1→R+γv2}},False} \bigl(\delta = 0 \text{ without drug},\ \delta = 0 \text{ with } D > 0\bigr): \quad \left\{\left\{\left\{v_1\to R+\gamma v_2\right\}\right\},\text{False}\right\}

14.11Beyond the Book: Distributions, Predictive Maps, and Ramps

Three lines of work since the book’s preparation have sharpened the dopamine–TD correspondence; each also complicates it.

14.11.1A Distributional Code in Dopamine Neurons

TD learning estimates a mean. Distributional RL (Section 16.7.1) learns the whole distribution of the return, and one of its simplest forms needs only a small change to the TD rule: give a family of predictors ViV_i different step sizes αi+\alpha_i^+ and αi−\alpha_i^- for positive and negative errors.Marc G. Bellemare, Will Dabney, and Rémi Munos. A Distributional Perspective on Reinforcement Learning. In Proceedings of the 34th International Conference on Machine Learning, volume 70 of Proceedings of Machine Learning Research, pages 449–458. PMLR, 2017. URL https://proceedings.mlr.press/v70/bellemare17a.htmlBeyond Sutton and Barto (2018). Distributional RL (Bellemare, Dabney and Munos, ICML 2017) appeared as the book went to press, which mentions it only in a bibliographical remark on auxiliary tasks. Dabney et al. (Nature, 2020) proposed that dopamine neurons implement its expectile form and tested the predictions in mouse VTA.

Proposition 14.11 (Asymmetric TD Learns Expectiles). For a one-step prediction of a random reward RR with update V←V+α+δV \leftarrow V + \alpha^+\delta if δ=R−V>0\delta = R - V > 0 and V←V+α−δV \leftarrow V + \alpha^-\delta otherwise, the expected update vanishes exactly when

τ 𝔼[(R−V)+]=(1−τ) 𝔼[(V−R)+],τ=α+α++α−, \tau\,\mathbb{E}[(R - V)^+] = (1 - \tau)\,\mathbb{E}[(V - R)^+], \qquad \tau = \frac{\alpha^+}{\alpha^+ + \alpha^-}, (14.10)

that is, when VV is the τ\tau-expectile of RR. For τ=12\tau = \frac12 this is the mean; larger τ\tau (an “optimistic” cell) gives larger VV.

Proof. The expected update is α+𝔼[(R−V)+]−α−𝔼[(V−R)+]\alpha^+\mathbb{E}[(R-V)^+] - \alpha^-\mathbb{E}[(V-R)^+]; divide by α++α−\alpha^+ + \alpha^-. The left side of (14.10) decreases and the right side increases in VV, so the solution is unique, and it equals 𝔼[R]\mathbb{E}[R] when τ=12\tau = \frac12. □

The theory predicts that dopamine neurons differ in their asymmetry and that each neuron’s reversal point, the reward magnitude at which its response changes sign, is its expectile: cells that amplify positive errors relative to negative ones should reverse at larger rewards. Dabney and colleagues recorded 40 optogenetically identified dopamine neurons in mouse VTA while rewards of seven magnitudes (from 0.10.1 to 20 μ20\ \muL) were delivered at random.Will Dabney, Zeb Kurth-Nelson, Naoshige Uchida, Clara Kwon Starkweather, Demis Hassabis, Rémi Munos, and Matthew Botvinick. A Distributional Code for Value in Dopamine-Based Reinforcement Learning. Nature, 577(7792):671–675, 2020. doi: 10.1038/s41586-019-1924-6 Reversal points were diverse and correlated with the asymmetry τ\tau, estimated on separate halves of the data to avoid circularity; treating the population’s reversal points as expectiles, they decoded a reward distribution that recovered the multiple modes of the true one, which a classical single-mean TD model cannot do. The population, not the single neuron, would then carry the code.

A two-point reward, 11 with probability pp and 00 otherwise: the asymmetric fixed point is τp/(τp+(1−τ)(1−p))\tau p/(\tau p + (1-\tau)(1-p)), which is the mean pp only when τ=12\tau = \frac12.
const expectile = await show`With[{sol = Solve[\[Tau] p (1 - V) == (1 - \[Tau]) (1 - p) V, V][[1, 1, 2]]}, {sol, Simplify[sol /. \[Tau] -> 1/2]}]`
(Vτ, V1/2)={pτ1−p−τ+2pτ,p} \bigl(V_\tau,\ V_{1/2}\bigr) = \left\{\frac{p \tau }{1-p-\tau +2 p \tau },p\right\}

A related result extends the idea from reward magnitude to time: dopamine neurons in mice were found to carry RPEs with a diversity of discount factors, so that the population could represent when, not only how much, reward is expected.P. Masset, P. Tano, H. R. Kim, A. N. Malik, A. Pouget, and N. Uchida. Multi-Timescale Reinforcement Learning in the Brain. Nature, 642(8068):682–690, 2025. doi: 10.1038/s41586-025-08929-9Beyond Sutton and Barto (2018). Masset, Tano, Kim, Malik, Pouget and Uchida (Nature, 2025) report multi-timescale reinforcement learning in mouse dopamine neurons, with heterogeneous discount time constants across neurons, and argue for its computational benefits.

14.11.2The Successor Representation and the Hippocampus

Between caching values (model-free) and recomputing them from a one-step model (model-based) lies the successor representation (SR) of Dayan.Peter Dayan. Improving Generalization for Temporal Difference Learning: The Successor Representation. Neural Computation, 5(4):613–624, 1993. doi: 10.1162/neco.1993.5.4.613 For a fixed policy with transition matrix 𝐏π\mathbf{P}_\pi, cache the expected discounted future occupancy of every state,

𝐌=∑t=0∞γt𝐏πt=(𝐈−γ𝐏π)−1,𝐯π=𝐌 𝐫π. \mathbf{M} = \sum_{t=0}^{\infty}\gamma^t\mathbf{P}_\pi^t = (\mathbf{I} - \gamma\mathbf{P}_\pi)^{-1}, \qquad \mathbf{v}_\pi = \mathbf{M}\,\mathbf{r}_\pi. (14.11)

𝐌\mathbf{M} can itself be learned by TD, row by row, with a vector of “state occupancy” targets in place of rewards. When rewards change, 𝐯π\mathbf{v}_\pi is recomputed by one matrix–vector product, as in model-based control; when transitions change, 𝐌\mathbf{M} must be relearned from experience, as in model-free control. Stachenfeld, Botvinick and Gershman proposed that hippocampal place cells encode rows of 𝐌\mathbf{M}, a predictive map, which explains why place fields skew backwards along habitual paths, cluster near rewards and depend on the policy, and that entorhinal grid cells encode a low-dimensional eigenvector basis of it.Kimberly L. Stachenfeld, Matthew M. Botvinick, and Samuel J. Gershman. The Hippocampus as a Predictive Map. Nature Neuroscience, 20(11):1643–1653, 2017. doi: 10.1038/nn.4650 In humans, Momennejad and colleagues found the asymmetry the SR predicts: people adapted better to changed rewards than to changed transitions.Ida Momennejad, Evan M. Russek, Jin H. Cheong, Matthew M. Botvinick, Nathaniel D. Daw, and Samuel J. Gershman. The Successor Representation in Human Reinforcement Learning. Nature Human Behaviour, 1(9):680–692, 2017. doi: 10.1038/s41562-017-0180-8Beyond Sutton and Barto (2018). The SR is older (Dayan, 1993) but absent from the book. Its revival as a theory of the hippocampus (Stachenfeld, Botvinick and Gershman, Nature Neuroscience, 2017) and of semi-flexible human choice (Momennejad et al., Nature Human Behaviour, 2017) postdates the book’s draft. Exercise 14.15 works through a revaluation.

14.11.3Ramps: Value or Prediction Error?

As a rat approaches a reward, dopamine concentration in the nucleus accumbens often ramps up over seconds. Hamid and colleagues found that this release tracked a temporally discounted estimate of future reward, a value, while minute-by-minute levels tracked reward rate and vigor, and argued that dopamine conveys a single evolving decision variable used for both learning and motivation.Arif A. Hamid, Jeffrey R. Pettibone, Omar S. Mabrouk, Vaughn L. Hetrick, Robert Schmidt, Caitlin M. Vander Weele, Robert T. Kennedy, Brandon J. Aragona, and Joshua D. Berke. Mesolimbic Dopamine Signals the Value of Work. Nature Neuroscience, 19(1):117–126, 2016. doi: 10.1038/nn.4173 Mohebi and colleagues then recorded identified VTA dopamine neurons and accumbens release in the same task: release ramped with reward expectation without a corresponding ramp in the cells’ firing, suggesting local control of release at the axons.A. Mohebi, J. R. Pettibone, A. A. Hamid, J.-M. T. Wong, L. T. Vinson, T. Patriarchi, L. Tian, R. T. Kennedy, and J. D. Berke. Dissociable Dopamine Dynamics for Learning and Motivation. Nature, 570(7759):65–70, 2019. doi: 10.1038/s41586-019-1235-y Value or prediction error?

Kim and colleagues designed virtual-reality experiments that separate the two.HyungGoo R. Kim, Athar N. Malik, John G. Mikhael, Pol Bech, Iku Tsutsui-Kimura, Fangmiao Sun, Yajun Zhang, Yulong Li, Mitsuko Watabe-Uchida, Samuel J. Gershman, and Naoshige Uchida. A Unified Framework for Dopamine Signals across Timescales. Cell, 183(6):1600–1616.e25, 2020. doi: 10.1016/j.cell.2020.11.013 Mice ran a virtual track to a reward; occasionally the scene teleported them closer. A value signal should step up and keep rising; a TD error, δ≈γV(s′)−V(s)\delta \approx \gamma V(s') - V(s), should burst at the jump. Dopamine burst, more strongly for teleports closer to the goal, which is what a convex value function predicts. Ramps followed the speed of the visual scene rather than the animal’s running, vanished without informative visual cues, and appeared at every stage measured, from somatic spiking to dopamine concentration. Their conclusion is that ramps are consistent with RPEs: dopamine neurons compute a moment-by-moment, derivative-like quantity of a convex value function, and a TD error ramps whenever the learned value rises faster than the discount curve, for instance because state uncertainty shrinks as the goal comes into view.Beyond Sutton and Barto (2018). Hamid et al. (2016) and Mohebi et al. (2019) argued for value-like dopamine release; Kim et al. (Cell, 2020) reconciled ramps with the RPE hypothesis. A more radical challenge, that accumbens dopamine signals a retrospective causal association rather than a prospective RPE (Jeong et al., Science, 2022), remains debated. The debate is not closed. Jeong and colleagues proposed that accumbens dopamine signals retrospective causal associations, learned by asking which cues precede rewards rather than which rewards follow cues, and reported experiments in which it did not behave like an RPE.H. Jeong, A. Taylor, J. R. Floeder, M. Lohmann, S. Mihalas, B. Wu, M. Zhou, D. A. Burke, and V. M. K. Namboodiri. Mesolimbic Dopamine Release Conveys Causal Associations. Science, 378(6626):eabq6740, 2022. doi: 10.1126/science.abq6740 Whatever the outcome, the questions are being asked in the vocabulary of this companion: values, discounting, state representations, and the difference between a reward, a value and an error.

The same vocabulary, and often the same algorithm, runs the engineered systems of the next chapter. TD-Gammon’s network learns by the TD(λ\lambda) rule that models the rabbit’s eyeblink, and the deep Q-network is driven by the same kind of error that dopamine neurons appear to broadcast; Chapter 15 looks at what it took to make these methods work at scale.

14.12Exercises

Exercise 14.12. Conditioned inhibition and overexpectation in the Rescorla–Wagner model. (a) Trials A++ (A alone, US of magnitude RR) and AX−- (compound, no US) are randomly intermixed with equal probability. Use Proposition 14.2 to find the asymptotic strengths and interpret the sign of wXw_X. (b) Cues A and B are each trained separately to asymptote RR; then the compound AB is reinforced with the same RR. What does the model predict, and why is it surprising?

Solution

(a) With 𝐱=(1,0)\mathbf{x} = (1, 0) and (1,1)(1, 1) each with probability 12\frac12, 𝐀=12(1000)+12(1111)\mathbf{A} = \frac12\begin{pmatrix}1 & 0 \\ 0 & 0\end{pmatrix} + \frac12\begin{pmatrix}1 & 1 \\ 1 & 1\end{pmatrix} and 𝐛=12(R,0)⊤\mathbf{b} = \frac12(R, 0)^\top. The normal equations give wA=Rw_A = R, wX=−Rw_X = -R: X becomes a conditioned inhibitor, a stimulus that predicts the absence of an otherwise expected US, and the compound predicts 00, as observed. (b) On AB trials δ=R−2R=−R<0\delta = R - 2R = -R < 0 at first, so both cues lose strength although every trial is reinforced. The difference wA−wB=0w_A - w_B = 0 is invariant (Proposition 14.3) and the sum goes to RR, so each ends at R/2R/2. This overexpectation effect was predicted by the model and confirmed in animals; no theory based on contiguity alone predicts loss of strength on reinforced trials.

The normal equations 𝐀𝐰=𝐛\mathbf{A}\mathbf{w} = \mathbf{b} for intermixed A++/AX−- trials.
const inhib = await show`LinearSolve[1/2 {{1, 0}, {0, 0}} + 1/2 {{1, 1}, {1, 1}}, 1/2 {R, 0}]`
(wA,wX)={R,−R} (w_A, w_X) = \{R,-R\}

Exercise 14.13. No traveling wave with λ=1\lambda = 1. In the setting of Theorem 14.7, replace TD(0) by its offline λ=1\lambda = 1 version, which moves each V(k)V(k) towards the Monte Carlo return γkR\gamma^k R at the end of every trial. Find Vn(k)V_n(k) and the TD errors of trial nn, and compare them with dopamine data.

Solution

Each value obeys Vn(k)=Vn−1(k)+α(γkR−Vn−1(k))V_n(k) = V_{n-1}(k) + \alpha(\gamma^k R - V_{n-1}(k)), so Vn(k)=γkR cnV_n(k) = \gamma^kR\,c_n with cn=1−(1−α)nc_n = 1 - (1-\alpha)^n: all states learn in parallel, in proportion. Inside the interval δn(k)=γVn−1(k−1)−Vn−1(k)=γkR(cn−1−cn−1)=0\delta_n(k) = \gamma V_{n-1}(k-1) - V_{n-1}(k) = \gamma^k R(c_{n-1} - c_{n-1}) = 0 for k≥1k \ge 1; at the reward δn(0)=R(1−cn−1)=R(1−α)n−1\delta_n(0) = R(1 - c_{n-1}) = R(1-\alpha)^{n-1}, and at the cue δncue=γK+1R cn−1\delta^{\text{cue}}_n = \gamma^{K+1}R\,c_{n-1}. The response to the reward decays while the response to the cue grows, with nothing in between, as Pan et al. (2005) observed in dopamine neurons; intermediate λ\lambda interpolates between this and the binomial wave of TD(0).

The λ=1\lambda = 1 values after n−1n - 1 trials, γkR(1−(1−α)n−1)\gamma^k R(1 - (1-\alpha)^{n-1}), fed to delta: errors at the cue and the reward only.
const mcErrors = await show`Simplify[${delta}[Table[R \[Gamma]^k (1 - (1 - \[Alpha])^(n - 1)), {k, 3, 0, -1}], R]]`
δnλ=1={R(1−(1−α)−1+n)γ4,0,0,0,R(1−α)−1+n} \delta^{\lambda = 1}_n = \left\{R \left(1-(1-\alpha )^{-1+n}\right) \gamma ^4,0,0,0,R (1-\alpha )^{-1+n}\right\}

Exercise 14.14. Early reward. After learning in Theorem 14.7 (CSC, values γkR\gamma^k R), the reward is delivered one step early, on leaving the state at distance k=1k = 1, and the cascade of CSC states continues to sKs_K without reward. Assume the trial still ends after sKs_K. Compute the TD errors at the early reward and at the usual time, and compare with Hollerman and Schultz (1998). What modification of the representation removes the discrepancy?

Solution

Leaving the state at distance 11 the agent receives RR and moves to the state at distance 00: δ=R+γV(0)−V(1)=R+γR−γR=R>0\delta = R + \gamma V(0) - V(1) = R + \gamma R - \gamma R = R > 0, a burst, as observed. At the usual time the agent leaves the state at distance 00 with no reward: δ=0−V(0)=−R\delta = 0 - V(0) = -R, a full dip, which dopamine neurons do not show. The CSC clock keeps predicting a reward that has already come. If the reward instead resets the representation (the cascade of the cue is canceled, as proposed by Suri and Schultz, or the animal’s belief about the hidden task state switches to “reward received”, as in the belief-state models of Daw, Courville and Touretzky), the post-reward state has value 00, and both the reward-time and the later errors are 00.

Exercise 14.15. Reward and transition revaluation with the successor representation. A policy moves deterministically along 1→2→31 \to 2 \to 3 and from 33 to a terminal state; rewards r1=r2=0r_1 = r_2 = 0, r3=rr_3 = r are received on leaving each state. Compute 𝐌\mathbf{M} and 𝐯π\mathbf{v}_\pi from (14.11). Then (a) the reward at 33 changes to r′r'; (b) state 22 now leads to the terminal state directly. Which change can an SR agent handle without new experience of the affected transitions, and what does its cached 𝐌\mathbf{M} predict after (b)?

Solution

With 𝐏π\mathbf{P}_\pi the chain matrix (row 3 is zero, since leaving 3 terminates), 𝐌\mathbf{M} is upper triangular with entries γj−i\gamma^{j-i} for j≥ij \ge i, and 𝐯π=(γ2r,γr,r)⊤\mathbf{v}_\pi = (\gamma^2 r, \gamma r, r)^\top. (a) A new reward vector only requires 𝐌𝐫′\mathbf{M}\mathbf{r}': the agent revalues states 11 and 22 at once, like a model-based agent, although it never revisited them. (b) The true values become (0,0,r)(0, 0, r), because state 33 is no longer reachable from 11 and 22; but the cached 𝐌\mathbf{M} still predicts visits to 33 and keeps 𝐯=(γ2r,γr,r)\mathbf{v} = (\gamma^2 r, \gamma r, r) until TD relearns the rows of 𝐌\mathbf{M} from new experience, like a model-free agent. This asymmetry is what Momennejad et al. (2017) found in human choices.

The SR of the three-state chain, (𝐈−γ𝐏π)−1(\mathbf{I} - \gamma\mathbf{P}_\pi)^{-1}, and the values under the original and the revalued reward, each a single product with 𝐌\mathbf{M}.
const srM = await wl`Inverse[IdentityMatrix[3] - \[Gamma] {{0, 1, 0}, {0, 0, 1}, {0, 0, 0}}]`
const srCheck = await show`{${srM}, ${srM} . {0, 0, r}, ${srM} . {0, 0, Subscript[r, new]}}`
(𝐌, 𝐌𝐫, 𝐌𝐫′)={(1γγ201γ001),{rγ2,rγ,r},{γ2rnew,γrnew,rnew}} \bigl(\mathbf{M},\ \mathbf{M}\mathbf{r},\ \mathbf{M}\mathbf{r}'\bigr) = \left\{\left( \begin{array}{ccc} 1 & \gamma & \gamma ^2 \\ 0 & 1 & \gamma \\ 0 & 0 & 1 \\ \end{array} \right),\left\{r \gamma ^2,r \gamma ,r\right\},\left\{\gamma ^2 r_{\text{new}},\gamma r_{\text{new}},r_{\text{new}}\right\}\right\}