Skip to content
AI360Xpert
Beta

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.

Off-policy learning with function approximation breaks the contraction property of the projected Bellman operator, causing unbounded parameter divergence.
Off-policy learning with function approximation breaks the contraction property of the projected Bellman operator, causing unbounded parameter divergence.

Why Does This Exist?

Modern reinforcement learning systems must satisfy three practical requirements simultaneously:

  1. Generalization across massive state spaces: Tabular lookups cannot represent continuous control or high-dimensional sensory inputs like images, requiring parametric function approximation v^(s,w)≈vπ(s)\hat{v}(s, \mathbf{w}) \approx v_\pi(s).
  2. 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 Rt+1+γv^(St+1,w)R_{t+1} + \gamma \hat{v}(S_{t+1}, \mathbf{w}).
  3. 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 μb\mu_b differs from the target stationary distribution dπd_\pi.

When used separately or in pairs, reinforcement learning algorithms remain provably stable:

  • Tabular + Bootstrapping + Off-Policy: Standard tabular Q-learning converges to q∗q^* with probability 1 because the tabular Bellman operator is an infinity-norm contraction (∥Tq1−Tq2∥∞≤γ∥q1−q2∥∞\|T \mathbf{q}_1 - T \mathbf{q}_2\|_\infty \le \gamma \|\mathbf{q}_1 - \mathbf{q}_2\|_\infty).
  • 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 TD(0)\text{TD}(0) contracts under the stationary distribution weighted norm ∥⋅∥dπ\|\cdot\|_{d_\pi}, converging to a unique fixed point w∗\mathbf{w}^*.

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 μb\mu_b, the composite projected Bellman operator ΠbTπ\Pi_b T_\pi 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 ss is approximated as:

v^(s,w)=w⊤x(s)\hat{v}(s, \mathbf{w}) = \mathbf{w}^\top \mathbf{x}(s)

where x(s)∈Rd\mathbf{x}(s) \in \mathbb{R}^d is the feature vector of state ss and w∈Rd\mathbf{w} \in \mathbb{R}^d is the parameter vector. In matrix notation across all states S={s1,…,sn}\mathcal{S} = \{s_1, \dots, s_n\}, v=Xw\mathbf{v} = \mathbf{X}\mathbf{w}, where X∈Rn×d\mathbf{X} \in \mathbb{R}^{n \times d} is the feature matrix.

Let Db=diag(μb(s1),…,μb(sn))\mathbf{D}_b = \text{diag}(\mu_b(s_1), \dots, \mu_b(s_n)) be the diagonal matrix of state visitation probabilities under the behavior policy bb. The weighted least-squares projection operator Πb\Pi_b maps any arbitrary state-value vector v∈Rn\mathbf{v} \in \mathbb{R}^n onto the linear subspace spanned by X\mathbf{X}:

Πb=X(X⊤DbX)−1X⊤Db\Pi_b = \mathbf{X} (\mathbf{X}^\top \mathbf{D}_b \mathbf{X})^{-1} \mathbf{X}^\top \mathbf{D}_b

The target policy Bellman evaluation operator TπT_\pi maps value vectors via:

Tπv=rπ+γPπvT_\pi \mathbf{v} = \mathbf{r}_\pi + \gamma \mathbf{P}_\pi \mathbf{v}

where rπ(s)=∑aπ(a∣s)R(s,a)\mathbf{r}_\pi(s) = \sum_a \pi(a|s) \mathcal{R}(s, a) is the expected reward vector, Pπ(s,s′)=∑aπ(a∣s)P(s′∣s,a)\mathbf{P}_\pi(s, s') = \sum_a \pi(a|s) \mathcal{P}(s'|s, a) is the state transition probability matrix, and γ∈[0,1)\gamma \in [0, 1) is the discount factor.

Semi-gradient linear TD seeks a parameter vector w\mathbf{w} satisfying the projected Bellman equation:

Xw=ΠbTπ(Xw)=Πb(rπ+γPπXw)\mathbf{X}\mathbf{w} = \Pi_b T_\pi (\mathbf{X}\mathbf{w}) = \Pi_b (\mathbf{r}_\pi + \gamma \mathbf{P}_\pi \mathbf{X}\mathbf{w})

