REINFORCE works — but its gradient is so noisy you can barely see the signal. Bolt a learned judge of how good each state is onto the policy, and the noise collapses. That judge is the critic, and it is the workhorse inside A2C, PPO, and SAC.
In Lecture 9 we built REINFORCE: roll out a whole episode, measure its total return, and nudge the policy so that every action it took becomes more likely in proportion to how good the whole episode turned out. It works. It is also, in the instructor's blunt words, high variance.
Here is the problem in one picture. Suppose a robot took a perfectly sensible action early in an episode, but then — thirty steps later, for unrelated reasons — the episode ended in disaster. REINFORCE doesn't know which step was to blame. It credits the entire trajectory's return to every action in it. A good action inside a bad episode gets punished; a lucky-but-dumb action inside a good episode gets rewarded.
So the lecture asks a sharp question. Could we keep a running estimate of how good a state is — a learned "expected score from here" — and use it to subtract off the boring, predictable part of the return? Then the gradient would only respond to the part that is genuinely surprising: did this action do better or worse than what we already expected from this state?
That single idea — a learned judge that says "from here, you should expect about this much" — is the critic. The policy that chooses actions is the actor. Train them together and you get the actor–critic family. Before any math, feel the variance problem yourself.
Each Roll samples one episode's return and plots the gradient weight REINFORCE would use on the first action. Toggle Use a critic baseline to subtract the state's expected value first. With the baseline, the weights cluster near zero and only the genuinely good/bad actions stand out.
Let us write down where Lecture 9 left us. The policy gradient, after applying causality (an action can only be credited with rewards that come after it), is an expectation over states and actions:
Read it slowly. The term ∇θ log πθ(a|s) is the direction in parameter space that makes action a more likely in state s. The scalar Qπ(s,a) — the action-value, the expected discounted return if you take action a in state s and then follow the policy — is the weight: how hard to push in that direction. In REINFORCE we estimate Q with the observed reward-to-go from each sampled action.
Now the trick. The instructor proves a small, beautiful fact: you can subtract any function b(s) that depends only on the state — called a baseline — and the gradient's expectation does not change at all:
The reason is one line of algebra. The extra term we introduced is the expectation of b(s) · ∇θ log πθ(a|s). Because b(s) does not depend on the action, we can pull it outside the sum over actions, and what is left is the policy's own gradient summed over all its actions:
The middle step uses the identity π · ∇ log π = ∇ π (the log-derivative trick). The action probabilities always sum to 1, and the gradient of the constant 1 is zero. So the baseline contributes nothing in expectation — it is unbiased.
So which b(s) is best? Intuitively: subtract off "how good this state typically is", so that the weight on an action measures only whether it beat the state's average. The natural choice is the state-value function Vπ(s) — the expected return from state s when you simply follow the current policy. That is the seed of the critic, and the subject of the next two chapters.
Returns from one state scatter around their mean (the dashed line). The gradient weight is return − baseline. Slide the baseline toward the mean and the bars shrink toward zero spread — the estimate gets quieter without moving its average.
Set the baseline to the state-value: b(s) = Vπ(s). The weight on each action becomes a quantity with its own name and its own deep meaning — the advantage function:
Translate it into English. Qπ(s,a) is "expected return if I take action a here, then follow my policy." Vπ(s) is "expected return if I just follow my policy from here" — the average over the actions my policy would have picked. Their difference is exactly:
With the advantage, the policy gradient takes the form that the rest of deep RL is built on:
Imagine a state where every action leads to a return around +100, give or take a little. Raw REINFORCE weights every action by ~+100 and shoves them all up hard — even though the policy learns nothing about which action to prefer (they're all the same). The advantage, by contrast, subtracts the ~+100 average, leaving small numbers that say "this one was +2 better, that one was −3 worse." The huge, shared, uninformative offset is gone. What remains is pure signal.
Three actions in one state, each with a noisy return around a high common mean. Warm bars = raw return (the weight REINFORCE uses). Teal bars = advantage (return minus V). Crank the common return level: the warm bars grow huge and nearly equal; the teal bars stay small and show the real ranking.
We want the advantage, which needs Vπ(s). But Vπ is exactly the thing we don't know — if we knew the value of every state we'd nearly have the problem solved. So we learn it. A second network, the critic Vφ with its own parameters φ, takes a state and outputs a single number: its estimate of the expected return from that state.
How do we train it? This is just policy evaluation — the problem from Lecture 7. The most direct option:
Roll out the policy, record the actual reward-to-go from each state, and fit the critic to those numbers by regression. Minimize the squared error between the critic's prediction and the observed return:
where Gt is the true observed discounted reward-to-go from state st. This is unbiased — Gt is a real sample of the return — but it inherits the same fat variance as REINFORCE, because each Gt is a full noisy rollout. We have moved the noise, not removed it. The instructor asks: can we do better?
There is a catch the lecture flags explicitly. We use Vφ inside the advantage that steers the actor. If Vφ is a bad estimate of the true Vπ, the advantage is wrong, and the actor is pushed in a wrong direction. Subtracting an inaccurate baseline can even add bias — the very thing baselines were supposed to avoid. So the critic must be good enough. This tension — a learned critic reduces variance but can introduce bias — is the heartbeat of the whole lecture, and we make it precise next with the TD trick.
"Can we do better?" than waiting for a full noisy rollout? Yes — and the idea is the single most important move in value-based RL. Recall the Bellman equation: the value of a state equals the immediate reward plus the discounted value of wherever you land next:
So instead of waiting for the whole future, take one real step, observe the reward r and the next state s′, and use the critic's own estimate of the rest. That gives a target:
and we train the critic to match it: L(φ) = ( y − Vφ(s) )². Using your own current estimate to build the target for your own update is called bootstrapping — pulling yourself up by your own bootstraps. The target y is a bootstrapped estimate: one real reward plus a guess about everything after.
Here is the payoff that ties everything together. Plug the one-step target into the advantage, A = Q − V, using the same Bellman idea for Q(s,a) ≈ r + γV(s′):
This quantity δ (delta) is the temporal-difference (TD) error: the gap between what we actually got plus where we landed, and what we expected. And it does double duty:
max in sight (unlike Q-learning), which is why the critic update is more stable — it evaluates the policy you actually have, rather than chasing a moving greedy target.
A true value (dashed). The Monte Carlo estimate is centered on it but scatters widely. The one-step bootstrap is tight but offset by the critic's error. Slide the critic error up: the teal cloud stays tight but drifts off-target (bias); the warm cloud stays centered but never gets quiet (variance).
Now build the advantage from raw returns yourself and watch its variance fall against the baseline.
Let us make the architecture concrete — what I cannot create, I do not understand. Actor–critic is two function approximators sharing one experience stream. Here is exactly what flows where, with shapes.
Notice the design decisions, each made for a reason:
max"? The critic evaluates the current policy (Vπ), not the best possible action (as Q-learning's max does). Evaluating a fixed target is more stable than chasing a greedy one.Now implement one full step of both updates on a tiny problem and confirm the critic moves toward its target while the actor shifts toward the higher-advantage action.
Numbers make it real. Take a tiny scenario and compute every quantity with a calculator — an advantage, one critic update, one actor update, and an n-step return — so you could reproduce the algorithm from memory.
A robot is in state s. Our critic currently believes:
The bootstrapped target is the reward plus the discounted next value:
The TD error — our one-step advantage estimate — is the target minus the current value:
Positive: the action did 2.4 better than the critic expected. Good news — we will make this action more likely.
Regress V toward the target. With critic learning rate αv = 0.5:
The critic moved from 5.0 toward the target 7.4 — it now expects more from this state. Notice it did not jump all the way to 7.4; the learning rate damps the move, because the target is itself only a one-sample estimate.
Say the actor is a 2-action softmax with equal logits, so before the update P(a) = 0.5. The update raises the chosen action's logit by απ · δ. With απ = 0.5, the logit of a rises by 0.5 × 2.4 = 1.2, so logits go from (0, 0) to (1.2, 0). The new probability of the chosen action:
The chosen action's probability climbed from 0.50 to about 0.77. The positive advantage pushed the policy toward it — exactly as intended.
Now a multi-step target, the bridge to the next chapter. Suppose over three steps the robot collects rewards r0 = 2, r1 = 1, r2 = 3, and the critic's value of the state after step 3 is V(s3) = 4, with γ = 0.9. The 3-step return sums the first three real rewards (discounted) and then bootstraps with the critic:
Compare to the 1-step target from the same start, which would be r0 + γV(s1): it trusts the critic after just one real reward. The 3-step version uses three real rewards before trusting the critic — more real signal, less reliance on the (possibly wrong) critic, but more accumulated reward noise. That is the n-step knob, and we turn it next.
We now have two extremes for the advantage. The 1-step TD error uses one real reward and trusts the critic for everything after — low variance, but biased by the critic's error. The Monte Carlo advantage uses the entire observed return — unbiased, but high variance. Everything good lives in between.
The obvious interpolation: take n real rewards, then bootstrap. The n-step advantage is
Small n → near the 1-step TD error (low variance, more bias). Large n → near Monte Carlo (high variance, less bias). The lecture notes this is exactly what eligibility traces implement efficiently.
Rather than pick a single n, Generalized Advantage Estimation (GAE, Schulman et al. 2016 — the slide that "unifies PG and actor–critic") takes an exponentially-weighted average over all n-step advantages, controlled by a single knob λ in [0, 1]. The clean way to write it: let δt = rt + γV(st+1) − V(st) be each step's TD error. Then
The single parameter λ sweeps the whole bias–variance line:
The advantage estimator's bias (from trusting an imperfect critic) and its variance (from real reward noise) as λ goes 0→1. At λ=0 it is the 1-step TD advantage (low variance, high bias); at λ=1 it is Monte Carlo (high variance, ~zero bias). The total error dips in the middle — that minimum is the sweet spot.
Implement GAE yourself and confirm the two endpoints: λ = 0 reproduces the 1-step TD advantage, λ = 1 reproduces the full Monte Carlo advantage.
Everything in one place. A robot lives on a small grid. The critic learns a value for every cell (shown as a heatmap — warm = high value, near the goal). The actor learns which way to move from each cell (shown as arrows). Both train from the same TD errors, online, as the robot wanders.
Press Train. The goal (teal ring) pays +1. Watch the heatmap fill in from the goal outward (the critic learning V) while the arrows swing to point along the value gradient (the actor learning the policy). Raise λ to use longer-horizon advantages; raise reward noise to see why a learned critic earns its keep.
Two things to notice as it trains. First, value propagates backward from the goal — the cell next to the goal learns its worth first, then its neighbors, then theirs. That is bootstrapping in action: each cell's target borrows its neighbor's current estimate. Second, the arrows follow the value — the moment a cell's neighbor looks more valuable, the actor's TD error there goes positive and the arrow swings toward it. The two networks bootstrap each other into a good policy without a single full Monte Carlo rollout.
You started with a gradient you could barely see and ended with two networks that quiet it down by sharing one signal. Here is the whole lecture in one frame, then where it leads.
max → more stable than Q-learning.This lesson sits in the model-free RL arc of the 16-831 series. Continue and go deeper:
"The actor chooses; the critic keeps score. Together they hear the signal through the noise."