Skip to content
mlmentorship

Policy gradient methods

Directly optimize the policy by following the gradient of expected return. REINFORCE, actor-critic, and the foundation of modern RL.

Published · 8 min read ·Specialist ·Advanced

Visual quick review

Given one sampled action and a baseline, use the sign of its advantage to determine whether a policy-gradient step raises, leaves unchanged, or lowers that action's log-probability.

A positive return can still suppress the sampled action

A positive return can still suppress the sampled actionA declared three-action softmax starts with zero logits and uniform probabilities. After sampling A with action-independent baseline three, returns five, three, one give advantages two, zero, minus two. Exact logit gradient-ascent steps of size .1 produce normalized probabilities; A increases, stays fixed for this sample, or decreases despite positive absolute return.Toy 3-action softmax: initial logits (0,0,0)Sampled A; baseline b=3; ascent step eta=0.1Return 5 - baseline 3 = +2A 37.9%B 31.0%C 31.0%A rises above 1/3; B and C renormalize.Return 3 - baseline 3 = 0A 33.3%B 33.3%C 33.3%This sample contributes zero, not the wholebatch.Return 1 - baseline 3 = -2A 29.0%B 35.5%C 35.5%Return is positive, yet A falls below 1/3.logit step = eta * advantage * (one_hot(A) - p)
Read it this way: Subtract the baseline before following the sign. Every stacked bar sums to one after the exact softmax step. Zero means this sample contributes nothing, not that an entire batch cannot update.
Check: Why can a positive absolute return still suppress the sampled action if it is below the state baseline?
Full explanation 8 min read

Summary

Policy gradient methods directly parametrize a policy and optimize by ascending the gradient of expected return:

This is the policy gradient theorem (Sutton et al., 1999).

Policy gradient methods are the foundation of modern continuous-control RL (SAC, PPO), of large-scale RL (AlphaGo’s policy net, OpenAI Five), and of LLM alignment (RLHF uses PPO). They are essential whenever:

  • The action space is continuous (no easy ).
  • A stochastic policy is desirable (exploration, multi-modal optimal policies).
  • You can write a clean, differentiable policy parametrization.

REINFORCE

The simplest policy gradient (Williams, 1992):

where is the return-to-go from step .

Sample a trajectory by running the policy. For each step, compute and weight by the actual return. Backprop. Take a gradient step.

Pros: extremely general. Works for any differentiable policy. Cons: high variance. Return is a noisy estimate of expected return; gradient estimator dominates by random rollout luck.

Variance reduction: baselines

Subtract any state-dependent baseline from . Does not change the expected gradient (so no bias) but can drastically reduce variance:

A common baseline is the value function , leading to actor-critic. It is not generally the minimum-variance baseline. For one conditional score-function term, let . When the denominator is nonzero, the scalar baseline minimizing the estimator’s total conditional variance is

This equals only under additional conditions on the score-norm weighting. Treat the baseline as constant when differentiating the policy term.

Predict before revealing: a one-step policy chooses action 1 with probability 0.8, receives reward equal to its action, and has logit score action - 0.8. Must baseline have less variance than baseline 0.2?

Compare the mean and variance separately

No. With baseline 0.8, the two gradient estimates are 0.04 and 0.64, with probabilities 0.8 and 0.2. Their mean is 0.16 and variance is 0.0576. With baseline 0.2, both actions give gradient 0.16, so variance is zero. Both baselines are action-independent and unbiased; that does not make their variances equal.

A positive return still suppresses an action when it falls below baseline

A positive return can still be below baselineReturn 3 minus baseline 5 gives advantage -2. This example decreases the sampled action probability despite its positive raw return.Measure from the baseline, not fromzero0123456return 3baseline 5Move backward by two: advantage -2Positive return; below-baselineaction.
Read it this way: Return 3 minus baseline 5 gives advantage -2. This example decreases the sampled action probability despite its positive raw return. Can a positive raw return still discourage the sampled action?
Reference drawing

A positive return still suppresses an action when it falls below baseline

