Simple Algorithm
Reinforcement Learning · Fixed Point · 26 min

TD vs Monte Carlo: Certainty Equivalence

What batch TD and batch Monte Carlo each converge to, and why TD often wins.

Eight episodes, two states, two answers. Batch Monte Carlo says state A is worth 0; batch TD says 0.75. Each is the best answer to a different question. This lesson proves what each method computes from a fixed batch of data, measures exactly how much TD gains by pooling evidence across states, constructs a problem where TD's answer stays wrong however much data arrives, and summarizes what theory says about the size of TD's advantage.

What you’ll learn

  • Work through Sutton and Barto's "You are the predictor" example, and prove that batch TD(0) converges to the certainty-equivalence estimate while batch Monte Carlo fits the observed returns.
  • Compute TD's variance advantage exactly in a two-state chain, and connect it to the plug-in principle of maximum likelihood.
  • Construct an aliased problem in which TD's error does not vanish with data, and find the sample size at which Monte Carlo overtakes it.
  • Summarize theoretical comparisons of TD and Monte Carlo: Kearns and Singh's bias–variance bounds and Cheikhi and Russo's characterization of TD's statistical benefit.

You are the predictor

Sutton and Barto (Example 6.4) ask you to play predictor. An unknown Markov reward process, with γ=1\gamma = 1, produced eight episodes:

  • one episode: A, reward 0, B, reward 0, end;
  • six episodes: B, reward 1, end;
  • one episode: B, reward 0, end.
Think first What are your best estimates of V(B)V(B) and V(A)V(A)? Commit to numbers before revealing.

V(B)=68=34V(B) = \tfrac68 = \tfrac34: B was seen eight times and was followed by a return of 1 six times. Everyone agrees on that. For V(A)V(A) there are two defensible answers. 0: the only return ever observed from A was 0. ¾: every time A occurred it moved to B with reward 0, and B is worth ¾. Batch Monte Carlo gives the first answer, batch TD(0) the second.

DerivationProof for batch TD(0)
  1. V←V+α N(r^+γP^V−V)=(I−αN(I−γP^))V+αNr^V \leftarrow V + \alpha\,N\big(\hat r + \gamma\hat P V - V\big) = \big(I - \alpha N(I - \gamma\hat P)\big)V + \alpha N\hat r

    Let N=diag⁡(N(s))N = \diag\big(N(s)\big) count the stored transitions out of each state. Summing the TD increments over the batch, one sweep is a linear iteration:

  2. P^\hat P is substochastic (the missing mass is termination), so I−γP^I - \gamma\hat P is a nonsingular M-matrix whenever every state in the data can reach termination under P^\hat P, which holds for data made of complete episodes. Multiplying by the positive diagonal NN keeps it one, so all eigenvalues of N(I−γP^)N(I - \gamma\hat P) have positive real parts, and for small enough α\alpha the iteration matrix has spectral radius below 1.

  3. N(r^+γP^V−V)=0⟺V=r^+γP^VN\big(\hat r + \gamma\hat P V - V\big) = 0\quad\Longleftrightarrow\quad V = \hat r + \gamma\hat P V

    The iteration therefore converges, to the point where the summed TD errors vanish. Since NN is invertible on the visited states, that point solves the Bellman equation of the estimated model, independently of α\alpha. ■\blacksquare

In the example, P^(B∣A)=1\hat P(B \mid A) = 1 with r^(A)=0\hat r(A) = 0, and B terminates with average reward 68\tfrac68. The model's values are V(B)=34V(B) = \tfrac34 and V(A)=0+V(B)=34V(A) = 0 + V(B) = \tfrac34: batch TD's answer. Batch Monte Carlo minimizes the squared error on the training returns, which it does perfectly with V(A)=0V(A) = 0. Fitting the past is one goal; predicting the future of a Markov process is another.

When certainty equivalence is right: pooling

