Simple Algorithm
Reinforcement Learning · Fixed Point · 28 min

Importance Sampling & Doubly Robust Estimators

Per-decision, weighted and doubly robust estimators, and their bias–variance trade-offs.

The doubly robust estimator is importance sampling with a model subtracted and added back. How much variance does that remove, and how much could any unbiased estimator remove? This lesson computes the variance exactly and shows that with the true value function it meets a Cramér–Rao bound. It then follows the estimators that give up a little bias for a lot of variance (weighted doubly robust, MAGIC, SWITCH), one that fits its model to minimize variance (MRDR), fitted Q-evaluation's error bound, and the efficiency bound that Markov structure makes polynomial in the horizon.

What you’ll learn

  • Derive the variance of the sequential doubly robust estimator, and identify which terms a better model removes and which remain for any unbiased estimator.
  • Explain weighted doubly robust, MAGIC's blending of partial importance-sampling estimates, and the SWITCH and MRDR alternatives by their bias–variance logic.
  • State fitted Q-evaluation's finite-sample error bound with its assumptions, and the minimax-optimal result for linear function classes.
  • State the semiparametric efficiency bounds for history-based and Markov models, and explain why the Markov bound grows only polynomially with the horizon.

The variance of doubly robust, exactly

Take a finite horizon HH, a discount γ\gamma, time-dependent values QtπQ^\pi_t and VtπV^\pi_t with VHπ=0V^\pi_H = 0, and a time-dependent model Q^t\hat Q_t with V^t(s)=∑aπ(a∣s)Q^t(s,a)\hat V_t(s) = \sum_a\pi(a\mid s)\hat Q_t(s,a). The doubly robust estimate from one trajectory is defined backward,

DH=0,Dt=V^t(St)+ρt(Rt+1+γDt+1−Q^t(St,At)),D_H = 0,\qquad D_t = \hat V_t(S_t) + \rho_t\big(R_{t+1} + \gamma D_{t+1} - \hat Q_t(S_t,A_t)\big),

and D0D_0 unrolls to the formula of Off-Policy Evaluation. Two quantities govern its variance: the model error Δt=Q^t−Qtπ\Delta_t = \hat Q_t - Q^\pi_t, and the one-step noise

σt2(s,a)=Var⁡(Rt+1+γVt+1π(St+1) ∣ St=s,At=a),\sigma_t^2(s,a) = \Var\big(R_{t+1} + \gamma V^\pi_{t+1}(S_{t+1})\,\big|\,S_t = s, A_t = a\big),

the randomness of a single reward and transition, measured with the true values.

DerivationThe law of total variance, one step at a time
  1. E[Dt ∣ St,At]=V^t(St)−ρt Δt(St,At),E[Dt ∣ St]=Vtπ(St)\E\big[D_t\,\big|\,S_t, A_t\big] = \hat V_t(S_t) - \rho_t\,\Delta_t(S_t,A_t),\qquad \E\big[D_t\,\big|\,S_t\big] = V^\pi_t(S_t)

    By induction from the end, E[Dt+1∣St+1]=Vt+1π(St+1)\E[D_{t+1}\mid S_{t+1}] = V^\pi_{t+1}(S_{t+1}), so given the action the estimate's mean is off by the weighted model error, and averaging over At∼bA_t\sim b removes it:

  2. Var⁡(Dt∣St)=Var⁡At∼b(ρtΔt(St,At) ∣ St)+EAt∼b[ρt2(σt2(St,At)+γ2 E[Var⁡(Dt+1∣St+1) ∣ St,At])]\Var\big(D_t\mid S_t\big) = \Var_{A_t\sim b}\big(\rho_t\Delta_t(S_t,A_t)\,\big|\,S_t\big) + \E_{A_t\sim b}\Big[\rho_t^2\Big(\sigma_t^2(S_t,A_t) + \gamma^2\,\E\big[\Var(D_{t+1}\mid S_{t+1})\,\big|\,S_t, A_t\big]\Big)\Big]

    Condition on (St,At)(S_t, A_t), then on (Rt+1,St+1)(R_{t+1}, S_{t+1}). The variance splits into the spread of the conditional mean over actions, the one-step noise, and the variance of the future estimate, the last two multiplied by ρt2\rho_t^2:

  3. Var⁡(D0)=Var⁡(V0π(S0))+∑t=0H−1γ2t(Eb[wt−12 Var⁡At∼b(ρtΔt∣St)]⏟model error+Eb[wt2 σt2(St,At)]⏟one-step noise)\Var(D_0) = \Var\big(V^\pi_0(S_0)\big) + \sum_{t=0}^{H-1}\gamma^{2t}\Big(\underbrace{\E_b\big[w_{t-1}^2\,\Var_{A_t\sim b}(\rho_t\Delta_t\mid S_t)\big]}_{\text{model error}} + \underbrace{\E_b\big[w_t^2\,\sigma_t^2(S_t,A_t)\big]}_{\text{one-step noise}}\Big)

    Unroll, and add the randomness of the start state. With cumulative weights wt=ρ0⋯ρtw_t = \rho_0\cdots\rho_t and w−1=1w_{-1} = 1:

