5.1.11 · D3Reinforcement Learning Foundations

Worked examples — Temporal Difference learning

3,025 words14 min readBack to topic

Recall the single machine we keep feeding inputs into. After observing :

Before any numbers, four plain-word reminders so no symbol is unearned:

  • — the reward you actually receive on the one step you are currently processing. A real observed number, not a guess. In the worked examples below we shorten to just — same thing, fewer subscripts — because each example looks at a single transition, so there is only ever one reward to name.
  • (gamma) — the discount factor, a dial in that says "how much do rewards later count compared to now?" means "ignore the future entirely"; means "the future counts as much as the present."
  • (alpha) — the learning rate, a dial in saying "how big a step do I take toward the target?" means "throw away the old estimate completely."
  • Terminal state — a state where the episode ends (goal reached, game over). By definition it has no future rewards, so its value is fixed at . This is not learned, it is a boundary condition we set. Whenever a transition lands in a terminal state, the bootstrapped future term collapses to and the target is reward only.

The picture below fixes the whole machine in your mind before we touch a single number — three quantities on a number line and the nudge that connects them.

Figure — Temporal Difference learning

The scenario matrix

Every TD transition you will ever compute falls into one of these cells. The examples below are labelled with the cell they cover.

# Case class What makes it special Covered by
C1 Positive TD error () target beats old estimate → value goes up Ex 1
C2 Negative TD error () target below old estimate → value goes down Ex 2
C3 Zero TD error () already consistent → no change Ex 3
C4 Terminal transition (defined above), target = reward only Ex 4
C5 (myopic) future term vanishes, TD = one-step reward chasing Ex 5
C6 (undiscounted) full future counts; back-propagation cascade Ex 6
C7 instability old estimate overwritten by noisy target Ex 7
C8 Stochastic reward never reaches 0, only its mean does Ex 8
C9 Real-world word problem build state/reward from a story Ex 9
C10 Exam twist: multi-step order update order changes intermediate numbers Ex 10

We build on Bellman Equations (the recursion the target comes from), contrast with Monte Carlo Methods and Dynamic Programming, and the noise cell touches Bias-Variance Tradeoff and Bootstrapping.


Worked examples


Recall Quick self-test

Positive means the old value was too ::: low (target beat it), so the value rises With , the TD target reduces to ::: just the immediate reward For a terminal next state the target is ::: the reward only, because Why does fail on stochastic rewards? ::: it overwrites the estimate with a single noisy sample instead of averaging If all transitions give , learning ::: stops — you are at a fixed point (Bellman-consistent) In online TD(0), when updating on , you use ::: the current , not any value gets later this episode