Off-Policy Learning with Approximation
Combining off-policy data, bootstrapping, and function approximation creates the Deadly Triad, where Bellman targets expand rather than contract, driving value estimates toward infinity.
Why Does This Exist?
Modern reinforcement learning systems must satisfy three practical requirements simultaneously:
- Generalization across massive state spaces: Tabular lookups cannot represent continuous control or high-dimensional sensory inputs like images, requiring parametric function approximation .
- Sample efficiency through online updating: Waiting for entire trajectories to complete (Monte Carlo rollouts) is high-variance and impossible in non-terminating tasks, requiring 1-step temporal difference bootstrapping .
- Exploration and sample reuse: Agents must explore safely while evaluating greedy target policies, reuse historical transition transitions from replay buffers, or evaluate multiple parallel behaviors from a single stream of experience, requiring off-policy data where the behavior distribution differs from the target stationary distribution .
When used separately or in pairs, reinforcement learning algorithms remain provably stable:
- Tabular + Bootstrapping + Off-Policy: Standard tabular Q-learning converges to with probability 1 because the tabular Bellman operator is an infinity-norm contraction ().
- Function Approximation + Off-Policy (No Bootstrapping): Monte Carlo policy evaluation with linear features is standard supervised regression. It minimizes mean-squared error with no feedback loop, guaranteeing stable convergence to the minimum-error projection.
- Function Approximation + Bootstrapping + On-Policy: Semi-gradient contracts under the stationary distribution weighted norm , converging to a unique fixed point .
However, combining all three elements forms what Richard Sutton termed The Deadly Triad. When bootstrapping targets are projected onto a lower-dimensional feature subspace under an off-policy visitation distribution , the composite projected Bellman operator ceases to be a contraction mapping. The update matrix develops eigenvalues with negative real parts, turning stable temporal difference corrections into an explosive positive feedback loop where weights grow exponentially toward infinity.
Think of It Like This
The Outdated Map and the Echoing Detour
Imagine an automated highway logistics planner trying to estimate driving times between cities. The planner uses a compressed lookup table that groups adjacent towns into single generalized regions (function approximation).
To update transit estimates without waiting for trucks to complete thousand-mile hauls, the dispatcher updates the departure city's estimate using the current estimate of the next town along the route plus the immediate leg's toll-booth time (bootstrapping).
However, the fleet is currently routed through rural secondary detours due to winter storms, so real trucks only visit rural backroads rather than the main interstates (off-policy sampling). When a driver on a detour reports a slight delay, the regional lookup table inadvertently raises the estimated transit time for both the rural road and the adjacent highway interchange.
On the next iteration, the bootstrapped calculation treats this newly inflated interchange estimate as ground truth. Because actual trucks rarely traverse the primary highway under the storm routing, the algorithm never gathers empirical evidence to correct the inflation. Instead, the inflated highway value feeds back into the rural detour calculation, which inflates the interchange further, echoing endlessly until the software predicts a 5-minute commute will take 10 million hours.
Where the analogy stops: Real-world fleet dispatchers can compare route plans against absolute GPS timestamps to reset drift. In semi-gradient temporal difference learning, there is no global supervising timestamp—the algorithm blindly trusts its own parameterized predictions as targets, creating runaway divergence when distribution weighting does not align with transition dynamics.
How It Actually Works
The Deadly Triad and Projected Bellman Divergence
Consider linear function approximation where the value of state is approximated as:
where is the feature vector of state and is the parameter vector. In matrix notation across all states , , where is the feature matrix.
Let be the diagonal matrix of state visitation probabilities under the behavior policy . The weighted least-squares projection operator maps any arbitrary state-value vector onto the linear subspace spanned by :
The target policy Bellman evaluation operator maps value vectors via:
where is the expected reward vector, is the state transition probability matrix, and is the discount factor.
Semi-gradient linear TD seeks a parameter vector satisfying the projected Bellman equation:
Multiplying both sides by removes the projection inversion , yielding the linear system:
Rearranging into standard form :
The expected continuous parameter evolution under semi-gradient TD updates with step size follows the ordinary differential equation (ODE):
For the discrete iteration to converge to , the matrix must be positive definite (all eigenvalues of must have strictly positive real parts, ).
-
On-Policy Stability (): When transitions are sampled from the target policy's stationary distribution , the matrix has a strictly positive-definite symmetric part:
Because has full column rank, is positive definite. The composite operator is a contraction with modulus in the norm, guaranteeing convergence to a unique solution with bounded approximation error:
-
Off-Policy Instability (): When data arrives from behavior distribution , the weighting matrix does not balance the target transition matrix . The symmetric part can have negative eigenvalues.
When has an eigenvalue with , the transition matrix has an eigenvalue with magnitude . The spectral radius satisfies , causing at a geometric rate regardless of step size magnitude.
Worked numerical example
To observe divergence directly, consider the classic minimal counterexample introduced by John Tsitsiklis and Benjamin Van Roy (1997):
- Environment: Two states .
- Feature Representation: A single parameter (): Approximated values: , .
- Target Policy : Moves deterministically from with reward , and remains in with reward .
- Discount Factor: .
- True Values: Because all rewards are zero, and . The optimal parameter is .
- Learning Rate: . Initial parameter: .
Scenario A: Off-Policy Sampling (Divergence)
Suppose the behavior policy samples only the transition with reward (visitation ):
The temporal difference error at step is:
The semi-gradient linear TD update rule is:
Let's compute the parameter trajectory step by step:
- Step 0:
- Step 1:
- Step 2:
- Step 3:
Because the multiplier , after steps . As , .
Scenario B: On-Policy Sampling (Convergence)
Now suppose data is sampled on-policy from the target policy's true stationary distribution. In policy , state is absorbing, so the stationary distribution is .
Transitions sampled in move with reward :
The semi-gradient linear TD update rule is:
Computing the on-policy trajectory:
- Step 0:
- Step 1:
- Step 2:
- Step 3:
Because the multiplier , the parameter contracts geometrically toward the true target value .
Code
The following self-contained Python script simulates the Tsitsiklis & Van Roy two-state counterexample, contrasting off-policy divergence with on-policy contraction.
from typing import List, Tuple
class TwoStateLinearTD: """Simulates linear semi-gradient TD on the Tsitsiklis & Van Roy counterexample."""
def __init__(self, gamma: float = 0.9, alpha: float = 0.1) -> None: self.gamma: float = gamma self.alpha: float = alpha # State features: x(s1) = 1.0, x(s2) = 2.0 self.features: dict[str, float] = {"s1": 1.0, "s2": 2.0}
def v_hat(self, state: str, w: float) -> float: """Evaluate linear value function approximation.""" return w * self.features[state]
def off_policy_step(self, w: float) -> Tuple[float, float]: """Perform one off-policy TD update on transition s1 -> s2 (reward = 0).""" reward = 0.0 td_target = reward + self.gamma * self.v_hat("s2", w) delta = td_target - self.v_hat("s1", w) w_next = w + self.alpha * delta * self.features["s1"] return delta, w_next
def on_policy_step(self, w: float) -> Tuple[float, float]: """Perform one on-policy TD update on absorbing transition s2 -> s2 (reward = 0).""" reward = 0.0 td_target = reward + self.gamma * self.v_hat("s2", w) delta = td_target - self.v_hat("s2", w) w_next = w + self.alpha * delta * self.features["s2"] return delta, w_next
def run_comparison(self, w_initial: float = 10.0, steps: int = 3) -> None: print(f"Initial weight: w0 = {w_initial:.4f}") print("=" * 60)
# Off-policy simulation print("--- OFF-POLICY (Behavior samples s1 -> s2) ---") w_off = w_initial for step in range(1, steps + 1): delta, w_off = self.off_policy_step(w_off) print(f"Step {step}: delta = {delta:+.4f}, w_{step} = {w_off:.4f}")
# On-policy simulation print("\n--- ON-POLICY (Stationary visitation s2 -> s2) ---") w_on = w_initial for step in range(1, steps + 1): delta, w_on = self.on_policy_step(w_on) print(f"Step {step}: delta = {delta:+.4f}, w_{step} = {w_on:.4f}")
print("=" * 60) print(f"Final Off-Policy weight: {w_off:.4f} (EXPANDING)") print(f"Final On-Policy weight: {w_on:.4f} (CONTRACTING)")
# Invariants assert w_off > w_initial, "Off-policy weights must diverge" assert w_on < w_initial, "On-policy weights must contract"
if __name__ == "__main__": sim = TwoStateLinearTD(gamma=0.9, alpha=0.1) sim.run_comparison(w_initial=10.0, steps=3)# -> expected output:Initial weight: w0 = 10.0000============================================================--- OFF-POLICY (Behavior samples s1 -> s2) ---Step 1: delta = +8.0000, w_1 = 10.8000Step 2: delta = +8.6400, w_2 = 11.6640Step 3: delta = +9.3312, w_3 = 12.5971
--- ON-POLICY (Stationary visitation s2 -> s2) ---Step 1: delta = -2.0000, w_1 = 9.6000Step 2: delta = -1.9200, w_2 = 9.2160Step 3: delta = -1.8432, w_3 = 8.8474============================================================Final Off-Policy weight: 12.5971 (EXPANDING)Final On-Policy weight: 8.8474 (CONTRACTING)Watch Out For
The False Safety of Ordinary Importance Sampling
A common misconception is that weighting transitions with per-step importance sampling ratios stabilizes off-policy semi-gradient algorithms.
While per-step importance sampling reweights action probabilities to compute unbiased expectations over target actions , it does not alter the underlying state distribution . The sequence of states visited by the agent continues to follow the behavior policy's visitation frequency , not the target policy's stationary distribution .
Because the state weighting matrix remains , the key matrix can still possess negative eigenvalues. Semi-gradient TD with ordinary importance sampling can diverge just as violently as unweighted TD, with the added drawback of extreme variance from the product of likelihood ratios.
The Fix: To achieve true stability under the Deadly Triad, practitioners must employ methods that fundamentally resolve the distribution mismatch:
- True Gradient Methods (Gradient TD / TDC / GTD2): Minimize the Mean Squared Projected Bellman Error (MSPBE) via two-timescale stochastic gradient descent, ensuring convergence regardless of off-policy distributions.
- Emphatic TD (ETD): Reweight state updates by tracking an emphasis scalar that restores stationary distribution weighting in expectation.
- Deep RL Stabilizers (DQN / SAC): Decouple bootstrap targets using slowly updating Polyak or periodic target networks () and reward clipping to limit feedback amplification within replay buffers.
The Quick Version
- The Deadly Triad: Instability occurs exclusively when function approximation, bootstrapping, and off-policy data are combined simultaneously; removing any one guarantees convergence.
- Lost Contraction: While on-policy projected Bellman operators contract with modulus in the stationary norm , off-policy operators expand distances under behavior weighting .
- Negative Eigenvalues: The expected update matrix is not positive definite when , producing spectral radius and unbounded parameter growth.
- Importance Sampling Limitation: Per-step action importance sampling corrects action choice probabilities but fails to fix state visitation mismatch , requiring Gradient TD (TDC/GTD2) or target networks for stability.