Multiplying both sides by X⊤Db\mathbf{X}^\top \mathbf{D}_b removes the projection inversion (X⊤DbX)−1(\mathbf{X}^\top \mathbf{D}_b \mathbf{X})^{-1}, yielding the linear system:

X⊤DbXw=X⊤Db(rπ+γPπXw)\mathbf{X}^\top \mathbf{D}_b \mathbf{X}\mathbf{w} = \mathbf{X}^\top \mathbf{D}_b (\mathbf{r}_\pi + \gamma \mathbf{P}_\pi \mathbf{X}\mathbf{w})

Rearranging into standard form Aw=b\mathbf{A}\mathbf{w} = \mathbf{b}:

A=X⊤Db(I−γPπ)X\mathbf{A} = \mathbf{X}^\top \mathbf{D}_b (\mathbf{I} - \gamma \mathbf{P}_\pi) \mathbf{X}

b=X⊤Dbrπ\mathbf{b} = \mathbf{X}^\top \mathbf{D}_b \mathbf{r}_\pi

The expected continuous parameter evolution under semi-gradient TD updates with step size αt\alpha_t follows the ordinary differential equation (ODE):

E[Δwt]=αt(b−Awt)\mathbb{E}[\Delta \mathbf{w}_t] = \alpha_t (\mathbf{b} - \mathbf{A}\mathbf{w}_t)

For the discrete iteration wt+1=wt+α(b−Awt)=(I−αA)wt+αb\mathbf{w}_{t+1} = \mathbf{w}_t + \alpha (\mathbf{b} - \mathbf{A}\mathbf{w}_t) = (\mathbf{I} - \alpha \mathbf{A})\mathbf{w}_t + \alpha \mathbf{b} to converge to w∗=A−1b\mathbf{w}^* = \mathbf{A}^{-1}\mathbf{b}, the matrix A\mathbf{A} must be positive definite (all eigenvalues of A\mathbf{A} must have strictly positive real parts, Re(λi)>0\text{Re}(\lambda_i) > 0).

  1. On-Policy Stability (Db=Dπ\mathbf{D}_b = \mathbf{D}_\pi): When transitions are sampled from the target policy's stationary distribution dπd_\pi, the matrix Dπ(I−γPπ)\mathbf{D}_\pi (\mathbf{I} - \gamma \mathbf{P}_\pi) has a strictly positive-definite symmetric part:

    y⊤Dπ(I−γPπ)y>0∀y≠0\mathbf{y}^\top \mathbf{D}_\pi (\mathbf{I} - \gamma \mathbf{P}_\pi) \mathbf{y} > 0 \quad \forall \mathbf{y} \neq \mathbf{0}

    Because X\mathbf{X} has full column rank, A=X⊤Dπ(I−γPπ)X\mathbf{A} = \mathbf{X}^\top \mathbf{D}_\pi (\mathbf{I} - \gamma \mathbf{P}_\pi) \mathbf{X} is positive definite. The composite operator ΠπTπ\Pi_\pi T_\pi is a contraction with modulus γ\gamma in the ∥⋅∥dπ\|\cdot\|_{d_\pi} norm, guaranteeing convergence to a unique solution with bounded approximation error:

    ∥vw∗−vπ∥dπ≤11−γ2∥Ππvπ−vπ∥dπ\|v_{\mathbf{w}^*} - v_\pi\|_{d_\pi} \le \frac{1}{\sqrt{1 - \gamma^2}} \|\Pi_\pi v_\pi - v_\pi\|_{d_\pi}

  2. Off-Policy Instability (Db≠Dπ\mathbf{D}_b \neq \mathbf{D}_\pi): When data arrives from behavior distribution μb\mu_b, the weighting matrix Db\mathbf{D}_b does not balance the target transition matrix Pπ\mathbf{P}_\pi. The symmetric part 12(A+A⊤)\frac{1}{2}(\mathbf{A} + \mathbf{A}^\top) can have negative eigenvalues.

    When A\mathbf{A} has an eigenvalue λ\lambda with Re(λ)<0\text{Re}(\lambda) < 0, the transition matrix (I−αA)(\mathbf{I} - \alpha \mathbf{A}) has an eigenvalue with magnitude ∣1−αλ∣>1|1 - \alpha \lambda| > 1. The spectral radius satisfies ρ(I−αA)>1\rho(\mathbf{I} - \alpha \mathbf{A}) > 1, causing ∥wt∥→∞\|\mathbf{w}_t\| \to \infty 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 S={s1,s2}\mathcal{S} = \{s_1, s_2\}.
  • Feature Representation: A single parameter w∈Rw \in \mathbb{R} (d=1d = 1): x(s1)=1.0,x(s2)=2.0\mathbf{x}(s_1) = 1.0, \quad \mathbf{x}(s_2) = 2.0 Approximated values: v^(s1,w)=1.0⋅w\hat{v}(s_1, w) = 1.0 \cdot w, v^(s2,w)=2.0⋅w\hat{v}(s_2, w) = 2.0 \cdot w.
  • Target Policy π\pi: Moves deterministically from s1→s2s_1 \to s_2 with reward R=0R = 0, and remains in s2→s2s_2 \to s_2 with reward R=0R = 0.
  • Discount Factor: γ=0.9\gamma = 0.9.
  • True Values: Because all rewards are zero, vπ(s1)=0v_\pi(s_1) = 0 and vπ(s2)=0v_\pi(s_2) = 0. The optimal parameter is w∗=0w^* = 0.
  • Learning Rate: α=0.1\alpha = 0.1. Initial parameter: w0=10.0w_0 = 10.0.

