Search

Search papers and lessons

Advantage Function

Level 4 · 14 min read

The advantage of an action is how much better it is than the policy's average choice in that state, found by subtracting the state value from the action value.

On this page

  • Colour = topic mix
  • Probability
  • Linear algebra
  • Reinforcement learning
  • Stochastic processes
  • Discrete math
  • Sign in to see your progress

TL;DR

The advantage of an action is how much better it is than the policy's usual choice in the same state. Formally, it is the action value minus the state value: Aπ(s,a)=qπ(s,a)−vπ(s)A_\pi(s, a) = q_\pi(s, a) - v_\pi(s). A positive advantage means the action beats the average, and a negative one means it falls short. Because the average is subtracted out, the advantage tells a learner which actions to reinforce without the large, shared offset that makes raw returns noisy.

Where you'll see it: as the learning signal in policy-gradient and actor-critic methods, inside PPO, and in the dueling network architecture that splits a Q-value into a state part and an advantage part.

Intuition

Grading against the usual move

A chess player judges a candidate move by comparing it with what they would normally play in that position. A move that is slightly weaker than the best line is a small slip; a move that drops the queen is a large one. The overall quality of the position is shared by every move the player might choose, so it says little about which move to pick. What matters is how far each move sits from the baseline.

The value function supplies the baseline. In state ss, vπ(s)v_\pi(s) is the expected return when the policy keeps playing, so it is the average over the actions the policy would take. qπ(s,a)q_\pi(s, a) is the expected return when the agent takes aa first. The gap between them is the advantage. An action with qq above vv is better than usual here, and an action with qq below vv is worse.

Why bother with the gap? Imagine a game where every state comes with a large, positive background reward. Raw returns are big whatever you do, and a learner that reinforces each action in proportion to its raw return pushes up every action in that state. The signal that separates good choices from bad ones is buried under the common offset. Subtracting the state value removes the offset, so the update only responds to how much each action differs from the average.

flowchart TD
  S["state s"] --> P["policy picks an action a"]
  S --> V["V(s): average over the policy's actions"]
  P --> Q["Q(s, a): return if a is taken first"]
  Q --> A["A(s, a) = Q - V: gap from the average"]
  V --> A

The math

Definition

Definition: Advantage function

For a policy π\pi, the advantage of action aa in state ss is

Aπ(s,a)=qπ(s,a)−vπ(s),A_\pi(s, a) = q_\pi(s, a) - v_\pi(s),

where qπq_\pi and vπv_\pi are the action-value and state-value functions from the value function lesson.

The average advantage is zero

Average the advantage over the policy's own choices in a state. Using the identity vπ(s)=∑aπ(a∣s) qπ(s,a)v_\pi(s) = \sum_a \pi(a \mid s)\, q_\pi(s, a) from the value-function lesson:

∑aπ(a∣s) Aπ(s,a)=∑aπ(a∣s) qπ(s,a)−vπ(s)∑aπ(a∣s)=vπ(s)−vπ(s)⋅1=0.\sum_a \pi(a \mid s)\, A_\pi(s, a) = \sum_a \pi(a \mid s)\, q_\pi(s, a) - v_\pi(s) \sum_a \pi(a \mid s) = v_\pi(s) - v_\pi(s) \cdot 1 = 0.

The second term uses the fact that the policy's probabilities sum to one. So the advantages of a state, weighted by how often the policy picks each action, always cancel. Some actions have positive advantage and some negative, and they balance.

Advantage as a one-step surprise

The Bellman expectation equation gives qπ(s,a)q_\pi(s, a) as one reward plus the discounted value of the next state:

qπ(s,a)=E[Rt+1+γ vπ(St+1)∣St=s,At=a].q_\pi(s, a) = \mathbb{E}\left[ R_{t+1} + \gamma\, v_\pi(S_{t+1}) \mid S_t = s, A_t = a \right].

