Simple Algorithm
Reinforcement Learning · Fixed Point · 28 min

Successor Representations & Features

Splitting value into where you will go and what you will find there.

Split a value into two questions: where will I go, and what will I find there? The successor representation answers the first question once, for a policy, and then any reward function gives values with one matrix–vector product. With features it becomes successor features, which, combined with generalized policy improvement, let an agent combine old policies to act well on a new task before learning anything about it. The same idea may describe how the hippocampus represents space.

What you’ll learn

  • Define the successor representation Mπ=(I−γPπ)−1M^\pi = (I - \gamma P^\pi)^{-1}, read its rows as discounted occupancies, and factor values as Vπ=MπrπV^\pi = M^\pi r^\pi.
  • Derive the Bellman equation of the successor representation and its TD learning rule, and contrast reward revaluation with transition revaluation.
  • Define successor features, prove the generalized policy improvement theorem, and state the transfer bound of Barreto et al. (2017).
  • Describe forward–backward representations and zero-shot RL, and the evidence for SR-like representations in the brain.

Where you will go: the successor representation

The factorization separates where the policy goes from what it finds there. For (go, stay) in the two-state MDP of the value-space widget, M=(19010)M = \begin{pmatrix}1 & 9\\ 0 & 10\end{pmatrix}: from s1s_1 the agent spends one discounted visit in s1s_1, at time 0, and 9 in s2s_2. With rπ=(0,2)r^\pi = (0, 2) this gives V=(18,20)V = (18, 20). The uniform random policy moves to either state with probability ½ from both, so M=I+γ1−γ⋅12(1111)=(5.54.54.55.5)M = I + \frac{\gamma}{1-\gamma}\cdot\frac12\begin{pmatrix}1 & 1\\ 1 & 1\end{pmatrix} = \begin{pmatrix}5.5 & 4.5\\ 4.5 & 5.5\end{pmatrix}, and with rπ=(0.5,1)r^\pi = (0.5, 1) it gives (7.25,7.75)(7.25, 7.75), the values found by hand in Value Functions & the Bellman Equations.

Predict before you look

The agent keeps the policy (go, stay), but the world changes: staying in s2s_2 now pays −1-1 instead of 2. Using the SR above, what is the new value of s1s_1?

Show the answer

-9

V′(s1)=M(s1,s1) r′(s1)+M(s1,s2) r′(s2)=1⋅0+9⋅(−1)=−9V'(s_1) = M(s_1, s_1)\,r'(s_1) + M(s_1, s_2)\,r'(s_2) = 1 \cdot 0 + 9 \cdot (-1) = -9, with no planning at all: the SR already knows that the policy spends 9 discounted steps in s2s_2. It does not say whether the policy is still a good one. It is not: staying in s1s_1 is now worth 10.

The SR sits between model-free and model-based methods. A model-free learner caches values, so a change of reward forces it to relearn by trial and error. A model-based learner caches one-step dynamics and must plan again. The SR caches multi-step predictions of states: a change of reward costs one product, but a change of transitions, a new wall or a moved door, invalidates the SR and must be relearned. The SR also belongs to a policy, not to the environment, which is a problem for control, where the policy keeps changing.

Learning the SR, and successor features

