Advantages & the Performance Difference Lemma
An exact formula for how much better one policy is than another.
How much better is one policy than another? The performance difference lemma answers exactly: average the old policy's advantages over the states the new policy visits. That one identity proves the policy improvement theorem, prices the regret of any policy, and explains why policy iteration, conservative policy iteration, TRPO and the natural policy gradient work. It also names their central difficulty: the states that matter belong to a policy you have not run yet.
What you’ll learn
- State and use the properties of the advantage function: zero mean under its policy, equality with the expected TD error, invariance under potential-based shaping, and nonpositivity at the optimum.
- Prove the performance difference lemma by telescoping and in matrix form, and verify it on a two-state MDP.
- Derive the policy improvement theorem, an optimality criterion and a regret decomposition as corollaries.
- Bound the distribution mismatch and derive the improvement guarantee behind conservative policy iteration and TRPO.
- Explain the tabular natural policy gradient as soft policy iteration and prove that it improves monotonically.
The advantage function
The advantage measures a single deviation: take now, then return to . Throughout, and is the normalized discounted occupancy measure of Occupancy Measures & the Dual View, with state marginal .
| Pair | for = (stay, stay) | , optimal policy (go, stay) |
|---|---|---|
In state a policy plays , and with probabilities 0.5, 0.25 and 0.25. You know and . What is ?
- It cannot be determined without
Show the answer
C.
The advantages average to zero under the policy: gives . Both and are worse than the policy's average, and makes up for them.
The performance difference lemma
Run from . Since is bounded and , the sum telescopes to . Add it inside the expected return of :
Each bracket is a TD error of the old value function on a transition of the new policy. Conditioned on , the Markov property makes its expectation an advantage of the old policy, whichever policy chose :
Sum over time with weights (bounded rewards justify exchanging sum and expectation) and regroup by state–action pair, as in the definition of the occupancy measure.
For stationary policies there is a second proof, in one line of linear algebra, that gives the improvement in every state at once. Let , which equals , the one-step gain from following for a single step:
Corollaries: improvement, optimality, regret
The successor matrix has nonnegative entries and satisfies entrywise. With :
Optimality. If no advantage is positive, every stationary has , so ; by the telescoping form, every history-dependent policy is no better either. Conversely, if , switching to in alone gives with , and the first part makes strictly better.
The criterion is the Bellman optimality equation in disguise: everywhere means , that is . Swapping the roles of the two policies in the lemma gives the regret of any policy against an optimal one:
Now the occupancy is that of the policy being judged, and is fixed once and for all. The regret is the discounted sum of the action gaps that pays along its own trajectories: a wrong action in a state the policy never visits costs nothing, and a small gap paid in a frequently visited state can cost more than a large one paid once.
Apply the regret decomposition to = (stay, go) started in . Its occupancy puts on and on , and the action gaps are and . What is ?
Show the answer
11
, which matches . Most of the regret comes from the small gap 0.8, paid at every step in , not from the large gap 3.8, paid once.
Differentiating the lemma gives the policy gradient theorem. Put and differentiate at . By the product rule there are two terms. The one in which the occupancy is differentiated is weighted by , which is zero in every state, so only the other survives: (The Policy Gradient Theorem & REINFORCE). The state distribution changes with , but to first order that change does not matter.
Whose states? Distribution mismatch
To choose , the lemma needs , which is unknown until has been run. Policy-improvement methods replace it by the current policy's distribution, which the data already collected can sample:
the surrogate objective, estimated from 's samples by reweighting actions with . It equals at and has the same gradient there (Kakade & Langford, 2002), so it is right to first order. Far from it can be badly wrong.
On the two-state MDP from , = (stay, stay) never leaves , so is a point mass there and the surrogate credits a switch to go with its advantage 8 at every step: it predicts a gain of . The true gain is 8, because after one go the new policy sits in , where there is nothing more to gain. The mixtures that go with probability in show the transition from right to wrong.
| True gain | Surrogate: | Guarantee: | |
|---|---|---|---|
| (largest) | |||
Let and , so that . The resolvent identity writes the new distribution as the old one plus a correction driven by the change in transitions:
The rows of sum to , so multiplying a row vector by multiplies its norm by at most that. And has norm at most . This is Lemma 3 of Achiam, Held, Tamar and Abbeel (2017):
Replace by in the lemma and pay for it. With and , the error is at most , which gives their Corollary 1.
For the mixtures, , and , so the guarantee is : it peaks at with a promise of 1.11, where the true gain is 1.78. This is the logic of conservative policy iteration (Kakade & Langford, 2002), which mixes an improved policy into the current one with a weight chosen to maximize such a bound. Schulman et al. (2015) extended it to general stochastic policies: with and the largest total variation , , and since , a penalty on the largest KL divergence works too. On the example () that bound promises at most 0.40, at , where the true gain is 0.74. Bounds this conservative are not run as they stand: TRPO keeps their shape, maximizing the surrogate while staying close to , but swaps the penalty for a hard limit on the KL divergence averaged over visited states, and PPO by clipping the probability ratio (Trust Regions: TRPO & PPO).
Why do surrogate objectives such as use the old policy's state distribution instead of the new policy's?
- Because the two distributions are always equal
- Because the lemma becomes false with
- Because the old policy's states are the more important ones
- Because can be sampled from data already collected, while is unknown until runs; the price is an error that grows with how far moves from
Show the answer
D. Because can be sampled from data already collected, while is unknown until runs; the price is an error that grows with how far moves from
The exact identity needs the new occupancy. The surrogate trades exactness for computability, and the mismatch lemma bounds the error by , which is why every practical method limits the size of the policy change.
Soft policy iteration: the natural policy gradient
Policy iteration takes the boldest step the advantages allow: jump to the greedy policy. The natural policy gradient takes a soft version of the same step. For a tabular softmax policy , Kakade's natural gradient with step size adds scaled advantages to the logits, so the policy is reweighted multiplicatively (Agarwal, Kakade, Lee & Mahajan, 2021):
As this becomes policy iteration's greedy step; for finite it is soft policy iteration, the multiplicative-weights update of online learning run in every state. The Fisher matrix cancels the state distribution: the update does not depend on .
Take logarithms of the update: . Average over , and write for the KL divergence from to :
By Jensen's inequality and , . The lemma, and , then give improvement from every start distribution (their Lemma 5.2).
Key takeaways
- Advantages average to zero under their policy, equal expected TD errors, are unchanged by potential-based shaping, and are never positive under an optimal policy.
- Performance difference lemma: , the old policy's advantages averaged over the new policy's occupancy; in matrix form .
- Corollaries: greedy steps never hurt any state, a policy is optimal exactly when no advantage is positive, and a policy's regret is the discounted sum of the action gaps it pays on its own trajectories.
- The new occupancy is unknown, so methods optimize a surrogate on the old policy's states. Its error is controlled by , the root of conservative policy iteration, TRPO and PPO.
- The tabular natural policy gradient is soft policy iteration, : it improves monotonically by the lemma and is -optimal after iterations.
Check yourself
In the interactive lesson these are scored with your confidence, and what you miss comes back for review.
You add a potential-based shaping reward to every transition of a continuing task. What happens to the advantage function of each policy?
- It shifts by
- It is unchanged
- It shifts by
- It is scaled by
Show the answer
B. It is unchanged
The shaping terms telescope along every trajectory, so every return from shifts by , whatever the first action. and both shift by , and their difference is untouched. This is one way to see why potential-based shaping cannot change which actions are better.
A policy picks, in every state, an action whose advantage under is nonnegative, and in state an action with . What is the smallest possible value of ?
Show the answer
D.
with entrywise and , so the gain at is at least . It equals 2 when never returns to and gains nothing elsewhere; it reaches only if collects that advantage at every step.
A colleague estimates by averaging , the new policy's advantages, over states and actions drawn from the old policy . What does the lemma say this estimates?
- , the same quantity, by symmetry
- , after multiplying by : the lemma with the roles of the two policies exchanged
- Zero, because advantages average to zero
- Nothing meaningful
Show the answer
B. , after multiplying by : the lemma with the roles of the two policies exchanged
Exchanging and in the lemma gives : the old policy's occupancy, the new policy's advantages, and the opposite sign. It is a valid identity, but is exactly what is unknown before has been evaluated.
In the tabular natural policy gradient, . What does the update become as ?
- The uniform policy
- No change:
- A plain gradient step on with step size
- Policy iteration: in every state all probability moves to
Show the answer
D. Policy iteration: in every state all probability moves to
Exponential weights concentrate on the largest advantage, and since , that is policy iteration's greedy action. A softmax policy gives every action positive probability, so no action is excluded. Small gives small, safe steps; large gives policy iteration's big jumps.
Further reading
- S. Kakade & J. Langford, "Approximately optimal approximate reinforcement learning," ICML (2002).
- S. M. Kakade, "A natural policy gradient," Advances in Neural Information Processing Systems 14 (2001).
- J. Schulman, S. Levine, P. Moritz, M. Jordan & P. Abbeel, "Trust region policy optimization," ICML, PMLR 37 (2015).
- J. Achiam, D. Held, A. Tamar & P. Abbeel, "Constrained policy optimization," ICML, PMLR 70 (2017).
- A. Agarwal, S. M. Kakade, J. D. Lee & G. Mahajan, "On the theory of policy gradient methods: Optimality, approximation, and distribution shift," Journal of Machine Learning Research 22(98), 1–76 (2021).