The random walk as a Markov reward process
When the policy is fixed, the agent has no decision left to make, and the MDP reduces to a Markov reward process (MRP), the tuple . Its transition probabilities and expected rewards are those of the MDP, averaged over the actions of the policy: Prediction is a question about this MRP: the value function of the MRP is .
Code
Code
TD(0) estimates during learning
The two update rules below act on one episode, stored as a list of transitions . TD(0) updates after every transition. MC computes the returns backward from the end of the episode and then moves each visited state toward its return.Code
Code
RMS error over episodes
A single run is noisy. The next figure measures the error of the estimates after each episode as the root-mean-square difference from the true values over the five states, averaged over 100 independent runs. It compares constant- MC with from 0.01 to 0.04 and TD(0) with from 0.05 to 0.15, the settings of Sutton and Barto’s figure.Code
Code
Batch updating
The two methods also differ when they see the same data. In batch updating the agent keeps a fixed set of episodes and presents them again and again. Each pass computes the TD(0) or MC increment for every transition, adds the increments up, and changes only at the end of the pass. With a small enough , both procedures converge, each to an answer that does not depend on :- Batch MC converges to the average of the returns observed from each state.
- Batch TD(0) converges to the exact values of the maximum-likelihood model of the data: the MRP whose transition probabilities and expected rewards are the frequencies and averages observed in the episodes. This is the certainty-equivalence estimate, because it treats the fitted model as if it were known to be right.
Code
Code
You are the predictor
Suppose you observe eight episodes of an unknown MRP with two states, A and B, and . One episode starts in A, moves to B with reward 0, and ends from B with reward 0. Six episodes start in B and end with reward 1. The last one starts in B and ends with reward 0. What are the values of A and B?Code
Code
The MC vs TD(0) trade-off
The two methods sit at opposite ends of a trade-off between bias, variance and use of the Markov structure. Bias. The MC target is the actual return , an unbiased sample of . The TD(0) target is biased whenever is wrong. At the start every state has , which is wrong everywhere except at C. Variance. depends on the whole random trajectory from to the end of the episode, so its variance grows with the length of the episode. The TD(0) target depends on one random transition. On the random walk, where an episode can take dozens of steps, the MC target is either 0 or 1, while the TD(0) target moves only by the difference between neighboring estimates. The lower variance lets TD(0) use larger step sizes without becoming unstable. Use of the Markov property. TD(0) treats as a summary of everything that happens after , which is the Markov assumption. MC averages the observed returns and does not use the Markov structure. When the process is Markov, as the random walk is, TD(0) reuses what it has learned about the successor states, and MC has to learn the value of each state from that state’s own returns. When to use each.- Episodic or continuing tasks. MC needs , so the episode has to end. TD(0) updates after every step and also works on continuing tasks.
- Long episodes. The variance of the MC target grows with the length of the episode, and the TD(0) target’s does not.
- Learning early. TD(0) learns from the first transition of the first episode, and MC waits until the episode ends.
- A state that is not Markov. MC does not rely on the Markov property, so it can be the safer choice when the state hides part of the past.
References
- Sutton, R., Barto, A. (2018). Reinforcement Learning: An Introduction. Link
Found an error on this page? Report an issue.