A positive return can still be below baselineReturn 3 minus baseline 5 gives advantage -2. This example decreases the sampled action probability despite its positive raw return.Measure from the baseline, not fromzero0123456return 3baseline 5Move backward by two: advantage -2Positive return; below-baselineaction.
Derivation
A positive return can still suppress the sampled actionA declared three-action softmax starts with zero logits and uniform probabilities. After sampling A with action-independent baseline three, returns five, three, one give advantages two, zero, minus two. Exact logit gradient-ascent steps of size .1 produce normalized probabilities; A increases, stays fixed for this sample, or decreases despite positive absolute return.Toy 3-action softmax: initial logits (0,0,0)Sampled A; baseline b=3; ascent step eta=0.1Return 5 - baseline 3 = +2A 37.9%B 31.0%C 31.0%A rises above 1/3; B and C renormalize.Return 3 - baseline 3 = 0A 33.3%B 33.3%C 33.3%This sample contributes zero, not the wholebatch.Return 1 - baseline 3 = -2A 29.0%B 35.5%C 35.5%Return is positive, yet A falls below 1/3.logit step = eta * advantage * (one_hot(A) - p)
Read it this way: Subtract the baseline before following the sign. Every stacked bar sums to one after the exact softmax step. Zero means this sample contributes nothing, not that an entire batch cannot update.
Check: Why can a positive absolute return still suppress the sampled action if it is below the state baseline?
Read it this way: Return 3 minus baseline 5 gives advantage -2. This example decreases the sampled action probability despite its positive raw return. Can a positive raw return still discourage the sampled action?

Actor-critic

Two networks:

  • Actor . The policy.
  • Critic . Value function estimator.

Use the critic as the baseline. Define the advantage . Update:

Critic is trained by TD: .

This is the basic A2C / A3C algorithm.

Generalized Advantage Estimation (GAE)

Instead of one-step or full-return advantages, use a weighted sum:

trades bias for variance. gives one-step TD; gives the full-return form, with terminal or truncation handling stated separately. A value such as 0.95 is a tuning choice, not a universal PPO requirement.

Trust regions and PPO

Naive policy gradient updates can drastically change the policy in one step, leading to collapse. Trust Region Policy Optimization (TRPO; Schulman et al., 2015) constrains the KL divergence between old and new policies. PPO (Schulman et al., 2017) replaces the constraint with a clipped surrogate objective:

with and typical.

PPO is used in control and some RLHF pipelines. Its clipped objective removes the incentive for certain sampled-action changes beyond the clipping boundary; it is not a hard constraint on policy ratios or KL.

Predict before revealing: old action probability is 0.1, advantage is 1, and clipping parameter is 0.2. Can new probability 0.9 have the same clipped objective as new probability 0.12?

Inspect the objective, not an imaginary constraint

Yes. The ratios are 9 and 1.2, but both clipped surrogate values are 1.2. A flat objective beyond the boundary does not make those policy parameters infeasible. Monitor ratios and KL; optional early stopping is a separate implementation safeguard, not a guarantee supplied by clipping.

Off-policy actor-critic

For sample efficiency in continuous control, use a replay buffer with importance sampling correction or Q-function critics. DDPG, TD3, SAC are the standard off-policy actor-critic algorithms. SAC adds a maximum-entropy bonus that encourages exploration.

Common pitfalls

  • High variance. Test an action-independent baseline. Advantage normalization changes finite-batch estimates and scale; evaluate it rather than assuming every baseline or normalization must help.
  • Insufficient exploration. An entropy bonus can help when appropriate; deterministic policies are not automatically a failure. For a minimized loss, rewards entropy.
  • Reusing stale samples. PPO uses rollout-policy probabilities in its importance ratios, but clipping does not bound staleness or make arbitrary off-policy reuse valid. Collect fresh rollouts and inspect drift.
  • Mismatch between rollout and learning. Record the behavior-policy version and log probabilities. Ratios require matching support and do not by themselves guarantee a safe update.
  • Treating policy gradient as universally low-variance. It isn’t. Q-learning often has lower variance for discrete-action problems.