If the process is Markov, the certainty-equivalence estimate is a plug-in estimate: V=(I−γP)−1rV = (I - \gamma P)^{-1}r is a smooth function of the model, and replacing the model by its maximum-likelihood estimate gives the maximum-likelihood estimate of VV. Such estimates are asymptotically efficient. The mechanism behind TD's advantage is that every transition out of a state informs the value of every state that leads to it. The smallest case can be computed exactly.

DerivationHow much pooling saves, exactly
  1. V^MC(A)=1nA∑i=1nAGi,MSEMC=p(1−p)nA\hat V_{\mathrm{MC}}(A) = \frac{1}{n_A}\sum_{i=1}^{n_A}G_i,\qquad \mathrm{MSE}_{\mathrm{MC}} = \frac{p(1-p)}{n_A}

    A moves to B with reward 0; B ends with reward 1 with probability pp and 0 otherwise. The data are nAn_A episodes starting in A (each passing through B) and nBn_B episodes starting in B. Batch Monte Carlo estimates V(A)V(A) from the nAn_A returns observed after A:

  2. V^TD(A)=1nA+nB∑j=1nA+nBGj(B),MSETD=p(1−p)nA+nB\hat V_{\mathrm{TD}}(A) = \frac{1}{n_A + n_B}\sum_{j=1}^{n_A + n_B}G^{(B)}_j,\qquad \mathrm{MSE}_{\mathrm{TD}} = \frac{p(1-p)}{n_A + n_B}

    Batch TD sets V^(A)=0+V^(B)\hat V(A) = 0 + \hat V(B), and V^(B)\hat V(B) averages all nA+nBn_A + n_B outcomes observed after B. Both estimates are unbiased here, but TD's uses all the data:

  3. MSETDMSEMC=nAnA+nB\frac{\mathrm{MSE}_{\mathrm{TD}}}{\mathrm{MSE}_{\mathrm{MC}}} = \frac{n_A}{n_A + n_B}

    The ratio is the fraction of B's data that Monte Carlo can use for A. In "You are the predictor" it is 18\tfrac18.

Predict before you look

In this chain, 10 episodes start in A and 30 start in B. By what factor is batch Monte Carlo's mean squared error for V(A)V(A) larger than batch TD's?

Show the answer

4

MSEMC/MSETD=(nA+nB)/nA=40/10=4\mathrm{MSE}_{\mathrm{MC}}/\mathrm{MSE}_{\mathrm{TD}} = (n_A + n_B)/n_A = 40/10 = 4. Monte Carlo uses only the 10 returns that followed A; TD uses all 40 observations of what follows B.

Cheikhi and Russo (2023) turned this intuition into a general asymptotic theory for finite Markov reward processes. They show that an inverse trajectory pooling coefficient completely characterizes the percentage reduction in mean squared error that TD achieves over direct (Monte Carlo) estimation: TD gains when trajectories from different starting states pass through common states, as A's and B's do here, and the reduction can be enormous or nonexistent depending on that structure. For estimating the difference between the values of two states, they bound TD's error by a trajectory crossing time, which can be much smaller than the horizon, so TD can be far more accurate at ranking states than at valuing them.

When certainty equivalence is wrong: aliasing

Certainty equivalence assumes the data come from a Markov process on the states you see. When the agent's states merge situations whose futures differ, the maximum-likelihood "Markov model" averages over the merged situations, and TD inherits that average. Here is the cleanest case, with numbers.

