Offline Policy Learning from Logged Data

On this page

Q-learning chooses treatments by comparing expected outcomes, starting with the final decision and working backward. We derive this recursion from the causal value formula, prove its population optimality, and show how Q-function estimation errors affect the learned regime's value. We follow Schulte et al. (2014), Sections 2–3 and 5.1, specializing the proofs to binary treatments; the numerical example is constructed for this note.

Recap: The regression result used in Q-learning

For a square-integrable outcome UU and covariates ZZ, conditional expectation gives the squared-error minimizer m(Z)=E[U∣Z]m(Z)=\mathbb E[U\mid Z]. For any fixed square-integrable predictor gg,

E[(U−g(Z))2]−E[(U−m(Z))2]=E[(g(Z)−m(Z))2]≥0.\mathbb E[(U-g(Z))^2] -\mathbb E[(U-m(Z))^2] =\mathbb E[(g(Z)-m(Z))^2]\ge0.

The expectations use the joint distribution of (Z,U)(Z,U). This identity explains the regression targets in Section 5; causal assumptions are additionally needed to interpret them as treatment comparisons.

1. From one treatment decision to a treatment rule

Let XX denote the covariates available before treatment, A∈{0,1}A\in\{0,1\} the treatment, and Y∈RY\in\mathbb R an outcome for which larger values are preferable. A deterministic treatment rule is a measurable function d:X→{0,1}d:\mathcal X\to\{0,1\}.

Write (X,A,Y)∼P(X,A,Y)\sim P for the observed-data distribution and PXP_X for its baseline marginal. For observed quantities, unmarked E\mathbb E and Pr⁡\Pr refer to PP. Conditional means average over the corresponding conditional outcome distribution; a rule dd is held fixed. The notation X∼PXX\sim P_X does not impose a parametric model for the covariates.

For now, suppose that the conditional mean outcome under treatment aa is identified by

Q(x,a)=EY∼PY∣X=x,A=a[Y].Q(x,a)=\mathbb E_{Y\sim P_{Y\mid X=x,A=a}}[Y].

Under the identification assumptions stated in Section 2, the rule's value is

V(d)=EX∼PX[Q{X,d(X)}].V(d)=\mathbb E_{X\sim P_X}[Q\{X,d(X)\}].

Define the baseline mean and treatment contrast:

m(x)=Q(x,0),Δ(x)=Q(x,1)−Q(x,0).m(x)=Q(x,0),\qquad \Delta(x)=Q(x,1)-Q(x,0).

For binary aa, the following is an identity, not a linear-model assumption:

Q(x,a)=m(x)+aΔ(x),Q{x,d(x)}=m(x)+d(x)Δ(x).\begin{aligned} Q(x,a)&=m(x)+a\Delta(x),\\ Q\{x,d(x)\}&=m(x)+d(x)\Delta(x). \end{aligned}

The maximizing rule is

d∗(x)=1{Δ(x)>0}.d^*(x)=\mathbf 1\{\Delta(x)>0\}.

Ties are assigned to treatment 00. For any competing rule dd,

V(d∗)−V(d)=LE[{d∗(X)−d(X)}Δ(X)]=SE[∣Δ(X)∣1{d(X)≠d∗(X)}]≥0.\begin{aligned} V(d^*)-V(d) &\overset{\mathrm{L}}{=}\mathbb E[\{d^*(X)-d(X)\}\Delta(X)]\\ &\overset{\mathrm{S}}{=}\mathbb E\left[ |\Delta(X)|\mathbf 1\{d(X)\ne d^*(X)\} \right]\ge 0. \end{aligned}

Here L is linearity of expectation and cancellation of m(X)m(X); S uses the sign of Δ\Delta. The loss from a wrong recommendation is ∣Δ(X)∣|\Delta(X)|, not an unweighted classification error.

2. Two-stage data and the causal target

Let LL be observed between the two treatments. The record and decision histories are

O=(X,A1,L,A2,Y),A1,A2∈{0,1}.O=(X,A_1,L,A_2,Y),\qquad A_1,A_2\in\{0,1\}.

Only information observed before a decision may enter its rule:

H1=X,H2=(X,A1,L).H_1=X,\qquad H_2=(X,A_1,L).

In this two-stage setup, PP now denotes the joint observed distribution of OO, and O1,…,On∼iidPO_1,\ldots,O_n\overset{\mathrm{iid}}\sim P: the records are independent draws from the same population. Subscripts identify marginal and conditional distributions, such as PXP_X and PL∣X,A1P_{L\mid X,A_1}.

Both treatments are feasible at each relevant history. Outcomes are fully observed and have finite second moments under the interventions considered. Conditional equalities hold almost surely on the relevant support, so they may exclude histories with probability zero.

A dynamic treatment regime, or DTR, consists of two measurable rules,

d=(d1,d2),dt:Ht→{0,1},t=1,2.d=(d_1,d_2),\qquad d_t:\mathcal H_t\to\{0,1\},\quad t=1,2.

We optimize over all measurable history-dependent rules, without cross-stage parameter restrictions.

Potential outcomes and regime value

Write L(a1)L(a_1) for the intermediate covariate that would be observed under first treatment a1a_1, and Y(a1,a2)Y(a_1,a_2) for the final outcome under the treatment sequence (a1,a2)(a_1,a_2). Under a regime dd, define

A1d=d1(X),Ld=L(A1d),A2d=d2(X,A1d,Ld),Yd=Y(A1d,A2d).\begin{aligned} A_1^d&=d_1(X),\\ L^d&=L(A_1^d),\\ A_2^d&=d_2(X,A_1^d,L^d),\\ Y^d&=Y(A_1^d,A_2^d). \end{aligned}

