Reinforcement Learning

Temporal-Difference Learning

Temporal-difference learning updates a state value after one sampled transition by comparing the old value with a reward-plus-next-value target.

status: reviewimportance: importantdifficulty 4/5math: graduateread: 20mlive demo

Concept Structure

Temporal-Difference Learning

01Intuition

Start with the picture, metaphor, or geometric mechanism.

02Math

Make the objects explicit and connect them with notation.

03Code

Mirror the equations with runnable implementation details.

04Interactive Demo

Manipulate the mechanism and watch the idea respond.

2prerequisites
1next concepts
3related links

Learner Contract

What this page should let you do.

You are here becauseTemporal-difference learning updates a state value after one sampled transition by comparing the old value with a reward-plus-next-value target.

This Reinforcement Learning concept is the current idea: keep the same invariant visible across Intuition, Math, Code, Interactive Demo.

By the end4/4 sections ready | runnable code expected | live demo

Explain the mechanism, trace the main notation, and test one prediction in the live demo.

Do this firstIntuition

Read the intuition before the notation; the math should name a mechanism you already felt.

Then go nextQ-Learning and SARSA (review)

Follow this edge after making one prediction here; the next page should reuse the result, not restart the route.

Test the linkManipulate one control and predict the visible change.Then continue to Q-Learning and SARSA (review)

Claim/source review status

Substantive review recorded

1/1 claims have bounded review metadata; still check caveats and source scope.Metadata-derived; review may be AI-assisted. Not a human certification.
Claims1/1 reviewed
Sources3 cited
Codeattached
Demolive
Reviewed2026-07-03
Updatedpage 2026-07-03

Learning item flow

4/4 sections readyAsk about thisResearch room
ConceptTemporal-Difference LearningReinforcement Learning
3 sources attachedLocal snapshot ready
concept:reinforcement-learning/temporal-difference-learning
01

01

Intuition

Build the mental picture first so the rest of the page has something to attach to.

Section prompt

Monte Carlo RL waits for the episode to end. Bellman backups use a known model to average over possible next states.

Temporal-difference learning sits between those two ideas. It looks at one real transition,

StRt+1St+1,S_t \rightarrow R_{t+1} \rightarrow S_{t+1},

then asks:

If the next state's current value estimate is my best guess of what happens from there, how wrong was my current value estimate?

That question is the learning move. TD does not wait for the complete return GtG_t. It also does not need the transition probabilities that a Bellman expectation backup needs. It uses the sampled reward plus the current value estimate of the sampled next state.

The price is that the target is partly made from an estimate. That is bootstrapping. The benefit is that the learner can update online, one transition at a time.

02

02

Math

Translate the story into symbols, assumptions, and a derivation you can inspect.

Section prompt

Assume a fixed policy π\pi in a finite discounted MDP. At time tt, the agent is in state StS_t, takes the action prescribed or sampled under π\pi, receives reward Rt+1R_{t+1}, and lands in St+1S_{t+1}.

TD(0) builds the one-step target

targett=Rt+1+γV(St+1),\text{target}_t = R_{t+1}+\gamma V(S_{t+1}),

where V(St+1)V(S_{t+1}) is the current value estimate of the sampled next state. If St+1S_{t+1} is terminal, use V(St+1)=0V(S_{t+1})=0.

The TD error is the gap between that one-step target and the current estimate:

δt=Rt+1+γV(St+1)V(St).\delta_t = R_{t+1} + \gamma V(S_{t+1}) - V(S_t).

Then TD(0) moves the current state's value estimate by a learning-rate-scaled error:

V(St)V(St)+αδt.V(S_t) \leftarrow V(S_t)+\alpha\delta_t.

Equivalently,

V(St)(1α)V(St)+α[Rt+1+γV(St+1)].V(S_t) \leftarrow (1-\alpha)V(S_t) + \alpha \left[ R_{t+1}+\gamma V(S_{t+1}) \right].

That last form shows the exponential-moving-average view: keep part of the old estimate and mix in the new sampled target.