DerivationAn aliased state: bias that data cannot remove
  1. MSEMC(A)=pA(1−pA)n\mathrm{MSE}_{\mathrm{MC}}(A) = \frac{p_A(1-p_A)}{n}

    Two distinguishable doors, A and C, both lead (reward 0) to an observation X that hides which door was used. After door A, X ends with reward 1 with probability pAp_A; after door C, with probability pCp_C; γ=1\gamma = 1. The data hold nn episodes through each door. Monte Carlo averages the nn returns after A, so it is unbiased:

  2. MSETD(A)=(pC−pA2)2+pA(1−pA)+pC(1−pC)4n\mathrm{MSE}_{\mathrm{TD}}(A) = \Big(\frac{p_C - p_A}{2}\Big)^2 + \frac{p_A(1-p_A) + p_C(1-p_C)}{4n}

    TD's model has a single X, which ended with reward 1 in a fraction close to 12(pA+pC)\tfrac12(p_A + p_C) of 2n2n episodes, and V^(A)=V^(X)\hat V(A) = \hat V(X). That estimate is biased by 12(pC−pA)\tfrac12(p_C - p_A), whatever nn is, but its variance is pooled over 2n2n outcomes:

  3. MSEMC<MSETD⟺n>12\mathrm{MSE}_{\mathrm{MC}} < \mathrm{MSE}_{\mathrm{TD}}\quad\Longleftrightarrow\quad n > 12

    With pA=0.6p_A = 0.6 and pC=0.4p_C = 0.4 the comparison is 0.24/n0.24/n against 0.01+0.12/n0.01 + 0.12/n. TD has the smaller error while 0.12/n>0.010.12/n > 0.01, and Monte Carlo afterwards:

So aliasing does not make TD useless: with little data its pooled, biased estimate can still be the more accurate one. But its error has a floor, here 0.10.1 in absolute terms, while Monte Carlo's keeps shrinking. Multi-step returns sit in between: an nn-step or λ-return target for A includes more of the return that actually followed A, so it inherits less of X's averaged value and less bias, at the price of more variance.

That trade-off was made quantitative by Kearns and Singh (2000), who gave the first rigorous upper bounds on the error of TD methods for policy evaluation as a function of the amount of experience, for a phased version of kk-step TD and TD(λ\lambda). Their bounds converge exponentially fast to an asymptote, and both the rate and the asymptote depend strongly on kk or λ\lambda: longer backups pass on less of the current estimates' error per phase but add more variance from the sampled rewards. The bounds formalize the long-standing intuition of a bias–variance trade-off, and let them derive schedules for λ\lambda that change as learning proceeds.

Predict before you look

Now pA=0.7p_A = 0.7 and pC=0.3p_C = 0.3, with nn episodes through each door. From what number of episodes per door on is Monte Carlo's mean squared error for V(A)V(A) smaller than TD's?

Show the answer

3

Monte Carlo: 0.21/n0.21/n. TD: bias 12(0.3−0.7)=−0.2\tfrac12(0.3 - 0.7) = -0.2, so 0.04+(0.21+0.21)/(4n)=0.04+0.105/n0.04 + (0.21 + 0.21)/(4n) = 0.04 + 0.105/n. Monte Carlo wins when 0.21/n<0.04+0.105/n0.21/n < 0.04 + 0.105/n, that is 0.105/n<0.040.105/n < 0.04, or n>2.6n > 2.6; with whole numbers of episodes, from n=3n = 3 on. A larger difference between the merged situations means a larger bias and an earlier crossover.

Choosing between them

SituationFavorsReason
Markov states, little data per stateTDcertainty equivalence pools the evidence of every transition
Many start states whose trajectories share statesTDlarge inverse pooling coefficient: shared futures are learned once
Merged or non-Markov states, plenty of dataMonte Carlo, or large λ\lambdaTD's aliasing bias does not shrink; Monte Carlo's variance does
Merged states, very little dataoften still TDa small bias can beat a large variance
Long horizons with noisy rewardsTD or intermediate λ\lambdaMonte Carlo's variance grows with the horizon
Function approximationit dependsTD's fixed point can be worse than the best fit Monte Carlo finds, but TD often learns faster (Function Approximation & Deep Q-Learning)

Key takeaways

  • On a fixed batch, Monte Carlo converges to the sample means of the observed returns; TD(0) converges to the values of the maximum-likelihood Markov model (certainty equivalence), because its fixed point is the Bellman equation with r^\hat r and P^\hat P.
  • On Markov problems certainty equivalence pools evidence: in the A→B chain, TD's mean squared error for V(A)V(A) is a fraction nA/(nA+nB)n_A/(n_A + n_B) of Monte Carlo's; Cheikhi and Russo characterize the general gain by an inverse trajectory pooling coefficient.
  • With aliased states TD's estimate is biased by the merged situations, and the bias does not shrink with data; Monte Carlo overtakes it once its variance falls below that bias (from n>12n > 12 in the 0.6/0.4 example).
  • Multi-step returns trade TD's bias for Monte Carlo's variance; Kearns and Singh's bounds make that trade-off quantitative.

