Reinforcement Learning/Policy Gradients and Actor-Critic Methods

Lesson 12.42,807 words

Policy Gradients and Actor-Critic Methods

Value-based reinforcement learning learns what each state is worth and acts greedily; policy-gradient methods skip the detour and optimize a parameterized policy directly by ascending the gradient of expected return. The policy gradient theorem makes this tractable through the log-derivative trick, turning an intractable gradient of an expectation into an expectation of a gradient.

╌╌╌╌

Value-based methods learn a value function and read a policy off it: estimate , then act greedily, . The policy is implicit, a byproduct of the value estimate, and the ties the approach to discrete action sets and to a deterministic, sometimes brittle, greedy rule. Policy-gradient methods invert the dependency: parameterize the policy itself as and adjust to make good trajectories more probable. There is no , the policy is stochastic by construction, and continuous action spaces come for free.

The parameterization is a design choice with concrete tensor shapes. A shared torso maps the state to a feature vector ; a policy head then reads a distribution off . The two standard heads differ only in what the head produces.

  • Discrete actions. A linear head with emits one logit per action, , and a softmax turns the logits into probabilities, . The output is a length- probability vector; sampling picks an index. The score has the softmax form , the gradient of the chosen logit minus the policy-weighted average logit gradient.
  • Continuous actions. For an -dimensional action the head emits a mean and a (log) standard deviation, and the action is drawn from a diagonal Gaussian . The log-density is , and its gradient in the mean is — the score pushes the mean toward actions that scored well. Parameterizing rather than keeps the standard deviation positive without a constraint.
One shared torso feeds two head types: a softmax over the discrete actions, or the mean and (log) standard deviation of a Gaussian for continuous actions.

The two paradigms differ in what they represent and how they improve it. The table fixes the contrast that the rest of the lesson refines.

Value-basedPolicy-based
Learns or directly
Policyimplicit ()explicit, parameterized
Action spacediscrete (needs the )discrete or continuous
Outputdeterministic greedystochastic
OptimizesBellman error (indirect)expected return (direct)
Convergencecan oscillate / diverge with approximationsmooth gradient ascent, local optimum
Value-based RL routes through an over learned -values; policy-based RL parameterizes and ascends the return gradient directly.

The objective

Fix a parameterization. The agent interacts with a Markov decision process, drawing a trajectory by sampling and . The return is the discounted sum of rewards , and the quantity to maximize is its expectation under the trajectory distribution the policy induces.

The obstacle is that the expectation is taken over a distribution that itself depends on . We cannot push inside an expectation whose measure moves with , and the transition kernel is unknown, so we cannot differentiate the trajectory probability analytically. The policy gradient theorem removes both problems at once.

The policy gradient theorem

Write the trajectory probability as a product of the initial-state distribution, the policy, and the transitions:

The key device is the log-derivative trick (the score function identity): for any differentiable density, , which converts the gradient of a probability into a probability times the gradient of its log. That lets the gradient of the integral become an expectation, recoverable from sampled trajectories.

Every method in this lesson builds on this result. The gradient is an expectation, so a Monte Carlo average over sampled trajectories estimates it without a model; each term is a score weighted by how good the action turned out to be.

REINFORCE

The simplest realization replaces the unknown with the actual sampled return-to-go from a complete episode. This is unbiased: the sampled return is an unbiased estimate of its own expectation . The result is a Monte Carlo policy gradient.

Algorithm:Reinforce(πθ,α,γ)\textsc{Reinforce}(\pi_\theta, \alpha, \gamma) — Monte Carlo policy gradient
  1. 1
    initialize policy parameters θ\theta
  2. 2
    repeat
  3. 3
    sample an episode s0,a0,r1,,sT1,aT1,rTπθs_0, a_0, r_1, \dots, s_{T-1}, a_{T-1}, r_T \sim \pi_\theta
  4. 4
    for t=0t = 0 to T1T-1 do
  5. 5
    Gtk=tT1γktrk+1G_t \gets \sum_{k=t}^{T-1} \gamma^{\,k-t}\, r_{k+1}
    return-to-go
  6. 6
    θθ+αγtGtθlogπθ(atst)\theta \gets \theta + \alpha\,\gamma^{\,t}\, G_t\,\nabla_\theta \log \pi_\theta(a_t \mid s_t)
    ascend
  7. 7
    until converged
  8. 8
    return θ\theta