Our target is the expected final outcome in the baseline population,

V(d)=E[Yd],d∗∈argmax⁡d  V(d).V(d)=\mathbb E[Y^d],\qquad d^*\in\underset{d}{\operatorname{argmax}}\;V(d).

Because the first treatment affects the intermediate covariate, the law of H2H_2 changes with d1d_1.

Expectations and probabilities involving potential variables use their underlying population distribution, whose observed-data marginal is PP. In particular, E[Yd]\mathbb E[Y^d] averages the potential outcome over individuals in the baseline population. Equivalently, write PdP^d for the distribution of (X,A1d,Ld,A2d,Yd)(X,A_1^d,L^d,A_2^d,Y^d) under the regime and V(d)=EPd[Yd]V(d)=\mathbb E_{P^d}[Y^d].

The regime determines treatment assignments in this average. It therefore differs from the unweighted observed mean EP[Y]\mathbb E_P[Y]. Below, the identification argument expresses the regime value using observed conditional distributions and X∼PXX\sim P_X.

Assumptions connecting the records to interventions

Use the following assumptions, specializing Schulte et al., Section 2.

  1. C: Consistency. Treatments are well defined, L=L(A1)L=L(A_1), and Y=Y(A1,A2)Y=Y(A_1,A_2).
  2. No interference. A patient's potential outcomes do not depend on other patients' treatments.
  3. E1–E2: Sequential exchangeability. For the potential-outcome collection
W={L(a1),Y(a1,a2):a1,a2∈{0,1}}\mathcal W=\{L(a_1),Y(a_1,a_2):a_1,a_2\in\{0,1\}\}

as

A1⊥ ⁣ ⁣ ⁣⊥W∣X,A2⊥ ⁣ ⁣ ⁣⊥W∣H2.A_1\perp\!\!\!\perp\mathcal W\mid X, \qquad A_2\perp\!\!\!\perp\mathcal W\mid H_2.
  1. Positivity. Define the logging propensities
et(a∣h)=Pr⁡(At=a∣Ht=h).e_t(a\mid h)=\Pr(A_t=a\mid H_t=h).

require et(a∣h)>0e_t(a\mid h)>0 for both treatments at almost every history reachable under the candidate regimes. Exchangeability is not testable from an observational regression; positivity cannot be replaced by extrapolation.

3. Deriving the two-stage value formula

Define

μ(x,a1,l,a2)=E[Y∣X=x,A1=a1,L=l,A2=a2].\mu(x,a_1,l,a_2) =\mathbb E[Y\mid X=x,A_1=a_1,L=l,A_2=a_2].

Intermediate law. For any measurable set BB,

Pr⁡{L(a1)∈B∣X=x}=E1Pr⁡{L(a1)∈B∣X=x,A1=a1}=CPr⁡(L∈B∣X=x,A1=a1).\begin{aligned} \Pr\{L(a_1)\in B\mid X=x\} &\overset{\mathrm{E1}}{=}\Pr\{L(a_1)\in B\mid X=x,A_1=a_1\}\\ &\overset{\mathrm C}{=}\Pr(L\in B\mid X=x,A_1=a_1). \end{aligned}

Outcome mean. First apply E1 to the joint pair (Y(a1,a2),L(a1))(Y(a_1,a_2),L(a_1)), then condition on L(a1)=lL(a_1)=l:

E[Y(a1,a2)∣X=x,L(a1)=l]=E1,CE[Y(a1,a2)∣X=x,A1=a1,L=l]=E2E[Y(a1,a2)∣X=x,A1=a1,L=l,A2=a2]=Cμ(x,a1,l,a2).\begin{aligned} &\mathbb E[Y(a_1,a_2)\mid X=x,L(a_1)=l]\\ &\quad\overset{\mathrm{E1,C}}{=}\mathbb E[Y(a_1,a_2)\mid X=x,A_1=a_1,L=l]\\ &\quad\overset{\mathrm{E2}}{=}\mathbb E[Y(a_1,a_2)\mid X=x,A_1=a_1,L=l,A_2=a_2]\\ &\quad\overset{\mathrm C}{=}\mu(x,a_1,l,a_2). \end{aligned}

Value formula. Fix xx and write a1=d1(x)a_1=d_1(x). By the tower property (T) and the two identification identities (I),

E[Yd∣X=x]=T∫E[Yd∣X=x,L(a1)=l] Pr⁡{L(a1)∈dl∣X=x}=I∫μ{x,a1,l,d2(x,a1,l)} Pr⁡(dl∣X=x,A1=a1),V(d)=TEX[E[Yd∣X]].\begin{aligned} \mathbb E[Y^d\mid X=x] &\overset{\mathrm T}{=}\int\mathbb E[Y^d\mid X=x,L(a_1)=l]\, \Pr\{L(a_1)\in dl\mid X=x\}\\ &\overset{\mathrm I}{=}\int \mu\{x,a_1,l,d_2(x,a_1,l)\}\, \Pr(dl\mid X=x,A_1=a_1),\\ V(d)&\overset{\mathrm T}{=}\mathbb E_X\big[\mathbb E[Y^d\mid X]\big]. \end{aligned}

Integrals become sums for discrete LL. Positivity makes the conditional treatment comparisons identifiable; positive point masses are not required for continuous covariates.

4. Backward induction: optimize the last decision first

Define the population Q-functions by

