The Advantage Function

Imagine training an agent to play a video game. Every action receives a reward of roughly +100. This happens whether it moves toward the goal or away from it. A naive policy-gradient method would push up the probability of every action. This is because every return is large and positive. The resulting updates would be swamped by noise. The real signal is not how good an action's outcome was in absolute terms. It is how much better or worse it was than what the agent expected. This is precisely what the advantage function measures. The advantage function, A(s,a)=Q(s,a)−V(s)A(s,a) = Q(s,a) - V(s), reframes the entire policy-gradient problem. It centers the problem around relative quality rather than absolute value. It answers a sharply focused question: given that the agent is in state ss, is action aa better or worse than the policy's average behavior there? This reframing is not a cosmetic trick. It is the mathematical device that makes actor-critic methods practical at scale. It is also the direct ancestor of nearly every modern policy-optimization algorithm, from A3C to PPO to TRPO. This article builds the advantage function from first principles. It starts from the policy-gradient theorem and the role of baselines. It shows precisely why subtracting V(s)V(s) is the variance-minimizing (in a specific, provable sense) and bias-free choice. We derive the actor-critic update that results. We trace through a full worked numerical example. We also highlight the classic implementation traps — from double-counting biases to stale critics. These traps cause real training runs to silently diverge or stagnate. By the end, you will understand not just the formula but the reasoning. You will see why Q−VQ - V is used rather than QQ alone. You will see why this doesn't bias the gradient. You will learn how it is estimated in practice with a single critic network. You will also see how this idea sets the stage for more refined estimators like Generalized Advantage Estimation.

Key takeaways
  • The advantage function is A(s,a)=Qπ(s,a)−Vπ(s)A(s,a) = Q^\pi(s,a) - V^\pi(s): how much better action aa is than the policy's average at state ss.
  • It arises naturally as the optimal (or near-optimal) baseline-subtracted term in the policy-gradient theorem.
  • Subtracting a state-dependent baseline like V(s)V(s) reduces gradient variance without introducing bias.
  • In practice, A(s,a)A(s,a) is estimated using a learned critic Vϕ(s)V_\phi(s) combined with the TD error δt=rt+γV(st+1)−V(st)\delta_t = r_t + \gamma V(s_{t+1}) - V(s_t), which is itself an unbiased (in expectation) estimator of the advantage.
  • Actor-critic algorithms use A^(s,a)\hat A(s,a) to scale the policy-gradient log-probability term, sharpening credit assignment for actions that outperform expectation.
  • The advantage function is the direct conceptual precursor to Generalized Advantage Estimation and to the surrogate objectives used in Trust-Region Policy Optimization and PPO.
The core insight

The advantage function A(s,a)=Q(s,a)−V(s)A(s,a) = Q(s,a) - V(s) converts absolute returns into a relative, low-variance signal that tells the policy gradient exactly which actions to reinforce more or less than average.

The idea

In a Markov Decision Process with policy π\pi, the state-value function Vπ(s)=Eπ[ Gt∣St=s ]V^\pi(s) = \mathbb{E}_\pi[\,G_t \mid S_t = s\,] gives the expected return from state ss under π\pi, while the action-value function Qπ(s,a)=Eπ[ Gt∣St=s,At=a ]Q^\pi(s,a) = \mathbb{E}_\pi[\,G_t \mid S_t=s, A_t=a\,] gives the expected return from taking action aa in ss and following π\pi thereafter. The advantage function is defined as their difference:

Aπ(s,a)  =  Qπ(s,a)−Vπ(s).A^\pi(s,a) \;=\; Q^\pi(s,a) - V^\pi(s).

Because Vπ(s)=∑aπ(a∣s) Qπ(s,a)V^\pi(s) = \sum_a \pi(a\mid s)\, Q^\pi(s,a), the advantage is exactly the deviation of Qπ(s,a)Q^\pi(s,a) from its π\pi-weighted average over actions at ss. Consequently, Ea∼π(⋅∣s)[Aπ(s,a)]=0\mathbb{E}_{a\sim\pi(\cdot\mid s)}[A^\pi(s,a)] = 0 for every state ss: on average, an action is neither better nor worse than the policy itself, by construction. This zero-centering is the key structural property that makes AA so useful — it isolates the relative merit of each action, stripped of the state's overall level of return. This idea connects directly to the concept of a Baselines and Variance Reduction in the policy-gradient theorem. Recall that the vanilla policy gradient is