The estimator is correct in expectation but its variance is enormous. is a sum of many random rewards across a stochastic policy and stochastic dynamics, so a single episode's return can swing wildly, and the gradient estimate swings with it. Learning is slow and noisy, and the noise grows with the episode horizon.

REINFORCE's gradient estimate (blue) has high variance around the true gradient (black); each dot is one episode's noisy single-sample estimate.

Baselines and the advantage

Variance reduction is the central engineering problem of policy gradients. The first and most important tool is a baseline: subtract a state-dependent quantity from the return before weighting the score. This leaves the gradient unbiased for any that does not depend on the action.

The variance-minimizing choice of baseline is close to the state-value , the expected return from . Using replaces the raw return with the advantage, which measures how much better action is than the policy's average behavior in that state.

Centering the weight is what shrinks variance. Without a baseline every action in a high-reward state gets reinforced, including the mediocre ones; with the advantage, above-average actions gain probability and below-average actions lose it. The policy gradient takes its canonical, low-variance form.

Subtracting the baseline recenters returns: raw returns (blue) all reinforce; advantages (split green/red) push above-average actions up and below-average down.

Actor-critic

REINFORCE waits for a full episode to compute . Actor-critic methods estimate the value online with a second learned function, the critic, and let the actor (the policy) step every transition using a bootstrapped advantage rather than a Monte Carlo return. The critic supplies a low-variance, biased estimate where REINFORCE used a high-variance, unbiased one, trading a little bias for a large variance reduction.

The cheapest critic-based advantage is the one-step temporal-difference error, which estimates from a single transition and the critic:

The same drives both updates: the actor ascends , and the critic descends the squared TD error . The loop is symmetric and runs every step.

The actor-critic loop: the actor picks actions, the environment returns reward and next state, and the critic's TD error trains both the actor and itself.

The synchronous batched form is A2C (advantage actor-critic): run several environment copies in parallel, collect a batch of transitions, and update both networks on the averaged gradient. A3C is the asynchronous predecessor, where many workers compute gradients on their own copies and apply them to shared parameters without locking, decorrelating the data the way a replay buffer does for value methods.

Algorithm:A2C(πθ,Vw,α,β,γ)\textsc{A2C}(\pi_\theta, V_w, \alpha, \beta, \gamma) — one synchronous advantage actor-critic update
  1. 1
    initialize actor params θ\theta and critic params ww
  2. 2
    repeat
  3. 3
    collect a batch of transitions (st,at,rt+1,st+1)(s_t, a_t, r_{t+1}, s_{t+1}) from parallel actors
  4. 4
    for each transition do
  5. 5
    δtrt+1+γVw(st+1)Vw(st)\delta_t \gets r_{t+1} + \gamma\, V_w(s_{t+1}) - V_w(s_t)
    TD error = advantage estimate
  6. 6
    θθ+αδtθlogπθ(atst)\theta \gets \theta + \alpha\, \overline{\delta_t\, \nabla_\theta \log \pi_\theta(a_t \mid s_t)}
    actor ascends
  7. 7
    ww+βδtwVw(st)w \gets w + \beta\, \overline{\delta_t\, \nabla_w V_w(s_t)}
    critic fits the return
  8. 8
    until converged
  9. 9
    return θ,w\theta,\, w

Generalized advantage estimation

The TD error is one extreme of a spectrum. A one-step advantage has low variance but high bias from the imperfect critic; the full Monte Carlo return has zero bias but high variance. The -step advantage interpolates by bootstrapping after real rewards. Generalized advantage estimation (GAE) takes an exponentially weighted average over all , governed by a single parameter .

The parameter controls the bias-variance trade-off, mirroring the role of in for value estimation. Typical values sit near , keeping most of the variance reduction while leaving the bias small. The estimator is a geometric blend: each TD residual enters the advantage with weight , so nearby residuals dominate and distant ones fade, which is what keeps variance in check.

