Skip to content
intermediate

Why Policy-Gradient Baselines Reduce Variance Without Changing the Gradient

Two runs of the same policy-gradient code. Same environment, same seed, same learning rate. One climbs. One flatlines. The usual advice is "subtract a…

Published 2026-10-02Updated 2026-10-049 min read
A serene view of fluffy white clouds against a vibrant blue sky, perfect for backgrounds.
A serene view of fluffy white clouds against a vibrant blue sky, perfect for backgrounds. Photo by luian C on Pexels.

Two runs of the same policy-gradient code. Same environment, same seed, same learning rate. One climbs. One flatlines. The usual advice is "subtract a baseline," and it works often enough that most of us accept it as a trick. But a trick you cannot derive is a trick you cannot debug.

Here is the sharper model: a baseline is a control variate. Its expected contribution to the gradient is exactly zero, which means it has no authority over the direction of learning. It can only move the noise. Once you see that, the design question changes from "should I use a baseline?" to "which baseline centers my weights without adding its own error?"

Let's derive it.

The Baseline Is a Control Variate, Not a Correction

You already know the sampled policy-gradient estimator. For a trajectory of states, actions, and returns, the update is a sum of score-function terms, each weighted by a return-like quantity:

g^=∑t∇θlog⁡πθ(at∣st) Φt\hat{g} = \sum_t \nabla_\theta \log \pi_\theta(a_t \mid s_t)\, \Phi_t

where Φt\Phi_t is the weight — a return, a reward-to-go, or a value estimate. The score function ∇θlog⁡πθ(at∣st)\nabla_\theta \log \pi_\theta(a_t \mid s_t) tells you which direction to push the action probability. The weight tells you how hard to push.

A baseline is a function b(st)b(s_t) subtracted from that weight:

g^b=∑t∇θlog⁡πθ(at∣st) (Φt−b(st))\hat{g}_b = \sum_t \nabla_\theta \log \pi_\theta(a_t \mid s_t)\, \bigl(\Phi_t - b(s_t)\bigr)

Two constraints define it. The baseline depends on the state only — not on the action taken, not on the policy parameters. And the expectation is taken under the same policy πθ\pi_\theta that generated the samples. Everything downstream depends on those two conditions.

Why call it a control variate? In Monte Carlo estimation, a control variate is a quantity you subtract from a noisy estimator because you know its expected value. If that expected value is zero, you have removed noise without moving the target. That is precisely what an action-independent baseline does.

Note: This article assumes the likelihood-ratio derivation — the log-derivative identity that turns the expected-return objective into a score-function estimator. If that step is not yet solid, the algebra below will look like sleight of hand. The mechanism is what matters here, not a re-derivation.

Why an Action-Independent Baseline Leaves the Gradient Unchanged

Two-column comparison: for a state-only baseline, b(s) sits outside the action sum and the sum of policy gradients becomes the gradient of one, yielding zero. For an action-dependent baseline, b(s,a) remains inside the sum, which generally does not cancel.
The invariance comes from action-independence: only a state-only baseline factors out of the normalized action-probability sum.

Write the expected contribution of the subtracted term. Under the state-visitation distribution d(s)d(s) and the policy, it is:

E[b(st)∇θlog⁡πθ(at∣st)]=∑sd(s) b(s)∑aπθ(a∣s) ∇θlog⁡πθ(a∣s)\mathbb{E}\bigl[b(s_t)\nabla_\theta \log \pi_\theta(a_t \mid s_t)\bigr] = \sum_s d(s)\, b(s) \sum_a \pi_\theta(a \mid s)\, \nabla_\theta \log \pi_\theta(a \mid s)

Now apply the log-derivative identity, ∇θlog⁡πθ(a∣s)=∇θπθ(a∣s)πθ(a∣s)\nabla_\theta \log \pi_\theta(a \mid s) = \dfrac{\nabla_\theta \pi_\theta(a \mid s)}{\pi_\theta(a \mid s)}. The policy factor cancels:

=∑sd(s) b(s)∑a∇θπθ(a∣s)= \sum_s d(s)\, b(s) \sum_a \nabla_\theta \pi_\theta(a \mid s)

The inner sum is the gradient of the action probabilities over all actions. Those probabilities must sum to 1 for every state, and the gradient of a constant is zero:

=∑sd(s) b(s) ∇θ∑aπθ(a∣s)⏟= 1=0= \sum_s d(s)\, b(s)\, \nabla_\theta \underbrace{\sum_a \pi_\theta(a \mid s)}_{=\,1} = 0

