RLS RL, Read as Statistics

Chapter 07 · Part 2: Learning values

Values as regression, and the winner's curse

Fitting a value function is regression on targets you build yourself; TD's fixed point, LSTD as instrumental variables, and why a max over noisy estimates is biased upward.

Chapter 5 ended with a table of values: one number per state. That is the right object when there are seven states and the wrong one when there are 102010^{20}, or when the state is a vector of pixels. We then need the estimate VV to be a function with far fewer parameters than states, fitted from data. That is a regression problem, and a statistician already has opinions about regression: what the estimand is, what the estimating equation is, when the estimator is consistent, and what goes wrong when a predictor is correlated with the error.

The twist is that in RL the response variable is not given. For Monte Carlo it is the observed return. For TD it is Rt+1+γV(St+1)R_{t+1} + \gamma V(S_{t+1}), which depends on the very function being fitted. Most of the chapter is about what that does to the estimator. The last third is about a second, independent trap: when the targets contain a max⁡\max over estimated values, selecting the best-looking option and then reading off its estimate gives a biased number.

What is gradient Monte Carlo estimating?

Fix a policy π\pi and write d(s)d(s) for the on-policy weighting: the long-run (or expected-visit) fraction of time steps spent in state ss. Let x(s)∈Rkx(s) \in \mathbb{R}^k be a feature vector and V(s)=w⊤x(s)V(s) = w^\top x(s). The natural loss is the mean squared value error

VE‾(w)=∑sd(s) (vπ(s)−w⊤x(s))2.\overline{\mathrm{VE}}(w) = \sum_s d(s)\,\big(v_\pi(s) - w^\top x(s)\big)^2 .

We cannot evaluate it because vπv_\pi is unknown, but we observe GtG_t with E[Gt∣St=s]=vπ(s)\mathbb{E}[G_t \mid S_t = s] = v_\pi(s) (chapter 1). So regress GtG_t on x(St)x(S_t) by least squares. The population normal equations are

E[x(St) (Gt−x(St)⊤w)]=0⟹wMC=(E[xx⊤])−1E[x Gt]=(X⊤DX)−1X⊤D vπ,\mathbb{E}\big[x(S_t)\,(G_t - x(S_t)^\top w)\big] = 0 \quad\Longrightarrow\quad w_{\mathrm{MC}} = \big(\mathbb{E}[x x^\top]\big)^{-1}\mathbb{E}[x\,G_t] = (X^\top D X)^{-1} X^\top D\, v_\pi ,

where XX has rows x(s)⊤x(s)^\top and D=diag⁡(d)D = \operatorname{diag}(d). The second equality is the tower property: E[xG]=E[x E[G∣S]]\mathbb{E}[x G] = \mathbb{E}[x\,\mathbb{E}[G \mid S]]. Nothing in this is special to RL. XwMCX w_{\mathrm{MC}} is the DD-weighted orthogonal projection Πvπ\Pi v_\pi of the true value function onto the span of the features, and least squares converges to it whether or not the linear model is correct. The online version, gradient Monte Carlo, is stochastic gradient descent on the squared error with the return as target:

w←w+α (Gt−w⊤x(St)) x(St).w \leftarrow w + \alpha\,\big(G_t - w^\top x(S_t)\big)\,x(S_t).

Two things to notice. First, the "data" are not independent: successive states in one episode are correlated, and the weighting dd is determined by the policy. Least squares still targets Πvπ\Pi v_\pi, but standard errors from an iid regression formula would be wrong; the episode, not the step, is the independent unit. Second, the targets GtG_t are unbiased for vπ(St)v_\pi(S_t) and typically have large variance, for the reasons given in chapter 4.

What does semi-gradient TD converge to?

Replace the return by the TD target, as in chapter 5:

w←w+α δt x(St),δt=Rt+1+γ w⊤x(St+1)−w⊤x(St).w \leftarrow w + \alpha\,\delta_t\,x(S_t), \qquad \delta_t = R_{t+1} + \gamma\, w^\top x(S_{t+1}) - w^\top x(S_t).

This is called semi-gradient because δt2/2\delta_t^2/2 is a squared error whose gradient would also differentiate through the target w⊤x(St+1)w^\top x(S_{t+1}); the update ignores that part and treats the target as a constant. It is a Robbins–Monro iteration, so its limit is the root of the mean update. Write

