# Understanding TD(0) algorithm implementation

I came across the $$TD(0)$$ algorithm from Sutton and Barto:

Clearly, the only difference of TD methods with the MC methods is that TD method is not waiting till the end of the episode to update the $$V(s)$$ or $$Q(s,a)$$, but according to David Silver's lecture (Lecture 4- ~34:00),

The $$TD(0)$$ algorithm learns from incomplete episodes, but in the earlier algorithm we can see that the loop repeats until $$s$$ is terminal which mean completion of episode.

So does David Silver by learning from incomplete episodes, mean learning of $$V(s)$$ even when the episode is not completed? Or Did I interpret the algorithm wrong? If so what is the correct interpretation?

The $$TD(0)$$ algorithm learns from incomplete episodes, but in the earlier algorithm we can see that the loop repeats until $$s$$ is terminal which mean completion of episode.

In the pseudocode, you have two loops: one for each episode and one (nested) for each step of the episode. The until $$S$$ is terminal means that you perform the updates until you end the episode (that is, you end up in a terminal state, e.g. checkmate in the game of chess). For each step of the episode, you perform the TD(0) update.

Apparently, you're confusing two things: the fact that each episode ends in a terminal state and the fact that TD learns from incomplete information. Each episode ends in a terminal state (otherwise it would not be called an episode), but this does not mean that it collects a full rollout before updating $$V$$. In fact, at each step of the episode, it updates $$V$$.

The information in the David Slider's slide is consistent with the pseudocode. TD learns from experience because it uses the given policy $$\pi$$ to behave.

learning from incomplete episodes, mean learning of $$V(s)$$ even when the episode is not completed

Yes, essentially you're updating the value function during each step of each episode.

• You just stated what I already said though. I more or less wanted to clarify my idea of TD(0) (one part of that is the consistency between the 2 pics) – DuttaA Jul 11 '19 at 21:26
• @DuttaA No, I am also saying that the information in Slider's slide is consistent with the pseudocode. Also, you say "but in the earlier algorithm we can see that the loop repeats until $s$ is terminal which mean completion of episode". I am addressing this in my answer. Apparently, you're confusing two things: the fact that each episode ends in a terminal state and the fact that TD learns from incomplete information. Each episode ends in a terminal state (otherwise it would not be called an episode), but this does not mean that it collects a full rollout before updating $V$! – nbro Jul 11 '19 at 21:30
• I don't think the edit is appropriate since I only wanted to clarify the consistency rather than understanding the concept of TD – DuttaA Jul 11 '19 at 21:40
• @DuttaA Ok, sorry for this. When I perform an edit, my intention is to improve the post, but I realize that I might also change the original intent of the user, so, in general, feel free to rollback my edits (especially when you give me some feedback back and explain why the edit wasn't appropriate). – nbro Jul 11 '19 at 21:48