Q2∗(h2,a2)=E[Y∣H2=h2,A2=a2].Q_2^*(h_2,a_2)=\mathbb E[Y\mid H_2=h_2,A_2=a_2].

At stage 2,

Δ2(h2)=Q2∗(h2,1)−Q2∗(h2,0),d2∗(h2)=1{Δ2(h2)>0},M2(h2)=max⁡a2∈{0,1}Q2∗(h2,a2).\begin{aligned} \Delta_2(h_2)&=Q_2^*(h_2,1)-Q_2^*(h_2,0),\\ d_2^*(h_2)&=\mathbf 1\{\Delta_2(h_2)>0\},\\ M_2(h_2)&=\max_{a_2\in\{0,1\}}Q_2^*(h_2,a_2). \end{aligned}

At stage 1, integrate the optimized continuation:

Q1∗(x,a1)=EL∼PL∣X=x,A1=a1[M2(x,a1,L)]=E[max⁡a2∈{0,1}Q2∗(H2,a2)∣X=x,A1=a1].\begin{aligned} Q_1^*(x,a_1) &=\mathbb E_{L\sim P_{L\mid X=x,A_1=a_1}}[M_2(x,a_1,L)]\\ &=\mathbb E\left[ \max_{a_2\in\{0,1\}}Q_2^*(H_2,a_2) \mid X=x,A_1=a_1 \right]. \end{aligned}

Then

Δ1(x)=Q1∗(x,1)−Q1∗(x,0),d1∗(x)=1{Δ1(x)>0}.\begin{aligned} \Delta_1(x)&=Q_1^*(x,1)-Q_1^*(x,0),\\ d_1^*(x)&=\mathbf 1\{\Delta_1(x)>0\}. \end{aligned}

The maximum is inside the expectation because d2d_2 may depend on the realized LL.

Theorem 1: Optimality of backward induction

Under the assumptions in Section 2, the rules just defined satisfy

V(d∗)=EX[max⁡a1Q1∗(X,a1)]≥V(d)for every admissible d.V(d^*)=\mathbb E_X\left[\max_{a_1}Q_1^*(X,a_1)\right] \ge V(d)\qquad\text{for every admissible }d.

Proof. Write Q2d(h)=Q2∗{h,d2(h)}Q_2^d(h)=Q_2^*\{h,d_2(h)\}. We use identification (I), pointwise maximization (M), monotonicity of conditional expectation (CE), and substitution of the definition of Q1∗Q_1^* (D).

First, at every relevant history,

Q2∗{h2,d2(h2)}≤M2(h2).Q_2^*\{h_2,d_2(h_2)\}\le M_2(h_2).

Consequently,

V(d)=IEX[E{Q2d(H2)∣X,A1=d1(X)}]≤M,CEEX[E{M2(H2)∣X,A1=d1(X)}]=DEX[Q1∗{X,d1(X)}]≤MEX[max⁡a1∈{0,1}Q1∗(X,a1)].\begin{aligned} V(d) &\overset{\mathrm I}{=}\mathbb E_X\left[ \mathbb E\{Q_2^d(H_2)\mid X,A_1=d_1(X)\} \right]\\ &\overset{\mathrm{M,CE}}{\le}\mathbb E_X\left[ \mathbb E\{M_2(H_2)\mid X,A_1=d_1(X)\} \right]\\ &\overset{\mathrm D}{=}\mathbb E_X[Q_1^*\{X,d_1(X)\}]\\ &\overset{\mathrm M}{\le}\mathbb E_X\left[\max_{a_1\in\{0,1\}}Q_1^*(X,a_1)\right]. \end{aligned}

For d=d∗d=d^*, Q2d∗=M2Q_2^{d^*}=M_2 and Q1∗(x,d1∗(x))=max⁡aQ1∗(x,a)Q_1^*(x,d_1^*(x))=\max_aQ_1^*(x,a). Both inequalities are equalities. □\square

This is the two-stage specialization of Schulte et al., Section 3, not a finite-sample guarantee for fitted regressions.

Why regressing the recorded outcome on the first treatment is different

Let Q1log(x,a1)=E[Y∣X=x,A1=a1]Q_1^{\mathrm{log}}(x,a_1)=\mathbb E[Y\mid X=x,A_1=a_1]. By iterated expectation,

Q1log(x,a1)=E[∑a2∈{0,1}e2(a2∣H2)Q2∗(H2,a2)∣X=x,A1=a1].\begin{aligned} Q_1^{\mathrm{log}}(x,a_1) =\mathbb E\Big[ &\sum_{a_2\in\{0,1\}} e_2(a_2\mid H_2)Q_2^*(H_2,a_2)\\ &\Bigm|X=x,A_1=a_1\Big]. \end{aligned}

The recorded outcome averages over the logging policy's second treatment, whereas Q-learning uses the best second treatment. Their first-stage treatment contrasts can therefore differ, even with perfect regression estimation.

5. From population Q-functions to fitted regressions

The backward recursion specifies conditional means, but those means are unknown. We estimate them by regression, writing qtq_t for a working regression model and Q^t\widehat Q_t for its fitted version. The squared-error identity recalled above identifies each regression target.

Lemma: The squared-error regression target

Let (Z,R)∼PZ,R(Z,R)\sim P_{Z,R} with RR square-integrable, and set m(Z)=E[R∣Z]m(Z)=\mathbb E[R\mid Z]. Within this lemma, a conditional expectation given Z=zZ=z integrates R∼PR∣Z=zR\sim P_{R\mid Z=z}; an unconditional expectation integrates (Z,R)∼PZ,R(Z,R)\sim P_{Z,R}. The candidate gg is fixed, not fitted on the same random pair. For any square-integrable gg,

