Why Monte Carlo Beats TD Learning in Some Partially Observable Environments¶
Introduction¶
Monte Carlo (MC) and temporal-difference (TD) learning are two different approaches to estimating the value function of a policy. MC uses the return observed over an episode, while TD uses the reward from the next step and a bootstrapped estimate of the remaining return. MC does not rely on the Markov property, which often leads to different value estimates. In the case of partially observable environments, MC can sometimes produce more accurate results.
Let’s use a small example to understand why.
Let’s Construct A Partially Observable Environment¶
Our environment has two equally likely kinds of episodes. An episode begins at either observation \(A\) or observation \(C\). Both lead to an observation \(B\), followed by a terminal reward. The first transition has reward zero. The environment actually contains two different hidden states behind \(B\): one reached from \(A\) and another reached from \(C\). The agent cannot distinguish them from the current observation alone.

We will use an undiscounted return (\(\gamma=1\)), with no actions to choose, since this is a policy-evaluation problem, not a control problem. Each episode starts at \(A\) or \(C\) with probability \(1/2\). The value of an observation is the expected return conditioned on it:
The returns from \(A\) and \(C\) are always \(+1\) and \(-1\) respectively. At \(B\), the two hidden states occur equally often, so the value of \(B\) is the mean:
Note that the value of \(B\) really is zero when we condition only on the current observation. Neither method can determine which hidden state it occupies from \(B\) alone.
What Monte Carlo Learns¶
MC updates the value estimate using the actual return from the current observation:
If we use step-size \(\alpha=1/N(O_t)\), where \(N(o)\) counts visits to \(o\), we obtain the sample average of observed returns. MC learns the following values:
The aliasing at \(B\) does not affect the return of \(A\) or \(C\). MC simply waits until the episode ends and uses the actual reward.
What TD Learns¶
TD(0) uses the Bellman update with a boostrapped value for the subsequent return:
The TD algorithm correctly learns \(V(B)\to 0\). Now consider the preceding observations. Their immediate reward is zero, and both are followed by \(B\). Their TD targets are therefore
TD(0) therefore learns
Both algorithms agree on the value of \(B\). The problem is when TD uses the averaged value to estimate observations prior to \(B\).
Let’s Test our Hypothesis¶
Let’s implement both algorithms. The environment and sampled episodes are identical for the two methods. We will generate many independent episodes which sample \(A\) and \(C\) with equal probability, and use \(\alpha=1/N(o)\) for both. We will run 64 independent trials of 5000 episodes each.
First, let’s see how the estimate of \(A\) develops during training. MC receives a return of \(+1\) from every visit to \(A\). TD instead bootstraps from its value estimate at \(B\).
/var/folders/x4/85_9sn3d1ng9q48ff6t3fw340000gn/T/ipykernel_65954/1754982773.py:15: UserWarning: The figure layout has changed to tight
fig.tight_layout()
MC reaches the correct value of \(A\) as soon as it has observed a complete episode from \(A\). TD, on the other hand, converges toward zero. The same issue occurs at \(C\), where the true value is \(-1\).
The final estimates make the difference clearer.
/var/folders/x4/85_9sn3d1ng9q48ff6t3fw340000gn/T/ipykernel_65954/2394775149.py:21: UserWarning: The figure layout has changed to tight
fig.tight_layout()
So Does Monte Carlo Solve Partial Observability?¶
No. Both methods still assign a single value to \(B\). In this example, MC accurately estimates the values of \(A\) and \(C\) because it uses complete returns. However, this does not necessarily mean that MC outperforms TD in a partially observable environment. MC often has higher variance, must wait for the episode to end and is unsuitable for infinitely long episodes.
Conclusion¶
MC and TD both calculate the same value for the aliased observation in our example. However, they disagree on the values of observations preceding it. This is because MC uses actual returns, while TD bootstraps from value estimates. Bootstrapping allows the information loss at \(B\) to affect the value estimates of previous observations.
References¶
Sutton, R. S., and Barto, A. G. (2018). Reinforcement Learning: An Introduction, 2nd edition. Chapters 5–6.