A=E[x(St) (x(St)−γ x(St+1))⊤],b=E[Rt+1 x(St)].A = \mathbb{E}\big[x(S_t)\,(x(S_t) - \gamma\, x(S_{t+1}))^\top\big], \qquad b = \mathbb{E}\big[R_{t+1}\,x(S_t)\big].

The mean update is b−Awb - A w, so the fixed point solves E[δt x(St)]=0\mathbb{E}[\delta_t\, x(S_t)] = 0:

wTD=A−1b.w_{\mathrm{TD}} = A^{-1} b .

Compare the two estimating equations. Least squares sets E[x (Gt−x⊤w)]=0\mathbb{E}[x\,(G_t - x^\top w)] = 0. TD sets E[x (Rt+1+γxt+1⊤w−xt⊤w)]=0\mathbb{E}[x\,(R_{t+1} + \gamma x_{t+1}^\top w - x_t^\top w)] = 0. Both are orthogonality conditions between the features and a residual; they differ in which residual. In matrix form, with PP the transition matrix under π\pi and rr the expected reward vector, the TD condition reads X⊤D (r+γPXw−Xw)=0X^\top D\,(r + \gamma P X w - X w) = 0, that is

XwTD=Π T(XwTD),(Tu)(s)=r(s)+γ∑s′P(s′∣s) u(s′).X w_{\mathrm{TD}} = \Pi\, T (X w_{\mathrm{TD}}), \qquad (Tu)(s) = r(s) + \gamma \sum_{s'} P(s' \mid s)\, u(s').

TT is the Bellman operator; Π\Pi projects. The fixed point is the projected Bellman equation. When the features can represent vπv_\pi exactly, vπ=Tvπv_\pi = T v_\pi is a fixed point and both estimators agree. When they cannot, they generally differ, and that is the situation the experiment below is built to show.

How far can TD be from the best linear fit? Tsitsiklis and Van Roy (1997) proved that, on-policy, γ<1\gamma < 1, and with linearly independent features, TD(0) converges with probability one and

∥XwTD−vπ∥D  ≤  11−γ2  ∥Πvπ−vπ∥D.\lVert X w_{\mathrm{TD}} - v_\pi \rVert_D \;\le\; \frac{1}{\sqrt{1-\gamma^2}}\;\lVert \Pi v_\pi - v_\pi \rVert_D .

The proof is short enough to give. TT is a γ\gamma-contraction in ∥⋅∥D\lVert\cdot\rVert_D, because d⊤P≤d⊤d^\top P \le d^\top makes ∥Pu∥D≤∥u∥D\lVert P u\rVert_D \le \lVert u\rVert_D by Jensen's inequality (the paper states this for the stationary distribution of an ergodic chain; the same argument works for expected-visit weights in an episodic problem). Π\Pi is non-expansive. Since vπ=Tvπv_\pi = Tv_\pi we have Πvπ=ΠTvπ\Pi v_\pi = \Pi T v_\pi, so

∥XwTD−Πvπ∥D=∥ΠTXwTD−ΠTvπ∥D≤γ ∥XwTD−vπ∥D.\lVert X w_{\mathrm{TD}} - \Pi v_\pi\rVert_D = \lVert \Pi T X w_{\mathrm{TD}} - \Pi T v_\pi\rVert_D \le \gamma\,\lVert X w_{\mathrm{TD}} - v_\pi\rVert_D .

Pythagoras (vπ−Πvπv_\pi - \Pi v_\pi is orthogonal to the feature span) gives ∥XwTD−vπ∥2=∥XwTD−Πvπ∥2+∥Πvπ−vπ∥2≤γ2∥XwTD−vπ∥2+∥Πvπ−vπ∥2\lVert X w_{\mathrm{TD}} - v_\pi\rVert^2 = \lVert X w_{\mathrm{TD}} - \Pi v_\pi\rVert^2 + \lVert \Pi v_\pi - v_\pi\rVert^2 \le \gamma^2 \lVert X w_{\mathrm{TD}} - v_\pi\rVert^2 + \lVert \Pi v_\pi - v_\pi\rVert^2, and rearranging yields the bound. Two honest remarks. The factor 1/1−γ21/\sqrt{1-\gamma^2} is a worst case and blows up as γ→1\gamma \to 1. And the bound is about bias in the limit; it says nothing about variance. The case for TD over Monte Carlo is the one from chapter 5: a biased target with much lower variance can win in mean squared error at realistic sample sizes. It is not a theorem that it wins, and the experiment below contains a case where it does not.

Why is LSTD an instrumental-variables estimator?

Semi-gradient TD finds the root of b−Awb - Aw by stochastic approximation, with all the step-size tuning that implies. But we can estimate AA and bb by sample averages and solve the linear system once. With data (St,Rt+1,St+1)(S_t, R_{t+1}, S_{t+1}), t=1,…,nt = 1, \dots, n, put xt=x(St)x_t = x(S_t) and zt=xt−γ xt+1z_t = x_t - \gamma\, x_{t+1}:

A^n=1n∑txtzt⊤,b^n=1n∑tRt+1 xt,w^LSTD=A^n−1b^n.\hat A_n = \frac1n\sum_t x_t z_t^\top, \qquad \hat b_n = \frac1n\sum_t R_{t+1}\, x_t, \qquad \hat w_{\mathrm{LSTD}} = \hat A_n^{-1}\hat b_n .

This is least-squares temporal-difference learning (Bradtke and Barto, 1996; the λ\lambda extension and a careful account are in Boyan, 2002). It needs no step size, converges to wTDw_{\mathrm{TD}} by the law of large numbers, and costs O(k2)O(k^2) per step with a rank-one update or O(k3)O(k^3) to solve once.

Now the statistical reading. Suppose the features are rich enough that vπ(s)=x(s)⊤w∗v_\pi(s) = x(s)^\top w^*. Define the Bellman residual noise

ηt=Rt+1+γ vπ(St+1)−vπ(St).\eta_t = R_{t+1} + \gamma\, v_\pi(S_{t+1}) - v_\pi(S_t).

By the Bellman equation (the law of total expectation from chapter 1), E[ηt∣St]=0\mathbb{E}[\eta_t \mid S_t] = 0. Rearranging gives a linear regression model for the reward:

Rt+1=zt⊤w∗+ηt,zt=x(St)−γ x(St+1).R_{t+1} = z_t^\top w^* + \eta_t, \qquad z_t = x(S_t) - \gamma\, x(S_{t+1}).

So w∗w^* is the coefficient of a linear model with response Rt+1R_{t+1}, regressor ztz_t, and error ηt\eta_t. Why not run OLS? Because the regressor contains x(St+1)x(S_{t+1}), and ηt\eta_t is not mean zero given St+1S_{t+1}: a lucky reward makes ηt\eta_t large and also tells us something about where we landed. Hence E[ztηt]=−γ E[x(St+1) ηt]≠0\mathbb{E}[z_t \eta_t] = -\gamma\,\mathbb{E}[x(S_{t+1})\,\eta_t] \ne 0 in general, OLS is inconsistent, and the usual name for this is endogeneity (an errors-in-variables problem: the "true" regressor is the expected next-state feature, we see a noisy draw of it).

The textbook repair is an instrument: a variable xtx_t that is uncorrelated with the error but correlated with the regressor. The features of the current state qualify on both counts:

  • Exogeneity: E[xt ηt]=E[xt E[ηt∣St]]=0\mathbb{E}[x_t\,\eta_t] = \mathbb{E}\big[x_t\,\mathbb{E}[\eta_t \mid S_t]\big] = 0.
  • Relevance: E[xtzt⊤]=A\mathbb{E}[x_t z_t^\top] = A is nonsingular on-policy.

The just-identified IV estimator solves ∑txt (Rt+1−zt⊤w)=0\sum_t x_t\,(R_{t+1} - z_t^\top w) = 0, which is w^=(∑txtzt⊤)−1∑txtRt+1\hat w = (\sum_t x_t z_t^\top)^{-1}\sum_t x_t R_{t+1}. That is exactly w^LSTD\hat w_{\mathrm{LSTD}}.

When the features are not rich enough, the regression model above is misspecified and there is no true w∗w^*. IV still has an estimand: the root of the moment condition E[xt(Rt+1−zt⊤w)]=0\mathbb{E}[x_t(R_{t+1} - z_t^\top w)] = 0, which is wTDw_{\mathrm{TD}}. So the same equation has two readings: the stationary point of TD learning, and a method-of-moments estimate whose instruments are the features. The two readings explain why LSTD and TD agree, and why neither agrees with least squares on returns.

How does regression become control? Fitted Q-iteration

So far we evaluated one policy. To find a good policy from a fixed batch of transitions {(si,ai,ri,si′)}i=1n\{(s_i, a_i, r_i, s_i')\}_{i=1}^n, fit action values with a regression and then act greedily. Fitted Q-iteration (Ernst, Geurts and Wehenkel, 2005, with extremely randomised trees as the regressor) repeats:

  1. Start from Q0≡0Q_0 \equiv 0.
  2. Build responses yi=ri+γmax⁡a′Qk(si′,a′)y_i = r_i + \gamma \max_{a'} Q_k(s_i', a').
  3. Fit Qk+1=arg⁡min⁡f∑i(yi−f(si,ai))2Q_{k+1} = \arg\min_f \sum_i \big(y_i - f(s_i, a_i)\big)^2 over a function class.

Neural fitted Q-iteration (Riedmiller, 2005) is the same loop with a multilayer perceptron as the regressor. Each round is a regression with a generated response. The squared loss is the right one because E[yi∣si,ai]=(TQk)(si,ai)\mathbb{E}[y_i \mid s_i, a_i] = (\mathcal{T}Q_k)(s_i, a_i), where T\mathcal{T} is the Bellman optimality operator; regression on yy therefore targets TQk\mathcal{T}Q_k projected onto the function class. The iteration is "project, apply the operator, project, ..." and inherits the projection error at every step, so errors can compound across rounds.

But look at step 2. The response contains a maximum over estimated values. Even if QkQ_k were unbiased for q∗q_* at every point, max⁡a′Qk(s′,a′)\max_{a'} Q_k(s', a') would not be unbiased for max⁡a′q∗(s′,a′)\max_{a'} q_*(s', a').

What is the winner's curse?

Let Q^1,…,Q^K\hat Q_1, \dots, \hat Q_K be estimates with E[Q^a]=μa\mathbb{E}[\hat Q_a] = \mu_a. The maximum is a convex function, so Jensen's inequality gives

E[max⁡aQ^a]  ≥  max⁡aE[Q^a]=max⁡aμa,\mathbb{E}\Big[\max_a \hat Q_a\Big] \;\ge\; \max_a \mathbb{E}[\hat Q_a] = \max_a \mu_a ,

with equality only when the same arm wins in every sample. The max of unbiased estimates is biased upward. In decision analysis this is the optimizer's curse: choose the option with the best estimated value, and its realised value is expected to fall short of the estimate, even though no estimate was biased (Smith and Winkler, 2006). In RL it was identified for Q-learning with function approximation by Thrun and Schwartz (1993), who observed that generalisation errors in QQ are compounded by the max operator. And because Bellman backups feed the biased max back in as the next target, the bias is not a one-off: it propagates through bootstrapping.

A worked example by hand

Take two arms with true means 00 and two unbiased estimates Q^1,Q^2\hat Q_1, \hat Q_2 that are iid N(0,1)\mathcal{N}(0,1). Use the identity max⁡(a,b)=a+b2+∣a−b∣2\max(a,b) = \tfrac{a+b}{2} + \tfrac{\lvert a-b\rvert}{2}:

E[max⁡(Q^1,Q^2)]=E[Q^1]+E[Q^2]2⏟0+12 E∣Q^1−Q^2∣.\mathbb{E}[\max(\hat Q_1,\hat Q_2)] = \underbrace{\tfrac{\mathbb{E}[\hat Q_1]+\mathbb{E}[\hat Q_2]}{2}}_{0} + \tfrac12\,\mathbb{E}\lvert \hat Q_1 - \hat Q_2\rvert .

Q^1−Q^2∼N(0,2)\hat Q_1 - \hat Q_2 \sim \mathcal{N}(0, 2), and for Z∼N(0,s2)Z \sim \mathcal{N}(0,s^2) we have E∣Z∣=s2/π\mathbb{E}\lvert Z\rvert = s\sqrt{2/\pi}. With s=2s = \sqrt2 that is 2/π2/\sqrt\pi, so

E[max⁡(Q^1,Q^2)]=1π≈0.564,\mathbb{E}[\max(\hat Q_1,\hat Q_2)] = \frac{1}{\sqrt\pi} \approx 0.564 ,

while max⁡aE[Q^a]=0\max_a \mathbb{E}[\hat Q_a] = 0. If each estimate is a mean of nn draws with standard deviation σ\sigma, replace 11 by σ/n\sigma/\sqrt n: the overestimate is 0.564 σ/n0.564\,\sigma/\sqrt n. For large KK with all means equal, E[max⁡]≈(σ/n)2ln⁡K\mathbb{E}[\max] \approx (\sigma/\sqrt n)\sqrt{2\ln K}. So the bias grows with the noise, shrinks like 1/n1/\sqrt n, and grows (slowly) with the number of options.

Double estimators as sample splitting

The bias arises because the same noise is used twice: once to pick the winner and once to score it. The cure is the one statisticians use for post-selection inference: split the sample. Take two independent estimates Q^aA\hat Q^A_a and Q^aB\hat Q^B_a of each arm. Select with one, evaluate with the other:

a^=arg⁡max⁡aQ^aA,estimate Q^a^B.\hat a = \arg\max_a \hat Q^A_a, \qquad \text{estimate } \hat Q^B_{\hat a}.

Given a^\hat a (a function of AA only), Q^a^B\hat Q^B_{\hat a} is unbiased for μa^\mu_{\hat a}, so E[Q^a^B]=E[μa^]≤max⁡aμa\mathbb{E}[\hat Q^B_{\hat a}] = \mathbb{E}[\mu_{\hat a}] \le \max_a \mu_a. The sign of the bias has flipped: the double estimator is biased downward, by an amount that depends on how often selection picks a suboptimal arm. Double Q-learning (van Hasselt, 2010) maintains two tables QAQ^A, QBQ^B and, on each transition, flips a coin to update one of them using the other to evaluate:

QA(s,a)←QA(s,a)+α(r+γ QB(s′,arg⁡max⁡a′QA(s′,a′))−QA(s,a)).Q^A(s,a) \leftarrow Q^A(s,a) + \alpha\Big(r + \gamma\, Q^B\big(s', \arg\max_{a'} Q^A(s',a')\big) - Q^A(s,a)\Big).

If you have used cross-fitting for double machine learning, this is the same idea: the nuisance function that picks is trained on a different fold from the one that scores. Double DQN (van Hasselt, Guez and Silver, 2016) carries the idea to deep networks without a second network: the online network selects arg⁡max⁡a′\arg\max_{a'} and the slowly moving target network evaluates it. The two networks are correlated, so this is a partial split rather than an independent one, and it reduces the overestimation rather than removing it.

Experiment

ch07_regression.py runs both parts below. Everything is NumPy.

(a) Overestimation as the number of arms and the noise vary

Each of KK arms has n=20n = 20 draws from N(μa,σ2)\mathcal{N}(\mu_a, \sigma^2). The single estimator is the largest sample mean. The double estimator selects the arm with the largest mean of the first 10 draws and reports that arm's mean over the other 10. We average over 20,000 replications and print the bias relative to max⁡aμa\max_a \mu_a, first with all true means zero, then with means spread evenly over [0,1][0, 1].

Output
(a) Bias of E[estimate of max_a mu_a] - max_a mu_a, n=20 draws per arm

  all true means equal (0)
  sigma   K |  single   double
    0.5   2 |  +0.063   -0.001
    0.5  10 |  +0.172   -0.000
    0.5 100 |  +0.280   +0.000
    1.0   2 |  +0.125   -0.002
    1.0  10 |  +0.344   -0.001
    1.0 100 |  +0.560   -0.002
    2.0   2 |  +0.246   -0.007
    2.0  10 |  +0.689   +0.007
    2.0 100 |  +1.120   +0.003

  means spread over [0, 1]
  sigma   K |  single   double
    0.5   2 |  -0.000   +0.001
    0.5  10 |  +0.026   -0.062
    0.5 100 |  +0.140   -0.067
    1.0   2 |  -0.001   -0.012
    1.0  10 |  +0.111   -0.144
    1.0 100 |  +0.347   -0.129
    2.0   2 |  +0.021   -0.128
    2.0  10 |  +0.364   -0.258
    2.0 100 |  +0.818   -0.228

Check the hand calculation: for K=2K = 2, σ=1\sigma = 1, n=20n = 20, the formula gives 0.564/20=0.1260.564/\sqrt{20} = 0.126, and the simulation prints +0.125+0.125. The bias of the single estimator is proportional to σ\sigma (it doubles from σ=1\sigma = 1 to σ=2\sigma = 2) and grows with KK, roughly like 2ln⁡K\sqrt{2 \ln K}: at σ=1\sigma = 1 it goes 0.125,0.344,0.5600.125, 0.344, 0.560 for K=2,10,100K = 2, 10, 100. When all means are equal the double estimator is unbiased to within simulation error, because whichever arm is chosen has true mean zero. When the means are spread, selection is informative, the single estimator's bias shrinks (the winner is usually the right arm), but the double estimator now underestimates, by up to 0.260.26 here: it sometimes picks a worse arm and pays for it, and the held-out half cannot compensate. Neither estimator is uniformly better; the double estimator trades a bias of known sign for one of the opposite sign, and which has the smaller magnitude depends on the gaps and the noise.

(b) LSTD, gradient MC and semi-gradient TD with coarse features

The environment is a random walk on 7 states, started in the middle. Each step moves left or right with probability 12\tfrac12; leaving on the right pays reward 11, leaving on the left pays 00, and γ=0.9\gamma = 0.9. The features are state aggregation: three indicator features, one for each of the groups {0,1}\{0,1\}, {2,3,4}\{2,3,4\} and {5,6}\{5,6\}. So VV is a step function, and vπv_\pi is not representable. The script computes wMCw_{\mathrm{MC}} and wTDw_{\mathrm{TD}} exactly from PP and rr, then runs 200 independent datasets of 100 episodes each through five estimators:

  • gradient MC and semi-gradient TD, both online with step size 0.1/(1+t/50)0.1/(1 + t/50) per episode;
  • batch least squares on returns ("MC least squares"), the estimator that gradient MC is trying to compute;
  • LSTD;
  • the naive OLS of Rt+1R_{t+1} on ztz_t, to show the endogeneity problem.
Output
(b) Random walk, 7 states, gamma=0.9, reward 1 on right exit,
    3 aggregated features (states {0,1},{2,3,4},{5,6}).

  true v      :  0.026  0.057  0.101  0.168  0.271  0.435  0.696
  on-policy d :  0.062  0.125  0.188  0.250  0.188  0.125  0.062
  MC limit  Xw:  0.047  0.047  0.179  0.179  0.179  0.522  0.522
  TD fixed  Xw:  0.100  0.100  0.184  0.184  0.184  0.403  0.403

  weights, MC limit : [0.0466 0.1787 0.522 ]
  weights, TD fixed : [0.1002 0.1837 0.4032]

  ||Pi v - v||_D            = 0.0751   (best possible, = MC limit)
  ||X w_TD - v||_D          = 0.0940
  TVR bound (1/sqrt(1-g^2)) = 0.1723

  100 episodes per run, 200 runs. Error is ||X w - v||_D.
  method               | mean err  | dist to MC limit | dist to TD fixed pt | sd of err
  grad MC (SGD)        |   0.1136  |          0.0402  |             0.1589  | 0.0314
  semi-grad TD (SGD)   |   0.0948  |          0.1113  |             0.0195  | 0.0096
  MC least squares     |   0.0793  |          0.0040  |             0.1334  | 0.0043
  LSTD                 |   0.0962  |          0.1299  |             0.0006  | 0.0070
  naive OLS of R on z  |   0.2424  |          0.3830  |             0.3617  | 0.0303

  LSTD on 20000 episodes: weights [0.0982 0.1805 0.3967]  (TD fixed point [0.1002 0.1837 0.4032])

What the numbers show.

  • The two population solutions differ. The MC limit has weights (0.047,0.179,0.522)(0.047, 0.179, 0.522) and the TD fixed point (0.100,0.184,0.403)(0.100, 0.184, 0.403). TD is pulled toward a more even profile: its estimate for the left group is more than twice the MC value, and for the right group is lower. The TD fixed point is slightly worse in the DD-norm (0.09400.0940 against the best-possible 0.07510.0751) and inside the Tsitsiklis–Van Roy bound (0.17230.1723). The bound is loose here, as expected for a worst-case result.
  • Each estimator converges to its own target. In the "dist to" columns, MC least squares sits 0.0040.004 from the MC limit and 0.1330.133 from the TD fixed point; LSTD sits 0.00060.0006 from the TD fixed point and 0.1300.130 from the MC limit. Semi-gradient TD (SGD) is 0.0200.020 from the TD fixed point, the remainder being step-size noise. Gradient MC (SGD) is closer to the MC limit (0.0400.040) than to the TD point, but it is the noisiest method (0.03140.0314 standard deviation of the error) at this step schedule.
  • LSTD equals the TD fixed point. With 20,000 episodes its weights are (0.098,0.181,0.397)(0.098, 0.181, 0.397) against (0.100,0.184,0.403)(0.100, 0.184, 0.403).
  • TD is not automatically better here. Among the online methods, semi-gradient TD beats gradient MC on both mean error and spread (0.09480.0948 against 0.11360.1136; 0.00960.0096 against 0.03140.0314). In the batch comparison, MC least squares has lower error and spread than LSTD (0.07930.0793 against 0.09620.0962). With γ=0.9\gamma = 0.9, binary rewards and episodes of about a dozen steps, returns are not very noisy, so there is little variance for TD to save and its projection bias costs more than it gains. The bias–variance advantage of chapter 5 is a statement about regimes, and this is one where it does not appear for the batch estimators. Longer horizons, noisier rewards, or richer features change it.
  • Endogeneity matters. The naive OLS of Rt+1R_{t+1} on ztz_t has mean error 0.24240.2424, three times that of LSTD, and is 0.360.36 from the TD fixed point in weight space. It uses exactly the same data and the same regressors; the only difference is that LSTD uses xtx_t as an instrument.

Deadly triad, in one paragraph

Function approximation (here, a linear model), bootstrapping (targets that depend on VV), and off-policy data (the sampling distribution is not the target policy's) are each harmless alone. Together, with a semi-gradient update, the mean update b−Awb - Aw no longer comes from a positive-definite AA and the iteration can diverge, even with linear features and exact expected updates. Sutton and Barto name this the deadly triad (2018, section 11.3); van Hasselt et al. (2018) study empirically how it shows up in deep Q-learning, including the role of overestimation. In the language of this chapter: with off-policy data the sampling weights DD are not the stationary weights of PP, the contraction argument fails, and ΠT\Pi T may not be a contraction. Chapter 6's importance ratios fix the bias of the targets but not this.

Exercises

  1. Pen and paper. Show that for three iid N(0,1)\mathcal{N}(0,1) estimates E[max⁡]=32π\mathbb{E}[\max] = \tfrac{3}{2\sqrt\pi}. (Hint: the density of the maximum is 3ϕ(x)Φ(x)23\phi(x)\Phi(x)^2; integrate x ϕ(x)Φ(x)2x\,\phi(x)\Phi(x)^2 by parts.) Compare with the K=2K=2 value and with 2ln⁡3\sqrt{2\ln 3}.
  2. Pen and paper. Show that E[xtηt]=0\mathbb{E}[x_t\eta_t] = 0 but E[ztηt]=−γ E[xt+1ηt]\mathbb{E}[z_t\eta_t] = -\gamma\,\mathbb{E}[x_{t+1}\eta_t]. Build a two-step example in which this is nonzero, so that OLS of Rt+1R_{t+1} on ztz_t is inconsistent.
  3. Change the code and predict. In experiment_a, double nn from 20 to 80. Predict the single estimator's bias at K=10K=10, σ=1\sigma=1 with equal means, then run it.
  4. Change the code and predict. Set GAMMA = 0.99 and rerun part (b). Which moves more, the distance between the MC limit and the TD fixed point, or the Tsitsiklis–Van Roy bound? What happens to the relative variance of gradient MC and TD?
  5. Change the code and predict. Give the random walk one-hot features (replace GROUPS with range(7) and X with 77 columns). What do you expect the distance between wMCw_{\mathrm{MC}} and wTDw_{\mathrm{TD}} to be, and why?

Sources