Episodic, discounted and average-reward forms, and the discounting mistake most code makes.
Most policy-gradient code follows a direction that is not the gradient of the discounted return and, as Nota and Thomas proved in 2020, in general not the gradient of any function at all. Seeing why takes the theorem in its three exact forms, episodic, discounted and average-reward, with proofs that show where each weighting of states comes from. This lesson gives them, dissects the missing γt, and sets the score-function estimator against its pathwise rival.
What you’ll learn
State the policy gradient theorem for the episodic, discounted and average-reward criteria, with the state weighting and normalization each one uses.
Prove the discounted form from the performance difference lemma and the average-reward form from stationarity.
Show with the symmetry of second derivatives that the usual update without γt is not a gradient, and construct a case where it converges to the worst policy.
Compare score-function and pathwise gradient estimators, and explain the deterministic policy gradient as the limit of stochastic ones.
Three objectives, three weightings
The three weightings differ in a way that will matter. The average-reward criterion weights states by how often the policy occupies them in the long run. The episodic criterion counts every visit equally. The discounted criterion weights a visit at time t by γt, so states that occur late barely count: with γ=0.99, a state first reached after 500 steps carries weight 0.99500≈0.0066.
Check your understanding
With γ=0.9, an estimator samples states from the normalized dμπ, actions from π, and averages Aγπ(S,A)∇logπ(A∣S). By what factor must that average be multiplied to equal ∇Jγ?
1
0.9
0.1
10
Show the answer
D. 10
The theorem has 1−γ1=10 in front of the expectation under the normalized distribution. The unnormalized discounted visits sum to 1−γ1, the effective horizon, and normalizing moves that factor outside. In practice it is absorbed into the step size, but it matters when gradients are compared across discount factors.
Two proofs that the state distribution drops out
DerivationDiscounted case, from the performance difference lemma
The performance difference lemma (Kakade & Langford, 2002; proved in Advantages & the Performance Difference Lemma) compares two policies through the advantages of one and the state distribution of the other. Fix θ and let θ′ vary:
Differentiate in θ′ at θ′=θ. In a finite MDP the row vector dμπθ′=(1−γ)μ⊤(I−γPπθ′)−1 is a smooth function of θ′, so the product rule applies:
The term carrying the derivative of the state distribution is multiplied by the policy's average advantage over itself, which is zero in every state. Since ∑a∇π(a∣s)=0, replacing Aγπ by Qγπ, or by Qγπ−b(s), changes nothing. ■
Differentiate V~π(s)=∑aπ(a∣s)Q~π(s,a) and the definition of Q~π. The gain depends on θ; the rewards and dynamics do not. (Differential values are defined up to a constant; fix it any smooth way, since constants cancel below.)
∇rˉ=a∑∇π(a∣s)Q~π(s,a)+s′∑Pπ(s′∣s)∇V~π(s′)−∇V~π(s)for every s
The gain's derivative appears with total weight ∑aπ(a∣s)=1. Solve for it:
The left side does not depend on s, so average the right side over s∼dπ. Stationarity, ∑sdπ(s)Pπ(s′∣s)=dπ(s′), cancels the last two terms exactly:
The episodic form is the trajectory derivation of The Policy Gradient Theorem & REINFORCE with γ=1, and its conditions are where care is needed. Termination with probability 1 for every policy near θ keeps the expected length finite and lets the gradient pass through the sum over trajectories (dominated convergence). Without it Jep can be infinite: in the switched corridor, J(p)→−∞ as p approaches 0 or 1. The average-reward proof needs the unichain assumption for the same reason: with several recurrent classes, the gain depends on the start state and can jump as θ changes which class is reached. Average-Reward Dynamic Programming develops gain and differential values.
The missing γᵗ
Sampling states from dμπ means weighting step t of every trajectory by γt. Almost no implementation does. REINFORCE, A2C and PPO codebases follow
with Qγπ estimated by discounted returns or a discounted critic. In expectation g weights states by their undiscounted visits while valuing actions with the discountedQγπ. Thomas (2014) showed that this mismatch makes several popular discounted natural actor–critic algorithms, including NAC-LSTD and eNAC, biased estimates of the natural gradient they were meant to follow. Then what does g climb?
DerivationNot the gradient of anything (Nota & Thomas, 2020)
g=∇f⟹∂θj∂gi=∂θj∂θi∂2f=∂θi∂gj
If g=∇f and g is continuously differentiable, then f is twice continuously differentiable and its Hessian, the Jacobian of g, is symmetric (Clairaut–Schwarz). One point with unequal cross-derivatives therefore rules out every f:
Their example has two states and deterministic transitions. In s1, action a1 moves to s2 with reward 0 and a2 ends the episode with reward 0; in s2, a1 ends with reward 1 and a2 ends with reward 0. Each state has its own parameter, π(a1∣si)=σ(θi) with the logistic function σ, so V(s2)=σ(θ2) and V(s1)=γσ(θ1)σ(θ2). Summing the undiscounted terms of g over the two time steps:
The cross-derivatives disagree whenever γ<1, so no function has g as its gradient:
gθs=∑tγtPr(St=s)∑tPr(St=s)∇θsJγ(one parameter block per state)
Here g=diag(1,1/γ)∇Jγ still points uphill, and that is no accident. With a separate parameter block θs for each state, each block of g is the true gradient's block times the ratio of undiscounted to discounted visits, a positive number. So for tabular policies g is an ascent direction for Jγ with the same stationary points; the trouble starts when states share parameters, as they always do with function approximation.
DerivationShared parameters: converging to the worst policy
A small example of the failure Nota and Thomas exhibit. Three states visited in order, γ=0.5, and one shared parameter: the agent cannot tell the states apart and plays a1 with probability p=σ(θ) everywhere. In s1, a1 pays 1 and a2 pays 0, and both lead to s2. In s2, a1 pays 0 and leads to s3, while a2 pays 2 and ends the episode. In s3 either action pays 1.9 and ends it. The discounted action values:
dpdJγ=s11+γ⋅s2(0.95−2)+γ2⋅s30=0.475>0
Both objectives prefer a1. The discounted return is Jγ(p)=p+0.5(0.95p+2(1−p))=1+0.475p, and the undiscounted total is Jep(p)=p+1.9p+2(1−p)=2+0.9p. Both are maximized at p=1 and minimized at p=0. The true discounted gradient weights s2 by γ:
g(θ)=σ′(θ)[1+(0.95−2)+p⋅0]=−0.05σ′(θ)<0for every θ
The update without γt weights each state by its visit count, 1 for s1 and s2 and p for s3, while still valuing actions with Qγ, which discounts the delayed 1.9:
So θ decreases forever and the policy converges to always playing a2, the worst policy for both objectives (Jγ=1 instead of 1.475, Jep=2 instead of 2.9), while the parameter diverges. Nota and Thomas build a counterexample of the same kind, whose limit is globally pessimal for the discounted and the undiscounted objective alike.
Predict before you look
In the three-state example with a general discount, the update without γt is proportional to 1+(1.9γ−2). Above which γ does it point toward a1 again?
Show the answer
0.53
1.9γ−1>0 when γ>1/1.9≈0.526. The true gradient, 1+γ(1.9γ−2)=1.9γ2−2γ+1, is positive for everyγ (its discriminant 4−7.6 is negative), so for γ below 0.526 the two disagree about the sign, and the update heads for the worst policy.
Three readings are on offer. Keep γt: treat the discount as part of the problem, as Thomas's (2014) unbiased natural actor–critics do; the cost is that late states get almost no weight, which wastes most of the data in long episodes. Treat γ as a variance knob: the real objective is undiscounted, the critic's discount trades bias for variance (as in generalized advantage estimation), and g is a biased estimate of the undiscounted gradient. Zhang, Laroche, van Seijen, Whiteson and Tachet des Combes (2022) interpret the critic's discounting in this setting as a bias–variance–representation trade-off, and, when the objective really is discounted, the dropped γt as an auxiliary task. Accept the heuristic: g follows no objective, yet it usually works in practice. As of the mid-2020s, which fixed points it reaches with function approximation, and when they are good, is not well characterized.
Score function or pathwise?
Policy gradients are one case of a general problem: differentiate Ex∼pθ[f(x)] with respect to the parameters of the distribution. Two classic estimators exist (reviewed by Mohamed, Rosca, Figurnov & Mnih, 2020).
Estimator
Single-sample form
Needs
Variance
Score function (likelihood ratio, REINFORCE)
f(x)∇θlogpθ(x)
a differentiable logpθ; f can be a black box
often high; grows with the dimension; baselines help
Pathwise (reparameterization)
∇θf(xθ(ε)) with x=xθ(ε), ε∼p(ε) fixed
f differentiable in x, and a reparameterization
usually lower; controlled by the smoothness of f
DerivationOne Gaussian, two estimators
Var=E[(ε+2ε2+ε3)2]−22=(1+12+15+6)−4=30
Estimate dmdEx∼N(m,1)[x2], whose true value is 2m, at m=1. Write x=1+ε with ε∼N(0,1), and recall Eε4=3 and Eε6=15. Score function:x2∂mlogp(x)=x2(x−m)=(1+ε)2ε=ε+2ε2+ε3, with mean 2 and
Var=Var(2ε)=4
Pathwise: differentiate through the sample, dmd(m+ε)2=2(m+ε)=2+2ε, with mean 2 and
Same mean, a variance 7.5 times smaller: the pathwise estimator uses the slope of f, information the score function never sees. Even the best constant baseline, b⋆=E[ε2x2]/E[ε2]=4, leaves the score function far behind:
In reinforcement learning, f is the return, which depends on unknown and often non-differentiable dynamics, so for the true return the score function is the only option. The pathwise estimator becomes available once a learned critic stands in for the return: differentiate Qw(s,a) with respect to the action. Deterministic policy gradients and soft actor–critic do exactly that, trading variance for the critic's bias.
Key takeaways
Three exact forms: episodic, ∑sη(s)∑a∇πQπ with visit counts; discounted, 1−γ1Edμπ[Aγπ∇logπ] with normalized discounted visits; average reward, ∑sdπ(s)∑a∇πQ~π with the stationary distribution.
The derivative of the state distribution never appears: in the discounted proof it multiplies the policy's average advantage over itself, which is zero, and in the average-reward proof stationarity cancels it.
Dropping γt weights states by undiscounted visits while valuing actions with the discounted Qγπ. The result has an asymmetric Jacobian, so it is the gradient of no function. Tabular policies still ascend Jγ, but shared parameters can drive the policy to the worst one.
Score-function estimators need only logpθ; pathwise estimators need a differentiable f and usually have far lower variance (4 against 30 in the Gaussian example). The deterministic policy gradient is the pathwise limit of stochastic policy gradients.
Check yourself
In the interactive lesson these are scored with your confidence, and what you miss comes back for review.
Question 1
In the proof of the average-reward form, which step removes every derivative of the state distribution?
Averaging over the stationary distribution: ∑sdπ(s)[∑s′Pπ(s′∣s)∇V~π(s′)−∇V~π(s)]=0
The differential values average to zero under dπ
The gain rˉ does not depend on θ
Discounting makes late states negligible
Show the answer
A. Averaging over the stationary distribution: ∑sdπ(s)[∑s′Pπ(s′∣s)∇V~π(s′)−∇V~π(s)]=0
Differentiating the differential Bellman equation leaves terms in ∇V~π at the current and the next state. Under the stationary distribution, the next state has the same distribution as the current one, so the two averages are equal and cancel, leaving only ∑sdπ(s)∑a∇π(a∣s)Q~π(s,a).
Question 2
To prove that an update direction g(θ) is not the gradient of any function, what is it enough to show?
That g vanishes at some suboptimal policy
That following g sometimes lowers the return
That the Jacobian of g is not symmetric at some point, for example ∂g1/∂θ2=∂g2/∂θ1
That g has a larger norm than ∇Jγ
Show the answer
C. That the Jacobian of g is not symmetric at some point, for example ∂g1/∂θ2=∂g2/∂θ1
If g=∇f with g continuously differentiable, then f is twice continuously differentiable and its Hessian, the Jacobian of g, is symmetric by the Clairaut–Schwarz theorem. One asymmetric pair of cross-derivatives rules out every f. Nota and Thomas's two-state example has ∂g1/∂θ2=γ∂g2/∂θ1.
Question 3
With a tabular policy, one parameter block per state, how does the update g that omits γt relate to ∇Jγ?
It is identical to ∇Jγ
Each state's block is the true gradient's block times a positive factor, so g still ascends Jγ and has the same stationary points
It points downhill on Jγ
It is exactly the gradient of the undiscounted return
Show the answer
B. Each state's block is the true gradient's block times a positive factor, so g still ascends Jγ and has the same stationary points
Block s of g uses the undiscounted visits ∑tPr(St=s) where the gradient uses ∑tγtPr(St=s); their ratio is positive. A positive per-block rescaling keeps g⊤∇Jγ>0 away from stationary points, but it is not a gradient field. Shared parameters mix the blocks, and then g can point downhill, as in the three-state example.
Question 4
Why can't the pathwise (reparameterization) estimator replace REINFORCE when f is the true return of an unknown environment?
It is biased even when f is differentiable
It only works for discrete actions
Its variance is always higher than the score function's
It needs the derivative of the return with respect to the action, which requires known, differentiable dynamics and rewards, or a learned critic standing in for them
Show the answer
D. It needs the derivative of the return with respect to the action, which requires known, differentiable dynamics and rewards, or a learned critic standing in for them
The pathwise estimator differentiates f through the sampled action, so f must be a known differentiable function of it. A real environment offers only samples of the return. Replacing the return by a learned Qw(s,a) makes the pathwise route possible, as in DPG and SAC, at the price of the critic's bias.
Further reading
R. S. Sutton, D. McAllester, S. Singh & Y. Mansour, "Policy gradient methods for reinforcement learning with function approximation," NIPS 12 (2000).
P. S. Thomas, "Bias in natural actor-critic algorithms," ICML (2014).
C. Nota & P. S. Thomas, "Is the policy gradient a gradient?" AAMAS (2020).
S. Zhang, R. Laroche, H. van Seijen, S. Whiteson & R. Tachet des Combes, "A deeper look at discounting mismatch in actor-critic algorithms," AAMAS (2022).
S. Mohamed, M. Rosca, M. Figurnov & A. Mnih, "Monte Carlo gradient estimation in machine learning," JMLR 21(132), 1–62 (2020).