Baselines and Variance Reduction
Imagine training a robot policy with REINFORCE: Monte Carlo Policy Gradient. Every episode's return is a huge positive number, say between 900 and 1100. REINFORCE pushes up the probability of every action taken, proportionally to the return. So it happily reinforces even mediocre actions just because the episode ended well overall. The gradient signal is technically correct in expectation. But its variance across episodes is enormous, and learning crawls or diverges. This is not a hypothetical nuisance. It is the central obstacle standing between the clean theory of policy gradients and their practical use in anything beyond toy problems. The fix that makes policy gradient methods usable in practice is deceptively simple: subtract a baseline from the return before using it to scale the gradient. If the baseline is chosen to depend only on the state (not on the action taken), this subtraction leaves the expected gradient completely unchanged. At the same time, it dramatically shrinks its variance. This single idea is the conceptual bridge from plain REINFORCE to modern actor-critic architectures. It underlies essentially every practical policy-gradient algorithm used today, from vanilla policy gradient to A2C, A3C, PPO, and TRPO. The big picture is a general statistical principle in disguise: control variates. Whenever we estimate an expectation via Monte Carlo sampling, we can subtract any zero-mean-correcting term. This reduces variance without touching the estimate's expected value. In reinforcement learning, the return is our noisy sample. A well-chosen baseline absorbs the state-dependent part of that noise. What remains is only the part of the signal that actually distinguishes good actions from bad ones in that state. This article develops the baseline trick rigorously. It explains why subtracting a state-dependent function leaves the gradient unbiased, and why it reduces variance. It shows how to pick a good baseline in practice, typically an estimated state-value function. Finally, it shows how this naturally sets the stage for the advantage function and actor-critic methods, where the "critic" is precisely a learned baseline.
- REINFORCE's raw return-based gradient estimator is unbiased but has very high variance, which slows or destabilizes learning.
- Subtracting any state-dependent baseline from the return leaves the policy gradient's expectation unchanged.
- The unbiasedness holds because for any function of state alone.
- A near-optimal baseline is the state-value function , giving the term , an early form of the advantage.
- Variance reduction scales with how well correlates with ; a learned value-function baseline typically helps enormously.
- This idea directly foreshadows actor-critic methods and the advantage function, where a learned critic replaces the raw return.
Subtracting any state-dependent baseline from the return reduces the variance of the policy gradient estimator while leaving its expectation exactly unchanged.
The idea
Recall the REINFORCE gradient estimator for a trajectory-based objective . The policy gradient theorem gives
where is the return from time onward. This estimator is unbiased: its expectation equals the true gradient. But is a Monte Carlo sample of a random variable that can have huge variance, especially in long-horizon or sparse-reward tasks, and this variance propagates directly into the gradient estimate. A baseline is any function that depends on the state but not on the action. The baselined gradient estimator replaces with :
The key structural requirement is that must not depend on the action (it may depend on the state, the time step, or even be a constant); if this is violated, the subtraction can introduce bias. Subject to that requirement, the identity above holds for any choice of , including the zero function, a running average of past returns, or — most usefully — an estimate of the state-value function . The terminology to fix: the quantity , when , is an estimator of the advantage function , which measures how much better action is than the average action in state . This is the natural conceptual endpoint of the baseline idea and the direct precursor to Actor-Critic Methods and The Advantage Function, where a learned critic network provides online rather than via Monte Carlo averaging.
How it works
Step 1 — Why subtracting a baseline is unbiased. The crux fact is a single lemma: for any function that does not depend on ,
Proof: pull out of the expectation (it is constant with respect to ), and use the "score function" identity . Since is a constant multiplier, this whole expectation vanishes. This means adding or subtracting to the REINFORCE gradient contributes exactly zero in expectation, so the estimator's mean is preserved for any choice of .
Step 2 — Why it reduces variance. Write (the un-baselined per-step gradient contribution, treated as a vector-valued random variable; consider one coordinate for simplicity). The baselined version is where . Since (Step 1), we have , and
If is chosen close to , then tracks the state-dependent part of the noise in closely, making large and positive, and the subtraction removes far more variance than it adds. In the ideal limit , the baselined target becomes , which has zero conditional mean given and thus the smallest possible variance attributable to the "which state did we land in" component of randomness — only the action-selection and future-trajectory noise conditioned on the state remains.
Step 3 — Choosing a practical baseline. Three common choices, in increasing order of effectiveness: 1. Constant baseline: subtract the running average return over recent episodes. Trivial to implement, removes only the overall scale/offset of returns. 2. State-dependent average: bucket states (or use a simple regression) to estimate average return per state. Better, but crude for large or continuous state spaces. 3. Learned value function baseline: train a separate function approximator (via regression toward observed returns) and use . This is the standard choice and is exactly the "critic" of actor-critic methods.
Step 4 — Putting it together in an algorithm. The following is REINFORCE with a learned baseline (sometimes called "REINFORCE with a value-function baseline," a stepping stone to full actor-critic): ``` Initialize policy parameters θ (actor) Initialize value-function parameters w (baseline), e.g. via a neural network v̂(s; w) Set learning rates α_θ (policy) and α_w (baseline) for each episode: generate trajectory s_0, a_0, r_1, s_1, a_1, r_2, ..., s_{T-1}, a_{T-1}, r_T using policy π_θ for t = 0 to T-1: G_t ← sum_{k=t}^{T-1} γ^{k-t} r_{k+1} # Monte Carlo return from step t for t = 0 to T-1: δ_t ← G_t - v̂(s_t; w) # baselined advantage estimate w ← w + α_w · δ_t · ∇_w v̂(s_t; w) # regress baseline toward G_t θ ← θ + α_θ · γ^t · δ_t · ∇_θ log π_θ(a_t | s_t) # policy gradient step end for end for ``` Notes on the pseudocode:
- The return is computed exactly as in plain REINFORCE (no change to the target being estimated).
- plays a dual role: it is the baselined return used to scale the policy gradient, and it is also the regression error used to update the baseline itself toward (this is why 's update uses the same , scaled by , i.e., gradient descent on squared error ).
- The factor in the policy update accounts for discounting from the start of the episode, consistent with the discounted objective; it is sometimes dropped in practice as a design choice that slightly changes what's being optimized.
- Because and are updated using data from the same trajectory, updating first, before using for the update in the same step, is a matter of convention — both orders are used in practice and remain unbiased since we use the same computed before either update. The version shown updates then uses the same for , which is standard.
Complexity & correctness
Time complexity. The baseline adds only a constant-factor overhead to REINFORCE. Per episode of length :
- Computing all returns : (one backward pass accumulating the discounted sum).
- Evaluating at each of the states: where is the cost of one forward pass of the value network (e.g., for a linear model in feature dimension , or the cost of a neural network forward pass).
- Updating via gradient descent on the squared error: for the backward pass, same order as forward.
- The policy gradient update itself: , unchanged from plain REINFORCE.
So overall the algorithm remains per episode — the same asymptotic order as plain REINFORCE, since a baseline is just one more function approximator evaluated alongside the policy. Space complexity is to store the trajectory (states, actions, rewards, returns) plus for the two parameter vectors — again, only an additive constant beyond REINFORCE's .
Correctness (unbiasedness). This is the central theoretical claim, and it deserves a full derivation, not just an assertion. Start from the exact policy gradient (single time step, to keep notation light; summing over recovers the full trajectory case):
Now consider the baselined estimator's expectation:
The second term vanishes because, as shown above, , using the fact that is a probability distribution summing to for every (this differentiate-under-the-sum step is valid under standard regularity conditions on , e.g., smoothness and dominated convergence, which hold for the softmax and Gaussian policies used in practice). Hence the baselined expectation equals the unbaselined one exactly — no approximation, no asymptotic argument, an exact algebraic cancellation for any function that does not depend on . This is why the "must not depend on the action" restriction is not a minor technicality: it is precisely the condition that makes the cancellation term equal to rather than something nonzero.
Correctness (variance reduction, and why it isn't automatic). Variance reduction is not guaranteed for every baseline — it is guaranteed only that the estimator stays unbiased. To see when variance actually goes down, expand:
Variance decreases exactly when — i.e., when is correlated enough with (through the shared randomness in ) relative to the extra noise itself injects via . Since is constant given , choosing close to makes the covariance term large, because it directly cancels the state-dependent mean shift in that has nothing to do with which action was chosen. A provably optimal (minimum-variance) baseline, per state, can even be derived as a weighted average of returns weighted by squared score-function norm, but in practice is used because it is simple to estimate and empirically works extremely well.
Tradeoffs. The baseline is free of bias but not free of cost: a second function approximator must be trained, adding hyperparameters (its own learning rate, architecture, regularization) and a second source of approximation error. If is badly miscalibrated (e.g., early in training), the baseline can be a poor variance reducer — it never introduces bias into the gradient, but a bad baseline may fail to reduce variance much, or even (in finite samples, due to using the same returns to fit and to compute ) introduce subtle correlations that complicate finite-sample analysis, though the population-level unbiasedness of the gradient is unaffected.
Worked example
Consider a tiny two-state MDP: state (start) and state (leads to episode end), with two actions "up" and "down" available in . Suppose across a batch of 4 episodes we observe:
| Episode | State | Action | Return | (baseline) | |
|---|---|---|---|---|---|
| 1 | up | 105 | 100 | +5 | |
| 2 | down | 96 | 100 | −4 | |
| 3 | up | 12 | 10 | +2 | |
| 4 | down | 7 | 10 | −3 |
Without a baseline, REINFORCE would scale the gradient for the "up" action in by and for "down" in by — both positive, so both actions get reinforced, even though "down" was clearly the worse choice in that state. Worse, the raw returns in (around 100) and in (around 10) live on completely different scales, purely because happens to be a state with high value regardless of action. This scale difference is the "nuisance variance" the baseline exists to remove. With the learned baseline and (estimates of each state's average return), the baselined signal becomes for "up" and for "down" in — now correctly signed to increase the probability of "up" and decrease the probability of "down," at a much smaller, more comparable magnitude to the signal in ( and ). The direction of the policy update is unchanged in expectation (both the raw and baselined estimators point the same way on average, by the unbiasedness proof above), but the per-sample gradient magnitudes are now centered near zero rather than swinging between roughly 7 and 105 — a reduction in scale of over an order of magnitude in this toy case, illustrating concretely why gradient noise (and hence required learning-rate tuning and number of samples) shrinks dramatically with a good baseline. To make the variance argument numeric: the sample variance of (crudely as "the scale multiplying the score function") is large — spanning nearly 100 in range — while the variance of spans only 9. Even in this four-point toy batch, the reduction in spread mirrors the general phenomenon: a state-appropriate baseline removes the part of the return's variance attributable to "which state am I in," leaving only the part attributable to "was this action better or worse than the state's average" — precisely the informative signal for policy improvement.
Common pitfalls & traps
| Pitfall | Why it happens | Fix |
|---|---|---|
| Letting the baseline depend on the action | Breaks the exact cancellation ; introduces bias into the gradient | Restrict to be a function of state (and/or time), never of the sampled action |
| Using a single global constant baseline only | Removes overall reward scale but leaves large state-dependent variance untouched | Prefer a learned that adapts per state |
| Training the baseline with too high a learning rate | Overfits noisy per-episode returns, making itself high-variance and destabilizing | Use a smaller/separate learning rate for ; consider more averaging (larger batches) for the value fit |
| Confusing "reduces variance" with "removes bias entirely" | The estimator can still have nonzero variance from action-conditional randomness and bootstrapping error later on | Understand that baselines control variance, not bias; bias enters separately if bootstrapped value estimates are later substituted for full returns |
| Forgetting the discount factor in the policy update | Leads to an estimator of a subtly different (undiscounted-style) objective, changing what is being optimized | Include consistently, or explicitly note the deliberate simplification if omitting it |
| Using the exact same minibatch of returns to both fit and compute for many epochs | Can cause the baseline to "chase" the specific noise in that batch, reintroducing correlated finite-sample bias in practice | Use fresh data or limit the number of gradient steps on per batch; in on-policy settings, this is a known practical subtlety even though population-level unbiasedness of 's gradient is unaffected |
Pioneers & history
The baseline trick sits at the intersection of statistics (control variates, a decades-old variance-reduction technique in Monte Carlo estimation) and the specific machinery of policy gradient reinforcement learning developed in the late 20th century.
Origins · 1 minRonald J. Williams and how this was discovered
Ronald Williams introduced the REINFORCE algorithm and, in the same body of work, the observation that subtracting a "reinforcement baseline" from the reward signal leaves the expected weight update unchanged while typically reducing its variance. This insight — stated originally for connectionist reinforcement learning units — is the direct ancestor of the state-value baselines used throughout modern deep policy-gradient methods.
Where this matters
Baseline subtraction is not a niche trick; it is load-bearing infrastructure in nearly every deployed policy-gradient system. Robotics control policies trained with policy gradients rely on learned value-function baselines to make training tractable within realistic sample budgets, since raw REINFORCE variance would otherwise require infeasibly many rollouts on physical or simulated hardware. Large-scale reinforcement learning from human feedback (RLHF) pipelines used to align language models employ a value-function baseline (often called the "critic" or "value head") precisely to stabilize policy updates over noisy, high-variance reward signals coming from a learned reward model. Game-playing agents, from classic Atari-playing deep RL agents to more recent large-scale game AI systems, use actor-critic architectures whose critic is functionally a baseline in the sense developed here — this article's advantage estimate is the direct ancestor of the advantage estimates used inside PPO and A3C. Simulation-based scientific and engineering optimization (e.g., chip placement, molecule design, resource scheduling formulated as sequential decision problems) similarly leans on baseline-subtracted policy gradients to make Monte Carlo policy optimization practical at all. Understanding this idea is therefore a prerequisite for understanding Actor-Critic Methods and The Advantage Function, both of which are simply more sophisticated, more tightly integrated versions of "learn a good baseline and subtract it."
Ask the tutor: Can you show why the minimum-variance baseline is weighted by the squared score-function norm, and how far that is from just using ?
Does subtracting a baseline change what policy the algorithm converges to?
No. Because the baseline subtraction leaves the expected gradient exactly unchanged (as shown by the cancellation ), the direction the parameters move in, on average, is identical with or without a baseline. What changes is the variance of each individual stochastic gradient step. Lower variance means the empirical average of many samples converges faster to the true expected gradient, and updates are less erratic, but the fixed point of gradient ascent — the local optimum the policy converges toward — is unaffected by the choice of baseline, as long as the baseline genuinely does not depend on the action.
Is the state-value function V(s) the "best possible" baseline?
It is an excellent and very commonly used baseline, but not provably variance-optimal in a strict sense. The theoretically minimum-variance baseline, per state, is a return-weighted average using weights proportional to the squared norm of the score function , which is impractical to compute exactly. is preferred in practice because it is simple to interpret, easy to estimate via regression toward observed returns, reuses the same feature representations as the policy, and empirically captures the large majority of the achievable variance reduction.
How is this different from bootstrapping, as in temporal-difference methods?
Baseline subtraction, by itself, does not require bootstrapping — you can subtract from a full Monte Carlo return and remain fully unbiased with respect to the true policy gradient, since only (not ) determines the expectation. Bootstrapping, by contrast, replaces itself with an estimate like , which introduces bias if is imperfect, in exchange for lower variance and the ability to update online without waiting for episode completion. Actor-critic methods typically combine both ideas: a learned baseline plus bootstrapped targets, trading a controlled amount of bias for large variance and efficiency gains.
Can the baseline depend on time step t, in addition to state?
Yes. Nothing in the unbiasedness proof requires to depend on state alone; it can depend on any information available at the time of the update that is independent of the specific action sampled, including the time index , the episode number, or even be a deterministic function of the entire trajectory prefix up to (but not including) the action choice. In practice, letting vary with can help further reduce variance in finite-horizon tasks, since the scale of expected returns often changes systematically as an episode progresses.
Why doesn't a bad baseline hurt correctness, only efficiency?
Because the proof of unbiasedness (the score-function identity ) holds for literally any function of state alone, regardless of how well or poorly it approximates . A badly miscalibrated (say, wildly overestimating returns) simply fails to correlate well with the true returns, so the variance-reduction benefit shrinks or, in pathological cases, the baseline's own noise could add variance rather than remove it — but the expected value of the gradient estimator is untouched either way, so learning direction on average remains correct, only the sample efficiency and stability suffer.
How does this connect to the advantage function used in later actor-critic algorithms?
The quantity is precisely a Monte Carlo estimate of the advantage function , since and the baseline approximates . Once you accept that a good baseline should approximate , the entire actor-critic framework follows naturally: train a "critic" network to estimate online (often with bootstrapped TD targets rather than full-episode returns), and use the resulting advantage estimate to scale the policy ("actor") gradient, exactly as the baseline-subtraction algorithm here does, but with faster, incremental updates.
Do baselines apply outside of policy gradient methods?
Yes — subtracting a control variate to reduce Monte Carlo variance without changing the expectation is a general statistical technique used throughout computational statistics, not unique to reinforcement learning. Within RL specifically, similar variance-reduction reasoning appears in other estimators too, such as certain formulations of importance-sampling-based off-policy evaluation, where carefully constructed correction terms play an analogous role. The REINFORCE baseline is simply the RL-specific instantiation of this broader idea, tailored to the score-function identity that makes state-dependent terms cancel in expectation.