A ai coolAId
Chapter 4 of 7

Policy Gradients & Modern RL

The progression from REINFORCE to Actor-Critic, Advantage & GAE, PPO clipping, Entropy bonuses, On-Policy vs. Off-Policy, and Vectorized Environments.

Mental Model

Modern RL algorithms are not magic—each one fixes a specific mathematical failure mode of the one before it: REINFORCE (high variance) → Baselines & Actor-Critic (lower variance) → GAE (clean multi-step credit) → PPO (safe, clipped updates).

1. REINFORCE & The Variance Problem

REINFORCE is the cleanest starting point in policy-gradient RL: run a full episode, measure total return \(G_t\), and nudge log-probabilities upward for actions in high-return runs:

\[\Delta\theta \propto \sum_t \nabla_\theta \log \pi_\theta(a_t \mid s_t)\,(G_t - b)\]

Why raw REINFORCE struggles:

  • You have to wait until the episode ends.
  • Every action in a lucky episode gets praised—even bad moves that happened along the way.

Subtracting a state-dependent Baseline / Advantage \(A_t = Q(s_t, a_t) - V(s_t)\) fixes half the problem: you only reinforce actions that turned out better than expected from that state.

2. Actor-Critic & GAE (Bridging Short and Long Horizons)

Instead of waiting for episode end, Actor-Critic trains a second network (the Critic, \(V_\phi(s)\)) to predict expected future return from any state. After every single step, you get an immediate surprise signal (the TD error):

\[\delta_t = r_t + \gamma V(s_{t+1}) - V(s_t)\]

  • Using only 1-step \(\delta_t\) has low variance but high bias if the Critic is still inaccurate.
  • Using full-episode \(G_t\) has zero bias but huge variance.

GAE (Generalized Advantage Estimation) smoothly blends all horizons with a single knob \(\lambda \in [0, 1]\):

\[\hat{A}_t^{\text{GAE}(\gamma, \lambda)} = \sum_{l \ge 0} (\gamma \lambda)^l \delta_{t+l}\]

With \(\gamma \approx 0.99\) and \(\lambda \approx 0.95\), GAE connects early preventative actions to delayed rewards without drowning in episode noise.

3. Why PPO Won: Safe Trust Regions + Entropy

Even with GAE, taking too large a gradient step on one noisy batch can wreck a neural policy—and unlike supervised learning, a wrecked RL policy collects garbage data on the next rollout, creating a death spiral.

PPO (Proximal Policy Optimization) solves this with one deceptively simple trick—clipping the probability ratio \(r_t = \frac{\pi_\theta(a_t \mid s_t)}{\pi_{\theta_{\text{old}}}(a_t \mid s_t)}\):

\[L^{\text{CLIP}}(\theta) = \min\!\big(r_t \hat{A}_t,\; \operatorname{clip}(r_t, 1-\epsilon, 1+\epsilon)\hat{A}_t\big)\]

If an update tries to move an action's probability by more than \(\pm \epsilon\) (typically 20%), the gradient flattens to zero. Pair that with an Entropy Bonus \(\beta H(\pi)\) so the policy doesn't lock prematurely onto one myopic habit, and you get the most dependable general-purpose RL algorithm in existence.

4. On-Policy vs. Off-Policy & Vectorized Throughput

Dimension On-Policy (PPO, GRPO) Off-Policy (DQN, SAC, TD3)
Data reuse Fresh rollouts only; discarded after update Reuses past transitions via a replay buffer
Stability High (easy to tune, predictable) Lower (bootstrapping + distribution shift)
Sample efficiency Lower (needs many env steps) High (10x fewer env interactions)
Best fit Fast parallel simulators, LLM rollouts Expensive real-world trials, physical robotics

When you do have a fast simulator, Vectorized Environments (Gymnasium AsyncVectorEnv, PufferLib, Isaac Gym) run dozens to thousands of copies in parallel—giving on-policy PPO the throughput it needs while a fixed step budget keeps algorithm comparisons honest.