Skip to content

Baselines & Variance Reduction

REINFORCE’s gradient estimate has high variance because the return GtG_t can vary wildly between episodes. This means we need many samples for a reliable gradient, making training slow.

We can subtract a baseline b(st)b(s_t) from the return without introducing bias:

θJ(θ)=Eτ[t=0Tθlogπθ(atst)(Gtb(st))]\nabla_\theta J(\theta) = \mathbb{E}_{\tau} \left[ \sum_{t=0}^{T} \nabla_\theta \log \pi_\theta(a_t \mid s_t) \cdot (G_t - b(s_t)) \right]

Why is this still unbiased? Because:

Eaπθ[θlogπθ(as)b(s)]=b(s)θaπθ(as)=b(s)θ1=0\mathbb{E}_{a \sim \pi_\theta} \left[ \nabla_\theta \log \pi_\theta(a \mid s) \cdot b(s) \right] = b(s) \cdot \nabla_\theta \sum_a \pi_\theta(a \mid s) = b(s) \cdot \nabla_\theta 1 = 0

The baseline doesn’t change the expected gradient — it only reduces variance.

The best common choice for the baseline is the state-value function Vπ(s)V^\pi(s):

b(st)=Vπ(st)b(s_t) = V^\pi(s_t)

This turns the weight from GtG_t into the advantage:

At=GtVπ(st)A_t = G_t - V^\pi(s_t)

The advantage is positive when the action was better than average, and negative when it was worse. This is much more informative than the raw return.

A 2-action bandit with Gaussian rewards. We draw N samples and form the REINFORCE single-sample gradient estimate with and without the value-function baseline. Both have the same mean (the proof above) but visibly different spread.

With μ0=8,μ1=10,σ=2\mu_0 = 8, \mu_1 = 10, \sigma = 2, policy π(a=1)=0.6\pi(a{=}1) = 0.6:

V(s)=0.610+0.48=9.4V(s) = 0.6 \cdot 10 + 0.4 \cdot 8 = 9.4

A single sample where action a=1a{=}1 is taken and reward r=11r = 11 is observed:

QuantityNo baselineWith baseline
advantager=11r = 11rV=119.4=1.6r - V = 11 - 9.4 = 1.6
score θlogπ(1s)\nabla_\theta \log \pi(1\|s)10.6=0.41 - 0.6 = 0.410.6=0.41 - 0.6 = 0.4
gradient0.411=4.400.4 \cdot 11 = 4.400.41.6=0.640.4 \cdot 1.6 = 0.64

If action a=0a{=}0 is taken with r=9r = 9:

QuantityNo baselineWith baseline
advantager=9r = 9rV=0.4r - V = -0.4
scorep1=0.6-p_1 = -0.60.6-0.6
gradient0.69=5.40-0.6 \cdot 9 = -5.400.60.4=0.24-0.6 \cdot -0.4 = 0.24

The baselined gradients are both small and same-signed (positive — both actions look slightly above average given the noisy draw); the unbaselined ones are huge and opposite-signed, even though the average return doesn’t actually distinguish the actions much.

The sampler above shows the spread of a single gradient estimate. Here is what that spread costs over a whole training run: two REINFORCE learners racing live on the same bandit, identical in every way except the baseline.

What it models. Two identical REINFORCE learners on the same 5-armed bandit (true mean rewards 3.2–3.8, best arm marked ▲); the only difference is that B subtracts a running-average-reward baseline before each update. Every reward is positive, so the plain learner A pushes up whichever arm it happens to sample — its updates are dominated by the constant +3 reward floor rather than by which arm is actually better, and it sometimes locks onto the wrong arm for good.

Knobs. The learning rate α is shared by both learners; σ is the reward noise around each arm’s mean.

Try this. Crank σ to 1.2 and watch the race gap widen — A whipsaws across the π = 0.8 line and takes roughly 3× longer to stay there, while B still climbs cleanly every run. Then drop σ to 0: A’s red gradient trace barely falls, because its variance never came from reward noise — it is the baseline-removable offset term, the same one that blows up the no-baseline gradients in the worked example above.

When we learn both:

  • A policy πθ\pi_\theta (the actor)
  • A value function VϕV_\phi (the critic)

we get an actor-critic method. The critic provides the baseline, and the actor updates using the advantage:

θθ+αθlogπθ(atst)A^t\theta \leftarrow \theta + \alpha \nabla_\theta \log \pi_\theta(a_t \mid s_t) \cdot \hat{A}_t ϕϕβϕ(Vϕ(st)Gt)2\phi \leftarrow \phi - \beta \nabla_\phi (V_\phi(s_t) - G_t)^2

This is the foundation for PPO, which we’ll cover next.

MethodWeightBiasVariance
REINFORCEGtG_tNoneHigh
With baselineGtb(s)G_t - b(s)NoneLower
Actor-CriticA^t\hat{A}_tSome (bootstrapping)Lowest

The bias-variance tradeoff is a recurring theme — we’ll see it again with GAE in the PPO section.

  • Williams. Simple Statistical Gradient-Following Algorithms for Connectionist Reinforcement Learning. Machine Learning 8, 1992 — already includes the baseline. Springer
  • Greensmith, Bartlett, Baxter. Variance Reduction Techniques for Gradient Estimates in Reinforcement Learning. JMLR 5, 2004 — the formal analysis of which baselines minimize variance. JMLR