5.2.9 · D4Deep & Advanced RL

Exercises — Proximal Policy Optimization (PPO)

2,114 words10 min readBack to topic

Throughout, we reuse the core object. Let me restate it in plain words so no symbol is unearned.


Level 1 — Recognition

Recall Solution

Numerator = the new policy (the one we are updating). Denominator = the old policy that collected the data. means the new policy makes this sampled action == less likely== than the old policy did. It sits exactly on the lower clip edge when .

Recall Solution

just squeezes the number back into :

  • is inside
Recall Solution

= better-than-average action, so we want it more likely ⇒ push up (above ). Recall from the Policy Gradient Theorem that we scale by : positive advantage pushes probability up.


Level 2 — Application

Recall Solution
  • Unclipped:
  • Clip:
  • . Both branches equal ⇒ gradient flows, PPO acts like plain policy gradient here.
Recall Solution
  • Unclipped:
  • Clip:
  • . Clipped branch active ⇒ : no reward for pushing further.
Recall Solution
  • Unclipped:
  • Clip:
  • . The more negative value wins the min. Clipped branch active ⇒ gradient : PPO refuses to suppress a bad action even more in one step.
Recall Solution
  • Unclipped:
  • Clip:
  • . Unclipped active ⇒ gradient flows to push down: we are always allowed to undo a mistake.
Figure — Proximal Policy Optimization (PPO)

Level 3 — Analysis

Recall Solution

: the objective rises with until it hits the cap . So gradient is zero for . Below that it flows. : objective is (a decreasing line since ). We want it larger, i.e. smaller. The clip caps the "reward" once . So gradient is zero for . Summary of the flat (zero-gradient) region: These are exactly the "you've moved far enough in the helpful direction" zones.

Recall Solution

For , compares two increasing multiples of ; the min tracks the smaller multiplier:

\begin{cases} r_t\,\hat A, & r_t\le 1.2\\[4pt] 1.2\,\hat A, & r_t> 1.2 \end{cases}$$ Below $r_t=0.8$: $\operatorname{clip}=0.8$ but $r_t<0.8$, and since $\hat A>0$ the **min picks $r_t$** (smaller) — so the low side is *not* flattened. The curve rises, flattens after $1.2$. (This is the blue curve in the next figure.)
Recall Solution

For , multiplying by a negative number flips which multiplier gives the smaller product; the min now picks the larger multiplier:

\begin{cases} 0.8\,\hat A, & r_t< 0.8\\[4pt] r_t\,\hat A, & r_t\ge 0.8 \end{cases}$$ Flat (gradient zero) for $r_t<0.8$; a downward-sloping line (penalty grows) for $r_t\ge0.8$, including the whole region above $1.2$ — so raising a bad action's probability is **never** shielded. (Pink curve, next figure.)
Figure — Proximal Policy Optimization (PPO)

Level 4 — Synthesis

Recall Solution

Ratios are computed from log-probs to stay numerically stable: Since and :

  • Unclipped
  • Clipped
  • , clipped branch active, gradient .
Recall Solution

Per-sample (from L2 logic):

  1. Mean .
Recall Solution
  • Value loss: ; times .
  • Entropy bonus: . (This term, from Entropy Regularization, keeps exploration alive.) Why signs: value loss is subtracted (we minimise squared error while maximising ); entropy is added (we reward randomness).

Level 5 — Mastery

Recall Solution

PPO stops rewarding a positive-advantage action once . To cap the rewarded range at , set . What it does NOT constrain: for , ratios above here are left open by design — so a bad action wrongly made more likely can still have arbitrarily large in the objective; the gradient (correctly) drives it back down but PPO does not hard-cap it. Clipping is a soft trust region, unlike TRPO's hard KL constraint.

Recall Solution

(a) ⇒ objective , slope ⇒ push up. (b) ⇒ flat ⇒ zero. (c) ⇒ flat ⇒ zero (already suppressed enough). (d) ⇒ objective , slope ⇒ increasing lowers , so gradient pushes down.

Recall Solution

Mechanism: the Importance Sampling ratio is only trustworthy near . With no clip, the optimizer keeps pushing for the largest (often noisy) positive . After a couple of epochs the new policy is far from the old one, so the surrogate no longer approximates the true return — the "improvement" is fictitious and the real policy degrades (collapse). Fix: reinstate (or add a KL penalty). The clip zeroes the gradient once for good actions, keeping every epoch's update inside the region where the surrogate is valid — this is precisely PPO's cheap stand-in for the Actor-Critic Methods + TRPO trust region.