Subtracting vπ(s)v_\pi(s) gives the advantage as the expected one-step surprise:

Aπ(s,a)=E[Rt+1+γ vπ(St+1)−vπ(St)∣St=s,At=a].A_\pi(s, a) = \mathbb{E}\left[ R_{t+1} + \gamma\, v_\pi(S_{t+1}) - v_\pi(S_t) \mid S_t = s, A_t = a \right].

The quantity inside the expectation is the TD error,

δt=Rt+1+γ v(St+1)−v(St).\delta_t = R_{t+1} + \gamma\, v(S_{t+1}) - v(S_t).

Given one observed transition, δt\delta_t is a single-sample estimate of Aπ(St,At)A_\pi(S_t, A_t). It is the quantity that temporal-difference learning computes at every step. When vv is exact, the TD error is an unbiased estimate of the advantage. When vv is only approximate, it carries that approximation's error.

Policy gradient with a baseline

The policy gradient for a stochastic policy πθ\pi_\theta is

∇θJ(θ)=Eπ[∇θlog⁡πθ(a∣s) qπ(s,a)].\nabla_\theta J(\theta) = \mathbb{E}_\pi\left[ \nabla_\theta \log \pi_\theta(a \mid s)\, q_\pi(s, a) \right].

Now subtract any function b(s)b(s) that does not depend on the action. The expectation does not change, because for each state

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

The steps are:

  1. Use π∇log⁡π=∇π\pi \nabla \log \pi = \nabla \pi to turn the weighted sum into a plain sum of gradients.
  2. Pull out b(s)b(s), which does not depend on aa.
  3. The probabilities sum to one, so their gradient is zero.

Choose b(s)=vπ(s)b(s) = v_\pi(s). The gradient becomes

∇θJ(θ)=Eπ[∇θlog⁡πθ(a∣s) Aπ(s,a)].\nabla_\theta J(\theta) = \mathbb{E}_\pi\left[ \nabla_\theta \log \pi_\theta(a \mid s)\, A_\pi(s, a) \right].

The expected gradient is the same, but the samples are usually much less noisy, because the advantage is near zero for actions that are close to average.

Estimating it in practice

The true qπq_\pi is unknown, so the advantage has to be estimated from data. There are three common routes.

  • Monte Carlo: A^t=Gt−v(St)\hat{A}_t = G_t - v(S_t), using the full sampled return. It is unbiased when vv is any fixed function, but its variance grows with the episode length.
  • One-step TD: A^t=δt\hat{A}_t = \delta_t. It has low variance, but it is biased whenever vv is wrong, and the error in vv feeds straight into the estimate.
  • Generalized advantage estimation (GAE): an exponentially weighted sum of TD errors,
A^tGAE(γ,λ)=∑l=0∞(γλ)l δt+l.\hat{A}_t^{\text{GAE}(\gamma, \lambda)} = \sum_{l=0}^{\infty} (\gamma \lambda)^l\, \delta_{t+l}.

With λ=0\lambda = 0 this is the one-step TD estimate. With λ=1\lambda = 1 it telescopes into the Monte Carlo estimate Gt−v(St)G_t - v(S_t). Values between them trade bias for variance, and GAE is the standard choice for policy-gradient training.

Worked examples

Example
A two-action state

A state ss has two actions. The policy picks left with probability 0.750.75 and right with probability 0.250.25. The action values are q(s,left)=4q(s, \text{left}) = 4 and q(s,right)=2q(s, \text{right}) = 2.

  1. State value: v(s)=0.75⋅4+0.25⋅2=3+0.5=3.5v(s) = 0.75 \cdot 4 + 0.25 \cdot 2 = 3 + 0.5 = 3.5.
  2. Advantage of left: A(s,left)=4−3.5=0.5A(s, \text{left}) = 4 - 3.5 = 0.5.
  3. Advantage of right: A(s,right)=2−3.5=−1.5A(s, \text{right}) = 2 - 3.5 = -1.5.
  4. Check the zero average: 0.75⋅0.5+0.25⋅(−1.5)=0.375−0.375=00.75 \cdot 0.5 + 0.25 \cdot (-1.5) = 0.375 - 0.375 = 0.