With nn trajectories, divide by nn. Jiang and Li (2016, Thm. 1) give the same decomposition in recursive form. Read the two sums separately.

  • The model-error sum is the only place Q^\hat Q appears. With Q^=0\hat Q = 0 (per-decision importance sampling) it is Var⁡b(ρtQtπ∣St)\Var_b(\rho_tQ^\pi_t\mid S_t), typically large; with Q^=Qπ\hat Q = Q^\pi it vanishes. A better model removes exactly this.
  • The one-step-noise sum does not involve the model at all: it is a single step's randomness, inflated by the squared cumulative weight.

Jiang and Li prove that, in tree-structured problems where the state is the entire history and rewards are deterministic given it, the one-step-noise sum plus Var⁡(V0π(S0))\Var(V^\pi_0(S_0)) is a Cramér–Rao lower bound for unbiased estimators (Off-Policy Monte Carlo & Importance Sampling). Doubly robust with the true QπQ^\pi attains it, so it is optimal among unbiased estimators there; what no unbiased estimator escapes is the factor wt2w_t^2, whose mean grows exponentially with tt.

Predict before you look

One decision (H=1H = 1) with deterministic rewards. The behavior takes two actions with probability 12\tfrac12 each, the target with probabilities 0.9 and 0.1, and the rewards are 1 and 0, so J(π)=0.9J(\pi) = 0.9 and inverse propensity scoring has variance 0.81 per sample. With the imperfect model Q^=(0.8,0.2)\hat Q = (0.8, 0.2), what is the doubly robust estimate's variance per sample?

Show the answer

0.04

V^=0.9×0.8+0.1×0.2=0.74\hat V = 0.9\times0.8 + 0.1\times0.2 = 0.74. Action 1 is logged half the time with ρ=1.8\rho = 1.8: the estimate is 0.74+1.8×(1−0.8)=1.100.74 + 1.8\times(1 - 0.8) = 1.10. Action 2, with ρ=0.2\rho = 0.2: 0.74+0.2×(0−0.2)=0.700.74 + 0.2\times(0 - 0.2) = 0.70. Both average to 0.9, with variance 0.5×0.22+0.5×0.22=0.040.5\times0.2^2 + 0.5\times0.2^2 = 0.04, which is the model-error term Var⁡b(ρΔ)\Var_b(\rho\Delta) for Δ=(−0.2,0.2)\Delta = (-0.2, 0.2). The rewards are deterministic, so the perfect model Q^=(1,0)\hat Q = (1, 0) would give variance 0.

Trading a little bias for a lot of variance

Weighted doubly robust. Thomas and Brunskill (2016) put self-normalized weights w~t(i)=wt(i)/∑jwt(j)\tilde w^{(i)}_t = w^{(i)}_t\big/\sum_jw^{(j)}_t, with w~−1(i)=1/n\tilde w^{(i)}_{-1} = 1/n, inside the doubly robust sum:

J^WDR=∑i=1n∑t=0H−1γt(w~t(i)(Rt+1(i)−Q^(St(i),At(i)))+w~t−1(i) V^(St(i))).\hat J_{\text{WDR}} = \sum_{i=1}^n\sum_{t=0}^{H-1}\gamma^t\Big(\tilde w^{(i)}_t\big(R^{(i)}_{t+1} - \hat Q(S^{(i)}_t,A^{(i)}_t)\big) + \tilde w^{(i)}_{t-1}\,\hat V\big(S^{(i)}_t\big)\Big).

