Part XVI — Reinforcement Learning: Bandits, MDPs, Policy Gradients & PPO · Chapter 9

Proximal Policy Optimization (PPO)

Hook

Actor-critic's gradient step can, in principle, be as large as the math allows — nothing stops a single update from making a good action ten times more likely in one shot. If the advantage estimate that step was based on happens to be wrong (and it often is, especially early on), that's a huge, hard-to-undo mistake.

Intuition
unclipped = 1.00, clipped = 1.00

Drag the ratio rr — how much more (or less) likely the new policy makes the action the old policy took. The dashed line is the plain, unlimited objective; the bold line is PPO's version. They agree almost everywhere, then the bold line goes flat once rr crosses 1+ε1+\varepsilon: past that point, moving further doesn't earn any more reward in the objective, no matter how far the policy actually moves.

Formalize

With probability ratio r(θ)=πθ(as)πθold(as)r(\theta) = \frac{\pi_\theta(a|s)}{\pi_{\theta_{\text{old}}}(a|s)} and advantage estimate AA, PPO's clipped surrogate objective is:

LCLIP(θ)=min(r(θ)A, clip(r(θ),1ε,1+ε)A)L^{\text{CLIP}}(\theta) = \min\big(r(\theta)\, A,\ \text{clip}(r(\theta),\, 1{-}\varepsilon,\, 1{+}\varepsilon)\, A\big)
  • r(θ)r(\theta) — the probability ratio: how much more (or less) likely the new policy makes the action taken, relative to the policy that generated the data.
  • AA — the advantage estimate for that action (e.g. the actor-critic TD error from last chapter).
  • ε\varepsilon — the clip range, typically around 0.20.2.
  • clip(r,1ε,1+ε)\text{clip}(r, 1{-}\varepsilon, 1{+}\varepsilon)rr clamped into [1ε, 1+ε][1{-}\varepsilon,\ 1{+}\varepsilon].
  1. r = 1 means 'no change yet'

    r(θ)=1r(\theta)=1 exactly when the new policy assigns the same probability to that action as the old one did — the starting point before any update has moved anything.

  2. The min makes it a pessimistic bound

    Taking the min\min of the raw and clipped terms means the objective can never be more generous about a large policy change than the honest, unclipped number — it can only be more conservative.

  3. The clip only bites on one side

    For a positive advantage, increasing rr past 1+ε1+\varepsilon gets capped — no extra credit for over-committing to a good action. But decreasing rr below 1ε1-\varepsilon isn't clipped at all: the min\min just picks the (already smaller) unclipped term, so nothing stops the policy from moving a good action's probability down as far as the raw gradient wants. The clip specifically prevents exploiting an advantage by moving too far in the rewarding direction, not the punishing one.

Play
r = 1.00 — no clipping in effect

Step through ratios from 0.70.7 up to 1.51.5. Below 1+ε=1.21+\varepsilon=1.2, the bold and dashed lines sit exactly on top of each other — nothing is being clipped. Past 1.21.2, the bold line stays flat at 1.2×A1.2 \times A no matter how much further rr climbs.

Worked example

With A=1A=1 and ε=0.2\varepsilon=0.2 (so the clip range is [0.8,1.2][0.8, 1.2]):

  1. r = 0.9 — inside the clip range, nothing happens

    clip(0.9)=0.9\text{clip}(0.9) = 0.9, so both terms equal 0.9×1=0.90.9 \times 1 = 0.9. The objective is just the plain policy gradient here — the clip hasn't engaged at all.

  2. r = 0.7 — below 1-epsilon, but still not clipped

    clip(0.7)=0.8\text{clip}(0.7) = 0.8, giving a clipped term of 0.80.8. But the raw unclipped term is 0.7×1=0.70.7 \times 1 = 0.7, which is smaller — so min(0.7,0.8)=0.7\min(0.7, 0.8) = 0.7 wins. The clip exists but never binds here, exactly the asymmetry described above.

  3. r = 1.3 — past 1+epsilon, and now it bites

    clip(1.3)=1.2\text{clip}(1.3) = 1.2, giving a clipped term of 1.21.2. The unclipped term is 1.3×1=1.31.3 \times 1 = 1.3. Now min(1.3,1.2)=1.2\min(1.3, 1.2) = 1.2 — the objective is held down to 1.21.2, even though the policy actually moved the ratio to 1.31.3. That gap is the clip doing its job: refusing to reward the update any further for moving past the trust region.

Checkpoint

Move the ratio slider until the policy has moved far enough (past 1+ε = 1.2) that the clip is actively flattening the objective.

r = 1.00 — unclipped 1.00, clipped 1.00
Move the ratio slider to try it
Summary
LCLIP(θ)=min(r(θ)A, clip(r(θ),1ε,1+ε)A)L^{\text{CLIP}}(\theta) = \min\big(r(\theta)\, A,\ \text{clip}(r(\theta),\, 1{-}\varepsilon,\, 1{+}\varepsilon)\, A\big)

PPO keeps actor-critic's exact advantage estimate and policy-gradient machinery, but caps how much credit a single update can take for moving the policy a long way in one step — cheaply approximating a hard trust-region constraint with nothing more than a min\min and a clip\text{clip}. That's the full arc of this part: from a policy with no memory of state at all (the bandit), to knowing a state's value under a fixed policy, to finding the optimal values and policy exactly, to learning them from experience, to learning a policy directly, and finally to constraining how aggressively that policy is allowed to change on any single step.