DerivationThe SR satisfies a Bellman equation
  1. Mπ(s,⋅)=es+γ∑s′Pπ(s,s′) Mπ(s′,⋅),that isMπ=I+γPπMπM^\pi(s, \cdot) = \mathbf e_s + \gamma\sum_{s'}P^\pi(s, s')\,M^\pi(s', \cdot),\qquad\text{that is}\qquad M^\pi = I + \gamma P^\pi M^\pi

    Split the sum at t=0t = 0, exactly as for values. The visit at time 0 contributes the indicator es\mathbf e_s of the current state; the rest is the SR of the next state, discounted:

  2. M(St,⋅)←M(St,⋅)+α[eSt+γ M(St+1,⋅)−M(St,⋅)]M(S_t, \cdot) \leftarrow M(S_t, \cdot) + \alpha\Big[\mathbf e_{S_t} + \gamma\,M(S_{t+1}, \cdot) - M(S_t, \cdot)\Big]

    It is a Bellman equation with a vector "reward", one entry per target state. So the SR can be learned from experience by temporal-difference learning, one TD(0) problem per column, with a vector-valued TD error:

  3. Each column is an ordinary tabular TD(0) problem with reward 1{St=s′}\mathbb 1\{S_t = s'\}, so the usual convergence results apply on-policy (Convergence of TD: Stochastic Approximation).

python
import numpy as np

gamma, alpha = 0.9, 0.05
P_pi = np.array([[0.5, 0.5],      # uniform random policy on the two-state MDP:
                 [0.5, 0.5]])     # from either state, s1 or s2 with probability 1/2
r_pi = np.array([0.5, 1.0])       # expected reward of a random action in each state
M_true = np.linalg.inv(np.eye(2) - gamma * P_pi)   # [[5.5, 4.5], [4.5, 5.5]]

rng = np.random.default_rng(0)
M, s = np.zeros((2, 2)), 0
for t in range(20_000):
    s_next = rng.choice(2, p=P_pi[s])
    target = np.eye(2)[s] + gamma * M[s_next]   # indicator of s, plus a bootstrap
    M[s] += alpha * (target - M[s])              # TD(0) on the whole row at once
    s = s_next

print(M, M @ r_pi)   # M fluctuates around M_true, and M_true @ r_pi = (7.25, 7.75)

Learning the SR from one long trajectory. With a constant step size the estimate keeps fluctuating around the true SR, as tabular TD estimates do; a decaying step size would make it converge.

In large state spaces one cannot count visits to each state, but one can accumulate features. If rewards are linear in features, r(s,a,s′)=ϕ(s,a,s′)⊤wr(s,a,s') = \boldsymbol\phi(s,a,s')^\top\mathbf w, then the successor features of π\pi,

ψπ(s,a)=Eπ[∑t≥0γtϕ(St,At,St+1) ∣ S0=s, A0=a],\boldsymbol\psi^\pi(s,a) = \E_\pi\Big[\sum_{t\ge0}\gamma^t\boldsymbol\phi(S_t, A_t, S_{t+1})\ \Big|\ S_0 = s,\ A_0 = a\Big],

give Qπ(s,a)=ψπ(s,a)⊤wQ^\pi(s,a) = \boldsymbol\psi^\pi(s,a)^\top\mathbf w for every w\mathbf w (Barreto et al., 2017). They obey the Bellman equation ψπ(s,a)=E[ϕ(s,a,S′)+γ ψπ(S′,π(S′))]\boldsymbol\psi^\pi(s,a) = \E\big[\boldsymbol\phi(s,a,S') + \gamma\,\boldsymbol\psi^\pi(S', \pi(S'))\big], with the features in the role of rewards, so any TD method learns them. One-hot state features give back the SR. The vector w\mathbf w is a task description: the same environment with different preferences.

Pairψ\boldsymbol\psi of πA\pi_A = (go, stay)ψ\boldsymbol\psi of πB\pi_B = (stay, go)
(s1,stay)(s_1, \text{stay})(1,8.1)(1, 8.1)(10,0)(10, 0)
(s1,go)(s_1, \text{go})(0,9)(0, 9)(8.1,0)(8.1, 0)
(s2,stay)(s_2, \text{stay})(0,10)(0, 10)(8.1,1)(8.1, 1)
(s2,go)(s_2, \text{go})(0,8.1)(0, 8.1)(9,0)(9, 0)
Successor features on the two-state MDP with ϕ=(1,0)\boldsymbol\phi = (1, 0) for staying in s1s_1, (0,1)(0, 1) for staying in s2s_2 and (0,0)(0, 0) for going (γ=0.9\gamma = 0.9). Task wA=(1,2)\mathbf w_A = (1, 2) is the widget's MDP, where πA\pi_A is optimal; in task wB=(2,1)\mathbf w_B = (2, 1), staying in s1s_1 pays 2 and staying in s2s_2 pays 1, and πB\pi_B is optimal, worth (20,18)(20, 18). Each policy's action values in any task are dot products: for instance QwAπA(s1,stay)=1+2⋅8.1=17.2Q^{\pi_A}_{\mathbf w_A}(s_1, \text{stay}) = 1 + 2 \cdot 8.1 = 17.2.

Generalized policy improvement

DerivationProof for exact values
  1. Qmax⁡(s′,π(s′))=max⁡bQmax⁡(s′,b)  ≥  max⁡bQπi(s′,b)  ≥  ∑bπi(b∣s′) Qπi(s′,b)Q_{\max}(s', \pi(s')) = \max_b Q_{\max}(s', b) \;\ge\; \max_b Q^{\pi_i}(s', b) \;\ge\; \sum_b\pi_i(b \mid s')\,Q^{\pi_i}(s', b)

    Let Qmax⁡=max⁡iQπiQ_{\max} = \max_i Q^{\pi_i} and let Tπ\mathcal T^\pi act on action values. Since π\pi is greedy with respect to Qmax⁡Q_{\max}, for every ii and every next state s′s':

  2. (TπQmax⁡)(s,a)≥(TπiQπi)(s,a)=Qπi(s,a)  for every i⟹TπQmax⁡≥Qmax⁡(\mathcal T^\pi Q_{\max})(s,a) \ge (\mathcal T^{\pi_i}Q^{\pi_i})(s,a) = Q^{\pi_i}(s,a)\ \text{ for every } i\quad\Longrightarrow\quad \mathcal T^\pi Q_{\max} \ge Q_{\max}

    Average over s′s' and add the reward: one backup with π\pi beats every πi\pi_i's own Bellman equation, so it beats their maximum:

  3. Qπ=lim⁡k→∞(Tπ)kQmax⁡  ≥  Qmax⁡=max⁡iQπiQ^\pi = \lim_{k\to\infty}(\mathcal T^\pi)^k Q_{\max} \;\ge\; Q_{\max} = \max_i Q^{\pi_i}

    By monotonicity of Tπ\mathcal T^\pi (Bellman Operators & Contraction), (Tπ)kQmax⁡≥Qmax⁡(\mathcal T^\pi)^k Q_{\max} \ge Q_{\max} for every kk, and the iterates converge to the fixed point QπQ^\pi. With ε\varepsilon-accurate estimates each backup loses at most (1+γ)ε(1+\gamma)\varepsilon; the constant shift adds these losses up as a geometric series, and comparing Q~max⁡\tilde Q_{\max} with Qmax⁡Q_{\max} costs one more ε\varepsilon, for 2ε/(1−γ)2\varepsilon/(1-\gamma) in all. ■\blacksquare

Predict before you look

Using the successor features of πB\pi_B in the table, what is Qw′πB(s2,stay)Q^{\pi_B}_{\mathbf w'}(s_2, \text{stay}) for the new task w′=(1,1)\mathbf w' = (1, 1)?

Show the answer

9.1

ψπB(s2,stay)⊤w′=8.1⋅1+1⋅1=9.1\boldsymbol\psi^{\pi_B}(s_2, \text{stay})^\top\mathbf w' = 8.1 \cdot 1 + 1 \cdot 1 = 9.1. Directly: staying pays 1 and leaves the agent in s2s_2, where πB\pi_B goes to s1s_1 and stays there, worth 0+0.9⋅10=90 + 0.9 \cdot 10 = 9; so Q=1+0.9⋅9=9.1Q = 1 + 0.9 \cdot 9 = 9.1.

Zero-shot RL, and the SR in the brain

GPI over a fixed set of policies is only as good as that set. Universal successor features condition ψ\boldsymbol\psi on a task vector, ψ(s,a,z)\boldsymbol\psi(s, a, \mathbf z), so that one network covers a continuum of policies. Touati and Ollivier (2021) push this to zero-shot RL: learn, from reward-free data, representations that yield a near-optimal policy for any reward revealed afterward, with no further learning or planning. Their forward–backward (FB) representation learns maps FF and BB into Rd\R^d such that the successor measure of a family of policies factors through them:

Mπz(s,a,ds′)≈F(s,a,z)⊤B(s′) ρ(ds′),πz(s)=arg max⁡aF(s,a,z)⊤z,zr=Es∼ρ[r(s) B(s)]M^{\pi_{\mathbf z}}(s, a, \mathrm ds') \approx F(s, a, \mathbf z)^\top B(s')\,\rho(\mathrm ds'),\qquad \pi_{\mathbf z}(s) = \argmax_a F(s, a, \mathbf z)^\top\mathbf z,\qquad \mathbf z_r = \E_{s\sim\rho}\big[r(s)\,B(s)\big]
ρ\rho is the distribution of the training data. Given a reward rr, the agent computes zr\mathbf z_r from reward samples and acts with πzr\pi_{\mathbf z_r}, whose action values are approximately F(s,a,zr)⊤zrF(s,a,\mathbf z_r)^\top\mathbf z_r. With exact training these policies are optimal for every reward; with errors, the suboptimality scales with the approximation error (Touati & Ollivier, 2021).

How well does this work? On reward-free offline datasets of continuous-control tasks, Touati, Rapin and Ollivier (2023) found that FB representations reached about 81% of the performance of supervised offline RL trained on each task, averaged over tasks and datasets (85% with a good replay buffer), while successor features depended heavily on the choice of base features: Laplacian eigenfunctions worked well, other choices inconsistently. Barreto, Hou, Borsa, Silver and Precup (2020) review how successor features and GPI combine into fast adaptation more broadly. The SR also appears in exploration: while it is being learned, the norm of a state's row grows with the number of visits to that state, so the inverse of the norm works as a count-based exploration bonus (Machado, Bellemare & Bowling, 2020). And for a random walk on an undirected graph, the SR has the same eigenvectors as the random-walk Laplacian of the graph, the kind of basis behind proto-value functions and eigenoptions.

Key takeaways

  • The successor representation Mπ=(I−γPπ)−1M^\pi = (I - \gamma P^\pi)^{-1} counts discounted future visits; its rows, scaled by 1−γ1-\gamma, are occupancy distributions, and Vπ=MπrπV^\pi = M^\pi r^\pi.
  • The SR obeys the Bellman equation Mπ=I+γPπMπM^\pi = I + \gamma P^\pi M^\pi and is learned by TD with the indicator of the current state as the reward; it makes reward revaluation instant but must be relearned when transitions change.
  • Successor features ψπ\boldsymbol\psi^\pi give Qπ=ψπ⊤wQ^\pi = \boldsymbol\psi^{\pi\top}\mathbf w for every reward linear in the features, so old policies can be evaluated on new tasks by dot products.
  • Generalized policy improvement acts greedily on the maximum of several policies' values and is at least as good as each of them everywhere, up to 2ε/(1−γ)2\varepsilon/(1-\gamma); with successor features it transfers to new tasks with a loss bounded by the distance to the nearest solved task.
  • Forward–backward representations aim at zero-shot RL for any reward; the SR is also a leading model of hippocampal place cells, a hypothesis still under test.

Check yourself

In the interactive lesson these are scored with your confidence, and what you miss comes back for review.

Question 1

For the policy (go, stay), the SR has M(s1,s2)=9M(s_1, s_2) = 9. What does that number mean?

  1. The agent needs 9 steps to reach s2s_2 from s1s_1
  2. Starting in s1s_1, the expected discounted number of visits to s2s_2, ∑tγtPr⁡(St=s2∣S0=s1)\sum_t\gamma^t\Pr(S_t = s_2 \mid S_0 = s_1), is 9
  3. The value of s2s_2 seen from s1s_1
  4. The probability of reaching s2s_2, times 9
Show the answer

B. Starting in s1s_1, the expected discounted number of visits to s2s_2, ∑tγtPr⁡(St=s2∣S0=s1)\sum_t\gamma^t\Pr(S_t = s_2 \mid S_0 = s_1), is 9

The agent reaches s2s_2 at t=1t = 1 and stays, so the count is 0.9+0.92+⋯=0.9/0.1=90.9 + 0.9^2 + \cdots = 0.9/0.1 = 9. Scaled by 1−γ1-\gamma, the row (1,9)(1, 9) becomes the discounted state distribution (0.1,0.9)(0.1, 0.9) of the policy from s1s_1.

Question 2

An agent that has learned the SR of its policy faces two changes: (a) the reward in one state is doubled; (b) a door closes, so one transition now leads elsewhere. What can it update immediately?

  1. Both: the SR stores everything about the environment
  2. Neither: it must relearn from scratch in both cases
  3. Only (b), because transitions are stored in the SR
  4. Only (a): new values follow from V=MrV = M r at once, while the SR itself is invalid after (b) and must be relearned
Show the answer

D. Only (a): new values follow from V=MrV = M r at once, while the SR itself is invalid after (b) and must be relearned

The SR caches multi-step predictions of states under the old dynamics. A new reward vector is combined with it in one product. A new transition changes every row of MM whose future passes through the door, and those predictions must be learned again, the asymmetry Momennejad et al. (2017) tested in people.

Question 3

An agent has exact action values Qπ1Q^{\pi_1} and Qπ2Q^{\pi_2} of two policies in the current task and acts greedily with respect to max⁡(Qπ1,Qπ2)\max(Q^{\pi_1}, Q^{\pi_2}). What does generalized policy improvement guarantee?

  1. Qπ(s,a)≥max⁡(Qπ1(s,a),Qπ2(s,a))Q^\pi(s,a) \ge \max\big(Q^{\pi_1}(s,a), Q^{\pi_2}(s,a)\big) everywhere: at least as good as the better of the two, pair by pair
  2. π\pi is optimal for the current task
  3. π\pi equals whichever of π1\pi_1 and π2\pi_2 has the larger value at the start state
  4. Qπ≥12(Qπ1+Qπ2)Q^\pi \ge \frac12\big(Q^{\pi_1} + Q^{\pi_2}\big) only
Show the answer

A. Qπ(s,a)≥max⁡(Qπ1(s,a),Qπ2(s,a))Q^\pi(s,a) \ge \max\big(Q^{\pi_1}(s,a), Q^{\pi_2}(s,a)\big) everywhere: at least as good as the better of the two, pair by pair

GPI's policy can mix the two old policies state by state and beats both everywhere. In the two-state example it combined πA\pi_A and πB\pi_B into (stay, stay), which happened to be optimal, but optimality is not guaranteed in general.

Question 4

In TD learning of the SR, what is the target for the row M(St,⋅)M(S_t, \cdot) after the transition St→St+1S_t \to S_{t+1}?

  1. Rt+1+γM(St+1,⋅)R_{t+1} + \gamma M(S_{t+1}, \cdot)
  2. eSt+1\mathbf e_{S_{t+1}}, the indicator of the next state
  3. eSt+γM(St+1,⋅)\mathbf e_{S_t} + \gamma M(S_{t+1}, \cdot), the indicator of the current state plus the discounted SR of the next one
  4. γM(St+1,⋅)\gamma M(S_{t+1}, \cdot)
Show the answer

C. eSt+γM(St+1,⋅)\mathbf e_{S_t} + \gamma M(S_{t+1}, \cdot), the indicator of the current state plus the discounted SR of the next one

The SR's Bellman equation is M(s,⋅)=es+γ∑s′Pπ(s,s′)M(s′,⋅)M(s,\cdot) = \mathbf e_s + \gamma\sum_{s'}P^\pi(s,s')M(s',\cdot): the "reward" of a step is the indicator of the state occupied, counted at time 0. No environment reward enters; that is what lets the SR be reused across rewards.

Further reading

  • P. Dayan, "Improving generalization for temporal difference learning: The successor representation," Neural Computation 5(4), 613–624 (1993).
  • A. Barreto, W. Dabney, R. Munos, J. J. Hunt, T. Schaul, H. van Hasselt & D. Silver, "Successor features for transfer in reinforcement learning," Advances in Neural Information Processing Systems 30 (2017).
  • A. Touati & Y. Ollivier, "Learning one representation to optimize all rewards," Advances in Neural Information Processing Systems 34 (2021).
  • K. L. Stachenfeld, M. M. Botvinick & S. J. Gershman, "The hippocampus as a predictive map," Nature Neuroscience 20(11), 1643–1653 (2017).
  • I. Momennejad, E. M. Russek, J. H. Cheong, M. M. Botvinick, N. D. Daw & S. J. Gershman, "The successor representation in human reinforcement learning," Nature Human Behaviour 1(9), 680–692 (2017).