Stable Off-Policy Learning: Gradient TD & Emphatic TD
True gradient methods on the projected Bellman error, and reweighting by emphasis.
Off-policy linear TD can diverge because its expected update is not the gradient of anything. Two repairs make it provably stable at cost per step. Gradient-TD methods do true stochastic gradient descent on the projected Bellman error, using a second weight vector to break a product of expectations; emphatic TD keeps the TD update but reweights it so that the key matrix becomes positive definite. This lesson derives both from scratch, through the saddle-point view that unifies the gradient methods, and weighs what each costs: slow progress, step-size sensitivity, or variance.
What you’ll learn
- Derive the mean squared projected Bellman error , and rewrite it as a convex–concave saddle point with unbiased single-sample gradients.
- Derive GTD2 and TDC, state their convergence conditions, and explain why TDC is fast on the projected Bellman error but slow on the value error in Baird's problem.
- Derive the followon trace and emphasis of emphatic TD, prove that the emphatic key matrix is positive definite, and explain the variance problem.
- Compare GTD2, TDC, emphatic TD and TDRC, and describe where these methods stand in practice.
An objective whose minimum is the TD fixed point
Fix linear features, a target policy with transition matrix and reward vector , and a behavior policy whose state distribution sits on the diagonal of . Transitions arrive as with , , and importance ratio , so that . Three expectations summarize everything linear TD needs:
Semi-gradient TD follows , which is not a gradient field, and off-policy can have eigenvalues with negative real part. The fix is to pick an objective that vanishes exactly at the TD fixed point and descend it.
With the -weighted projection and the Bellman residual, , so the projected Bellman error collapses to three expectations:
It is a convex quadratic in , zero exactly at the TD fixed point (when is invertible). But its gradient is a product of expectations, and multiplying independent-looking single-sample estimates of each factor would be biased, the double-sampling problem again:
The Fenchel identity , attained at , moves the inverse into an optimization. Every term inside is now the expectation of a single-transition quantity:
is linear in and concave in , so minimizing is the convex–concave saddle-point problem , and one transition gives unbiased stochastic gradients of both arguments (Liu, Liu, Ghavamzadeh, Mahadevan & Petrik, 2015). The optimal is the least-squares regression of on the features: the expected TD error, as the features can see it.
The first gradient-TD method (GTD; Sutton, Szepesvári & Maei, 2008) minimized a different objective with the same zero, the norm of the expected update . The projected Bellman error weights that vector by , which corresponds to the geometry of the feature space and gave faster algorithms (Sutton et al., 2009).
GTD2 and TDC
GTD2 is stochastic gradient descent in and ascent in on :
TDC (TD with gradient correction) uses one more identity before sampling. Since , the gradient direction equals : the ordinary TD update minus a correction. Replacing by gives
When , TDC is off-policy semi-gradient TD; the correction term is what removes the instability.
import numpy as np
def tdc_step(w, h, x, r, x_next, rho, gamma, alpha, beta):
"""One TDC update from an off-policy transition; rho = pi(a|s) / b(a|s)."""
delta = r + gamma * (w @ x_next) - w @ x
hx = h @ x # features' estimate of E[rho * delta | s]
w = w + alpha * rho * (delta * x - gamma * x_next * hx) # TD step minus gradient correction
h = h + beta * rho * (delta - hx) * x # least-mean-squares regression
return w, hBoth vectors cost per step. At termination pass x_next as zeros.
Think first TDC on Baird's problem makes the projected Bellman error tiny while the value error stays near 2. Since the seven feature vectors are independent, the projection is the identity and equals the full Bellman error, which is zero only at the true values. Why is progress on the value error so slow?
Because a value function that is nearly constant is nearly a fixed point of the target policy's backup. In Baird's problem , so a constant function has Bellman error . An expected-update computation (step sizes , ) gives after 500 sweeps with , and thousands of sweeps later barely anything has changed: the gradient of an objective that is already almost zero is almost zero. The method does converge to the true values, but at a rate governed by -small curvature. Minimizing the projected Bellman error is the right limit and a weak signal when is near 1.
The same construction extends to action values and control. GQ() (Maei & Sutton, 2010) learns action values with eligibility traces; Greedy-GQ (Maei, Szepesvári, Bhatnagar & Sutton, 2010) targets the greedy policy of a linear from a fixed behavior policy, at per step, with convergence to a stationary point of its objective rather than to . For smooth nonlinear approximators, Maei et al. (2009) proved convergence of gradient-TD methods to local optima of a projected objective.
Emphatic TD: reweight until the key matrix is positive definite
Emphatic TD (Sutton, Mahmood & White, 2016) keeps the semi-gradient update and changes how much each state's update counts. Recall the column-sum criterion: a key matrix , with nonnegative state weights on the diagonal of , is positive definite if its row sums and column sums are positive. Under the behavior's own weighting, the column sums can be negative. So choose the weights to make them positive by construction: give each state an interest and solve
The emphasis is the discounted flow of interest into under the target policy: the weighting an on-policy learner would have used, rebuilt from off-policy data.
ETD(0) multiplies each update by a scalar followon trace , with :
In steady state, satisfies the same recursion as : reaching means arriving from some through an action whose ratio converts the behavior's transition probabilities into the target policy's:
So the expected update is with , whose state-space key matrix has positive row sums and column sums . With the column-sum criterion applies and is positive definite: stable for any behavior policy that covers the target's actions. With the emphasis becomes and the same argument goes through.
In Baird's problem with interest 1 everywhere, and the target policy funnels everything into , so : about 0.143 for each upper state and for . The emphatic key matrix then has eigenvalues (the null direction ), five times, about and , all nonnegative, and the expected iteration converges to an exact solution. Yu (2015) proved that ETD() converges with probability one under general off-policy conditions.
In Baird's problem with and interest 1 in every state, how many times more emphasis does receive than an upper state? Use .
Show the answer
694
. Emphatic TD concentrates almost all of its weight where the target policy actually goes, as an on-policy learner would. The catch is how it estimates that weight: accumulates products of importance ratios, and to represent a factor of about 700 from data in which solid actions carry and dashed ones , the trace must occasionally become very large. Its variance is so high on this problem that Sutton and Barto report it "nigh impossible" to get consistent results from sampled runs; they show only the expected trajectory.
Saddle points, regularized corrections, and practice
The saddle-point view does more than tidy the derivation. Because is convex–concave, primal–dual stochastic gradient methods come with finite-sample guarantees, and accelerated or proximal variants apply (Liu et al., 2015). The same Fenchel trick handles control: SBEED (Dai et al., 2018) applies it to a smoothed, entropy-regularized Bellman optimality error, obtaining a primal–dual algorithm for general nonlinear function classes, with a guarantee of convergence to a stationary point.
The most practical descendant so far is TDRC (Ghiassian, Patterson, Garg, Gupta, White & White, 2020). It fits the secondary weights by ridge regression, solving , and keeps TDC's update for . With it is TDC; as , and it becomes plain TD. With the default and a single step size it behaved as well as TD where TD works, remained sound where TD diverges, and outperformed other gradient-TD methods across their benchmarks; its control version, QRC, extends the idea to deep networks.
| Method | Cost per step | Off-policy guarantee (linear) | Main weakness |
|---|---|---|---|
| Semi-gradient TD | None; can diverge | Instability (Baird) | |
| LSTD | Solves ; off-policy fixed point may be poor | Quadratic cost | |
| GTD2, TDC | , two vectors | Converge to the TD fixed point (GTD2 with proportional step sizes, TDC on two timescales) | Second step size; slow where the objective is flat |
| Emphatic TD | , one scalar trace | Positive definite key matrix; converges w.p. 1 (Yu, 2015) | High variance of the followon trace |
| TDRC | , two vectors | Sound where TD diverges | Regularization biases ; mostly empirical support beyond the linear theory |
TDRC fits its secondary weights by ridge regression with penalty . What does TDRC reduce to as ?
- TDC
- GTD2
- Ordinary semi-gradient TD
- Emphatic TD
Show the answer
C. Ordinary semi-gradient TD
An infinite ridge penalty forces , and with TDC's correction term vanishes, leaving semi-gradient TD. At the secondary weights are an unregularized regression and TDRC is TDC. The default sits between.
Key takeaways
- The projected Bellman error is , zero at the TD fixed point; a Fenchel identity turns it into a convex–concave saddle point with single-sample gradients.
- GTD2 and TDC learn a second vector and converge off-policy at per step (TDC's proof uses two timescales); on Baird's problem TDC zeroes the projected Bellman error quickly but approaches the true values very slowly.
- Emphatic TD reweights each update by a followon trace whose expectation is the discounted flow of interest under the target policy; this makes the key matrix positive definite, at the cost of high variance.
- TDRC interpolates between TD and TDC with a ridge penalty on ; in deep RL, target networks and replay remain the common stabilizers as of the mid-2020s.
Check yourself
In the interactive lesson these are scored with your confidence, and what you miss comes back for review.
Why can't plain stochastic gradient descent on use one transition per update?
- Because the objective is not convex
- Because its gradient is a product of expectations, and multiplying single-sample estimates of the factors gives a biased estimate
- Because the importance ratios have mean zero
- Because the projected Bellman error cannot be computed for linear features
Show the answer
B. Because its gradient is a product of expectations, and multiplying single-sample estimates of the factors gives a biased estimate
multiplies three expectations. Gradient-TD methods learn separately, or equivalently solve the saddle point , whose gradients are expectations of single-transition quantities.
What does TDC's secondary weight vector converge to, on its faster timescale?
- The TD fixed point
- The true value function's weights
- , the least-squares regression of the TD error on the features
- The emphasis weights
Show the answer
C. , the least-squares regression of the TD error on the features
Its update is a least-mean-squares regression of on (importance-weighted). It estimates where the features say the TD errors are systematically positive or negative, which is exactly the factor needed to complete the gradient.
Why is emphatic TD's expected update stable for any behavior policy that covers the target's actions?
- Because the followon trace has low variance
- Because it is a true gradient method on the projected Bellman error
- Because it updates only on-policy transitions
- Because its emphasis makes the key matrix's column sums equal to , with positive row sums, so the key matrix is positive definite
Show the answer
D. Because its emphasis makes the key matrix's column sums equal to , with positive row sums, so the key matrix is positive definite
The emphasis solves by construction, so the column-sum criterion holds whatever the mismatch between and . The expected update is then a stable linear system, which Yu (2015) turned into an almost-sure convergence result for ETD().
Further reading
- R. S. Sutton, H. R. Maei, D. Precup, S. Bhatnagar, D. Silver, C. Szepesvári & E. Wiewiora, "Fast gradient-descent methods for temporal-difference learning with linear function approximation", ICML (2009).
- R. S. Sutton, A. R. Mahmood & M. White, "An emphatic approach to the problem of off-policy temporal-difference learning", Journal of Machine Learning Research 17 (2016).
- H. Yu, "On convergence of emphatic temporal-difference learning", COLT (2015).
- B. Liu, J. Liu, M. Ghavamzadeh, S. Mahadevan & M. Petrik, "Finite-sample analysis of proximal gradient TD algorithms", UAI (2015).
- S. Ghiassian, A. Patterson, S. Garg, D. Gupta, A. White & M. White, "Gradient temporal-difference learning with regularized corrections", ICML (2020).