E[(R−g(Z))2∣Z]=E[{R−m(Z)+m(Z)−g(Z)}2∣Z]=E[(R−m(Z))2∣Z]+(m(Z)−g(Z))2+2(m(Z)−g(Z))E[R−m(Z)∣Z]=Var⁡(R∣Z)+(m(Z)−g(Z))2.\begin{aligned} \mathbb E[(R-g(Z))^2\mid Z] &=\mathbb E[\{R-m(Z)+m(Z)-g(Z)\}^2\mid Z]\\ &=\mathbb E[(R-m(Z))^2\mid Z]+(m(Z)-g(Z))^2\\ &\quad+2(m(Z)-g(Z))\mathbb E[R-m(Z)\mid Z]\\ &=\operatorname{Var}(R\mid Z)+(m(Z)-g(Z))^2. \end{aligned}

The expansion uses linearity and measurability of m(Z),g(Z)m(Z),g(Z) given ZZ; the cross term vanishes because E[R−m(Z)∣Z]=0\mathbb E[R-m(Z)\mid Z]=0. Taking expectations yields

E[(R−g(Z))2]−E[(R−m(Z))2]=E[(g(Z)−m(Z))2]≥0.\mathbb E[(R-g(Z))^2]-\mathbb E[(R-m(Z))^2] =\mathbb E[(g(Z)-m(Z))^2]\ge0.

Apply the lemma to (R,Z)=(Y,(H2,A2))(R,Z)=(Y,(H_2,A_2)) and then (R,Z)=(M2(H2),(X,A1))(R,Z)=(M_2(H_2),(X,A_1)). The unrestricted regression targets are exactly Q2∗Q_2^* and Q1∗Q_1^*. Restricted regression families introduce approximation error.

Fit the second-stage regression

For each stage, choose fixed feature maps ut(h)∈Rrtu_t(h)\in\mathbb R^{r_t} and vt(h)∈Rstv_t(h)\in\mathbb R^{s_t}. A useful linear working model is

qt(h,a;θt)=ut(h)⊤βt+a vt(h)⊤ψt,zt(h,a)=(ut(h)a vt(h)),θt=(βtψt).\begin{aligned} q_t(h,a;\theta_t) &=u_t(h)^\top\beta_t+a\,v_t(h)^\top\psi_t,\\ z_t(h,a)&=\begin{pmatrix}u_t(h)\\a\,v_t(h)\end{pmatrix},\qquad \theta_t=\begin{pmatrix}\beta_t\\\psi_t\end{pmatrix}. \end{aligned}

Both ztz_t and θt\theta_t have pt=rt+stp_t=r_t+s_t entries, and qt=zt⊤θtq_t=z_t^\top\theta_t. The treatment contrast under this working model is vt(h)⊤ψtv_t(h)^\top\psi_t.

At stage 2, ordinary least squares minimizes

θ^2∈argmin⁡θ2∈Rp21n∑i=1n{Yi−z2(H2i,A2i)⊤θ2}2.\widehat\theta_2\in\underset{\theta_2\in\mathbb R^{p_2}}{\operatorname{argmin}} \frac1n\sum_{i=1}^n \{Y_i-z_2(H_{2i},A_{2i})^\top\theta_2\}^2.

Let Z2Z_2 be the n×p2n\times p_2 matrix whose iith row is z2(H2i,A2i)⊤z_2(H_{2i},A_{2i})^\top, and let Y=(Y1,…,Yn)⊤\mathbf Y=(Y_1,\ldots,Y_n)^\top. Differentiating the criterion gives

∇θ21n∥Y−Z2θ2∥22=−2nZ2⊤(Y−Z2θ2),Z2⊤Z2θ^2=Z2⊤Y.\begin{aligned} \nabla_{\theta_2}\frac1n\|\mathbf Y-Z_2\theta_2\|_2^2 &=-\frac2nZ_2^\top(\mathbf Y-Z_2\theta_2),\\ Z_2^\top Z_2\widehat\theta_2&=Z_2^\top\mathbf Y. \end{aligned}

If Z2Z_2 has full column rank, the solution is (Z2⊤Z2)−1Z2⊤Y(Z_2^\top Z_2)^{-1}Z_2^\top\mathbf Y. In computation, a least-squares solver avoids explicitly forming the inverse. Set Q^2(h,a)=q2(h,a;θ^2)\widehat Q_2(h,a)=q_2(h,a;\widehat\theta_2) and recommend

d^2(h)=1{v2(h)⊤ψ^2>0}.\widehat d_2(h)=\mathbf1\{v_2(h)^\top\widehat\psi_2>0\}.

Construct the first-stage pseudo-outcome

For each recorded second-stage history, predict both treatment outcomes and retain the larger prediction:

Y~1i=max⁡a2∈{0,1}Q^2(H2i,a2)=u2(H2i)⊤β^2+max⁡{0,v2(H2i)⊤ψ^2}.\begin{aligned} \widetilde Y_{1i} &=\max_{a_2\in\{0,1\}}\widehat Q_2(H_{2i},a_2)\\ &=u_2(H_{2i})^\top\widehat\beta_2 +\max\{0,v_2(H_{2i})^\top\widehat\psi_2\}. \end{aligned}

The pseudo-outcome is a fitted prediction of the best conditional outcome at the second stage. It is not a measurement of what would have happened under an unobserved treatment. When computing it, keep the recorded A1i,LiA_{1i},L_i in H2iH_{2i}.