That is the whole result. The subtracted term vanishes in expectation for any b(s)b(s). The baseline is free. It cannot bias the gradient, which is exactly why you are allowed to choose it for variance rather than for correctness.

Now watch the assumption do its work. If the baseline depended on the action — b(s,a)b(s, a) — the subtracted expectation becomes:

E[b(st,at)∇θlog⁡πθ(at∣st)]=∑sd(s)∑ab(s,a) ∇θπθ(a∣s)\mathbb{E}\bigl[b(s_t, a_t)\nabla_\theta \log \pi_\theta(a_t \mid s_t)\bigr] = \sum_s d(s) \sum_a b(s,a)\, \nabla_\theta \pi_\theta(a \mid s)

The b(s,a)b(s,a) factor sits inside the action sum, so it cannot be pulled out front. The inner sum is no longer ∇θ∑aπθ(a∣s)\nabla_\theta \sum_a \pi_\theta(a \mid s); it is a weighted sum of per-action probability gradients, and that weighted sum generally does not vanish. Action-independence is not a stylistic preference. It is the load-bearing wall.

Common mistake: Assuming every action-dependent baseline is automatically biased. Some action-dependent estimators add a correction term that restores unbiasedness. The clean invariance result belongs to the state-only case; anything else needs its own proof.

Knowledge check

Check your understanding

Answer this question before you continue.

Why does the expected contribution from a state-only baseline vanish in the derivation?
Single Choice

Focus: Explain why subtracting a state-only baseline preserves the expected policy gradient.

Where the Variance Actually Lives

The estimator's variance comes from two sources: the spread of the score function, and the spread of the weight multiplying it. The baseline touches only the second.

Consider raw returns as the weight. The same action in the same state can be followed by a great return in one episode and a poor one in the next, because everything after that action is noisy. The weight swings wildly even when the action's merit has not changed. That swing is the variance you feel as unstable learning.

Subtracting b(st)b(s_t) shifts the weight's center. It does not touch the score function at all. So it attacks the spread directly: instead of weights scattered around some large absolute return, you get weights scattered around zero, with a much smaller range.

Here is the honest limit. The variance-minimizing baseline is not simply the value function. The exact optimum weights rewards by the squared norm of the score function:

b∗=E[Φt ∥∇θlog⁡πθ(at∣st)∥2]E[∥∇θlog⁡πθ(at∣st)∥2]b^* = \frac{\mathbb{E}\bigl[\Phi_t\, \|\nabla_\theta \log \pi_\theta(a_t \mid s_t)\|^2\bigr]}{\mathbb{E}\bigl[\|\nabla_\theta \log \pi_\theta(a_t \mid s_t)\|^2\bigr]}

The value function is a practical approximation to this, not the exact answer. Keep that in mind when someone claims V(s)V(s) is "the optimal baseline." It is the convenient one.

Knowledge check

Check your understanding

Answer this question before you continue.

A learner argues that any baseline, including one that depends on the sampled action, must leave the expected gradient unchanged. Which response matches the article's derivation?
Misconception Check

Focus: Distinguish the invariance argument for state-only baselines from the general action-dependent case.

Why the State-Value Function Is the Practical Baseline

The state-value function Vπ(s)V^\pi(s) is the expected return from state ss under the current policy. By construction it depends on the state alone — so it satisfies the invariance condition for free.

Substituting it turns the weight into the advantage:

Aπ(st,at)=Qπ(st,at)−Vπ(st)A^\pi(s_t, a_t) = Q^\pi(s_t, a_t) - V^\pi(s_t)

Positive advantage means the action did better than the state's average. Negative means worse. The update now compares an action to its own context instead of to an absolute number. An agent that gets exactly what it expected should feel neutral — and the baseline is what encodes that neutrality.

A Small Worked Example

One state, two actions, four sampled returns. Say the policy currently assigns 0.50.5 to each action, and the score function magnitude is the same for both, so we can compare weights directly.

SampleActionReturnWeight (no baseline)Weight (b=V=5b = V = 5)
1A1010+5
2A22−3
3B88+3
4B00−5

Without a baseline, the weights are {10,2,8,0}\{10, 2, 8, 0\} — mean 5, spread 10. With b=5b = 5, they are {+5,−3,+3,−5}\{+5, -3, +3, -5\} — mean 0, spread 10 in range but centered, and the sign now carries meaning: action A was reinforced on sample 1 and suppressed on sample 2.

The gradient direction is unchanged in expectation. What changed is that the weight now tells the policy relative merit. Smaller, better-centered weights mean fewer samples to average out the noise.

