5.2.7 · D2Deep & Advanced RL

Visual walkthrough — Actor-critic methods

2,467 words11 min readBack to topic

Step 0 — The words we will use (drawn, not assumed)

Before any math, three plain-language ideas, each pinned to the first figure.

  • A state is "the situation right now" — where the little robot is standing on a board.
  • An action is "the move it picks" — up/down/left/right.
  • A reward is "the points the world hands back" right after the move.
  • A policy is a dice the robot rolls: given the situation , it gives a probability to each action . The little (theta) is just the set of knobs we can turn to bias those dice.
Figure — Actor-critic methods

Step 1 — The goal, and the gradient that chases it

WHAT. We want to turn the knobs so the robot's average return is as big as possible. Call that average . The Policy Gradient Theorem tells us which way to turn the knobs:

WHY this shape. Read it as a product of two arrows.

  • is a vector in knob-space pointing in the direction that makes the action we actually took more probable. (, "nabla theta", just means "the slope with respect to every knob at once.")
  • is a scalar weight — a single number saying how much we want that action repeated. Positive → push the action up; negative → push it down.

PICTURE. Figure s02 shows knob-space with the "make--likelier" arrow, and the weight stretching or flipping it.

Figure — Actor-critic methods

REINFORCE's choice is . Correct on average, but is that whole-future dice roll. We will now transform step by step: first , then , then the advantage , and finally the TD error . Watch the same slot get better and better.


Step 2 — Picture the variance villain

WHAT. Plot the same good action taken many times; each time lands somewhere different because the rest of the episode is random luck.

WHY. If the weight jumps between and for an identically good action, the knob-pushes fight each other and learning crawls. The average is right; the scatter is the problem.

PICTURE. Figure s03: a cloud of dots with a wide spread, and one honest "true expected value" line through the middle. The gap between any dot and that line is pure noise we want to delete.

Figure — Actor-critic methods

Step 3 — We are allowed to subtract a baseline (the zero-trick)

WHAT. Replace with , where is any number that depends only on the state, not the action. Claim: this changes nothing about the average gradient.

WHY it's legal. The extra piece averages to exactly zero:

  • because probabilities over all actions must add to one.
  • The slope of the constant is . Done — the baseline vanishes in expectation, so the update stays unbiased.

PICTURE. Figure s04: the arrows for each action, summed, cancel to zero when weighted by — a balanced mobile hanging level.

Figure — Actor-critic methods

Step 4 — Name the middle: the value , and the advantage

WHAT. Define the state-value = the average return you expect starting from and following the policy. Choose the baseline . And define the action-value = the average return if you take action first, then follow the policy. Our weight slot is now , the advantage:

WHY. Subtracting the state's own average removes the "is this state rich or poor at all?" nuisance, leaving only how much action beats the average action here. That sign is all the actor needs.

PICTURE. Figure s05: a number line at state . is the middle mark; for several actions sit above/below it; the coloured gap is what we keep.

Figure — Actor-critic methods

Step 5 — We can't compute and exactly, so bootstrap (the TD trick)

WHAT. needs the full future — the very thing we're avoiding. The Bellman relation splits it into "one step, then the rest" — but it holds only as an average over the randomness of the reward and the next state:

  • The says: average over which reward and which next state the world hands back after taking in . Only on average does one step plus the rest equal .

On a single sampled transition we drop the average and use the one draw we actually got as a noisy estimate. Replace the true, unknown with a learned estimate (the critic — is its own set of knobs). Our weight slot becomes:

WHY this tool and not full returns? Full returns wait for the episode to end (high variance, offline). Bootstrapping — trusting your own next-step estimate — turns the infinite future into one real reward plus one guess. This is exactly Temporal Difference Learning: learn a guess from a guess.

Term by term:

  • — the one honest fact this step gives us.
  • — discounted critic-guess of the rest of the future from the new state.
  • — subtract what we expected the whole thing to be worth. The difference is the surprise.

PICTURE. Figure s06: two stacked bars — "what we predicted" versus "what we now believe" — with the gap labelled .

Figure — Actor-critic methods
Recall The whole chain of substitutions into the same slot

(REINFORCE) ::: then (baseline, Step 3) ::: then (Step 4) ::: then (one-sample bootstrap, Step 5). Same slot, four upgrades.


Step 6 — One number, two jobs (and where the update rules come from)

WHAT. The single scalar drives both updates. First, a word on the step sizes and :

WHY the critic update has that exact form. The critic wants its guess to match the one-step target. Measure the miss with a squared-error loss (squared so over- and under-shooting both count, and big misses hurt more): Take the slope with respect to , treating the target as a frozen constant (only the end is differentiated): Gradient descent moves against the slope, , which flips the sign back to :

WHY the same twice.

  • To the critic, is "you mis-predicted by this much" → move toward the truth.
  • To the actor, is the one-sample advantage that now fills the slot from Step 1 → scale the "make--likelier" arrow by it.

Stop-gradient warning (a case you must not fumble): the target is a frozen constant, as we used above. This is semi-gradient TD; differentiating the target too creates chasing-your-own-tail instability.

PICTURE. Figure s07: in the centre, two arrows fanning out — left to the critic net, right to the actor net.


Step 7 — Walk every sign (no scenario left unshown)

The whole method hinges on the sign of . Three cases, all pictured together in s08 with the numbers from the parent's worked examples.

Case Numbers () Actor does Critic does
Positive make more likely raise
Negative make less likely lower
Zero no push leave

Notice case two: a positive reward still gives a negative , because the future collapsed (we expected , realized only ). Advantage compares against expectation, not against zero — the entire reason this beats raw reward.


The one-picture summary

Figure s09 compresses all seven steps into one blueprint: state → actor rolls the policy dice → world returns and → critic computes → the same pushes both nets → loop. Every symbol on it was earned above.

Recall Feynman: retell the whole walkthrough in plain words

We wanted the robot's dice () to favour good moves. The honest way (REINFORCE) rewards each move by the whole random future — correct but wildly noisy. So we subtract a "how good is this spot normally?" number ; that subtraction is free because it averages to zero, and it deletes most of the noise. The leftover is the advantage: how much this move beats the typical move. We can't know the future exactly, so we peek one real step (), guess the rest with the critic , and compare to what we predicted . That gap is the TD error — one number that says "you were surprised this much." It tells the critic to fix its guess (it's the slope of a squared-error loss) and tells the actor to repeat (or avoid) the move, scaled by the surprise. The same slot from the very first formula just kept getting sharper: return → return-minus-baseline → advantage → TD error. Positive pushes up, negative pushes down, zero does nothing — even when the reward looked great.



Connections

  • Actor-critic methods — the parent; this page is its derivation in pictures.
  • Policy Gradient Theorem — Step 1's starting arrow.
  • REINFORCE — the high-variance baseline we improved on (Step 2).
  • Advantage function — formalised in Steps 3–4.
  • Temporal Difference Learning — the bootstrap of Step 5.
  • A3C and A2C — same math, parallel plumbing.
  • Generalized Advantage Estimation (GAE) — smoother multi-step version of Step 5's advantage.
  • Proximal Policy Optimization (PPO) — clips the actor step of Step 6 for stability.