5.2.8 · D4Deep & Advanced RL

Exercises — Advantage Actor-Critic (A2C - A3C)

2,930 words13 min readBack to topic

This page is a self-testing ladder. Each rung is harder than the last:

  • L1 Recognition — can you name the pieces?
  • L2 Application — can you plug numbers into the formulas?
  • L3 Analysis — can you explain why a step works and what breaks if you skip it?
  • L4 Synthesis — can you combine ideas (n-step, entropy, on-policy) into new reasoning?
  • L5 Mastery — can you design, debug, and prove?

Every problem hides its full solution inside a collapsible [!recall]- callout — read the problem, try it yourself, then reveal. Parent topic: Advantage Actor-Critic (A2C - A3C).

Before we start, one reminder of the symbols we will reuse (each was built in the parent note):


L1 — Recognition

Recall Solution 1.1

(a) → (ii): the actor chooses actions. (b) → (i): the critic estimates a state's value. (c) → (iii): the TD error is the surprise — did the action do better or worse than the critic predicted? A positive means "better than expected."

Recall Solution 1.2

The blank is , the state value (the value averaged over actions). So measures "how much better is this specific action than the state's average action?" Subtracting a baseline that depends only on the state reduces variance without changing the expected gradient — this was proven in the parent note (Policy Gradient Theorem): .

Recall Solution 1.3

False. A2C/A3C are on-policy — every gradient must come from the current policy. They decorrelate data with parallel environments/workers, not a stale buffer. (See the parent-note mistake callout.)


L2 — Application

Recall Solution 2.1

→ the action did better than expected, so the actor loss pushes to make more likely.

Recall Solution 2.2

Strongly negative → the outcome was far worse than average from , so the actor loss decreases this action's probability. We steer away from .

Recall Solution 2.3

Why the on the bootstrap? Each reward is discounted by how far in the future it lands: by , by , by . After using 3 real rewards, the next thing we count is the critic's estimate of everything from step onward — and step is three steps ahead, so its whole value must be discounted by to sit on the same footing as the rewards. Using instead of would treat a far-future estimate as if it happened right now. Real rewards: Bootstrap tail:

Recall Solution 2.4

Uniform: Peaked: The uniform policy has much higher entropy (more exploration); the peaked one is nearly collapsed. The bonus in the actor loss rewards the high-entropy state, keeping the door open.


L3 — Analysis

Recall Solution 3.1

First verify the scores form a valid gradient of : they must satisfy because . Check: ✓ Now the baseline term: Interpretation: the baseline factors out and multiplies a sum that is structurally zero. That is why we can subtract for free — the parent-note proof, made concrete.

Recall Solution 3.2
  • (1-step) uses one real reward and leans heavily on the critic . If the critic is wrong, this estimate is biased, but it is low variance (only one random reward inside).
  • (3-step) uses three real rewards. It trusts the (possibly noisy) environment more and the critic less → less bias, more variance. They differ numerically because they are different points on the same bias–variance dial; Generalized Advantage Estimation (GAE) blends all smoothly to get the best of both.
Recall Solution 3.3

With a stop-gradient, only moves toward a fixed target — genuine learning. Without it, the optimizer can shrink the loss by moving both ends together: it can push (inside the target) toward , minimizing the squared difference without either being correct. You'd be "moving the goalposts to meet the ball." The value function collapses toward a self-consistent but meaningless constant. Hence: treat the target as a constant.

The figure below makes the trade-off visible: the flat magenta line is the low-variance 1-step (critic) estimate, and the widening orange envelope is the growing spread of n-step returns as increases. Read it as: the further into the future you sum real rewards, the wider the cloud of possible advantage values — that width IS the extra variance you pay for lower bias.

Figure — Advantage Actor-Critic (A2C - A3C)

L4 — Synthesis

Recall Solution 4.1

A2C average: One synchronous step of size . A3C is asynchronous: each worker pushes its own gradient to the shared network the moment it's ready — no waiting, no averaging. This gives speed on many CPUs but noisier, order-dependent updates. A2C = "A3C Awaiting All workers."

Recall Solution 4.2

Set . The sum has a single term : . The bootstrap becomes . So The n-step family contains the TD error as its simplest member — exactly the Temporal-Difference Learning connection.

Recall Solution 4.3

Increase , the entropy coefficient. Mechanism:

  1. A collapsed policy has near-zero entropy .
  2. The term in the loss becomes a large penalty when is small (minimizing means maximizing ).
  3. Gradient descent therefore pushes back toward a spread-out distribution → the agent explores again and can escape the bad local optimum. This is the parent-note "keeps the door open" idea, quantified.

L5 — Mastery

Recall Solution 5.1

Take the expectation over the reward and next state, holding fixed: By the definition of the action-value function, (this is the Bellman expectation for : reward now plus discounted value of wherever we land). Hence So is an unbiased advantage estimate when the critic is perfect — the theoretical justification for "the TD error IS the advantage."

Recall Solution 5.2

(a) (b) Positive advantage → minimizing this loss increases → action becomes more likely. ✓ (c) target . Loss Critic pushes from up toward .

Recall Solution 5.3

Algebra (telescoping). Write out the sum of discounted TD errors: Split into three running pieces: Now look at the two value sums. The forward sum, reindexed with , runs over giving terms . The backward sum runs over giving terms . Every interior value for appears once with (from forward) and once with (from backward), so they cancel. What survives is only the two endpoints:

  • the forward sum's last term ,
  • the backward sum's first term .

Therefore Numeric check (). Directly: Via TD errors: Both routes give — the identity holds.

The figure below shows the same telescoping visually: two TD-error arcs whose interior value term cancels, leaving only the endpoints.

Figure — Advantage Actor-Critic (A2C - A3C)

Recall One-line self-audit of every numeric answer

2.1 → · 2.2 → · 2.3 → · 2.4 → · 4.1 → · 5.2 → · 5.3 → (both ways).