Regress the pseudo-outcome on first-stage information

Fit the first-stage working model by

θ^1∈argmin⁡θ1∈Rp11n∑i=1n{Y~1i−z1(Xi,A1i)⊤θ1}2.\widehat\theta_1\in\underset{\theta_1\in\mathbb R^{p_1}}{\operatorname{argmin}} \frac1n\sum_{i=1}^n \{\widetilde Y_{1i}-z_1(X_i,A_{1i})^\top\theta_1\}^2.

With Z1Z_1 defined analogously and Y~1\widetilde{\mathbf Y}_1 the vector of pseudo-outcomes, the normal equations are

Z1⊤Z1θ^1=Z1⊤Y~1.Z_1^\top Z_1\widehat\theta_1=Z_1^\top\widetilde{\mathbf Y}_1.

Finally, set Q^1(x,a)=q1(x,a;θ^1)\widehat Q_1(x,a)=q_1(x,a;\widehat\theta_1) and

d^1(x)=1{v1(x)⊤ψ^1>0},d^=(d^1,d^2).\widehat d_1(x)=\mathbf1\{v_1(x)^\top\widehat\psi_1>0\}, \qquad \widehat d=(\widehat d_1,\widehat d_2).

We fit the rules backward so that the first-stage regression accounts for optimal continuation, then apply the fitted rules in treatment order. Although these least-squares criteria do not use propensity weights, their causal interpretation still requires exchangeability and positivity. See Schulte et al., Section 5.1.

Algorithm 1 Two-stage fitted Q-learning

Input: Trajectories {(H1i,A1i,H2i,A2i,Yi)}i=1n\{(H_{1i},A_{1i},H_{2i},A_{2i},Y_i)\}_{i=1}^n; linear features z1,z2z_1,z_2 defined above.

Output: A regime d^=(d^1,d^2)\widehat d=(\widehat d_1,\widehat d_2) with treatments in {0,1}\{0,1\}.

  1. Fit θ^2\widehat\theta_2 by least squares of YiY_i on z2(H2i,A2i)z_2(H_{2i},A_{2i}).
  2. Set Q^2(h,a)←z2(h,a)⊤θ^2\widehat Q_2(h,a)\gets z_2(h,a)^\top\widehat\theta_2.
  3. for i=1,…,ni=1,\ldots,n do
  4. Set Y~1i←max⁡a∈{0,1}Q^2(H2i,a)\widetilde Y_{1i}\gets\max_{a\in\{0,1\}}\widehat Q_2(H_{2i},a).
  5. end for
  6. Fit θ^1\widehat\theta_1 by least squares of Y~1i\widetilde Y_{1i} on z1(Xi,A1i)z_1(X_i,A_{1i}).
  7. Set Q^1(x,a)←z1(x,a)⊤θ^1\widehat Q_1(x,a)\gets z_1(x,a)^\top\widehat\theta_1.
  8. return d^t(h)=min⁡arg⁡max⁡a∈{0,1}Q^t(h,a)\widehat d_t(h)=\min\arg\max_{a\in\{0,1\}}\widehat Q_t(h,a) for t=1,2t=1,2.

Theorem 2: From Q-function error to value regret

For an integrable function gg, define expectation under first-stage rule d1d_1 as follows.

Draw X∼PXX\sim P_X, assign A1=d1(X)A_1=d_1(X), and draw L∼PL∣X,A1=d1(X)L\sim P_{L\mid X,A_1=d_1(X)}. The induced H2H_2 distribution is the one used by Ed1\mathbb E_{d_1}, rather than the logged H2H_2 marginal. Thus

Ed1[g(H2)]=EX[E{g(H2)∣X,A1=d1(X)}].\mathbb E_{d_1}[g(H_2)] =\mathbb E_X\left[\mathbb E\{g(H_2)\mid X,A_1=d_1(X)\}\right].

Let d^t(h)∈arg⁡max⁡aQ^t(h,a)\widehat d_t(h)\in\arg\max_a\widehat Q_t(h,a), with ties assigned to 00. If, on all relevant histories and treatment options,

∥Q^t−Qt∗∥∞≤ϵt,t=1,2,\|\widehat Q_t-Q_t^*\|_\infty\le\epsilon_t,\qquad t=1,2,

where ∥⋅∥∞\|\cdot\|_\infty denotes the essential supremum over the reachable-history support and the finite treatment set, then

0≤V(d∗)−V(d^)≤2ϵ1+2ϵ2.0\le V(d^*)-V(\widehat d)\le2\epsilon_1+2\epsilon_2.

First, we decompose the regret by adding and subtracting V(d^1,d2∗)V(\widehat d_1,d_2^*), then applying the value formula:

V(d∗)−V(d^)={V(d∗)−V(d^1,d2∗)}+{V(d^1,d2∗)−V(d^)}=EX[Q1∗(X,d1∗(X))−Q1∗(X,d^1(X))]+Ed^1[Q2∗(H2,d2∗(H2))−Q2∗(H2,d^2(H2))].\begin{aligned} V(d^*)-V(\widehat d) &=\{V(d^*)-V(\widehat d_1,d_2^*)\}\\ &\quad+\{V(\widehat d_1,d_2^*)-V(\widehat d)\}\\ &=\mathbb E_X\left[ Q_1^*(X,d_1^*(X))-Q_1^*(X,\widehat d_1(X)) \right]\\ &\quad+\mathbb E_{\widehat d_1}\left[ Q_2^*(H_2,d_2^*(H_2))-Q_2^*(H_2,\widehat d_2(H_2)) \right]. \end{aligned}

