Off-Policy Learning with Approximation
Training on data from one policy while chasing the values of another sounds efficient, until bootstrapping plus function approximation turns small errors into runaway weights.
Why Does This Exist?
Real agents almost never learn from the policy they are trying to evaluate. The data comes from an older policy, a safe exploratory policy, or a replay buffer full of last week's behavior, while the values being chased belong to the shiny new target policy. That mismatch is off-policy learning, and every practical system needs it.
Three conveniences make it scale, and each one is harmless on its own:
- Function approximation stands in for giant state spaces. You cannot keep a table of every camera image, so a weight vector plus features does the job.
- Bootstrapping updates from the next state's estimate instead of waiting for an episode to end. That is temporal difference learning: fast, online, no waiting.
- Off-policy data lets you reuse experience gathered under some behavior policy while evaluating a different target policy .
Pairs of these are safe. Tabular Q-learning is off-policy plus bootstrapping with no approximation, and it converges. Monte Carlo with linear features is approximation plus off-policy data with no bootstrapping, and it is just regression. On-policy TD is approximation plus bootstrapping with matching distributions, and it settles down.
Combine all three and the guarantees evaporate. This page shows exactly how, on the smallest example that breaks. For the name of the pattern, see the deadly triad. For a bigger demonstration, see Baird's counterexample. For the family of fixes, see gradient TD methods.
The one idea you need first
Semi-gradient TD(0) adjusts weights with , where the TD error compares the current estimate against a bootstrapped target built from the same weights. On-policy, the states arrive in the target policy's own frequencies, and that weighting makes the update a contraction. Off-policy, the weighting belongs to someone else, and the contraction proof no longer applies. The full on-policy story is in semi-gradient TD.
Think of It Like This
Two surveyors sharing one map
Two surveyors share a single paper map of a valley. The first surveyor walks the north ridge every day and pencils in corrections, but only for the north ridge. The second surveyor never visits at all; she just reads the map and plans routes for the south face, trusting whatever is written down.
The catch is that the map is drawn on stretchy rubber with only a few printed grid lines, so each pencil correction tugs its neighbours along. The north surveyor's daily tweaks slowly drag the south face markings out of place. The south surveyor plans from those dragged markings, reports satisfaction, and the north surveyor keeps correcting against a map that keeps moving. Each round stretches the rubber a little further, and the elevations printed on the map climb toward nonsense.
Where it stops: surveyors can walk over and check a peak with their own eyes. Semi-gradient TD has no independent eyes. Its target is built from its own weights, so once the feedback loop turns positive there is nothing outside the loop to pull it back.
How It Actually Works
Use linear features, so . States arrive with behavior frequencies , collected in a diagonal weight matrix . TD wants to satisfy the projected Bellman equation , where is the least-squares projection weighted by and is the target policy's Bellman operator.
Unwrap that into a linear system with . The expected update is , which converges only if is positive definite, meaning every eigenvalue has positive real part. On-policy, equals the target stationary distribution and the math works out. Off-policy, is the wrong weighting, can grow a negative eigenvalue, and then the iteration matrix has an eigenvalue bigger than 1. Every step multiplies the error by a number above 1. That is divergence, and no step size rescues it, because shrinking only moves the multiplier closer to 1 from above.
Worked example
Two states, one weight , features and , discount , step size , start . All rewards are 0, so the true values are 0 and . This is the Tsitsiklis and Van Roy setup from 1997.
Off-policy, only the transition is ever sampled. The TD error is , and the update is . The multiplier 1.08 sits above 1, so:
- , ,
- ,
- ,
After steps , marching to infinity while the truth sits at 0.
On-policy, only the absorbing transition is sampled. Then and :
- , ,
- ,
- ,
Same features, same discount, same start. The only difference is which distribution feeds the updates, and it flips growth into shrinkage.
Code
This snippet replays both traces from the worked example so you can see the multiplier at work:
def td_weight_trace(sampling: str, steps: int = 3) -> list[float]: """One-weight TD trace on the two-state example from the worked section.""" w = 10.0 gamma, alpha = 0.9, 0.1 trace: list[float] = [] for _ in range(steps): if sampling == "off": delta = gamma * 2.0 * w - 1.0 * w w = w + alpha * delta * 1.0 else: delta = gamma * 2.0 * w - 2.0 * w w = w + alpha * delta * 2.0 trace.append(round(w, 4)) return trace
print(td_weight_trace("off")) # -> [10.8, 11.664, 12.5971]print(td_weight_trace("on")) # -> [9.6, 9.216, 8.8474]The off-policy trace grows every step while the on-policy trace shrinks, exactly as the hand computation says.
Watch Out For
Importance ratios do not fix the state weighting
When people meet this divergence, the first reflex is to weight each update by and call it fixed. It is not. Those ratios correct which actions get emphasized, but the states themselves still arrive in behavior frequencies . The matrix stays wrong, keeps its negative eigenvalue, and the weights still blow up, now with extra variance from the ratios on top.
If you need stability under all three conditions, reach for a true fix: gradient TD methods, emphatic weighting that repairs the state distribution, or target networks that slow the feedback loop.
A smaller step size only slows the explosion
Another reflex is to turn down until the shaking stops. Check the multiplier: stays above 1 for every positive . At the weight still grows, just 80 times slower, so short runs look stable and long runs still overflow. A learning rate that only delays the blowup is not a cure. If your off-policy linear TD looks fine for a thousand steps and then drifts upward forever, suspect the distribution, not the step size.
The Quick Version
- Off-policy learning with approximation combines three conveniences: linear features, bootstrapped TD targets, and data from a different behavior policy.
- Any two of the three are safe, but all three together can make the projected Bellman operator expand instead of contract.
- Convergence needs the matrix positive definite, and off-policy weighting can break exactly that.
- In the two-state example the weight multiplies by 1.08 per step off-policy and 0.96 on-policy, from the same start of 10.
- Action importance ratios do not repair the state distribution mismatch, and shrinking the step size only slows the growth.