Warning: This example illustrates recentering and sign interpretation, not variance reduction. Subtracting the same constant from every return leaves the variance of the weights unchanged in this equal-score, single-state setup. Variance reduction appears when the baseline correlates with the score-weighted return across states — the case the next section addresses.

Knowledge check

Check your understanding

Answer this question before you continue.

In the worked example, all samples come from one state and have equal score-function magnitude. What does subtracting 5 from each return establish?
Scenario Interpretation

Focus: Interpret what subtracting a constant baseline does and does not demonstrate in the worked example.

What Approximation Error Does to the Benefit

In practice you do not have Vπ(s)V^\pi(s). You have a learned critic v^(s;w)\hat{v}(s; w) that is wrong in two distinct ways.

First, its own estimation error. Second, the fact that it is evaluated under a policy that keeps changing. The critic chases a value function the actor keeps invalidating, so the baseline is always slightly stale.

Here is the key consequence: a biased baseline does not bias the gradient in expectation. Invariance holds for any b(s)b(s), good or bad. But a bad baseline can shrink the variance benefit, or reverse it. If the baseline's error is large relative to the return spread, you are subtracting something closer to noise than to a center, and the update noise returns.

The practical diagnostic: watch whether the critic's predictions track returns. If they do not, the baseline is a random shift wearing a value function's clothes.

Common mistake: Treating a baseline as a correctness fix. It is not. A zero baseline is unbiased but noisy. A perfect baseline is unavailable. The useful region is a baseline good enough to center the weights without adding its own noise.

Knowledge check

Check your understanding

Answer this question before you continue.

A learned critic is inaccurate but still outputs a state-only baseline. What follows from the article's argument?
Comparison Reasoning

Focus: Explain how critic approximation error affects gradient invariance and variance reduction differently.

When a Baseline Helps and When It Misleads

Use a baseline when returns are large and variable relative to the differences between actions. That is where centering buys the most.

Be cautious when the critic is trained on very little data, when the reward scale is unstable, or when the policy is changing faster than the value function can track.

BaselineWhat it assumesWhat it costs
ZeroNothingFull return noise
ConstantA fixed offset is enoughNo state-relative centering
State-valueA learned critic tracks returnsCritic error, moving target
AdvantageCritic plus action-value estimateTwo estimates to keep honest

One more correction, and it matters. A baseline does not improve the gradient's direction. It changes the noise around a direction that was already correct in expectation. And lower variance is not a complete explanation of why one baseline beats another — baselines with identical variance can produce different learning behavior, because they change which regions of the policy space the optimization visits. Variance is the first-order story, not the whole story.

The Decision Rule

The baseline is safe because its expected contribution is zero. It is useful because it centers the weight. It is limited because it is learned.

That is the entire derivation in three clauses. Now prove it to yourself. Instrument your own policy-gradient loop to log the spread of the weight term with and without a value baseline. Watch the estimator's noise change while the average update direction does not. That experiment is the proof that the derivation was not decoration.

Knowledge check

Final check

Finish the article by checking the ideas you just learned.

Why does the article call the state-value function a practical baseline rather than the exact variance-minimizing baseline?
Question 1 of 2Single Choice

Focus: Compare the practical state-value baseline with the variance-minimizing baseline described in the article.

An agent has large, variable returns, but its critic is trained on very little data and is not tracking returns well. Which conclusion is best supported by the article?
Question 2 of 2Scenario Interpretation

Focus: Choose a baseline strategy by weighing expected-gradient invariance against likely variance benefit and critic reliability.

References

  1. Part 3: Intro to Policy Optimization — Spinning Up documentationspinningup.openai.com
  2. Beyond Variance Reduction: Understanding the True Impact ...proceedings.mlr.press
Practical resource

Build a stronger RL mental model

Use structured resources to connect equations, algorithms, and observable agent behavior.

Browse resources
Related sites

Continue across related AI foundations

Use LearnPyFast for Python foundations and LearnLLMFast for practical language-model and agent application concepts.

Python tutorialstutorial

LearnPyFast

Beginner-friendly Python tutorials, examples, and learning paths for practical programming foundations.

PythonProgrammingBeginners
Visit LearnPyFast
LLM tutorialstutorial

LearnLLMFast

Practical LLM tutorials for builders who want to understand prompting, workflows, agents, and AI applications.

LLMAIBuilders
Visit LearnLLMFast

Keep learning

Related reinforcement learning tutorials

Continue with nearby RL concepts, algorithms, and experiments that build on the same decision process.