Both summands are nonnegative by pointwise optimality. Equivalently, by the binary sign identity in Section 1,

V(d∗)−V(d^)=EX[∣Δ1(X)∣1{d^1(X)≠d1∗(X)}]+Ed^1[∣Δ2(H2)∣1{d^2(H2)≠d2∗(H2)}].\begin{aligned} V(d^*)-V(\widehat d) &=\mathbb E_X\left[|\Delta_1(X)|\mathbf1\{\widehat d_1(X)\ne d_1^*(X)\}\right]\\ &\quad+\mathbb E_{\widehat d_1}\left[ |\Delta_2(H_2)|\mathbf1\{\widehat d_2(H_2)\ne d_2^*(H_2)\} \right]. \end{aligned}

Next, we bound each treatment comparison. Fix t,ht,h, and abbreviate a∗=dt∗(h)a^*=d_t^*(h) and a^=d^t(h)\widehat a=\widehat d_t(h). Add and subtract fitted values:

Qt∗(h,a∗)−Qt∗(h,a^)={Qt∗(h,a∗)−Q^t(h,a∗)}+{Q^t(h,a∗)−Q^t(h,a^)}+{Q^t(h,a^)−Qt∗(h,a^)}≤ϵt+0+ϵt.\begin{aligned} Q_t^*(h,a^*)-Q_t^*(h,\widehat a) &=\{Q_t^*(h,a^*)-\widehat Q_t(h,a^*)\}\\ &\quad+\{\widehat Q_t(h,a^*)-\widehat Q_t(h,\widehat a)\}\\ &\quad+\{\widehat Q_t(h,\widehat a)-Q_t^*(h,\widehat a)\}\\ &\le\epsilon_t+0+\epsilon_t. \end{aligned}

The outer terms use the assumed uniform error bound; the middle term is nonpositive because a^\widehat a maximizes Q^t\widehat Q_t.

Finally, substitute these bounds into the regret decomposition and use monotonicity of expectation:

V(d∗)−V(d^)≤EX[2ϵ1]+Ed^1[2ϵ2]=2ϵ1+2ϵ2.□V(d^*)-V(\widehat d) \le\mathbb E_X[2\epsilon_1]+\mathbb E_{\widehat d_1}[2\epsilon_2] =2\epsilon_1+2\epsilon_2.\qquad\square

Conditional on the training data T=(O1,…,On)∼P⊗n\mathcal T=(O_1,\ldots,O_n)\sim P^{\otimes n}, the fitted rules and Q-functions are fixed. The value expectations average over a fresh individual. The bound holds whenever the stated error bounds hold; it does not show that least squares achieves a particular error rate.

Convergence in probability refers to repeated training samples T∼P⊗n\mathcal T\sim P^{\otimes n}. If both uniform errors converge to zero in that sense, the difference between the optimal and learned values also converges to zero.

How second-stage error enters the first-stage target

For a fixed fitted Q^2\widehat Q_2, define

Q‾1(x,a)=E[max⁡bQ^2(H2,b)∣X=x,A1=a].\overline Q_1(x,a)=\mathbb E\left[\max_b\widehat Q_2(H_2,b)\mid X=x,A_1=a\right].

The maximum is 1-Lipschitz in the sup norm:

∣max⁡bQ^2(h,b)−max⁡bQ2∗(h,b)∣≤max⁡b∣Q^2(h,b)−Q2∗(h,b)∣≤ϵ2.\begin{aligned} \left|\max_b\widehat Q_2(h,b)-\max_bQ_2^*(h,b)\right| &\le\max_b|\widehat Q_2(h,b)-Q_2^*(h,b)|\\ &\le\epsilon_2. \end{aligned}

Conditional Jensen's inequality and the last bound give

∣Q‾1(x,a)−Q1∗(x,a)∣≤E[ϵ2∣X=x,A1=a]=ϵ2.|\overline Q_1(x,a)-Q_1^*(x,a)| \le\mathbb E[\epsilon_2\mid X=x,A_1=a]=\epsilon_2.

If ∥Q^1−Q‾1∥∞≤δ1\|\widehat Q_1-\overline Q_1\|_\infty\le\delta_1, the triangle inequality yields

∥Q^1−Q1∗∥∞≤δ1+ϵ2,V(d∗)−V(d^)≤2δ1+4ϵ2.\|\widehat Q_1-Q_1^*\|_\infty\le\delta_1+\epsilon_2, \qquad V(d^*)-V(\widehat d)\le2\delta_1+4\epsilon_2.

The first-stage error therefore has two sources: error in fitting its regression and error inherited from the estimated second-stage continuation.

6. An exactly solvable example

For an artificial population, let X∼Bernoulli⁡(1/2)X\sim\operatorname{Bernoulli}(1/2) and

L∣X=x,A1=a1∼Bernoulli⁡{p(x,a1)},p(x,a1)=0.2+0.1x+0.5a1.L\mid X=x,A_1=a_1\sim\operatorname{Bernoulli}\{p(x,a_1)\}, \qquad p(x,a_1)=0.2+0.1x+0.5a_1.

The outcome is

Y=2+X+A1(1.4X−0.3)+0.5L+A2(1.5−2L)+ε,\begin{aligned} Y={}&2+X+A_1(1.4X-0.3)+0.5L\\ &+A_2(1.5-2L)+\varepsilon, \end{aligned}

where ε\varepsilon is an independent standard normal error. Treatments and LL are generated in their time order using independent random draws conditional on the stated histories. This construction satisfies sequential exchangeability.