At each step the weights sum to one, so the estimate stays within the range of its terms however extreme one trajectory's weight; the price is a bias that vanishes as nn grows, as for weighted importance sampling.

MAGIC. Thomas and Brunskill also blend. For j=−1,0,1,…j = -1, 0, 1, \dots the off-policy jj-step return g(j)g^{(j)} uses the weighted doubly robust correction for the first j+1j + 1 steps and the model's values afterward, just as an nn-step return in TD learning switches from samples to estimates. g(−1)g^{(-1)} is the pure model estimate and g(∞)g^{(\infty)} is WDR. MAGIC (model and guided importance sampling combining) returns a convex combination over a set JJ of these, with weights minimizing an estimate of the mean squared error,

x^=arg min⁡x∈Δ∣J∣ x⊤Ω^ x+(x⊤b^)2,\hat{\mathbf x} = \argmin_{\mathbf x\in\Delta^{\abs J}}\ \mathbf x^\top\hat\Omega\,\mathbf x + \big(\mathbf x^\top\hat{\mathbf b}\big)^2,

where Ω^\hat\Omega is the sample covariance of the g(j)g^{(j)} and b^\hat{\mathbf b} estimates their biases from their distances to a bootstrap confidence interval around WDR. In their experiments MAGIC often had orders of magnitude lower mean squared error than earlier estimators.

SWITCH. For one decision, Wang, Agarwal and Dudík (2017) proved a minimax lower bound on the mean squared error when no consistent reward model is available, matched up to constants by IPS and doubly robust. When a model is available, even a biased one, that bound is pessimistic. SWITCH weights the logged reward when the action's ratio is at most a threshold τ\tau, and uses the model for the actions whose ratio exceeds it:

J^SWITCH=1n∑i=1n[ρiri 1(ρi≤τ)+∑aπ(a∣xi) r^(xi,a) 1(ρ(xi,a)>τ)],\hat J_{\text{SWITCH}} = \frac1n\sum_{i=1}^n\Big[\rho_i r_i\,\mathbb{1}(\rho_i\le\tau) + \sum_a\pi(a\mid x_i)\,\hat r(x_i,a)\,\mathbb{1}\big(\rho(x_i,a) > \tau\big)\Big],

with τ\tau chosen from the data to minimize an estimated error bound. The large weights, the source of variance, are exactly where the model is trusted instead.

MRDR. The model that minimizes doubly robust's variance is not the one that best fits rewards. Since Var⁡b(ρtΔt∣St)=Eb[ρt2Δt2∣St]−(Eπ[Δt∣St])2\Var_b(\rho_t\Delta_t\mid S_t) = \E_b[\rho_t^2\Delta_t^2\mid S_t] - \big(\E_\pi[\Delta_t\mid S_t]\big)^2, model errors count in proportion to ρt2\rho_t^2: errors at actions the target likes and the behavior rarely takes matter most. Farajtabar, Chow and Ghavamzadeh (2018) fit Q^\hat Q by minimizing a sample estimate of this variance instead of the squared error under the data, and prove the resulting estimators strongly consistent and asymptotically optimal.

Fitted Q-evaluation: an error bound

If the class is closed under the policy's backup, dFπ=0d^\pi_{\mathcal F} = 0 and only the statistical term (ϵ∝1/n\epsilon\propto1/\sqrt n) and the truncation term (exponentially small in KK) remain. Otherwise the error grows linearly with how far one backup can leave the class, amplified by concentrability and by the effective horizon. That coefficient is an all-policy worst case, often infinite for narrow data, which makes the bound a statement about well-covered problems.

For linear function classes, Duan, Jia and Wang (2020) gave a sharper, instance-dependent analysis. FQE's error is governed by a chi-squared divergence between the target policy's distribution and the data's, restricted to the function class: for linear features it measures the mismatch only in the directions the features can see. A nearly matching minimax lower bound shows that no estimator does better in that setting. Compare the unrestricted χ2\chi^2 that drives importance sampling's variance: the function class is what lets the direct method ignore mismatch it cannot detect, and also what biases it when the class is wrong.

Efficiency when the state is Markov

