Off-policy approximation and the deadly triad
How and why combining off-policy learning, function approximation and bootstrapping can make value-based RL algorithms diverge (the deadly triad), and how to reason about and fix it.
Drafted with Aria, reviewed by the AiCanCode.org team · Updated . How we write and check our notes. Spotted an error? Use Give Feedback at the bottom of the page.
Why it matters
Engineers use off-policy approximation when they want to learn from data collected by one policy (the behaviour policy) while evaluating or improving another policy (the target policy). This is common in offline RL, learning from logs, experience replay, and actor–critic methods. Knowing the deadly triad (off-policy learning, function approximation, and bootstrapping) helps avoid algorithms that diverge and choose stable methods (for example GTD family, importance-sampling corrections, or on-policy algorithms).
Key ideas
Start by defining terms used below.
- Reinforcement learning (RL): learning to make decisions from trial-and-error interactions to maximise long-term reward. (Used before: Multi-armed bandits, MDPs, policies.)
- Policy (π): a probability distribution over actions given a state. If π(a|s) = 1 for one action, it is deterministic. Unit: unitless.
- Behaviour policy (µ): the policy that generates data (unitless).
- Target policy (π): the policy we want to evaluate or improve (unitless).
- Value function (vπ or qπ): expected return following policy π from a state or state-action pair. Unit: reward units (depends on reward definition).
- Function approximation: representing value functions with a parameterised function v_w(s) or q_w(s,a) where w ∈ R^d. Common forms: linear v_w(s)=φ(s)^T w, or nonlinear (neural networks).
- Bootstrapping: using an estimate (value at next state) as part of the target in a learning update (e.g., TD methods).
- Off-policy learning: learning about one policy (target) from data produced by another (behaviour).
- Importance sampling ratio (ρ): the correction factor π(a|s)/µ(a|s) to reweight off-policy samples so they are as if generated by the target policy. Unitless.
- Deadly triad: the combination of (1) function approximation, (2) bootstrapping, and (3) off-policy updates; together these can cause instability and divergence of commonly used updates (e.g., Q-learning with function approximation and experience replay). The phrase is a succinct warning — not a formal theorem.
Important formal statements and derivations universities expect:
The TD(0) semi-gradient update for a parameter vector w with a differentiable approximate value v_w(s): draw transition (s, a, r, s') under behaviour policy and update by bootstrapping target r + γ v_w(s'). The error is defined δ = r + γ v_w(s') − v_w(s). The semi-gradient update is w ← w + α δ ∇_w v_w(s). Assumption: using the current w to compute both target and gradient (this is the semi-gradient). This update is not a true gradient descent on any fixed scalar objective when bootstrapping is used off-policy; that leads to possible instability.
Importance sampling for off-policy Monte Carlo: to estimate expectations under π when samples come from µ, multiply returns by product of ratios ρ_t:T−1 = Π_{k=t}^{T−1} π(a_k|s_k)/µ(a_k|s_k). This is unbiased but has high variance; with bootstrapping we often use per-step or truncated ratios. This requires coverage (absolute continuity): whenever π(a|s) > 0 we must have µ(a|s) > 0, otherwise the ratio is undefined and truncated/clipped ratios introduce bias.
Matrix view of linear TD: with linear features Φ (rows are states), on-policy TD(0) expected update gives a fixed-point equation A w = b where A = Φ^T D (Φ − γ P_π Φ) and b = Φ^T D r_π. If A is positive definite then the method converges to w* solving A w* = b. Here D is the diagonal matrix of the stationary state distribution under the sampling (behaviour) policy; in the on-policy case the sampling and target policies coincide so D is the stationary distribution of π. Off-policy, D corresponds to μ while P_π remains for the target; this decoupling can make A not positive definite (equivalently, some eigenvalues of A can have nonpositive real parts) and cause divergence.
Baird's counterexample: a concrete MDP with linear function approximation where off-policy TD-style updates diverge. The key exam point: show how the mismatch of D and P_π makes the expected update matrix have eigenvalues with negative real parts (so that the spectral radius of I − αA exceeds 1 for any α > 0), causing w to grow without bound. For a diagram, draw 7 states in a star: six peripheral states each pointing deterministically to a central state under the behaviour policy while the target policy prefers peripheral-to-peripheral transitions; label feature vectors so approximation cannot represent true values. Then show iterates blow up.
Remedies and stable algorithms: methods derived as true stochastic gradient descent on a well-defined objective converge under linear function approximation and off-policy sampling. Examples:
- GTD (Gradient TD) and TDC/GTD2: derived to minimize the mean-squared projected Bellman error (MSPBE), explicitly MSPBE(w) = || Pi_D T_pi v_w − v_w ||_D^2. They maintain an extra vector y (secondary weights) and have two-timescale updates which provably converge under standard assumptions for linear function approximation and decreasing step-sizes.
- Emphatic TD (ETD/ETD(λ)): uses emphasis weights to correct the state-distribution mismatch; converges off-policy under linear function approximation with diminishing step-sizes.
- Multi-step off-policy methods with truncated importance sampling (e.g., Retrace(λ), V-trace): reduce variance and improve stability in control; they introduce bias that decreases as truncation becomes less aggressive.
- Experience replay + target networks (in deep RL) mitigate but do not eliminate the problem; they are engineering fixes used in DQN but theoretically not guaranteed.
Diagrams to draw for exams:
- For Baird: draw 7 states (center+6 spokes). Show behaviour transitions (spokes → center) and target transitions (spokes → other spoke). Label feature vectors for each state (so students can show the projected Bellman operator).
- For matrix A: draw a block that shows D and P_π multiplication order to emphasise why off-policy breaks symmetry (D P_π vs P_π D).
Be explicit about assumptions: linear function approximation, fixed feature mapping, Markov chain irreducible under behaviour policy, step-size sequences for stochastic approximation when giving convergence theorems.
Formulas
ρ_t = π(a_t | s_t) / μ(a_t | s_t)
- ρ_t = importance-sampling ratio at time t; unitless; applies when you have behaviour µ and target π and µ(a_t|s_t) > 0.
δ_t = r_{t+1} + γ v_w(s_{t+1}) − v_w(s_t)
- δ_t = TD(0) error at time t; r in reward units, γ unitless discount factor (0 ≤ γ ≤ 1); applies in bootstrapping TD updates.
w_{t+1} = w_t + α δ_t ∇_w v_w(s_t)
- w_t = parameter vector (unit depends on feature scaling), α = step-size > 0 (unitless), applies for semi-gradient TD(0).
q_w(s,a) = φ(s,a)^T w
- Linear action-value approximation: φ(s,a) feature vector (unitless), w parameter vector, applies for linear function approximation.
Q(s,a) ← Q(s,a) + α [r + γ max_{a'} Q(s',a') − Q(s,a)]
- Off-policy Q-learning tabular update; applies when using max operator as target; units: Q in reward units.
A = Φ^T D (Φ − γ P_π Φ) and b = Φ^T D r_π
- Appears in the linear expected TD fixed-point A w = b; Φ is feature matrix, D is diagonal distribution under behaviour (unitless probabilities), P_π is transition matrix under π (unitless probabilities), r_π expected reward vector. Applies in linear TD analysis; when A is positive definite, on-policy TD converges.
(For GTD/TDC you can recall the two updates but derive them in class; they use an auxiliary vector to approximate A w − b.)
Worked examples
Example 1 — Long-answer exam question (model answer): Q: Explain why naive Q-learning with linear function approximation and off-policy samples can diverge. Include diagram and outline the proof idea. Answer (model):
- Define linear approximation q_w(s,a) = φ(s,a)^T w and Q-learning update using bootstrapping target r + γ max_{a'} q_w(s',a').
- Off-policy sampling means states are visited according to behaviour µ while the target policy in the max operator induces a different transition distribution; for analysis we look at expected update E[Δw] = α (b − A w) where A depends on µ and P induced by the max operator. Explain how A is built (see formula A = Φ^T D (Φ − γ P_π Φ) for the policy version). For Q-learning, the greedy target depends on w, so this A,b notation is a local linearization device rather than an exact fixed P_π.
- Show that A need not be positive definite; with a simple 2D example or Baird's star, eigenvalues of A can have negative real parts, making w grow. Conclude that updates can diverge. (Full marks answer draws the star diagram, states the role of D and P_π, and explains the linear algebra reason — mismatch of sampling distribution and bootstrap dynamics.)
Example 2 — Baird summary (exam style short derivation):
- Draw star (6 peripheral + 1 center). Behaviour µ always goes peripheral → center; target π prefers peripheral → peripheral. Choose linear features so peripheral states share features that make their true values nearly identical under approximation but targets differ.
- Compute expected update matrix A for this toy MDP (in exam you show a reduced representation) and show at least one eigenvalue of A has negative real part, implying the spectral radius of (I − αA) exceeds 1 for any α > 0, so iterates grow without bound. Conclude divergence.
Common mistakes
- Treating the semi-gradient TD update as true gradient descent when bootstrapping is present; on-policy linear TD has a projected fixed point, but off-policy changes the distribution D and breaks the symmetric structure.
- Not stating assumptions when quoting convergence results (linear feature representation, diminishing step-sizes, irreducible Markov chain, bounded features).
For your exam
Typical question forms:
- Define and explain the deadly triad (short note).
- Derive the expected linear TD update and state the fixed-point equation (derivation and linear algebra).
- Explain Baird's counterexample and draw the diagram (diagram + reasoning).
- Derive importance-sampling corrections for off-policy Monte Carlo (derivation + variance discussion).
- Compare remedies (what GTD/TDC do and why they converge) — explain high-level derivation.
What full-marks answers include:
- Clear definitions of all terms used (behaviour/target policy, bootstrapping, function approximation).
- Correct derivation of the expected matrix form A w = b and explanation of when A is positive definite.
- For counterexamples: a labelled diagram and the eigenvalue-based explanation of divergence.
- Mention of convergent alternatives and their assumptions (GTD family; note linear case).
Quick check
- What three ingredients form the "deadly triad"?
- Give the TD(0) error formula δ_t.
- Why can off-policy linear TD diverge (one sentence)?
Answers: 1) Function approximation, bootstrapping, off-policy sampling. 2) δ_t = r_{t+1} + γ v_w(s_{t+1}) − v_w(s_t). 3) Because the sampling distribution under behaviour decouples from the transition operator for the target, the expected update matrix A can fail to be positive definite and iterates can grow without bound.
Finished this topic? Mark it so your progress, study plan and readiness keep up.
Stuck on something here?