Interpretation: left is a little better than the policy's usual choice, so it deserves a small push upward. Right is clearly worse. The policy takes right only a quarter of the time, but when it does, the advantage is three times larger in magnitude, so the update still carries a strong correction.

Example
One TD error from one step

Take γ=0.9\gamma = 0.9, v(St)=5v(S_t) = 5, and suppose the agent took its action, received reward Rt+1=2R_{t+1} = 2, and landed in a state with v(St+1)=6v(S_{t+1}) = 6.

  1. Bootstrapped target: Rt+1+γ v(St+1)=2+0.9⋅6=2+5.4=7.4R_{t+1} + \gamma\, v(S_{t+1}) = 2 + 0.9 \cdot 6 = 2 + 5.4 = 7.4.
  2. TD error: δt=7.4−5=2.4\delta_t = 7.4 - 5 = 2.4.
  3. Interpretation: the step went 2.42.4 better than the value function expected, so this sample says the action's advantage is about +2.4+2.4.

Change one number. If the reward is 00 and the next state has v(St+1)=4v(S_{t+1}) = 4, then the target is 0+0.9⋅4=3.60 + 0.9 \cdot 4 = 3.6 and δt=3.6−5=−1.4\delta_t = 3.6 - 5 = -1.4. The same action now looks worse than expected.

Example
Three steps of GAE

A trajectory has rewards r1=1r_1 = 1, r2=0r_2 = 0, r3=2r_3 = 2, and the episode ends after step 3. Values are v0=1.0v_0 = 1.0, v1=1.5v_1 = 1.5, v2=1.0v_2 = 1.0, and v3=0v_3 = 0 at the terminal state. Use γ=0.9\gamma = 0.9 and λ=0.8\lambda = 0.8.

  1. TD errors: δ0=1+0.9⋅1.5−1.0=1.35\delta_0 = 1 + 0.9 \cdot 1.5 - 1.0 = 1.35, δ1=0+0.9⋅1.0−1.5=−0.6\delta_1 = 0 + 0.9 \cdot 1.0 - 1.5 = -0.6, and δ2=2+0−1.0=1.0\delta_2 = 2 + 0 - 1.0 = 1.0.
  2. Work backwards with γλ=0.72\gamma\lambda = 0.72. The last advantage is A^2=δ2=1.0\hat{A}_2 = \delta_2 = 1.0.
  3. A^1=δ1+0.72⋅A^2=−0.6+0.72=0.12\hat{A}_1 = \delta_1 + 0.72 \cdot \hat{A}_2 = -0.6 + 0.72 = 0.12.
  4. A^0=δ0+0.72⋅A^1=1.35+0.0864=1.4364\hat{A}_0 = \delta_0 + 0.72 \cdot \hat{A}_1 = 1.35 + 0.0864 = 1.4364.
  5. Compare with the extremes at t=0t = 0. One-step TD gives 1.351.35. Monte Carlo gives G0−v0=(1+0+0.81⋅2)−1.0=1.62G_0 - v_0 = (1 + 0 + 0.81 \cdot 2) - 1.0 = 1.62. The GAE value 1.43641.4364 sits between them, as λ=0.8\lambda = 0.8 should.

Interpretation: the first step looks clearly better than the value function predicted, and the estimate uses the later steps as well, but discounts them.

Tradeoffs and failure modes

Advantages are the right signal whenever you train a policy and have a value estimate. They are not free, though. The table below sorts the common situations.