Solve the second stage

Since the error has conditional mean zero,

Q2∗(x,a1,l,a2)=2+x+a1(1.4x−0.3)+0.5l+a2(1.5−2l).Q_2^*(x,a_1,l,a_2) =2+x+a_1(1.4x-0.3)+0.5l+a_2(1.5-2l).

The contrast Δ2=1.5−2l\Delta_2=1.5-2l gives

d2∗(x,a1,l)=1−l.d_2^*(x,a_1,l)=1-l.

Substituting this choice yields

M2(x,a1,l)=2+x+a1(1.4x−0.3)+0.5l+max⁡(0,1.5−2l)=3.5+x+a1(1.4x−0.3)−l.\begin{aligned} M_2(x,a_1,l) &=2+x+a_1(1.4x-0.3)+0.5l+\max(0,1.5-2l)\\ &=3.5+x+a_1(1.4x-0.3)-l. \end{aligned}

The second equality uses l∈{0,1}l\in\{0,1\}.

Average over the intermediate response

The first-stage target averages M2M_2 over LL conditional on the first treatment:

Q1∗(x,a1)=3.5+x+a1(1.4x−0.3)−E[L∣x,a1]=3.5+x+a1(1.4x−0.3)−(0.2+0.1x+0.5a1)=3.3+0.9x+a1(1.4x−0.8).\begin{aligned} Q_1^*(x,a_1) &=3.5+x+a_1(1.4x-0.3)-\mathbb E[L\mid x,a_1]\\ &=3.5+x+a_1(1.4x-0.3)-(0.2+0.1x+0.5a_1)\\ &=3.3+0.9x+a_1(1.4x-0.8). \end{aligned}

Hence Δ1(x)=1.4x−0.8\Delta_1(x)=1.4x-0.8 and d1∗(x)=xd_1^*(x)=x.

Baseline xxQ1∗(x,0)Q_1^*(x,0)Q1∗(x,1)Q_1^*(x,1)Optimal first treatment
003.33.32.52.500
114.24.24.84.811

The optimal value is

V(d∗)=12(3.3)+12(4.8)=4.05.V(d^*)=\tfrac12(3.3)+\tfrac12(4.8)=4.05.

Compare with the logged continuation

To see why the raw first-stage outcome regression differs, let the logging mechanism use

e1(1∣x)=0.2+0.6x,e2(1∣x,a1,l)=0.2+0.6{(1−a1)l+a1(1−l)}.\begin{aligned} e_1(1\mid x)&=0.2+0.6x,\\ e_2(1\mid x,a_1,l) &=0.2+0.6\{(1-a_1)l+a_1(1-l)\}. \end{aligned}

All treatment probabilities are 0.20.2 or 0.80.8.

At x=0x=0, calculate the raw outcome regression by summing over LL and the logged A2A_2:

Q1log(0,0)=2+0.5(0.2)+(0.8)(0.2)(1.5)+(0.2)(0.8)(−0.5)=2.26,Q1log(0,1)=1.7+0.5(0.7)+(0.3)(0.8)(1.5)+(0.7)(0.2)(−0.5)=2.34.\begin{aligned} Q_1^{\mathrm{log}}(0,0) &=2+0.5(0.2)+(0.8)(0.2)(1.5)+(0.2)(0.8)(-0.5)\\ &=2.26,\\ Q_1^{\mathrm{log}}(0,1) &=1.7+0.5(0.7)+(0.3)(0.8)(1.5)+(0.7)(0.2)(-0.5)\\ &=2.34. \end{aligned}

The raw regression prefers a1=1a_1=1, although Q1∗(0,0)>Q1∗(0,1)Q_1^*(0,0)>Q_1^*(0,1). At x=1x=1, the logged means are 3.243.24 and 4.664.66. Its resulting first-stage rule always selects 11, and its value after optimal second-stage continuation is (2.5+4.8)/2=3.65<4.05(2.5+4.8)/2=3.65<4.05.

7. A reproducible Python implementation

The working regressions below contain the true Q-functions of this example. Python 3 and NumPy are required.

Python code and numerical output
import numpy as np

rng = np.random.default_rng(17)

def mean_y(x, a1, l, a2):
    return 2 + x + a1 * (1.4 * x - 0.3) + 0.5 * l + a2 * (1.5 - 2 * l)

def simulate(n):
    x = rng.binomial(1, 0.5, n)
    p1 = 0.2 + 0.6 * x
    a1 = rng.binomial(1, p1)
    l = rng.binomial(1, 0.2 + 0.1 * x + 0.5 * a1)
    p2 = 0.2 + 0.6 * ((1 - a1) * l + a1 * (1 - l))
    a2 = rng.binomial(1, p2)
    y = mean_y(x, a1, l, a2) + rng.normal(size=n)
    return x, a1, l, a2, y, p1, p2

def z2(x, a1, l, a2):
    return np.column_stack([np.ones_like(x), x, a1, l, x * a1, a2, a2 * l])

def z1(x, a1):
    return np.column_stack([np.ones_like(x), x, a1, x * a1])

x, a1, l, a2, y, _, _ = simulate(5000)
zero, one = np.zeros_like(x), np.ones_like(x)

# Fit the terminal outcome regression and optimize its continuation.
theta2 = np.linalg.lstsq(z2(x, a1, l, a2), y, rcond=None)[0]
pseudo = np.maximum(z2(x, a1, l, zero) @ theta2,
                    z2(x, a1, l, one) @ theta2)