Scenario A: Off-Policy Sampling (Divergence)

Suppose the behavior policy bb samples only the transition s1→s2s_1 \to s_2 with reward R=0R = 0 (visitation μb(s1)=1.0,μb(s2)=0.0\mu_b(s_1) = 1.0, \mu_b(s_2) = 0.0):

The temporal difference error at step tt is:

δt=Rt+1+γv^(s2,wt)−v^(s1,wt)=0+0.9(2.0wt)−1.0wt=(1.8−1.0)wt=+0.8wt\delta_t = R_{t+1} + \gamma \hat{v}(s_2, w_t) - \hat{v}(s_1, w_t) = 0 + 0.9 (2.0 w_t) - 1.0 w_t = (1.8 - 1.0) w_t = +0.8 w_t

The semi-gradient linear TD update rule is:

wt+1=wt+αδtx(s1)=wt+0.1(+0.8wt)(1.0)=(1+0.08)wt=1.08wtw_{t+1} = w_t + \alpha \delta_t \mathbf{x}(s_1) = w_t + 0.1 (+0.8 w_t)(1.0) = (1 + 0.08) w_t = 1.08 w_t

Let's compute the parameter trajectory step by step:

  • Step 0: w0=10.0000w_0 = 10.0000 δ0=0.8×10.0000=+8.0000\delta_0 = 0.8 \times 10.0000 = +8.0000
  • Step 1: w1=10.0000+0.1×8.0000×1.0=10.8000w_1 = 10.0000 + 0.1 \times 8.0000 \times 1.0 = 10.8000 δ1=0.8×10.8000=+8.6400\delta_1 = 0.8 \times 10.8000 = +8.6400
  • Step 2: w2=10.8000+0.1×8.6400×1.0=11.6640w_2 = 10.8000 + 0.1 \times 8.6400 \times 1.0 = 11.6640 δ2=0.8×11.6640=+9.3312\delta_2 = 0.8 \times 11.6640 = +9.3312
  • Step 3: w3=11.6640+0.1×9.3312×1.0=12.5971w_3 = 11.6640 + 0.1 \times 9.3312 \times 1.0 = 12.5971

Because the multiplier 1.08>1.01.08 > 1.0, after kk steps wk=10.0×(1.08)kw_k = 10.0 \times (1.08)^k. As k→∞k \to \infty, wk→+∞w_k \to +\infty.

Scenario B: On-Policy Sampling (Convergence)

Now suppose data is sampled on-policy from the target policy's true stationary distribution. In policy π\pi, state s2s_2 is absorbing, so the stationary distribution is dπ(s1)=0.0,dπ(s2)=1.0d_\pi(s_1) = 0.0, d_\pi(s_2) = 1.0.

Transitions sampled in s2s_2 move s2→s2s_2 \to s_2 with reward R=0R = 0:

