Chapter 6: Temporal-Difference Learning
Temporal-difference (TD) methods are a combination of the ideas from Monte Carlo and dynamic programming methods.
6.1 TD Prediction
Recall a simple every-visit Monte Carlo method
where is constant, i.e. the constant- MC method.
Whereas Monte Carlo methods must wait until the episode's termination to change (as they must calculate from sampling), TD methods need wait only one time step by bootstrapping.
In other words, we replace the sampled return with an estimated return , using our current estimate of to determine the target .
This method is known as or one-step TD; we explore with nonzero in more detail next chapter.
Note that is similar to DP methods in that both use the estimate of in calculating the target return ; however, notably does so in expectation over Monte Carlo sampling, unlike dynamic programming. Thus, they merge Monte Carlo sampling with DP bootstrapping.
Also, note that the quantity within the brackets,
can be interpreted as an "error" between our current estimate of and the improved estimate that follows from this sample. This quantity is known as TD error, and shows up often in RL. For instance, Monte Carlo error may be written as
or a sum of TD errors.
Note that this Monte Carlo error may also serve as an approximation for the error of methods like , in which is updated during the episode rather than kept constant.
6.2 Advantages of TD Prediction Methods
Compared to DP methods, TD methods have a clear advantage in that they do not require a model of the environment.
Compared to Monte Carlo methods, TD methods are better in the sense that they may be updated in an online, incremental fashion (i.e. during the episode). Moreover, the use of discounting in Monte Carlo methods slows learning; TD methods reduce this issue because they learn from each transition regardless of subsequent actions.
Moreover, TD methods still converge to the correct answer for nay fixed policy . And, in practice, TD methods converge faster than constant- MC methods on stochastic tasks.
6.3 Optimality of
A common method of learning is to present a static dataset of experience until our model or estimator converges.
- Evaluate estimator on entire dataset.
- Improve with desired changes.
- Repeat.
This is known as batch updating, and is known to converge deterministically to a single answer under this procedure, independent of . Notably, a constant- MC method also converges deterministically, but to a different answer.
In particular, batch MC finds estimates that minimize MSE on the training set, while batch finds the maximum-likelihood estimate of the Markov process. The maximum-likelihood estimate of a Markov process corresponds to a value function estimate known as the certainty-equivalence estimate; this is what batch converges to!
6.4 Sarsa: On-policy TD Control
We now apply TD prediction methods to the control problem. (We will still use TD methods for the prediction portion of GPI).
First, we learn an action-value function rather than a state-value function.
where the update is applied after every transition from a nonterminal state , and if is terminal.
Note that the update rule uses the elements , which inspired its nomenclature of Sarsa!
Now, as with other on-policy methods, we continually estimate for our current policy and simultaneously improve toward a greedy solution with respect to . Notably, though, we must ensure that is -soft to maintaining convergence guarantees; often, an schedule like is used to produce eventual convergence to the optimal policy overall.
6.5 -Learning: Off-policy TD Control
-Learning was a major milestone in reinforcement learning, and was the first off-policy TD control algorithm. It's defined by the following updated rule
the key idea of this off-policy algorithm is that we don't need to use in our update rule. Instead, we replace the behavior policy's action with the target policy's action , where we implicitly assume the target policy is a simple greedy policy.
Our estimate of is ultimately controlled by the trajectory/sample we're learning from, which is not produced the target policy we're trying to learn. In contrast, is dependent on the target policy's choice of action and isn't really influenced by the behavior policy; the behavior policy's provision of trajectories only serves to eliminate the need to know state transition probabilities (i.e. produces interaction with the environment to essentially emulate the state transition probability of moving to each from ).
6.6 Expected Sarsa
With -learning, we previously used an implicit target policy that was greedy. What if we'd like to learn the -function for any target policy, though? Expected Sarsa is useful for this purpose, and has update rule
This is essentially Sarsa, but rather than learn on-policy and use the trajectory's given to estimate , we compute the estimate over the entire action space, weighted by their probability under our behavior policy . This expectation-based update reduces variance compared to the stochastic/sample-based update of Sarsa.
Expected Sarsa also performs better than -learning during online training. -learning uses an implicit greedy target policy, which may result in updates to the -soft behavioral policy that perform poorly on trajectories (e.g. cliff walking example, where the target policy OKs walking right next to the cliff, causing the choice of the behavioral policy to fall off the cliff at times). In contrast, Sarsa may use a target policy that is on-policy or near on-policy (more accurately reflects the behavior policy) to provide better updates to the -soft behavioral policy (e.g. cliff walking example, target policy encourages moving away form cliff).
Expected Sarsa is often used in both off-policy and on-policy formats, and is also a generalization of -learning—choosing to be the greedy policy then produces -learning.
6.7 Maximization Bias and Double Learning
Sarsa often learns -greedy policy, and -learning learns a greedy policy. Such policies all involve a operator. Unfortunately, this maximum over estimated values is implicitly used as an estimate of the maximum value, which can induce significant positive bias. This is because
Think about why this should make sense, intuitively, due to the inherent noise of random variables! This bias is known as maximization bias.
Double -learning is a solution that eliminates this bias by learning two distinct -functions. Its update rules are
where, essentially, 's update rule uses to select its maximizing action, and vice versa for . This removes bias involved with evaluating with the -maximizing function, as it would positively bias the estimate since it now becomes, effectively, .
Typically, one of the two -functions is randomly chosen for each transition/step to update.
Note that double versions of Sarsa and Expected Sarsa exist as well.
6.8 Games, Afterstates, and Other Special Cases
So far, our approach has involved learning either an action-value or state-value function. However, there exist problems where such functions are not applicable!
For instance, consider the game of tic-tac-toe. After playing a move, we only have partial observability of the environment's dynamics; in particular, we do not know the full dynamics because we cannot know the move our opponent will play. In such cases, we use a state-value function that evaluates the environment state after the agent performs its action, in contrast to conventional state-value functions that evaluate the state with the assumption that the agent will then have the option of selecting an action. Such states are known as afterstates, and their value functions are known as afterstate value functions.
Notably, we don't have to use afterstate value functions for these types of problems; however, it's much more efficient. A conventional action-value function would map from a state-action pair to a value estimate. In contrast, an afterstate value function would map only from the result of the state-action pair (the next state) to a value estimate. This is important for learning state-action pairs that produce the same afterstate, as these are effectively identical.
We will not discuss afterstate methods in depth; however, the methods and principles in this book (e.g. GPI) still apply to afterstate methods!