theta1 = np.linalg.lstsq(z1(x, a1), pseudo, rcond=None)[0]

def d1(x):
    q0 = z1(x, np.zeros_like(x)) @ theta1
    q1 = z1(x, np.ones_like(x)) @ theta1
    return (q1 > q0).astype(int)

def d2(x, a1, l):
    q0 = z2(x, a1, l, np.zeros_like(x)) @ theta2
    q1 = z2(x, a1, l, np.ones_like(x)) @ theta2
    return (q1 > q0).astype(int)

# In this artificial population we can compute the learned regime's value exactly.
exact_value = 0.0
for xv in (0, 1):
    av = int(d1(np.array([xv]))[0])
    p = 0.2 + 0.1 * xv + 0.5 * av
    for lv in (0, 1):
        bv = int(d2(np.array([xv]), np.array([av]), np.array([lv]))[0])
        exact_value += 0.5 * (p if lv else 1 - p) * mean_y(xv, av, lv, bv)

# Evaluate the frozen regime on independent logged records with known propensities.
x, a1, l, a2, y, p1, p2 = simulate(100000)
prob1 = np.where(a1 == 1, p1, 1 - p1)
prob2 = np.where(a2 == 1, p2, 1 - p2)
matches = (a1 == d1(x)) & (a2 == d2(x, a1, l))
ipw_value = np.mean(matches * y / (prob1 * prob2))

print("First-stage choices for X = 0, 1:", d1(np.array([0, 1])))
print("Exact value of learned regime:", round(float(exact_value), 4))
print("Held-out IPW estimate:", round(float(ipw_value), 4))
print("Optimal population value:", 4.05)

With the stated seed, the run gives:

First-stage choices for X = 0, 1: [0 1]
Exact value of learned regime: 4.05
Held-out IPW estimate: 4.0246
Optimal population value: 4.05

The exact value uses the known artificial population. The held-out estimate is one noisy realization, not a finite-sample guarantee.

Why the held-out weighting estimates regime value

Condition on the training data so that the learned rules are fixed. For an independent evaluation record, write

It=1{At=d^t(Ht)},W=I1I2e1(A1∣X)e2(A2∣H2).I_t=\mathbf1\{A_t=\widehat d_t(H_t)\},\qquad W=\frac{I_1I_2}{e_1(A_1\mid X)e_2(A_2\mid H_2)}.

At stage 2, averaging over the logged treatment cancels its probability:

E[I2Ye2(A2∣H2)∣H2]=∑a21{a2=d^2(H2)}Q2∗(H2,a2)=Q2∗{H2,d^2(H2)}.\begin{aligned} \mathbb E\left[ \frac{I_2Y}{e_2(A_2\mid H_2)}\Bigm|H_2 \right] &=\sum_{a_2}\mathbf1\{a_2=\widehat d_2(H_2)\}Q_2^*(H_2,a_2)\\ &=Q_2^*\{H_2,\widehat d_2(H_2)\}. \end{aligned}

The first-stage weight performs the analogous cancellation. Applying iterated expectation gives

E[WY∣X]=∑a11{a1=d^1(X)}×E[Q2∗{H2,d^2(H2)}∣X,A1=a1].\begin{aligned} \mathbb E[WY\mid X] &=\sum_{a_1}\mathbf1\{a_1=\widehat d_1(X)\}\\ &\quad\times\mathbb E\left[ Q_2^*\{H_2,\widehat d_2(H_2)\}\mid X,A_1=a_1 \right]. \end{aligned}

Averaging over XX recovers the identified value formula for d^\widehat d. Thus the ordinary, unnormalized inverse-probability-weighted average used in the code is conditionally unbiased for V(d^)V(\widehat d) when the logging propensities are known and the stated identification and integrability conditions hold. Estimated propensity scores require additional analysis; the exact cancellation is not a finite-sample unbiasedness result for arbitrary fitted weights.

8. Scope of the results

Theorem 1 concerns population optimality; Theorem 2 is conditional on uniform Q-function error bounds. Linear Q-functions need not remain linear after maximization and averaging. Ordinary regression Q-learning is not doubly robust, and generated pseudo-outcomes do not justify naive first-stage standard errors. Treatment ties can create nonregular inference; see Schulte et al., Section 8. We assume full histories, complete outcomes, and a terminal-outcome objective, not a general deep or long-horizon offline-RL setting.

9. Extending the recursion to more stages

The same population construction applies to TT stages with a terminal outcome. Let HtH_t contain all information available before AtA_t, and let At(ht)\mathcal A_t(h_t) be the finite set of feasible treatments. Under corresponding consistency, exchangeability, positivity, and moment conditions, define

QT∗(h,a)=E[Y∣HT=h,AT=a],Qt∗(h,a)=E[max⁡b∈At+1(Ht+1)Qt+1∗(Ht+1,b)∣Ht=h,At=a],t<T.\begin{aligned} Q_T^*(h,a)&=\mathbb E[Y\mid H_T=h,A_T=a],\\ Q_t^*(h,a)&=\mathbb E\left[ \max_{b\in\mathcal A_{t+1}(H_{t+1})}Q_{t+1}^*(H_{t+1},b) \mid H_t=h,A_t=a \right],\quad t<T. \end{aligned}

At every stage, choose a treatment maximizing its Q-function, using a fixed convention to resolve ties. The fitted version works backward by replacing each future maximum with its fitted counterpart and regressing it on the current history and treatment.

For cumulative stage rewards, use the corresponding reward recursion; do not add a reward twice if it is already included in the target outcome.

References and further reading