δt=Rt+1+γv^(s2,wt)−v^(s2,wt)=0+0.9(2.0wt)−2.0wt=(1.8−2.0)wt=−0.2wt\delta_t = R_{t+1} + \gamma \hat{v}(s_2, w_t) - \hat{v}(s_2, w_t) = 0 + 0.9(2.0 w_t) - 2.0 w_t = (1.8 - 2.0) w_t = -0.2 w_t

The semi-gradient linear TD update rule is:

wt+1=wt+αδtx(s2)=wt+0.1(−0.2wt)(2.0)=(1−0.04)wt=0.96wtw_{t+1} = w_t + \alpha \delta_t \mathbf{x}(s_2) = w_t + 0.1 (-0.2 w_t)(2.0) = (1 - 0.04) w_t = 0.96 w_t

Computing the on-policy trajectory:

  • Step 0: w0=10.0000w_0 = 10.0000 δ0=−0.2×10.0000=−2.0000\delta_0 = -0.2 \times 10.0000 = -2.0000
  • Step 1: w1=10.0000+0.1×(−2.0000)×2.0=9.6000w_1 = 10.0000 + 0.1 \times (-2.0000) \times 2.0 = 9.6000 δ1=−0.2×9.6000=−1.9200\delta_1 = -0.2 \times 9.6000 = -1.9200
  • Step 2: w2=9.6000+0.1×(−1.9200)×2.0=9.2160w_2 = 9.6000 + 0.1 \times (-1.9200) \times 2.0 = 9.2160 δ2=−0.2×9.2160=−1.8432\delta_2 = -0.2 \times 9.2160 = -1.8432
  • Step 3: w3=9.2160+0.1×(−1.8432)×2.0=8.8474w_3 = 9.2160 + 0.1 \times (-1.8432) \times 2.0 = 8.8474

Because the multiplier 0.96<1.00.96 < 1.0, the parameter contracts geometrically toward the true target value w∗=0.0w^* = 0.0.

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 ρt=π(At∣St)b(At∣St)\rho_t = \frac{\pi(A_t|S_t)}{b(A_t|S_t)} stabilizes off-policy semi-gradient algorithms.

While per-step importance sampling reweights action probabilities to compute unbiased expectations over target actions π(⋅∣St)\pi(\cdot|S_t), it does not alter the underlying state distribution μb\mu_b. The sequence of states StS_t visited by the agent continues to follow the behavior policy's visitation frequency μb\mu_b, not the target policy's stationary distribution dπd_\pi.

Because the state weighting matrix remains Db\mathbf{D}_b, the key matrix A=X⊤Db(I−γPπ)X\mathbf{A} = \mathbf{X}^\top \mathbf{D}_b (\mathbf{I} - \gamma \mathbf{P}_\pi) \mathbf{X} 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:

  1. 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.
  2. Emphatic TD (ETD): Reweight state updates by tracking an emphasis scalar Mt=γρt−1Mt−1+ItM_t = \gamma \rho_{t-1} M_{t-1} + I_t that restores stationary distribution weighting in expectation.
  3. Deep RL Stabilizers (DQN / SAC): Decouple bootstrap targets using slowly updating Polyak or periodic target networks (w−\mathbf{w}^-) 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 γ\gamma in the stationary norm ∥⋅∥dπ\|\cdot\|_{d_\pi}, off-policy operators ΠbTπ\Pi_b T_\pi expand distances under behavior weighting ∥⋅∥μb\|\cdot\|_{\mu_b}.
  • Negative Eigenvalues: The expected update matrix A=X⊤Db(I−γPπ)X\mathbf{A} = \mathbf{X}^\top \mathbf{D}_b (\mathbf{I} - \gamma \mathbf{P}_\pi) \mathbf{X} is not positive definite when Db≠Dπ\mathbf{D}_b \neq \mathbf{D}_\pi, producing spectral radius ρ(I−αA)>1\rho(\mathbf{I} - \alpha \mathbf{A}) > 1 and unbounded parameter growth.
  • Importance Sampling Limitation: Per-step action importance sampling corrects action choice probabilities but fails to fix state visitation mismatch μb≠dπ\mu_b \neq d_\pi, requiring Gradient TD (TDC/GTD2) or target networks for stability.