The Cramér–Rao bound for trees is exponential in the horizon because, when every history is a distinct state, nothing learned along one trajectory transfers to another. In an MDP, histories that reach the same state share their futures. Kallus and Uehara (2020) computed the semiparametric efficiency bound, the smallest asymptotic variance of any regular estimator, in both models, for an undiscounted problem with HH steps. Write λt=ρ0⋯ρt\lambda_t = \rho_0\cdots\rho_t for the cumulative ratio (the wtw_t above) and

ηt(s,a)=dtπ(s,a)dtb(s,a)\eta_t(s,a) = \frac{d^\pi_t(s,a)}{d^b_t(s,a)}

for the marginal ratio of the two policies' state–action distributions at step tt.

Both bounds have the shape of doubly robust's variance with the true QπQ^\pi. The Markov bound replaces the cumulative weight λt\lambda_t by the marginal ratio ηt\eta_t, which need not grow with tt at all, so no estimator built from products of action ratios can attain it. Kallus and Uehara's double reinforcement learning (DRL) estimator does. It is doubly robust with estimated marginal ratios η^t\hat\eta_t and action values q^t\hat q_t, each fitted on folds of the data other than the one it is applied to (cross-fitting):

J^DRL=1n∑i=1n∑t=0H−1[η^t(St,At)(Rt+1−q^t(St,At))+η^t−1(St−1,At−1) v^t(St)](i),\hat J_{\text{DRL}} = \frac1n\sum_{i=1}^n\sum_{t=0}^{H-1}\Big[\hat\eta_t(S_t,A_t)\big(R_{t+1} - \hat q_t(S_t,A_t)\big) + \hat\eta_{t-1}(S_{t-1},A_{t-1})\,\hat v_t(S_t)\Big]^{(i)},

with v^t(s)=∑aπ(a∣s)q^t(s,a)\hat v_t(s) = \sum_a\pi(a\mid s)\hat q_t(s,a) and η^−1=1\hat\eta_{-1} = 1. It attains the Markov bound when the product of the two nuisances' errors shrinks faster than 1/n1/\sqrt n, for example when both converge at rate n−1/4n^{-1/4}, and it remains consistent if either one is. Estimating the marginal ratios is the subject of Breaking the Curse of Horizon.

Key takeaways

  • Var⁡(DR)=Var⁡(V0π(S0))+∑tγ2t(Eb[wt−12Var⁡b(ρtΔt∣St)]+Eb[wt2σt2])\Var(\text{DR}) = \Var(V^\pi_0(S_0)) + \sum_t\gamma^{2t}\big(\E_b[w_{t-1}^2\Var_b(\rho_t\Delta_t\mid S_t)] + \E_b[w_t^2\sigma_t^2]\big) per trajectory. A better model removes only the first sum; the rest is a Cramér–Rao bound for history-based problems, attained by DR with Q^=Qπ\hat Q = Q^\pi.
  • Weighted DR normalizes the weights; MAGIC blends partial importance-sampling estimates with the model by estimated MSE; SWITCH trusts the model where weights are large; MRDR fits the model to minimize DR's variance, which weights errors by ρ2\rho^2.
  • FQE's error is at most γ1/2(1−γ)−3/2βD (2dFπ+ϵ)\gamma^{1/2}(1-\gamma)^{-3/2}\sqrt{\beta_{\data}}\,(2d^\pi_{\mathcal F} + \epsilon) plus a term that vanishes with the number of iterations; for linear classes, a chi-squared divergence restricted to the features governs a minimax-optimal error.
  • In an MDP the efficiency bound weights each step's noise by the squared marginal ratio dtπ/dtbd^\pi_t/d^b_t instead of the cumulative product of action ratios, so it is polynomial in the horizon; cross-fitted doubly robust estimation with marginal ratios attains it.

Check yourself

In the interactive lesson these are scored with your confidence, and what you miss comes back for review.

Question 1

In the variance of the doubly robust estimator, which term can a better model Q^\hat Q reduce?

  1. The one-step-noise sum ∑tγ2tEb[wt2σt2]\sum_t\gamma^{2t}\E_b[w_t^2\sigma_t^2]
  2. The model-error sum ∑tγ2tEb[wt−12Var⁡b(ρtΔt∣St)]\sum_t\gamma^{2t}\E_b\big[w_{t-1}^2\Var_b(\rho_t\Delta_t\mid S_t)\big]
  3. The start-state term Var⁡(V0π(S0))\Var(V^\pi_0(S_0))
  4. All three