Check yourself

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

Question 1

In "You are the predictor", what do batch Monte Carlo and batch TD(0) estimate for V(A)V(A)?

  1. Monte Carlo 34\tfrac34, TD 00
  2. Both 34\tfrac34
  3. Both 00
  4. Monte Carlo 00, TD 34\tfrac34
Show the answer

D. Monte Carlo 00, TD 34\tfrac34

Monte Carlo averages the returns observed after A: one return, equal to 0. TD solves the estimated model's Bellman equation: A always went to B with reward 0, and V^(B)=34\hat V(B) = \tfrac34, so V^(A)=34\hat V(A) = \tfrac34.

Question 2

What does "certainty equivalence" mean here?

  1. Estimating the model by maximum likelihood and then computing its values as if that model were certainly correct
  2. Using only the episodes whose returns are certain
  3. Requiring TD and Monte Carlo to agree before accepting an estimate
  4. Replacing random rewards by their certain upper bounds
Show the answer

A. Estimating the model by maximum likelihood and then computing its values as if that model were certainly correct

The term comes from control theory: plug the estimated parameters into the optimal rule as if they were the true ones, ignoring the uncertainty in them. Batch TD(0) computes the certainty-equivalence values without ever storing the estimated model.

Question 3

In the aliased example with pA=0.6p_A = 0.6 and pC=0.4p_C = 0.4, what happens to batch TD's error for V(A)V(A) as the number of episodes grows without bound?

  1. It tends to 0, like Monte Carlo's
  2. It grows, because errors propagate
  3. It tends to an absolute error of 0.1: TD converges to 12(0.6+0.4)=0.5\tfrac12(0.6 + 0.4) = 0.5 instead of 0.6
  4. It oscillates forever between 0.4 and 0.6
Show the answer

C. It tends to an absolute error of 0.1: TD converges to 12(0.6+0.4)=0.5\tfrac12(0.6 + 0.4) = 0.5 instead of 0.6

The variance term 0.12/n0.12/n vanishes, but the bias does not: the merged state is valued at the average of the two situations it hides, and A inherits that value. Monte Carlo's error goes to 0, which is why it overtakes TD from about 12 episodes per door.

Question 4

What did Kearns and Singh's (2000) bounds for phased kk-step TD and TD(λ\lambda) formalize?

  1. That TD always beats Monte Carlo
  2. A bias–variance trade-off: the rate at which errors shrink across phases, and the level they settle at, both depend on kk or λ\lambda, with longer backups trading bias for variance
  3. That TD(λ\lambda) diverges for λ\lambda close to 1
  4. That certainty equivalence is the minimum-variance unbiased estimator
Show the answer

B. A bias–variance trade-off: the rate at which errors shrink across phases, and the level they settle at, both depend on kk or λ\lambda, with longer backups trading bias for variance

Their upper bounds converge exponentially fast to an asymptote, with the rate and the asymptote depending strongly on the backup length. Short backups lean on current estimates (bias); long ones sum more sampled rewards (variance). The bounds turn the intuition into numbers and suggest schedules for λ\lambda.

Further reading

  • R. S. Sutton, "Learning to predict by the methods of temporal differences," Machine Learning 3, 9–44 (1988).
  • R. S. Sutton & A. G. Barto, Reinforcement Learning: An Introduction, §6.3 (MIT Press, 2nd ed., 2018).
  • M. Kearns & S. Singh, "Bias-variance error bounds for temporal difference updates," Proceedings of the 13th Annual Conference on Computational Learning Theory (COLT), 142–147 (2000).
  • D. Cheikhi & D. Russo, "On the statistical benefits of temporal difference learning," Proceedings of the 40th International Conference on Machine Learning (ICML), PMLR 202, 4269–4293 (2023).