L5 - TD Learning
L5 - TD Learning
5 Temporal-difference learning
Temporal-difference prediction
Temporal-difference on-policy control: SARSA
Temporal-difference off-policy control: Q-learning
Maximization bias and double learning
Temporal-difference (TD) learning combines the previous ideas introduced in DP and MC:
▶ From Monte Carlo (MC) methods: learns directly from experience.
▶ From dynamic programming (DP): updates estimates based on other learned estimates
(bootstrap).
width
of update Dynamic
Temporal-
difference programming
learning
depth
(length)
of update
Exhaustive
Monte search
Carlo
...
Until terminate
ranging from one-step TD updates to full-return Monte Carlo updates. Between these
is a spectrum including methods based on n-step updates (and in Chapter 12 we will
Oliver Wallscheid extend this to mixtures of n-step updates such as thelearning
Reinforcement -updates implemented by eligibility 170
Driving home example 6.1. TD Prediction 123
45 45
actual outcome actual
outcome
40 40
Predicted Predicted
total total
travel 35 travel 35
time time
30 30
leaving reach exiting 2ndary home arrive leaving reach exiting 2ndary home arrive
office car highway road street home office car highway road street home
Situation Situation
Gone
Figure 5.4: Forest MDP with fifty-fifty-policy including state values
Figure 5.5: State-value estimate of forest tree MDP using TD(0) prediction over the number of episodes
being evaluated (mean and standard deviation are calculated based on 2000 independent runs)
1.5
0.5
higher alpha => converge faster
0
0 50 100 150 200 250 300 350 400 450 500
Figure 5.6: Averaged mean of state-value estimates of forest tree MDP using TD(0) and MC over 1000
independent runs with v̂0 (x) = 0 ∀x ∈ X
0.05
0
0 20 40 60 80 100 120 140 160 180 200
Figure 5.7: Averaged mean of state-value estimates of forest tree MDP using TD(0) and MC over 1000
independent runs with v̂0 (x) ≈ v(x) ∀x ∈ X
Above k is the sample index (i.e., how often the TD update was applied).
Batch training
▶ Process all available episodes j ∈ [1, J] repeatedly to MC and TD.
▶ If the step size α is sufficiently small both will converge to certain steady-state values.
Oliver Wallscheid Reinforcement learning 177
timate V (A) given this data? Here there are
hatBatch
100% oftraining:
the AB-example (1)
immediately to
already decided r=1
3 75%
▶ Only two states: A, B
value 4 as well. r= 0
s based on first A 100% B ▶ No discounting
r= 0
as shown to the
25%
▶ 8 episodes of experience available
mates given the (see Table 5.1)
A) = 34 . This is
▶ What is v̂(A) and v̂(B) using
Figure 5.8: Example environment (source: R. Sutton and G.
Barto, Reinforcement learning: an introduction, 2018, CC batch training TD(0) and MC?
BY-NC-ND 2.0)
A, 0, B, 0 B,1
B,1 B,1
B,1 B,1
B,1 B,0
Table 5.1: Example state-reward sequences for Figure 5.8
Apply the previous equations first to state B. Since B is a terminal state, v̂(xk+1 ) = 0 and
gk,j = rk+1,j apply, i.e., the MC and TD updates are identical for B:
J J
1X
MC|x=B :
X
0= gk,j − v̂(xk,j ) ⇔ v̂(B) = gk,j ,
j=1
J j=1
J J
1X
TD|x=B :
X
0= rk+1,j − v̂(xk,j ) ⇔ v̂(B) = gk,j .
j=1
J j=1
This is the average return of the available episodes from Table 5.1 , i.e., 6 × 1 and 2 × 0:
6
v̂(B)|MC = v̂(B)|TD = = 0.75 . (5.6)
8
J J
MC :
X X
0= gk,j − v̂(xk,j ) = gk,j − v̂(A)
j=1 j=1
J J
TD :
X X
0= rk+1,j + γv̂(xk+1,j ) − v̂(xk,j ) = γv̂(B) − v̂(A).
j=1 j=1
Looking at Table 5.1 there is only one episode visiting state A, where the sample return is
gk,j = 0. Hence, it follows:
3
v̂(A)|MC = 0, v̂(A)|TD = γv̂(B) = .
4
Where does this mismatch between the MC and TD estimates come from?
Oliver Wallscheid Reinforcement learning 181
Certainty equivalence
▶ MC batch learning converges to the least squares fit of the sampled returns:
Tj
J X
(gk,j − v̂(xk,j ))2 . (5.7)
X
j=1 k=1
▶ TD batch learning converges to the maximum likelihood estimate such that X , U, P̂, R̂, γ
D E
▶ Here, TD assumes an MDP problem structure and is absolutely certain that its internal
model concept describes the real world perfectly (so-called certainty equivalence).
Oliver Wallscheid Reinforcement learning 182
Table of contents
5 Temporal-difference learning
Temporal-difference prediction
Temporal-difference on-policy control: SARSA
Temporal-difference off-policy control: Q-learning
Maximization bias and double learning
Figure 5.9: SARSA-based control with αSARSA = 0.2 and ε-greedy policy with ε = 0.2 of forest tree
MDP over the number of episodes being evaluated (mean and standard deviation are calculated based
on 2000 independent runs)
Figure 5.10: SARSA-based control with αSARSA = 0.1 and ε-greedy policy with ε = 0.2 of forest tree
MDP over the number of episodes being evaluated (mean and standard deviation are calculated based
on 2000 independent runs)
Figure 5.11: SARSA-based control with adaptive αSARSA = √1j (j =episode) and ε-greedy policy with
ε = 0.2 of forest tree MDP over the number of episodes being evaluated (mean and standard deviation
are calculated based on 2000 independent runs)
5 Temporal-difference learning
Temporal-difference prediction
Temporal-difference on-policy control: SARSA
Temporal-difference off-policy control: Q-learning
Maximization bias and double learning
This is an off-policy update, since the optimal action-value function is updated independent of
a given behavior policy.
5 Temporal-difference learning
Temporal-difference prediction
Temporal-difference on-policy control: SARSA
Temporal-difference off-policy control: Q-learning
Maximization bias and double learning
q(x, u∗ ) ≈ q̂2 (x, u∗ ) = q̂2 (x, arg max q̂1 (x, u)). (5.14)
u
...
75% left right
% left
actions 50%
Q-learning
from A
Double
25% Q-learning
5% optimal
0
1 100 200 300
Episodes