Learn once where a policy goes. Then the value of any new reward is one dot product per cell, with zero new experience. On our 31-cell grid, GPI combines three stored policies and reaches the optimal average value, 7.39, for a reward none of them learned.
Learn the successor representation: a map of where a policy spends its future. It turns a new reward into a value, and a new policy, at once.
Pick Successor map and tap a cell to see where the random walk goes from there. Pick Value and tap cells to place rewards: the values change at once. Pick GPI to see three stored policies share the work. Then we build, piece by piece, distances, the map, its backup, features, transfer and C-learning.
You need the value function and its Bellman equation (Q-learning) and goal-conditioned values (Multi-task and goal-conditioned RL). We build the rest from zero.
A supplement to UC Berkeley CS 185/285, Deep Reinforcement Learning, Sergey Levine (Spring 2026). It follows Part 4 of Lecture 24, multi-task and hierarchical RL (PDF). The words, toys and numbers here are our own.
Illustrative toy: a 6 × 6 grid with a wall in column 2 (31 open cells), gamma 0.9, a uniform random walk for the map. Cells are (row, column) from (0, 0) at the top left. The stored policies head for three corners (top left, top right, bottom right), with 10% random moves.
Chapter 0
Move a reward and count what a model-free learner must pay to catch up
A delivery robot learns the value of each spot in a warehouse for one drop-off point. Then the drop-off point moves. A model-free learner throws its values away and collects new experience. The robot's habits did not change. Only the reward did.
The course asks a sharp question: what is the smallest model that lets you evaluate a policy? A full model predicts the next state. For evaluation you need less: where the policy goes in the future, and how often. That map is the successor representation (SR), from Dayan (1993).
Left: TD learning rebuilds the values from new steps of experience. Right: the successor map prices the new reward at once. Pick a reward, then press Relearn.
Illustrative: the hero's grid and random walk, TD(0) with step size 0.05 on one long walk. The reward is 1 per step on a reward cell. "Within 10%" means the largest error is under a tenth of the largest true value.
TD needs thousands of new steps. The SR needs none, because it keeps the part that did not change: the policy's future. It sits between the two families of RL.
| Approach | What it stores | When the reward changes |
|---|---|---|
| Model-free (V or Q) | one number per state, for one reward | relearn from new experience |
| Successor representation | where the policy goes, for any reward | one dot product per state |
| Full model | the next-state chances p(s′|s,a) | plan again |
The failure. The SR belongs to one policy. If the robot's habits change, the map is stale. Measure it: compare the map's predicted value with real returns. Chapter 5 shows how to improve a policy anyway.
Chapter 1
Charge one point per step, read the value as a step count, and plan through a waypoint
A goal-conditioned value V(s,g) says how good state s is for reaching goal g (Multi-task and goal-conditioned RL, Chapter 3). Pick one reward: minus 1 for every step not at the goal. Set the discount gamma to 1 and end the episode at the goal.
V of s and g equals minus one plus the expected V of s-prime and g, if s is not g. It is zero if s is g.
Pay 1 for each step until you reach g. Unroll it and V(s,g) is minus the number of steps from s to g.
On our grid, cell (4, 0) to cell (4, 4) is 12 steps: 4 up, 4 across the top, 4 down. So V = −12.
Write d(s,g) = −V(s,g) for the step count of the best policy. A detour through any waypoint w is one way to reach g, so it can only cost as much or more.
V of s and g is at least V of s and w plus V of w and g.
Add the two legs through w. The total is never better than going straight. It ties when w lies on a best route.
From (4, 0) to (4, 4): through (0, 2) the legs are −6 and −6, a tie at −12. Through (5, 5) they are −14 and −2: −16, 4 steps worse.
Each cell shows minus its step count to the goal g. Choose what a tap moves, then tap a cell.
Step counts by breadth-first search on the hero's grid; moves are up, down, left and right.
This is why the course calls goal-conditioned RL "a lot like a model": V(s,g) tells you how easy each state is to reach. A planner can search over waypoints that maximise V(s,w) + V(w,g) (Nasiriany et al.). The inequality can also serve as an extra loss on the value network.
The failure. A learned V can break the inequality, so a planner trusts a shortcut that does not exist. Measure it: sample triples (s, w, g) and count the violations. Fix it with that count as a penalty in training.
Chapter 2
Swap two sums in the value function and pull out a map of where the policy goes
Take a reward that depends only on the state, r(s). The value of state st under policy π adds the reward of every future step t′, discounted by gamma. Each future reward is an average over where you might be at step t′. Group the terms by state instead of by time. Each state s then collects one weight: how often you stand there, discounted.
p-pi of s-future equals i, given s-t, equals one minus gamma, times the sum over t-prime of gamma to the t-prime minus t, times p of s-t-prime equals i.
For each future step, take the chance of being in state i. Shrink it by gamma once per step of delay. Add them all, then multiply by one minus gamma.
With made-up numbers: two states. From A you always go to B. From B you stay or go back to A, half and half. At gamma 0.9, the share of B in A's future is 0.621, and A's share is 0.379. They sum to 1.
Stack these shares for every state i into one vector, μπ(st). That vector is the successor representation of st. The value is now a weighted sum.
V-pi of s-t equals mu-pi of s-t, transposed, times r, over one minus gamma.
Multiply each state's share by its reward. Add them. Divide by one minus gamma.
In the two-state toy, reward 1 in B only: V(A) = 0.621 × 1 / 0.1 = 6.21. Solving the Bellman equation directly gives the same 6.21.
Teal shows μ(s) for the outlined cell under the random walk. Tap a cell, then drag gamma.
Exact maps: μ = (1 − γ)(I − γPπ)−1 on the hero's illustrative grid.
At low gamma the map hugs the cell. At high gamma it spreads through the doorway. The average look-ahead is gamma/(1 − gamma) steps: 9 at gamma 0.9.
The failure. A tabular map needs |S| numbers per state, so |S|² in all. For images that is hopeless. Measure your state count before you choose a table. Chapters 4 and 6 are the fixes.
Chapter 3
Split off the first step of the sum and learn the map by TD, one transition at a time
The sum in Chapter 2 runs to infinity. Nobody computes it directly. Pull out the step t′ = t. What is left is the same sum, started one step later, times gamma.
mu-i of s-t equals one minus gamma times delta of s-t equals i, plus gamma times the expected mu-i of s-t-plus-one.
It is a Bellman backup whose "reward" is one minus gamma when you stand in i. Do it for all 31 entries i at once: one vector update per transition.
The two-state toy, entry B of A's map: A is not B, so the first term is 0. Then 0.9 × μB(B) = 0.9 × 0.690 = 0.621, the value from Chapter 2.
The TD version replaces the average with one sampled transition from s to s′. With step size α, move the whole row toward the target.
μ̂(s) ← μ̂(s) + α [ (1 − γ) es + γ μ̂(s′) − μ̂(s) ]
Here es is the vector with 1 at s and 0 elsewhere. From a map of zeros, one step from A to B with α = 0.5 gives μ̂(A) = (0.05, 0). In matrix form the exact answer is (1 − γ)(I − γPπ)−1, the evaluation operator of RL theory, Chapter 1.
Left: the TD map of the outlined cell. Right: the exact map. Below: the largest error as experience grows. Press Learn.
Illustrative: one long random walk on the hero's grid, α = 0.1, gamma 0.9, every row updated by the TD rule above.
The failure. TD noise does not vanish with a fixed step size; the error stalls at a floor. Measure the error curve, as above. Fix it with a step size that decays, or by averaging the last updates.
Chapter 4
Track a few features in place of every state, and turn three weights into a value map
Suppose the reward is a weighted sum of a few features φj(s), such as "in the left room": r(s) = φ(s)Tw. Then you do not need the share of every state. You need the discounted total of each feature along the future. That total is the successor feature ψj. Here is the Q-like version, which also takes the first action.
psi-j of s and a equals phi-j of s, plus gamma times the expected psi-j of s-prime and a-prime.
The SR backup again, with the feature φ-j as the "reward". Choose φ-i to be one minus gamma when s is i, and you get the SR back.
The two-state toy with features "in A" and "in B": ψ(A) = (3.79, 6.21). Each entry is A's map share divided by 0.1.
The value follows in one line, because sums and weights commute.
Q-pi of s and a equals psi-pi of s and a, transposed, times w, when r of s equals phi of s transposed times w.
Multiply each successor feature ψ-j by its weight w-j and add. A new w gives a new Q with no new learning.
Toy, with weights w = (2, 1): V(A) = 2 × 3.79 + 1 × 6.21 = 13.79. Solving the Bellman equation for rewards (2, 1) also gives 13.79.
Three features: left room, right room, top row. Drag the weights w and watch V = ψTw. Then ask for a reward in one corner.
Illustrative: the hero's grid and random walk. ψ = (I − γPπ)−1Φ is exact here; a network would learn it by the backup above.
The win is size: 3 numbers per state in place of 31. If the features are few, learning ψ is much easier.
The failure. A reward outside the span of the features gets the best fit, not the truth. Ask for the corner reward above: the fit spreads it over the right room. Measure the fit error of w on reward samples. Fix it with richer features.
Chapter 5
Fit the weights of a new reward, then act greedily on one stored policy, or on the best of many
A new task arrives as reward samples {si, ri}. Successor features turn them into a policy in three steps. First, fit the weights.
w gets the argmin over w of the sum over i of phi of s-i transposed w, minus r-i, squared.
Find the weights whose predicted rewards miss the observed rewards by the least, in squared error. This is linear regression.
With made-up samples: features (1, 0) with reward 2, (0, 1) with 1, and (1, 1) with 3. The fit is w = (2, 1), with zero error.
Second, Qπ = ψπTw. Third, act greedily: π′(s) = argmaxa Qπ(s,a). That is one step of policy iteration. It beats π, but it is not optimal, because Qπ assumes you follow the old π afterwards.
Store successor features for several policies πk and you can do better. Generalized policy improvement (GPI, Barreto et al.) takes the best of them, in each state.
pi-prime of s equals the argmax over a of the max over k of psi-pi-k of s and a, transposed, times w.
For each action, ask every stored policy what it would earn afterwards. Keep the best answer. Pick the action with the best kept answer.
With made-up values in one state: policy 1 gives Q = (3, 1) for actions (a1, a2), policy 2 gives (2, 4). The max over k is (3, 4), so GPI picks a2, worth at least 4. Improving on policy 1 alone picks a1.
Arrows show GPI's action, coloured by the stored policy that wins there. Bars compare average values. Pick a reward, then switch policies off.
Illustrative toy: rewards of 1 per step on the rewarded corners ("Half and one" puts 0.5 on the top left). Values are exact, averaged over the 31 cells. "One step" improves the best stored policy alone.
GPI's promise: the new policy does at least as well as every stored policy, in every state. In the toy, "Two corners" gives GPI the optimum. "Half and one" leaves it a hair below.
The failure. If no stored policy goes near the reward, every Q is near zero and GPI picks almost at random. Measure the largest stored Q on the new reward. If it is tiny, learn a new policy.
Chapter 6
Tell real future states from random ones, and read the successor density off the classifier
In a continuous state space, the target δ(st = i) is zero for every sampled state: you never land exactly on i. C-learning (Eysenbach, Salakhutdinov and Levine, 2020) turns the problem into classification.
Build two piles of candidate future states. Positives D+ come from the real future of (st, at). Negatives D− are any states the policy visits, drawn from pπ(s). With equal piles, the best classifier gives this chance that a candidate is a real future, F = 1.
p of F equals one, given s-t, a-t and s-f, equals p-pi of s-f given s-t and a-t, over that plus p-pi of s-f.
The classifier compares two densities at s-f: how likely s-f is as a real future, and how likely as a random visit.
With made-up densities 0.3 and 0.1 at s-f, p(F=1) = 0.3 / 0.4 = 0.75.
Divide p(F=1) by p(F=0) and the shared denominator cancels. Multiply by pπ(sf), which does not depend on st or at.
p-pi of s-f given s-t and a-t equals p of F equals one over p of F equals zero, times p-pi of s-f.
Read the odds off the classifier. Multiply by how often the policy visits s-f. That is the successor density.
Odds 0.75 / 0.25 = 3. Times 0.1 gives 0.3: the density we started with.
How do you sample a real future? The SR weighs step t + Δ by (1 − γ)γΔ. So draw the gap Δ from that distribution and take the state Δ steps ahead in a trajectory.
P of Delta equals k equals one minus gamma, times gamma to the k, for k from zero up.
At each step, flip a coin that stops with chance one minus gamma. The number of steps before it stops is Δ. The course writes Δ ~ Geom(γ).
At gamma 0.9: P(Δ = 0) = 0.1, P(Δ = 1) = 0.09. The mean gap is gamma/(1 − gamma) = 9 steps.
A 12-cell chain, start at cell 2. Teal outlines: the exact map. Grey bars: odds times p(sf). Press Train.
Illustrative: moves right 0.5, left 0.4, stay 0.1, gamma 0.9. Episodes start at a random cell and last 20 steps. One logit per cell for this start state, cross-entropy, a step size that starts at 0.05 and shrinks. We fold the action into the policy.
This version is on-policy: D+ comes from π's own futures. The paper also derives an off-policy version.
The failure. Where the policy rarely visits, D− has few samples and the odds are noisy. Measure how many negatives each region gets. Fix it with more varied start states.
Chapter 7
Keep the terms, the numbers, the checks and the code in one place
One idea runs through the lesson. Store where a policy goes, separate from what it earns. Then a new reward costs a dot product, and several stored policies combine through GPI.
| Term | What it is | Number to remember |
|---|---|---|
| Goal value V(s,g) | minus the step count, reward −1, gamma 1 | (4, 0) to (4, 4): −12; via (5, 5): −16 |
| Successor map μ(s) | discounted share of the future in each state; sums to 1 | two-state toy: (0.379, 0.621) |
| Value from the map | V = μTr / (1 − γ) | 0.621 / 0.1 = 6.21 |
| SR backup | "reward" (1 − γ) in state i | 0.9 × 0.690 = 0.621 |
| Successor features ψ | discounted feature totals; Q = ψTw | w = (2, 1): 13.79 |
| GPI | argmax over a of max over k of Qπk | toy, two corners: 7.39, the optimum |
| C-learning | SR = classifier odds × pπ(sf) | odds 3 × 0.1 = 0.3 |
| Future gap Δ | P(Δ = k) = (1 − γ)γk | mean 9 steps at gamma 0.9 |
pythonimport numpy as np def successor_map(P_pi, gamma): # P_pi: [S, S] next-state chances under pi. Row s of M is mu(s); each row sums to 1. S = P_pi.shape[0] return (1 - gamma) * np.linalg.inv(np.eye(S) - gamma * P_pi) def value_from_map(M, r, gamma): return M @ r / (1 - gamma) # V = mu^T r / (1 - gamma), every state def td_update(M, s, s_next, gamma, alpha): target = gamma * M[s_next] target[s] += 1 - gamma # "reward" (1 - gamma) in the current state M[s] += alpha * (target - M[s]) def gpi_action(psi, w): # psi: [K, A, d] successor features of K stored policies in one state; w: [d] q = psi @ w # [K, A]: Q of every stored policy return int(np.argmax(q.max(axis=0))) # best policy per action, then best action def future_gap(gamma, rng): return rng.geometric(1 - gamma) - 1 # P(k) = (1 - gamma) gamma^k, k = 0, 1, ... # C-learning: label (s_t, a_t, s_{t+gap}) as 1 and (s_t, a_t, s ~ p_pi(s)) as 0, train a classifier C, # then density(s_f | s_t, a_t) = C / (1 - C) * p_pi(s_f).
Now press Present or Teach and derive from memory: the SR from V-pi, its backup, and the C-learning odds. Then go back to the hero, place two rewards, and predict which stored policy wins each room before you pick GPI.
This supplement follows UC Berkeley CS 185/285, Deep Reinforcement Learning, Sergey Levine (Spring 2026): the course page and Lecture 24 on multi-task and hierarchical RL, Parts 3 and 4. The lecture cites Dayan (1993) for the SR, Barreto et al. (2016) for successor features and transfer, and Eysenbach, Salakhutdinov and Levine (2020) for C-learning. The words, toys and numbers here are our own.