Off-policy methods with approximation
Learning about one policy from data generated by another worked well with tables. Combine it with function approximation and bootstrapping, and the weights can grow without bound, even on a tiny problem with exact features. This page reproduces the classic counterexample, explains why it happens, and shows a gradient-TD method that does converge.
01Semi-gradient off-policy TD
The simplest extension of off-policy learning to approximation is to multiply the semi-gradient TD update by the per-step importance-sampling ratio ρt = π(At|St) / b(At|St):
This fixes the targets, which now have the right expected value under π. What it does not fix is the distribution of updates. States are updated as often as b visits them, not π, and the on-policy distribution was exactly what chapter 9's convergence guarantees relied on.
02Worked example: Baird's counterexample
Seven states, all rewards zero, γ = 0.99, so the true value of every state is 0. Each state has two actions. Dashed moves to one of the six upper states at random. Solid moves to the lower state 7. The behaviour policy picks dashed with probability 6/7 and solid with 1/7, so it visits all seven states equally often. The target policy π always picks solid.
The value estimate is linear with 8 weights. Upper state i has v̂ = 2wi + w8, and state 7 has v̂ = w7 + 2w8. The features are linearly independent, so they can represent any value function, including the true one (w = 0). The approximation is not the problem. Start from w = (1, 1, 1, 1, 1, 1, 10, 1).
Baird's counterexample
The MDP (current estimates v̂ inside each state)
Weights
Errors (true v = 0)
What to try
- Sampled TD: click One update a few times. Most transitions are dashed, so ρ = 0 and nothing changes. When solid is taken, ρ = 7, and the update pushes v̂(S) toward 0.99 v̂(7). Since w8 is shared with state 7, raising v̂ of the upper states also raises the target. Run +1000 and the weights head off to the hundreds.
- Switch to expected semi-gradient DP. There is no sampling noise at all: each sweep updates every state equally, with the exact expected target under π. It still diverges. The cause is the update distribution, not randomness.
- Switch to TDC. Within a few hundred sweeps the Bellman error (red) is close to zero, and the value error (green) settles near 1.9. From there it creeps toward zero only very slowly.
03The deadly triad
Instability arises whenever three ingredients are combined:
- Function approximation, which generalizes across states, so updating one state moves others.
- Bootstrapping, where targets include current estimates (TD, DP), rather than only actual returns (MC).
- Off-policy training, which updates states with a distribution other than the target policy's own.
Any two are safe. Drop function approximation and you have tabular Q-learning. Drop bootstrapping and you have Monte Carlo with importance sampling, which is high-variance but stable. Drop off-policy training and semi-gradient TD converges. All three together, as in Baird's example, can diverge. Planning, and learning about many policies in parallel, need off-policy updates, and large problems need approximation. Bootstrapping is the most tempting to give up, but it is usually what makes learning fast.
04Linear value-function geometry
To find a better objective, picture value functions as vectors with one entry per state, and the representable ones (Xw) as a subspace. Distance is measured with weights μ(s). Three errors matter:
- Value error VE: distance from v̂ to vπ. The best achievable point is the projection Πvπ, but reaching it needs vπ, which bootstrapping methods don't have.
- Bellman error BE: distance from v̂ to Bπv̂, its one-step Bellman update. Applying Bπ usually leaves the subspace.
- Projected Bellman error PBE: the length of Π(Bπv̂ − v̂), the part of the Bellman error the representation can see. Linear TD's fixed point is exactly where PBE = 0.
In Baird's example the features span every value function, so Π is the identity and PBE = BE. That is why the chart above plots a single Bellman-error curve.
05Gradient-TD methods
The BE itself is not learnable from data: two MDPs can produce identical observable data yet have different Bellman errors. The PBE is learnable, and true stochastic gradient descent on it is possible. Its gradient is a product of three expectations, and the trick is to learn the middle two as a separate weight vector v ≈ 𝔼[xx⊤]−1𝔼[ρδx], by least squares, on a faster timescale:
The first term of the w update is ordinary off-policy TD. The second is the correction that stops divergence. TDC and its sibling GTD2 cost O(d) per step, about twice as much as TD, and are guaranteed to converge to the PBE minimum under linear approximation with any behaviour policy.
06Emphatic TD and variance
Another fix is to correct the distribution of updates directly. Emphatic TD reweights each update by an "emphasis" that accumulates importance-sampling ratios along the trajectory, so states are effectively updated as if visited on-policy. It is stable in expectation on Baird's example, but its variance is so high that the sampled version is hard to use there.
That points to the chapter's broader lesson: in off-policy learning, the variance of importance sampling is as serious a problem as instability. Tools that help include tree-backup and Retrace-style targets, which avoid ratios or truncate them; weighted importance sampling; and keeping the target and behaviour policies close together. Off-policy learning with approximation is still an active research area.