∇θJ(θ)=Eπ[∑t∇θlog⁡πθ(at∣st) Gt],\nabla_\theta J(\theta) = \mathbb{E}_\pi\Big[\sum_t \nabla_\theta \log \pi_\theta(a_t\mid s_t)\, G_t\Big],

and that subtracting any state-only baseline b(st)b(s_t) from GtG_t leaves the gradient unbiased while typically reducing its variance, since Eat[∇θlog⁡πθ(at∣st) b(st)]=0\mathbb{E}_{a_t}[\nabla_\theta \log\pi_\theta(a_t\mid s_t)\, b(s_t)] = 0. Choosing b(s)=Vπ(s)b(s) = V^\pi(s) turns the term Gt−b(st)G_t - b(s_t) into (in expectation) exactly the advantage Aπ(st,at)A^\pi(s_t,a_t). This is not an arbitrary choice of baseline: Vπ(s)V^\pi(s) is the action-independent part of Qπ(s,a)Q^\pi(s,a), so subtracting it is the natural way to remove state-level variance while retaining all information about which action is better than another. This connects the advantage function tightly to Actor-Critic Methods, where a learned critic estimates V(s)V(s) (or, in some variants, Q(s,a)Q(s,a) directly) precisely to compute this quantity online.

How it works

The practical challenge is that QπQ^\pi and VπV^\pi are unknown and must be estimated from experience. The standard actor-critic recipe avoids learning two separate networks by exploiting the Bellman equation for QπQ^\pi:

