5.2.7 · D3Deep & Advanced RL

Worked examples — Actor-critic methods

4,085 words19 min readBack to topic

The scenario matrix

Every actor-critic step reduces to computing and asking "was this better or worse than the critic expected?". The table below lists every distinct cell — every sign, every degenerate input, every limit. Each of the worked examples below is tagged with the cell(s) it covers.

Cell Situation What is special Sign of Example
C1 Reward good and future looks up ordinary "good" step Ex 1
C2 Reward positive but future collapses good reward, bad news Ex 2
C3 Reward negative but future brightens bad reward, good news Ex 3
C4 Critic already perfect expectation met exactly Ex 4
C5 Terminal state () no future term either sign Ex 5
C6 (myopic) vs (far-sighted) limiting values of changes with Ex 6
C7 Softmax actor direction which logits move, how much driven by Ex 7
C8 Real-world word problem translate to either Ex 8
C9 Exam twist: backprop-through-target trap why stop-gradient Ex 9
C10 Multi-step / -step return vs 1-step bias–variance trade either Ex 10

Worked examples

Example 1 — the ordinary "good" step (Cell C1)

Figure below (s01): a value "thermometer" for this exact example. The chalk-blue mark is the critic's belief ; the pale-yellow mark is the realized target ; the pink arrow between them is . Read the figure as: " is literally the vertical gap between what we believed and what we observed — and its arrow points UP, so the action's probability goes UP."

Figure — Actor-critic methods

Example 2 — good reward, bad news (Cell C2)


Example 3 — bad reward, good news (Cell C3)


Example 4 — the critic is already perfect (Cell C4)


Example 5 — terminal state, no future (Cell C5)

Figure below (s03): the terminal-state convention made visual. The left path (correct) multiplies the future value by a "done" mask of , so only the reward survives and the pink arrow points down (). The right path (buggy) leaks a nonzero through, flipping the arrow up (). The picture makes the sign flip literal: forgetting the mask reverses what the actor learns.

Figure — Actor-critic methods

Example 6 — the two limits of (Cell C6)

Figure below (s02): plotted against for this fixed transition. Follow the yellow curve from left (myopic, ) to right (far-sighted, ); the pink dot marks the sign-flip at . The lesson the figure makes visible: your choice of horizon can turn the same real experience from "punish this action" into "strongly reward it".


Example 7 — softmax actor, which logits move (Cell C7)


Example 8 — real-world word problem (Cell C8)


Example 9 — exam twist: the stop-gradient trap (Cell C9)


Example 10 — 1-step vs n-step return (Cell C10)


Active recall

Recall Same reward, opposite update — how?

Reward sign () does not determine the update sign; does. A positive reward with a collapsing future (Ex 2) gives ; a negative reward with a brightening future (Ex 3) gives .

Recall What is

at a terminal state, and why does it matter? It is by definition (no future after the episode ends). In code, a (1 - done) mask multiplies the future term. Forgetting this and plugging a nonzero value can flip the sign of and corrupt learning (Ex 5).

Recall What is the difference between

and , and how does the advantage use both? = value of committing to this specific action; = value of the average action in . Advantage is "how much better than average this move is", and its one-sample estimate is .

Recall Why does

mean "no update"? multiplies both the actor and critic update rules. If the critic's forecast was exactly met, there is no surprise, so the correct behaviour is to leave everything unchanged — a healthy fixed point (Ex 4).

Recall What does "stop-gradient on the target" mean in code?

Compute with current weights, then .detach() / tf.stop_gradient it so autodiff treats as a constant. This yields the correct one-term semi-gradient ; differentiating through the target adds a spurious -scaled residual term (Ex 9).


Mnemonic


Connections