Temporal-Difference Learning: TD(0)
Imagine an agent driving home from work, trying to predict how long the whole trip will take. Ten minutes in, it hits unexpected traffic and immediately revises its estimate. It does not wait until arriving home to learn something useful. This simple instinct — updating a prediction using a later prediction rather than waiting for the final outcome — is the essence of temporal-difference (TD) learning. TD(0) is its purest form. TD(0) matters because most real-world sequential decision problems are far too long for an agent to wait. Some never actually terminate, so it cannot wait until an episode ends before learning. Monte Carlo Prediction must wait for a full return before updating a value estimate. TD(0) updates after every single transition. This one change — bootstrapping off your own current estimate instead of the true final return — is what makes reinforcement learning practical at scale. It powers everything from game-playing agents to recommendation systems that must learn continuously from streaming interaction data. The big picture is this: TD(0) sits at the intersection of dynamic programming and Monte Carlo methods. Like dynamic programming, it bootstraps — it uses an existing estimate to update another estimate. Like Monte Carlo, it learns directly from raw experience. It needs no model of the environment's transition probabilities or reward function. This hybrid nature is why Sutton called TD learning "the central and novel idea in reinforcement learning." This article gives a precise, self-contained treatment of TD(0) prediction. It covers the update rule, the TD error, and a careful pseudocode implementation. It also includes a full complexity and convergence analysis, a worked numerical trace, and the historical context that led to its discovery. It sets up the ideas that generalize to control algorithms and multi-step methods later.
- TD(0) estimates the state-value function from experience, updating after every single transition rather than at the end of an episode.
- The core mechanism is the TD target , compared against the current estimate via the TD error .
- TD(0) combines Monte Carlo's model-free sampling with dynamic programming's bootstrapping, giving it lower variance than Monte Carlo but some bias.
- It converges to under standard stochastic approximation conditions on the step size, for a fixed policy .
- Update cost is per transition and space for a tabular value function, making it usable in continuing (non-episodic) tasks.
- TD(0) is the foundation for SARSA, Q-learning, and n-step / TD() methods used throughout modern reinforcement learning.
TD(0) updates a value estimate toward a target built from one real reward plus its own current guess of the future, learning online without waiting for episodes to end.
The idea
Temporal-difference learning is a method for estimating a value function from experience generated by interacting with an environment, without requiring a model of that environment. Recall that the state-value function under a fixed policy is defined as the expected discounted return from a state:
Monte Carlo Prediction estimates by averaging complete sampled returns following visits to . This requires waiting until an episode terminates before any return is known, and the resulting estimates have high variance because a single return depends on every reward and every random transition for the rest of the episode. TD(0) makes one conceptual substitution: instead of using the full return , it uses a one-step lookahead estimate called the TD target:
Here is the current estimate of the value function — the same object being updated. The agent replaces "the true remaining return from onward" with "my current best guess of it," namely . This is called bootstrapping: building an estimate partly from another estimate, a hallmark shared with dynamic programming, foreshadowed further in Bootstrapping in TD Learning. The discrepancy between the TD target and the current value estimate is the TD error:
TD(0) nudges toward the TD target by a step-size :
This single line is the entire learning rule. It can be applied after every transition — the agent observes , computes , and immediately updates . No episode needs to finish; TD(0) works identically in continuing tasks with no terminal state, and it works in episodic tasks by simply treating a terminal state's value as fixed at zero.
How it works
TD(0) is used for prediction: given a fixed policy , estimate . The agent does not choose actions to optimize reward here — it simply follows and learns to evaluate it. (Choosing actions to improve the policy is control, covered in SARSA: On-Policy TD Control.) The algorithm maintains a table for every state, typically initialized arbitrarily (often to zero), with any terminal state fixed at . Each episode (or, in a continuing task, each fixed-length chunk of interaction) proceeds by taking an action dictated by , observing the reward and next state, and updating immediately. ``` Algorithm: TD(0) Prediction for estimating v_π Input: policy π to be evaluated, step-size α ∈ (0, 1], discount γ ∈ [0, 1] Initialize: V(s) ← arbitrary, for all non-terminal s V(terminal) ← 0 Repeat (for each episode): S ← initial state of episode Repeat (for each step of episode), until S is terminal: A ← action given by π for S Take action A; observe reward R and next state S' δ ← R + γ V(S') - V(S) # TD error V(S) ← V(S) + α δ # TD(0) update S ← S' ``` Two implementation subtleties matter for correctness. First, must be the value stored before any update happens in that step — the update uses the pre-update estimate as its bootstrap target. Second, terminal states must always evaluate to exactly , since by definition no reward accrues after termination; forgetting this is a common source of silent bugs (see pitfalls below). The diagram below shows the information flow of a single TD(0) update: one real transition supplies the reward , and the stored value of the next state supplies the rest of the target, in contrast to Monte Carlo, which would need the entire rest of the trajectory.
Complexity & correctness
Time complexity. Each TD(0) update touches exactly one table entry, computes one reward, one lookup of , and one arithmetic combination: per transition. An episode of length costs total, and never needs to be finite — the algorithm applies unchanged to continuing tasks. This is the key practical advantage over Monte Carlo, whose per-episode update also costs but which cannot produce any update until the episode ends; TD(0) produces incremental updates spread across the episode's duration, enabling learning in real time and in tasks without a natural end.
Space complexity. A tabular implementation stores for each state: space. No model of transition probabilities or rewards is stored, distinguishing TD(0) from dynamic-programming methods that require the full transition model.
Correctness — bias/variance tradeoff. The Monte Carlo target is an unbiased estimate of by definition of as an expectation, but it has high variance because it is a function of many random rewards and transitions across an entire trajectory. The TD target has much lower variance — it depends on only one random reward and one random next state — but it is biased whenever , since it bootstraps from a possibly-wrong estimate. As converges toward during learning, this bias vanishes. This is the fundamental tradeoff TD(0) makes: it accepts transient bias in exchange for a large variance reduction, which in practice usually yields faster and more stable learning.
Convergence proof sketch (tabular case). Fix a policy generating an ergodic Markov chain over states. Consider TD(0)'s expected update at state :
where is the Bellman expectation operator for :
The operator is a -contraction in the max norm (for ): , and its unique fixed point is exactly , i.e. (the Bellman equation). TD(0)'s expected update thus pushes toward this fixed point in expectation, sampling a stochastic approximation of the operator rather than computing it exactly (which would require the full model, as in policy evaluation via Value functions). Formally, TD(0) is an instance of stochastic approximation for finding the root of . Under the classical Robbins–Monro step-size conditions —
for every state (each state visited infinitely often) — standard stochastic approximation theory guarantees with probability 1. Intuitively: the sum-to-infinity condition ensures the step size never shrinks so fast that learning stalls before reaching the fixed point, while the square-summable condition ensures the noise from single-sample updates eventually averages out rather than causing permanent oscillation. In practice a small constant is often used instead, which does not satisfy these conditions exactly and yields convergence to a neighborhood of rather than exact convergence — a standard, deliberate tradeoff favoring adaptability in nonstationary settings.
Honest tradeoffs. TD(0) requires or a properly terminating task for the contraction argument to apply cleanly; with function approximation instead of a table, this convergence guarantee weakens substantially (bootstrapping combined with off-policy sampling and function approximation can even diverge — the so-called "deadly triad," a topic beyond this article). TD(0) also introduces a hyperparameter, , whose tuning affects both speed and final estimation error, whereas tabular Monte Carlo's only real hyperparameter is how counts are used to average returns.
Worked example
Consider Sutton and Barto's classic random-walk chain: five non-terminal states arranged in a line, with terminal states on both ends. From any state, the agent moves left or right with probability each. Reaching the right terminal yields reward ; reaching the left terminal yields reward ; all other rewards are . Under this fully random policy, the true values are known analytically: . Initialize all for , with , . Suppose one episode produces the trajectory:
Trace the TD(0) updates step by step (all values start at ):
| step | before update | new | ||||
|---|---|---|---|---|---|---|
| 1 | C | 0 | D | 0.5 | ||
| 2 | D | 0 | E | 0.5 | ||
| 3 | E | 1 | terminal | 0.0 |
After this single episode, only changed, moving from to — a step toward its true value of . Notice and did not change on this episode even though they lay on the path to the reward, because their bootstrap targets exactly matched their current values (both neighbors were still at ). This is a genuinely instructive contrast with Monte Carlo: a Monte Carlo update on this same episode would immediately push and toward the observed return of as well, since Monte Carlo uses the actual final outcome for every visited state in the episode. TD(0) instead only "notices" the surprise () exactly at the boundary where the current value table disagrees with reality — namely at , adjacent to the terminal reward. Over many more episodes, this asymmetry corrects itself: as rises above , the next time occurs, at becomes nonzero too, and the correction propagates backward one state per episode, like a wave. This staged, local propagation of information — updating only where a genuine discrepancy in one-step prediction was observed — is precisely what makes TD(0) computationally cheap and is also why it can take many episodes for information to travel far from a reward source, a limitation partially addressed by multi-step methods in n-Step Bootstrapping Methods.
Common pitfalls & traps
| Pitfall | Why it happens | Consequence |
|---|---|---|
| Using post-update in the target | Updating and then reading from a table already touched this step, in an implementation that processes states out of order | Introduces subtle order-dependent bias; correctness relies on using the pre-update estimate |
| Forgetting | Terminal states are sometimes left at their initialized value or never explicitly created | Silently inflates or deflates every TD target near episode ends, corrupting learning everywhere |
| Step size too large | Treating as a free tuning knob without care | Estimates oscillate or diverge instead of converging, especially with stochastic rewards |
| Step size constant but expecting exact convergence | Robbins–Monro conditions require appropriately | Value estimates converge only to a noisy neighborhood of , not to it exactly |
| Confusing prediction with control | Applying TD(0)'s state-value update while trying to improve the policy | TD(0) as described only evaluates a fixed policy; policy improvement needs action values, e.g. SARSA |
| Insufficient state visitation | Some rare states are almost never reached under | Their value estimates barely update and remain near initialization for a long time |
Pioneers & history
TD(0) prediction is inseparable from the broader story of temporal-difference learning, developed principally by Richard Sutton in the early 1980s while exploring how animals and machines might learn predictions incrementally from experience, inspired partly by psychological theories of classical conditioning.
Origins · 1 minRichard S. Sutton and how this was discovered
Sutton formalized temporal-difference learning as a distinct family of algorithms, introducing the TD error as the central learning signal and later co-authoring, with Andrew Barto, the standard reference text that established reinforcement learning as a coherent field. His work connected trial-and-error learning, dynamic programming, and Monte Carlo estimation into one unified framework, and TD(0) is the simplest member of that family.
Where this matters
TD(0) prediction underlies value estimation in nearly every modern reinforcement learning system, even when the surface algorithm looks quite different. Deep Q-Networks estimate action-values using a TD-style target built from a bootstrapped next-state estimate, extending the same signal to neural function approximators. Actor-critic architectures, used across robotics and simulated control, train their critic network with a TD(0)-like loss, often literally , to provide a low-variance baseline for policy gradient updates. TD-Gammon demonstrated decades ago that a TD-trained value function alone could reach expert-level performance in backgammon, foreshadowing the value networks later used in AlphaGo and its successors. Beyond games, TD-style bootstrapping appears in recommendation systems that continuously update estimates of long-term user engagement from streaming click data, in industrial process control where feedback must be incorporated online rather than after an artificial "episode" ends, and in financial and operations models that treat ongoing decision processes as continuing tasks with no terminal state. Any system that must learn a long-horizon prediction from an unbounded or very long stream of experience, without waiting for a final outcome, is a natural candidate for TD-style prediction — which is precisely why it remains foundational to control methods such as SARSA: On-Policy TD Control and multi-step generalizations in n-Step Bootstrapping Methods.
Ask the tutor: How does TD(0)'s bias-variance tradeoff change as you move to n-step TD or TD(λ) methods?
Is TD(0) an on-policy or off-policy method?
TD(0) as presented here is a prediction method, not a control method, so the on-policy/off-policy distinction applies once you specify how actions are chosen and how the target is constructed. In the pure prediction setting, the agent follows a single fixed policy to generate the transitions used for learning, and it estimates , the value function for that same policy — this makes it on-policy prediction. Off-policy variants exist, such as TD(0) with importance sampling, where transitions are generated by a different behavior policy while still estimating the value of a target policy, but that extension is not part of the basic TD(0) rule.
How does TD(0) differ from full dynamic programming policy evaluation?
Dynamic programming policy evaluation also bootstraps, updating using the Bellman expectation equation, but it requires a complete model: the transition probabilities and reward function must be known, and the update sums over all possible next states weighted by their true probabilities. TD(0) replaces that full expectation with a single sampled transition drawn from actual experience, requiring no model at all. This is why TD(0) is classified as model-free, while dynamic programming is model-based, even though both rely on the same underlying Bellman fixed-point structure.
Why is TD(0) called a bootstrapping method?
Bootstrapping in this context means updating an estimate using another estimate of the same kind, rather than using only ground-truth outcomes. TD(0)'s target contains , which is itself just the algorithm's current guess, not a verified true value. Dynamic programming methods bootstrap in the same sense, since Bellman-equation updates use of successor states. Monte Carlo methods do not bootstrap, since a full return is composed only of actual observed rewards, never another value estimate.
Can TD(0) be used in tasks that never terminate?
Yes, and this is one of its major practical advantages over Monte Carlo. Because the TD(0) update only needs one transition at a time, it applies unchanged to continuing tasks with no terminal state, as long as keeps returns finite in expectation. Monte Carlo methods, by contrast, require a complete return computed from an entire episode, so they cannot directly handle tasks lacking a natural endpoint without additional machinery such as truncation.
What happens to TD(0) convergence guarantees when using a neural network instead of a table?
The clean stochastic-approximation convergence argument relies on each state having its own independently updated table entry, so updating never changes for . With function approximation, a single gradient step can change the values of many states simultaneously, including states not visited on that step, because parameters are shared. This breaks the simple contraction argument, and combined with bootstrapping and off-policy data, can in principle cause divergence — a phenomenon known as the deadly triad. In practice, techniques like target networks and careful step sizes are used to stabilize learning, but the tabular convergence proof does not transfer directly.
How does the TD error δₜ relate to reward prediction error in neuroscience?
Researchers studying dopamine neuron firing found that its patterns closely resemble the TD error signal from reinforcement learning models, firing more when an outcome is better than predicted and less when it is worse, matching the sign and rough magnitude of . This correspondence, discovered in the late 1990s, gave TD learning substantial credibility as a plausible model of biological reward learning, beyond its role as an engineering algorithm, and remains a widely cited connection between reinforcement learning theory and computational neuroscience.
Does a larger step size α always make TD(0) learn faster?
Not reliably. A larger does make each individual update larger, which can speed early learning, but it also makes the value estimates more sensitive to the randomness in any single transition's reward and next state. This increases variance in the running estimate and can cause oscillation or failure to settle near , especially in stochastic environments. Practical use typically anneals downward over time, satisfying something close to the Robbins–Monro conditions, or uses a small constant chosen to balance adaptability against stability.