GAE weights the TD residual by : near residuals count most, far ones decay geometrically. Larger flattens the decay toward the Monte Carlo return.
-step / BiasVarianceBootstraps after
One-step TDhighlow reward
GAEtunabletunableweighted mix
Monte Carlononehighend of episode
The bias-variance trade in advantage estimation: short horizons () are low-variance but biased; long horizons () are unbiased but high-variance.

Trust-region methods

Vanilla policy gradients are fragile in step size. A learning rate that is fine in one region of policy space causes a catastrophic, irreversible collapse in another, because a small change in parameters can be a large change in the policy distribution . The remedy is to bound how far the policy may move per update, measuring distance in distribution space rather than parameter space.

TRPO (trust region policy optimization) makes this a hard constraint: maximize a surrogate advantage objective subject to a cap on the average KL divergence between the new and old policies. Write the probability ratio .

TRPO works but is heavy: it solves a constrained optimization with conjugate gradients and a line search every update. PPO (proximal policy optimization) achieves nearly the same effect with a first-order objective by clipping the ratio, removing the incentive to move it outside a small interval .

The clip is asymmetric in the sign of the advantage. For the objective flattens once exceeds , capping how much a good action's probability can rise in one step; for it flattens below . Either way the gradient is zeroed outside the interval, so a single batch cannot overshoot.

PPO's clipped objective in the ratio . For positive advantage (blue) the gain saturates above ; for negative advantage (red) it saturates below .
Algorithm:PPO(πθ,Vw,ϵ,K)\textsc{PPO}(\pi_\theta, V_w, \epsilon, K) — clipped proximal policy optimization
  1. 1
    initialize actor θ\theta and critic ww
  2. 2
    repeat
  3. 3
    run policy πθold\pi_{\theta_{\text{old}}}, collect trajectories, store πθold(atst)\pi_{\theta_{\text{old}}}(a_t\mid s_t)
  4. 4
    compute advantages A^t\hat A_t by GAE and value targets R^t\hat R_t
  5. 5
    for KK epochs over the batch do
  6. 6
    rtπθ(atst)/πθold(atst)r_t \gets \pi_\theta(a_t\mid s_t) / \pi_{\theta_{\text{old}}}(a_t\mid s_t)
    probability ratio
  7. 7
    LCLIPmin(rtA^t, clip(rt,1ϵ,1+ϵ)A^t)L^{\mathrm{CLIP}} \gets \overline{\min\parens{r_t \hat A_t,\ \mathrm{clip}(r_t, 1-\epsilon, 1+\epsilon)\,\hat A_t}}
  8. 8
    θθ+αθLCLIP\theta \gets \theta + \alpha\,\nabla_\theta L^{\mathrm{CLIP}}
    clipped actor step
  9. 9
    wwβw(Vw(st)R^t)2w \gets w - \beta\,\nabla_w\, \overline{\parens{V_w(s_t) - \hat R_t}^2}
    critic regression
  10. 10
    θoldθ\theta_{\text{old}} \gets \theta
  11. 11
    until converged
  12. 12
    return θ\theta

Deterministic and continuous control

The methods so far carry a stochastic policy. For continuous control an alternative learns a deterministic policy and pushes its gradient through a learned -critic via the chain rule, the deterministic policy gradient. DDPG combines this with a replay buffer and target networks, an off-policy actor-critic that is to continuous actions what DQN is to discrete ones.

DDPG is brittle because the critic overestimates. TD3 adds three fixes: two critics with a to curb overestimation, delayed actor updates, and target-policy smoothing. SAC instead makes stochasticity a first-class objective by adding the policy's entropy to the reward, the maximum-entropy formulation, which keeps the policy exploratory and the optimization well-conditioned.

The family spans on-policy and off-policy, discrete and continuous, stochastic and deterministic. The master table places each method on those axes.

MethodPolicyAction spaceOn/off-policyKey idea
REINFORCEstochasticdiscrete or continuouson-policyMonte Carlo policy gradient
A2C / A3Cstochasticdiscrete or continuouson-policylearned critic gives the advantage
TRPOstochasticdiscrete or continuouson-policyKL-constrained trust region
PPOstochasticdiscrete or continuouson-policyclipped surrogate, first-order
DDPGdeterministiccontinuousoff-policydeterministic gradient + replay
TD3deterministiccontinuousoff-policytwin critics, delayed updates
SACstochasticcontinuousoff-policymaximum-entropy actor-critic