Show the answer

B. The model-error sum ∑tγ2tEb[wt−12Var⁡b(ρtΔt∣St)]\sum_t\gamma^{2t}\E_b\big[w_{t-1}^2\Var_b(\rho_t\Delta_t\mid S_t)\big]

Only the model-error sum contains Q^\hat Q, and it vanishes when Q^=Qπ\hat Q = Q^\pi. The other two terms are, in tree-structured problems, the Cramér–Rao bound for every unbiased estimator.

Question 2

MRDR fits its model to minimize the variance of doubly robust instead of the squared error of the reward model on the data. Why do the two objectives differ?

  1. Doubly robust's variance weights model errors by squared importance ratios, so errors at actions the target likes and the behavior rarely takes count most
  2. Because doubly robust is biased, so its variance and its error differ
  3. Because squared error ignores the reward noise
  4. They do not differ; MRDR is a renaming
Show the answer

A. Doubly robust's variance weights model errors by squared importance ratios, so errors at actions the target likes and the behavior rarely takes count most

Var⁡b(ρΔ∣S)=Eb[ρ2Δ2∣S]−(Eπ[Δ∣S])2\Var_b(\rho\Delta\mid S) = \E_b[\rho^2\Delta^2\mid S] - (\E_\pi[\Delta\mid S])^2. A regression under the data distribution weights errors by how often bb takes each action; the variance weights them by ρ2\rho^2 under bb, which is π2/b\pi^2/b.

Question 3

SWITCH uses the model's prediction for actions whose ratio π/b\pi/b exceeds a threshold τ\tau. What are its limits as τ→∞\tau\to\infty and τ→0\tau\to0?

  1. τ→∞\tau\to\infty gives the direct method; τ→0\tau\to0 gives inverse propensity scoring
  2. Both limits give doubly robust
  3. τ→∞\tau\to\infty gives inverse propensity scoring; τ→0\tau\to0 gives the direct method
  4. Neither limit is defined
Show the answer

C. τ→∞\tau\to\infty gives inverse propensity scoring; τ→0\tau\to0 gives the direct method

With an infinite threshold every logged reward is importance-weighted (IPS). With a threshold of zero, every action with positive target probability has ratio above it, so only the model's predictions remain (the direct method). The data-driven τ\tau sits in between.

Question 4

Why can the Markov efficiency bound of Kallus and Uehara grow only polynomially with the horizon, while the history-based bound can grow exponentially?

  1. Because Markov problems have fewer states
  2. Because the Markov bound assumes deterministic rewards
  3. Because the Markov bound holds only for discounted problems
  4. Because it weights each step's noise by the squared marginal ratio of state–action distributions, which need not grow with tt, instead of the squared product of action ratios
Show the answer

D. Because it weights each step's noise by the squared marginal ratio of state–action distributions, which need not grow with tt, instead of the squared product of action ratios

Histories that reach the same state share their futures, so what matters is how much more often π\pi visits (s,a)(s,a) at step tt, not the probability of the whole action sequence. With bounded marginal ratios and rewards the bound is O(H2Rmax⁡2)O(H^2R_{\max}^2).

Further reading

  • N. Jiang & L. Li, "Doubly robust off-policy value evaluation for reinforcement learning," Proceedings of the 33rd International Conference on Machine Learning (ICML), 652–661 (2016).
  • P. S. Thomas & E. Brunskill, "Data-efficient off-policy policy evaluation for reinforcement learning," Proceedings of the 33rd International Conference on Machine Learning (ICML), 2139–2148 (2016).
  • M. Farajtabar, Y. Chow & M. Ghavamzadeh, "More robust doubly robust off-policy evaluation," Proceedings of the 35th International Conference on Machine Learning (ICML) (2018).
  • H. M. Le, C. Voloshin & Y. Yue, "Batch policy learning under constraints," Proceedings of the 36th International Conference on Machine Learning (ICML) (2019).
  • N. Kallus & M. Uehara, "Double reinforcement learning for efficient off-policy evaluation in Markov decision processes," Journal of Machine Learning Research 21(167), 1–63 (2020).