The comparison is the core idea:

  • Monte Carlo target: GtG_t, a complete sampled return.
  • Bellman expectation target: sP(ss,π(s))[r(s,π(s),s)+γV(s)]\sum_{s'}P(s'\mid s,\pi(s))[r(s,\pi(s),s')+\gamma V(s')], a model average.
  • TD(0) target: Rt+1+γV(St+1)R_{t+1}+\gamma V(S_{t+1}), one sampled step plus a bootstrapped next value.
03

03

Code

Keep the implementation aligned with the notation so the algorithm is legible.

Section prompt
gamma = 0.90
alpha = 0.40
values = {"Start": 1.20, "Practice": 1.80, "Confused": 0.80, "Mastered": 0.0}

stream = [
    ("Start", "drill", 1.0, "Practice"),
    ("Practice", "repeat", -0.6, "Confused"),
    ("Confused", "ask", 0.7, "Practice"),
]

for state, action, reward, next_state in stream:
    bootstrap = 0.0 if next_state == "Mastered" else values[next_state]
    target = reward + gamma * bootstrap
    td_error = target - values[state]
    update = alpha * td_error
    values[state] += update
    print(
        state,
        action,
        "target", round(target, 3),
        "error", round(td_error, 3),
        "new", round(values[state], 3),
    )

Notice the online dependence: the third line uses the already-updated Practice value. TD learning is not just a formula applied to a frozen table; it is a stream of value repairs.

04

04

Interactive Demo

Use direct manipulation to connect the explanation to a moving system.

Section prompt

Use the Temporal-Difference Update Lab to predict which state value changes most after a short sampled transition stream.

Choose a stream, inspect the current values and the sampled transitions, then commit to the state whose estimate should change most. After reveal, the lab shows the TD target, TD error, learning-rate-scaled update, and before/after value table for every transition.

The comparison strip keeps the boundary clear: Monte Carlo waits for a complete return, a Bellman backup needs model probabilities, and TD updates now from one sampled transition plus a bootstrapped next value.

Live Concept Demo

Explore Temporal-Difference Learning

The stage is code-native and interactive. Use it to test the explanation against the mechanism.

difficulty 4/5graduatecode-aligned
Demo Prediction Checkpoint

Manipulate one control and predict the visible change.

Commit to what Temporal-Difference Learning should make visible before reading the result.

After The First Pass

Turn the concept into an inspected object.

Once the invariant is visible in the intuition, math, code, and demo, use these panels to inspect the mechanism visually, check source support, practice the idea, and attach a grounded research question.

Mechanism Storyboard

See the idea move before the page explains it

Temporal-difference learning updates a state value after one sampled transition by comparing the old value with a reward-plus-next-value target.

Prediction open01 / Intuition
Prediction lens

Start with the picture, metaphor, or geometric mechanism.

Commit first

Before reading further, choose the kind of change Temporal-Difference Learning should make visible.

Visual Inquiry

Make the image answer a mathematical question

Temporal-difference learning updates a state value after one sampled transition by comparing the old value with a reward-plus-next-value target.

4/4 stages readyLive demo connected
Prediction

Which visible object should carry the first intuition?

Commit first

Pick the cue that should make Temporal-Difference Learning easier to reason about before the page gives the answer.

Source Grounding

Canonical references for the mechanism on this page.

book · 2018Reinforcement Learning: An Introduction, Second EditionRichard S. Sutton and Andrew G. Barto

Canonical source for TD learning as a combination of Monte Carlo experience and dynamic-programming bootstrapping, TD(0), one-step TD targets, and TD error.

Open source
course-notes · 2026Stanford CS234: Lecture 3, Model-Free Policy EvaluationStanford CS234

Graduate RL source for TD(0) targets, TD error, immediate update after an observed transition, and MC-vs-TD bias/variance framing.

Open source
course-notes · 2026UC Berkeley CS188: Model-Free LearningUC Berkeley CS188

Course-note source for passive model-free learning, temporal-difference sample values, exponential-moving-average update, and the Q-learning downstream bridge.

Open source

Claim Review

Temporal-difference learning updates a state value after one sampled transition by comparing the old value with a reward-plus-next-value target.

Status1 substantive review recorded