Why PPO won practice

Goodfellow's text predates most of this family, so the citations are the papers themselves: the policy-gradient theorem,1 TRPO,2 GAE,3 PPO,4 DDPG,5 TD3,6 and SAC.7 Two observations connect this lesson to the full reinforcement-learning subject's policy-gradient module and to modern practice.

PPO became the default for a mundane reason: it is robust and simple. TRPO's KL constraint is provably better-behaved, but its conjugate-gradient inner loop is fiddly to implement and tune. PPO throws away the hard constraint for a clipped objective that any autodiff framework optimizes with plain SGD, and in exchange for a small loss in principle it gains enormous robustness across tasks and hyperparameters. That practicality is why PPO, not TRPO, is the algorithm behind the RLHF of the large-language-model alignment lesson and the next lesson: when the environment is a reward model over text, PPO's stability is worth more than TRPO's tighter guarantee.

The stochastic/deterministic split maps onto exploration. On-policy stochastic methods (PPO, A2C) explore through the policy's own randomness and are simple but sample-hungry; off-policy deterministic methods (DDPG, TD3) reuse a replay buffer for sample efficiency but need injected exploration noise and are brittle. SAC's maximum-entropy objective is the reconciliation: off-policy sample efficiency and built-in stochastic exploration, which is why it became a default for continuous control. The choice among them is, at bottom, a choice about how the agent explores.

The reading is that the policy-gradient theorem is one clean idea — reweight action log-probabilities by how good the action was — and everything after is variance reduction (baselines, advantages, GAE) and step-size control (TRPO, PPO), with the continuous-control branch (DDPG, TD3, SAC) adding a critic-driven gradient for actions the of value methods cannot enumerate.

Takeaways

  • Policy-gradient methods parameterize and maximize expected return by ascent, skipping the value-function detour and the ; they handle continuous actions and stochastic policies natively.
  • The policy gradient theorem uses the log-derivative trick to write , an expectation estimable by sampling, with the unknown dynamics differentiated away.
  • REINFORCE plugs in the Monte Carlo return ; it is unbiased but high-variance. A state-dependent baseline leaves the gradient unbiased and, taken as , yields the advantage that sharply reduces variance.
  • Actor-critic learns the value online with a critic and steps on the TD error ; A2C/A3C parallelize it, and GAE dials bias against variance with .
  • Trust-region methods bound the per-step policy change: TRPO by a hard KL constraint, PPO by clipping the probability ratio to .
  • Continuous control specializes further: DDPG and TD3 push a deterministic gradient through a -critic off-policy, while SAC maximizes reward plus entropy.
  • In practice: PPO displaced TRPO because a clipped first-order objective is far simpler and more robust, which is why it is the optimizer behind RLHF; the stochastic/deterministic split is at bottom a choice about how to explore.

Footnotes

  1. Sutton et al., Policy Gradient Methods for Reinforcement Learning with Function Approximation, NeurIPS 2000 — the policy gradient theorem and its actor-critic realization.
  2. Schulman et al., Trust Region Policy Optimization, ICML 2015 — maximizes a surrogate advantage subject to a hard KL-divergence trust region on the policy update.
  3. Schulman et al., High-Dimensional Continuous Control Using Generalized Advantage Estimation, ICLR 2016 — the -weighted advantage estimator that dials bias against variance.
  4. Schulman et al., Proximal Policy Optimization Algorithms, 2017 — replaces TRPO's hard constraint with a clipped first-order surrogate, the default deep-RL policy optimizer.
  5. Lillicrap et al., Continuous Control with Deep Reinforcement Learning (DDPG), ICLR 2016 — an off-policy deterministic actor-critic with replay and target networks for continuous actions.
  6. Fujimoto et al., Addressing Function Approximation Error in Actor-Critic Methods (TD3), ICML 2018 — twin critics with a min, delayed actor updates, and target-policy smoothing to curb overestimation.
  7. Haarnoja et al., Soft Actor-Critic, ICML 2018 — a maximum-entropy off-policy actor-critic that augments reward with policy entropy for exploration and stability.

╌╌ END ╌╌