Qπ(s,a)=E[r+γVπ(s′)∣s,a].Q^\pi(s,a) = \mathbb{E}\big[r + \gamma V^\pi(s')\mid s,a\big].

Substituting a single sampled transition (s,a,r,s′)(s,a,r,s') gives a one-sample, unbiased estimate of Qπ(s,a)Q^\pi(s,a) as r+γVπ(s′)r + \gamma V^\pi(s'). Plugging this into the advantage definition:

Aπ(s,a)  ≈  r+γVπ(s′)−Vπ(s)  =  δ,A^\pi(s,a) \;\approx\; r + \gamma V^\pi(s') - V^\pi(s) \;=\; \delta,

which is exactly the TD error δ\delta. This is the crucial simplification: a single learned value function Vϕ(s)V_\phi(s) suffices to estimate the advantage, with no need to separately learn QQ. The TD error is an unbiased estimator of Aπ(s,a)A^\pi(s,a) given a perfect critic Vϕ=VπV_\phi = V^\pi; with an imperfect (learned, bootstrapped) critic it is a biased but typically much lower-variance estimator, since it uses only a one-step lookahead instead of the full Monte Carlo return. The resulting actor-critic training loop alternates policy improvement (actor update) using A^\hat A and value-function fitting (critic update) using TD targets. ``` Algorithm: One-Step Advantage Actor-Critic (A2C-style) Input: policy network pi_theta, value network V_phi, learning rates alpha_theta, alpha_phi, discount gamma Initialize theta, phi arbitrarily for each episode: s <- initial state while s is not terminal: a ~ pi_theta( . | s) # sample action s', r, done <- environment.step(a)

# --- compute advantage estimate via TD error --- if done: target <- r else: target <- r + gamma * V_phi(s') delta <- target - V_phi(s) # delta ≈ A(s,a)

# --- critic update: regress V_phi(s) toward target --- phi <- phi + alpha_phi delta grad_phi V_phi(s)

# --- actor update: policy gradient scaled by advantage --- theta <- theta + alpha_theta delta grad_theta log pi_theta(a | s) s <- s' ``` Two implementation details matter for correctness. First, the TD target `target` must be computed using a stopped-gradient copy of `V_phi(s')` — the critic parameters used inside the target should not receive gradient flow from the target term itself, otherwise the regression is not a valid semi-gradient TD update (this mirrors the target-network discipline used in value-based methods). Second, in batched/parallel implementations (e.g. A3C, A2C), the same `delta` is reused for both the actor and critic updates, which is efficient but means any critic bias directly contaminates the actor's gradient — motivating more careful multi-step estimators later.

Figure
Actor-critic advantage computation: how a single TD error serves as A(s,a)
s s′ a, reward r Critic V_φ V_φ(s′) ← target (no grad) V_φ(s) ← current estimate δ = r + γV_φ(s′) − V_φ(s) ≈ A(s, a) (TD-error estimate) Actor: θ += α·δ·∇logπ(a|s) Critic: φ += α·δ·∇V_φ(s)

Complexity & correctness

Time and space complexity. The advantage estimate via TD error costs O(1)O(1) per transition beyond the forward pass of the critic network, since it is a single subtraction and scalar multiply once Vϕ(s)V_\phi(s) and Vϕ(s′)V_\phi(s') are computed. If the critic is a neural network with PP parameters, each update costs O(P)O(P) for the forward and backward pass, identical order to a plain value-based or REINFORCE-style update — the advantage machinery adds no asymptotic overhead. Space is O(Pθ+Pϕ)O(P_\theta + P_\phi) for actor and critic parameters, plus O(1)O(1) additional storage for the scalar advantage per transition (versus O(T)O(T) if full Monte-Carlo returns for an episode of length TT were stored and processed for a REINFORCE-style baseline).

Why the baseline doesn't bias the gradient. This is the central correctness argument and deserves a careful derivation. Start from the policy-gradient theorem in its state-value form:

∇θJ(θ)=Es∼dπ[∑a∇θπθ(a∣s) Qπ(s,a)].\nabla_\theta J(\theta) = \mathbb{E}_{s\sim d^\pi}\Big[\sum_a \nabla_\theta \pi_\theta(a\mid s)\, Q^\pi(s,a)\Big].

For any function b(s)b(s) that does not depend on aa,

∑a∇θπθ(a∣s) b(s)=b(s) ∇θ∑aπθ(a∣s)=b(s) ∇θ(1)=0,\sum_a \nabla_\theta \pi_\theta(a\mid s)\, b(s) = b(s)\, \nabla_\theta \sum_a \pi_\theta(a\mid s) = b(s)\, \nabla_\theta (1) = 0,

since ∑aπθ(a∣s)=1\sum_a \pi_\theta(a\mid s) = 1 for every θ\theta. Therefore

Es[∑a∇θπθ(a∣s) Qπ(s,a)]=Es[∑a∇θπθ(a∣s) (Qπ(s,a)−b(s))],\mathbb{E}_{s}\Big[\sum_a \nabla_\theta \pi_\theta(a\mid s)\, Q^\pi(s,a)\Big] = \mathbb{E}_s\Big[\sum_a \nabla_\theta \pi_\theta(a\mid s)\,\big(Q^\pi(s,a) - b(s)\big)\Big],

for any choice of b(s)b(s), including b(s)=Vπ(s)b(s) = V^\pi(s). This proves that replacing Qπ(s,a)Q^\pi(s,a) with Aπ(s,a)=Qπ(s,a)−Vπ(s)A^\pi(s,a) = Q^\pi(s,a) - V^\pi(s) inside the policy-gradient expectation changes nothing in expectation — the estimator remains exactly unbiased. This is why the advantage function is not a heuristic fix but a mathematically justified reparameterization of the same gradient.

Why it (typically) reduces variance. Writing the per-sample gradient estimator as g(s,a)=∇θlog⁡πθ(a∣s)⋅X(s,a)g(s,a) = \nabla_\theta\log\pi_\theta(a\mid s)\cdot X(s,a) for some scalar XX, the variance of gg scales (holding the log-prob factor fixed in distribution) with Var[X(s,a)]\mathrm{Var}[X(s,a)]. Since Aπ(s,a)=Qπ(s,a)−Vπ(s)A^\pi(s,a) = Q^\pi(s,a) - V^\pi(s) subtracts off the state-dependent mean of Qπ(s,⋅)Q^\pi(s,\cdot) under π\pi, it satisfies Vara[Aπ(s,a)]≤Vara[Qπ(s,a)−c]\mathrm{Var}_{a}[A^\pi(s,a)] \le \mathrm{Var}_a[Q^\pi(s,a) - c] for a constant baseline cc, and more importantly removes cross-state variance that raw returns GtG_t carry (different states can have wildly different typical returns, all irrelevant to which action is better within a state). It can be shown that the variance-minimizing baseline within the class of state-dependent baselines is not exactly Vπ(s)V^\pi(s) but a QQ-weighted quantity; however Vπ(s)V^\pi(s) is extremely close to optimal in practice and is vastly simpler to estimate, which is why it is the standard choice.

Tradeoff: bias from bootstrapping. The one-step TD error δt\delta_t used in practice is an unbiased estimate of Aπ(s,a)A^\pi(s,a) only if Vϕ=VπV_\phi = V^\pi exactly. Since VϕV_\phi is itself learned and imperfect, δt\delta_t carries bias proportional to the critic's approximation error, in exchange for a large reduction in variance relative to full Monte-Carlo advantage estimates (Gt−Vϕ(st)G_t - V_\phi(s_t), which have zero bootstrapping bias but much higher variance because they sum many stochastic future rewards). This precise bias–variance knob — one-step TD versus full Monte Carlo — is exactly what motivates blending multiple horizons, the idea developed fully in Generalized Advantage Estimation.

Worked example

Consider a tiny two-state MDP: a robot at position s0s_0 (far from goal) or s1s_1 (adjacent to goal), with actions `advance` and `wait`, discount γ=0.9\gamma = 0.9, and reward +10+10 upon reaching the goal, 00 otherwise. Suppose the critic has already learned (approximately correct) value estimates:

Vϕ(s0)=4.0,Vϕ(s1)=9.0,Vϕ(goal)=0.V_\phi(s_0) = 4.0, \qquad V_\phi(s_1) = 9.0, \qquad V_\phi(\text{goal}) = 0.

The agent is in s0s_0 and samples action `advance`, transitioning to s1s_1 with reward r=0r=0.

QuantityValueComputation
rr00observed reward
γVϕ(s1)\gamma V_\phi(s_1)8.18.10.9×9.00.9 \times 9.0
TD target8.18.1r+γVϕ(s1)r + \gamma V_\phi(s_1)
Vϕ(s0)V_\phi(s_0)4.04.0current critic estimate
δ\delta (≈ A(s0,advance)A(s_0,\text{advance}))+4.1+4.18.1−4.08.1 - 4.0

The advantage is strongly positive: advancing from s0s_0 led to a state (s1s_1) worth much more than s0s_0 was estimated to be worth, so `advance` outperformed the policy's expectation at s0s_0. The actor update increases log⁡πθ(advance∣s0)\log \pi_\theta(\text{advance}\mid s_0) proportionally to +4.1+4.1. Now suppose instead the agent had sampled `wait` at s0s_0, staying at s0s_0 with reward 00:

QuantityValueComputation
rr00observed reward
γVϕ(s0)\gamma V_\phi(s_0)3.63.60.9×4.00.9 \times 4.0
TD target3.63.6r+γVϕ(s0)r + \gamma V_\phi(s_0)
Vϕ(s0)V_\phi(s_0)4.04.0current critic estimate
δ\delta (≈ A(s0,wait)A(s_0,\text{wait}))−0.4-0.43.6−4.03.6 - 4.0

Here the advantage is mildly negative: waiting is slightly worse than average at s0s_0, so its log-probability is nudged down. Notice the contrast with what a raw-return-based (no baseline) REINFORCE update would do: both actions eventually lead to a terminal reward of +10+10 several steps later, so both trajectories would receive large positive returns Gt>0G_t > 0, and both `advance` and `wait` would have their probabilities pushed up — failing to distinguish that `advance` is markedly better. The advantage function is precisely what recovers this distinction, since it references each action's outcome against the state's own expected value rather than against zero.

Figure
Advantage sign flips reinforcement direction for two actions from the same state
s₀ (V=4.0) s₁ (V=9.0) s₀ (V=4.0) advance → A = +4.1 wait → A = −0.4 reinforce ↑ log π(advance|s₀) suppress ↓ log π(wait|s₀)

Common pitfalls & traps

PitfallWhy it happensConsequence
Letting gradients flow through the TD targetTreating r+γVϕ(s′)r+\gamma V_\phi(s') as fully differentiable in ϕ\phiBreaks the semi-gradient TD update; critic can chase a moving, self-referential target and destabilize
Reusing a stale critic for many actor stepsUpdating actor multiple times per critic refresh in async/parallel setupsAdvantage estimates become systematically biased, slowing or misdirecting learning
Confusing A(s,a)A(s,a) with Q(s,a)Q(s,a)Assuming the advantage alone tells you absolute action qualityAdvantage is relative to the current policy's V(s)V(s); a negative advantage can still be the best available action if all actions are bad
Ignoring reward/return scale mismatchesEnvironments with very large or sparse rewards make δ\delta noisy or explodingActor updates become unstable; typically fixed with reward scaling/normalization
Not zero-centering advantages in batched estimatorsSkipping normalization (subtracting batch mean, dividing by batch std) of A^\hat AHigher-variance gradients across minibatches; slower, noisier convergence in practice
Using single-step TD error when the environment has long-horizon delayed rewardsOne-step bootstrapping introduces heavy bias when rewards are sparse and delayedCritic bias dominates, and the resulting advantage estimate systematically misjudges actions taken far from reward

Pioneers & history

The advantage function traces back to foundational work connecting dynamic programming and reinforcement learning, formalized clearly once the actor-critic architecture and the policy-gradient theorem were established.

Origins · 1 minRichard S. Sutton and how this was discovered
RS
Richard S. Sutton
born 1957 · reinforcement learning theory and actor-critic architectures

Sutton's work on temporal-difference learning and the policy-gradient theorem, developed with collaborators through the 1980s–1990s, provided the mathematical scaffolding — value functions, TD errors, and baseline-corrected gradients — from which the advantage function's role in policy optimization directly follows.

History
1983
— Barto, Sutton, and Anderson introduce the actor-critic architecture for pole-balancing control.
1999
— Sutton, McAllester, Singer, and Mansour formalize the policy-gradient theorem with general baselines.
2000
— Kakade and Langford analyze conservative policy iteration, connecting advantage estimates to monotonic improvement guarantees.
2016
— Mnih et al. popularize the advantage actor-critic (A3C/A2C) architecture for deep RL at scale.
2015–2016
— Schulman et al. introduce Generalized Advantage Estimation, unifying multi-step advantage estimators.

Where this matters

The advantage function underlies nearly every modern deep policy-gradient system. Trust-Region Policy Optimization (TRPO) and Proximal Policy Optimization (PPO) — used to train large-scale robotic control policies and, notably, to fine-tune large language models via reinforcement learning from human feedback — both scale their surrogate objectives by advantage estimates rather than raw returns, because stable, low-variance credit assignment is essential when updates must remain conservative. Asynchronous Advantage Actor-Critic (A3C) and its synchronous counterpart A2C were among the first deep-RL algorithms to train competitively on Atari benchmarks using many parallel actors, each computing local advantage estimates. In robotics, advantage-based actor-critic methods are used to train locomotion and manipulation policies where reward signals are sparse and credit assignment across long horizons is otherwise intractable. Even value-based methods borrow the idea: the Dueling DQN architecture explicitly decomposes its Q-network output into separate value and advantage streams, directly exploiting the identity Q(s,a)=V(s)+A(s,a)Q(s,a) = V(s) + A(s,a) for more sample-efficient learning. Understanding the advantage function is therefore a prerequisite for understanding essentially all contemporary policy-optimization algorithms.

Ask the tutor: How does Generalized Advantage Estimation blend multiple n-step TD errors to further control the bias–variance tradeoff in advantage estimation?

Is the advantage function the same as the TD error?

Not exactly — they are closely related but conceptually distinct. Aπ(s,a)=Qπ(s,a)−Vπ(s)A^\pi(s,a) = Q^\pi(s,a) - V^\pi(s) is defined in terms of the true value functions under policy π\pi. The TD error δ=r+γVϕ(s′)−Vϕ(s)\delta = r + \gamma V_\phi(s') - V_\phi(s) is a sample-based estimator of the advantage, valid in expectation only when the critic VϕV_\phi equals the true VπV^\pi. In practice, with a learned and imperfect critic, the TD error is a biased but low-variance stand-in for the true advantage. Multi-step and generalized estimators (like GAE) interpolate between the one-step TD error and full Monte Carlo advantage estimates to trade off this bias against variance more flexibly.

Why not just use Q(s,a) directly in the policy gradient instead of A(s,a)?

Mathematically, using Qπ(s,a)Q^\pi(s,a) alone in the policy-gradient theorem is also unbiased — the theorem holds without any baseline. The issue is variance, not correctness. Qπ(s,a)Q^\pi(s,a) contains a large state-dependent component (how good is ss overall) that varies enormously across states but carries no information about which action within a state is preferable. Subtracting Vπ(s)V^\pi(s) removes exactly this state-level variance while leaving the action-discriminating signal intact, since it is a per-state constant with respect to aa. Empirically and theoretically, this produces substantially lower-variance gradient estimates and faster, more stable convergence.

Does using the advantage function ever introduce bias into the policy gradient?

The advantage function itself, when defined using true value functions QπQ^\pi and VπV^\pi, introduces zero bias — this follows directly from ∑a∇θπθ(a∣s)=0\sum_a \nabla_\theta \pi_\theta(a\mid s) = 0. Bias only enters through the estimation process: because VϕV_\phi is a learned approximation and the TD target bootstraps off it, any error in VϕV_\phi propagates into the estimated advantage. This estimation bias is a practical concern (and is the reason critics are trained carefully with target networks or n-step returns) but is a separate issue from the mathematical unbiasedness of the advantage-based policy gradient itself.

How does the advantage function relate to Dueling DQN architectures?

Dueling DQN exploits the identity Q(s,a)=V(s)+A(s,a)Q(s,a) = V(s) + A(s,a) in the opposite direction from actor-critic methods: instead of computing AA from separately estimated QQ and VV, it parameterizes a single network with two output streams, one estimating V(s)V(s) and one estimating a shifted version of A(s,a)A(s,a), then recombines them (typically subtracting the mean advantage across actions for identifiability) to produce Q(s,a)Q(s,a). This lets the network learn state values even when action choice doesn't matter much in a given state, improving sample efficiency in value-based deep RL, even though Dueling DQN is not a policy-gradient method.

What role does the advantage function play in PPO and TRPO?

Both algorithms build a surrogate objective that approximates the policy-gradient's effect on expected return while constraining or clipping how far the new policy can move from the old one. The surrogate objective in both cases is expressed in terms of the advantage: TRPO maximizes Et[ πθ(at∣st)/πθold(at∣st)⋅A^t ]\mathbb{E}_t[\,\pi_\theta(a_t\mid s_t)/\pi_{\theta_\text{old}}(a_t\mid s_t)\cdot \hat A_t\,] subject to a KL constraint, and PPO clips this same importance-weighted advantage ratio. In both, A^t\hat A_t is typically computed with Generalized Advantage Estimation rather than a raw one-step TD error, since the additional multi-step averaging further reduces variance while controlling bias, which matters greatly when updates must be trusted across many parallel environments.

Can the advantage function be negative, and what does that mean?

Yes, and negative advantages are common and expected — roughly half of all actions sampled from a stochastic policy at a given state will have below-average value, by the zero-mean property Ea∼π[Aπ(s,a)]=0\mathbb{E}_{a\sim\pi}[A^\pi(s,a)]=0. A negative advantage does not mean the action was objectively bad in absolute terms; it means the action underperformed the policy's own expectation at that state. The policy-gradient update correspondingly decreases the log-probability of that action, gradually reshaping the policy toward actions with positive relative advantage, even in states where all available actions lead to modest returns overall.

Why is V(s) considered close to the "optimal" baseline rather than provably optimal?

The variance-minimizing baseline, derived by minimizing Vara[(Qπ(s,a)−b(s))⋅∇θlog⁡πθ(a∣s)]\mathrm{Var}_a[(Q^\pi(s,a)-b(s))\cdot \nabla_\theta\log\pi_\theta(a\mid s)] over choices of b(s)b(s), is technically a ∇log⁡π\nabla\log\pi-weighted average of Qπ(s,⋅)Q^\pi(s,\cdot), not the plain expectation Vπ(s)=Ea[Qπ(s,a)]V^\pi(s)=\mathbb{E}_a[Q^\pi(s,a)]. These coincide only under specific conditions. In practice the gap between the two is small, while Vπ(s)V^\pi(s) is far easier to estimate — it requires only a state-indexed critic rather than a gradient-weighted quantity — so V(s)V(s) is used almost universally as the practical, near-optimal baseline.

Before this

Where this leads