Claims without a substantive review badge still need exact source-support review.

Sources3 references

sutton-barto-2018-rl, stanford-cs234-td-learning, berkeley-cs188-model-free-learning

Local checks4 local checks

Use equations, runnable code, and demos to check whether the source support is operational.

Substantively reviewedTabular TD(0) policy evaluation updates V(S_t) immediately after observing one transition by moving V(S_t) toward the one-step target R_{t+1} + gamma V(S_{t+1}); the bracketed difference between that target and the current estimate is the TD error.Claim metadata: source checked

The sources support finite tabular TD(0) policy evaluation as a model-free, one-step sample update that bootstraps from the current next-state value estimate instead of waiting for a complete Monte Carlo return or averaging over a known transition model.

Sources: Reinforcement Learning: An Introduction, Second Edition, Stanford CS234: Lecture 3, Model-Free Policy Evaluation, UC Berkeley CS188: Model-Free LearningFinite tabular on-policy teaching MDP only; excludes TD control, SARSA, Q-learning, n-step returns, eligibility traces, off-policy corrections, convergence proofs, stochastic-approximation schedules, continuing-task average reward, and function approximation.A bounded review summary is present; still check caveats and exact reference scope.

Checked Sutton/Barto Chapter 6 for TD as the combination of Monte Carlo experience and DP bootstrapping, the TD(0) update, one-step TD target, and TD error; checked Stanford CS234 Lecture 3 for target/error/update framing and immediate update after an observed transition; checked Berkeley CS188 model-free learning notes for passive TD learning as a sample-value exponential update. GPT Pro publication critique remains pending because 127.0.0.1:51672 is unavailable.

Reviewer: codex-local-source-review; reviewed 2026-07-03

Practice Loop

Try the idea before it explains itself

Temporal-difference learning updates a state value after one sampled transition by comparing the old value with a reward-plus-next-value target.

Readiness0/3 checks ready
Predict

Before touching the demo, predict one visible change that should happen in Temporal-Difference Learning.

Hint 1

Reveal when your model needs a nudge.

Hint 2

Reveal when your model needs a nudge.

Hint 3

Reveal when your model needs a nudge.

Grounded research drawerClose
ConceptTemporal-Difference LearningReinforcement Learning

Research Room

Attach the question to a claim, equation, code, or demo

Pick the concept, equation, source, runnable code, claim, misconception, or demo state before asking for help. The handoff keeps that page item in context.
Next local actionNo local draft saved yet

Open the draft below to save one note and next action in this browser.

conceptReinforcement Learning

Temporal-Difference Learning

Attached question

What is the smallest example that makes Temporal-Difference Learning click without losing the math?

Local action draftNo local draft saved yetExpand only when ready to capture one local next action
Local action draft

This draft stays in this browser, attached to the selected learning item.

No local draft saved.
Evidence to inspect
  • References to inspect: attached references on this page.
  • Definition, prerequisite, and contrast concept links
  • The equation or runnable code that makes the concept operational
  • One demo state that shows the invariant instead of a slogan
What would resolve this
  • The learner can state the mechanism in their own words
  • The learner can name the prerequisite that would repair confusion
  • The learner can predict how the mechanism changes under one perturbation
Grounded AI handoff

I am working in Continuous Function's research reading room. Object: concept - Temporal-Difference Learning Selected item key: recorded for copy. Context: Reinforcement Learning Page anchor: recorded for copy. Open question: What is the smallest example that makes Temporal-Difference Learning click without losing the math? Evidence to inspect: - References to inspect: attached references on this page. - Definition, prerequisite, and contrast concept links - The equation or runnable code that makes the concept operational - One demo state that shows the invariant instead of a slogan What would resolve this: - The learner can state the mechanism in their own words - The learner can name the prerequisite that would repair confusion - The learner can predict how the mechanism changes under one perturbation Answer as a careful research tutor: stay source-grounded, separate verified evidence from assumptions, name the relevant math objects, and end with one next action.

View it in context
concept/concept-notebook/reinforcement-learning/temporal-difference-learning concept:reinforcement-learning/temporal-difference-learning