SituationWhat goes wrongBetter choice
Raw returns as the learning signalLarge common offset per state, high varianceSubtract a baseline, usually v(s)v(s)
Long episodes with sparse rewardMonte Carlo advantage has huge varianceGAE with λ\lambda below 1
Poor value estimateOne-step TD inherits the biasLarger λ\lambda or more steps before bootstrapping
Small discrete action set you can enumeratePolicy gradient is more machinery than you needLearn qq directly, as in [[q-learning
Action the policy almost never takesIts advantage estimate rests on very few samplesAccept the noise, or explore more

Two failure modes come up often in practice. First, advantages are usually normalised across a batch (zero mean, unit variance) before the update. That keeps step sizes stable, but it throws away information about how big the advantages are in one state compared with another. Second, an advantage is defined relative to the current policy. As the policy changes, the advantages it implies change too, which is part of why PPO limits how far one update may move the policy.

History

Advantage-style learning predates deep reinforcement learning. In the early 1990s, Leemon Baird proposed advantage updating, which stores the advantage of each action directly so that learning stays stable when the time step is short. The idea was not widely used at the time, while most work centred on value tables and Q-learning.

It came back in two strands in the mid-2010s. John Schulman and colleagues introduced generalized advantage estimation in 2015, showing that the exponentially weighted sum of TD errors gave a strong trade-off between bias and variance for policy gradients. Ziyu Wang and colleagues introduced the dueling network in 2016, which writes Q(s,a)Q(s, a) as a state value plus an advantage and learns both parts. Both ideas spread quickly, and the advantage became the default signal in actor-critic methods such as A2C and PPO.

Check yourself

QuestionWhat is the advantage of action aa in state ss under policy π\pi, in words and in a formula?Show answer

It is how much better taking aa first is than the policy's average behaviour from ss: Aπ(s,a)=qπ(s,a)−vπ(s)A_\pi(s, a) = q_\pi(s, a) - v_\pi(s). Positive means better than usual, negative means worse.

QuestionA state has v(St)=3v(S_t) = 3. The agent takes an action, receives reward Rt+1=−1R_{t+1} = -1, and lands in a state with v(St+1)=3.5v(S_{t+1}) = 3.5. With γ=0.9\gamma = 0.9, what is the one-step TD error?Show answer

The bootstrapped target is −1+0.9⋅3.5=−1+3.15=2.15-1 + 0.9 \cdot 3.5 = -1 + 3.15 = 2.15. The TD error is 2.15−3=−0.852.15 - 3 = -0.85. This single sample says the action was worse than the value function expected.

QuestionWhy does subtracting vπ(s)v_\pi(s) from the policy gradient leave its expected value unchanged?Show answer

Because for each state, ∑aπ(a∣s) ∇θlog⁡πθ(a∣s) b(s)=b(s)∇θ∑aπθ(a∣s)=b(s)∇θ1=0\sum_a \pi(a \mid s)\, \nabla_\theta \log \pi_\theta(a \mid s)\, b(s) = b(s) \nabla_\theta \sum_a \pi_\theta(a \mid s) = b(s) \nabla_\theta 1 = 0. The baseline term is a constant in aa and it multiplies a gradient that sums to zero over the actions, so it vanishes in expectation. It can still change the variance of the samples, which is the reason to use it.

QuestionA game has a state where every action leads to the same reward and the same next state. What is the advantage of each action there, and what does that imply for learning?Show answer

Every action has the same qq, which equals vv because the policy's average over identical values is that value. So each advantage is zero. The state gives no learning signal about which action is better, and training effort is better spent on states where the actions actually differ.

QuestionIn a game where the value function is only roughly right, why might a one-step TD advantage estimate be worse than a multi-step GAE estimate, even though it has lower variance?Show answer

The one-step estimate uses δt=Rt+1+γv(St+1)−v(St)\delta_t = R_{t+1} + \gamma v(S_{t+1}) - v(S_t), so any error in vv enters the estimate directly, and it cannot correct that error. GAE with λ\lambda above zero adds several later rewards before it relies on vv, so the bootstrapped part matters less. The cost is more variance, so λ\lambda sets a trade-off, not a free improvement.

Sources