Model-Free Prediction and Control
When the dynamics are unknown, an agent cannot plan against a model; it must learn directly from sampled experience. We build prediction and control from two estimators of the same return: Monte Carlo averages whole episodes, while temporal-difference learning bootstraps from its own next estimate.
╌╌╌╌
The foundations of reinforcement learning gave us the Bellman equations and the policy-/value-iteration machinery that solves them. Both assume a model: the transition kernel and the reward function are known, so every backup is an exact expectation over . The agent in this lesson has neither. It sees only a stream of transitions drawn by acting in the environment, and must estimate value functions and improve its policy from that stream alone. This is the model-free setting, and it splits into two problems we treat in turn.
The object both methods estimate is the return, the discounted sum of rewards from time onward, and the value functions are its expectation:
Without a model the expectation cannot be computed, only sampled. Every algorithm below is a different answer to one question: given a stream of experience, how do you estimate ?
Monte Carlo prediction
The most direct estimator is the one from Monte Carlo methods: is an expectation, so average sampled returns. Run an episode to termination, compute the realized return from each visited state, and let be the mean of the returns observed from . No model, no bootstrapping; the estimate is grounded entirely in completed experience.
The distinction matters for the analysis. If a state recurs inside one episode, its two returns share a common tail of rewards, so they are correlated. First-visit MC sidesteps this by keeping only one return per episode: the returns it averages are independent draws of the same random variable , so the ordinary law of large numbers applies and its estimate is unbiased at every sample size with error shrinking like in the number of visits . Every-visit MC reuses the correlated within-episode returns; it is biased for finite but the bias vanishes as , and it often wastes less data.
The sample mean is an incremental update
Averaging returns does not require storing every return seen from . The arithmetic mean of numbers can be written as a correction to the mean of the first , which turns a batch average into a constant-memory online rule. Write for the mean of the first returns observed from . Then
Expand and regroup the last expression around :
The batch average and this one-line update produce the identical number at every ; nothing is approximated. Maintaining a visit count , each new return therefore nudges the running estimate toward itself by a fraction of the residual:
The bracketed residual is a prediction error, and the step size shrinks as evidence accumulates, so early returns move the estimate a lot and later ones barely at all. Replacing with a constant step gives a running average that tracks a nonstationary target, the form we keep for the rest of the lesson:
A constant never lets the step size vanish, so this update weights recent returns more heavily than old ones, a geometric recency weighting worth having when the policy (and thus the return distribution) is still changing. The estimator is unbiased in the case because exactly; MC regresses directly onto the very quantity it targets, with no model and no bootstrap in between.
Monte Carlo control
Prediction estimates ; control must improve . Two obstacles appear at once. First, greedy improvement needs action values, not state values: requires , since without a model we cannot turn into a one-step lookahead. So MC control estimates directly, averaging returns following each state-action pair. Second, a purely greedy policy stops exploring: actions it currently rates poorly are never tried, so their estimates never improve. The standard fix is -greedy action selection.
The single parameter sets the balance between exploitation (act on what you believe is best now) and exploration (try alternatives to correct a wrong belief). Large gathers information but earns little reward; maximizes immediate reward but can lock in a suboptimal action whose true value was never sampled.
-greedy improvement is sound: any -greedy policy with respect to is at least as good as itself.
Interleaving -greedy evaluation with -greedy improvement converges, provided exploration decays so that the limiting policy is greedy. That condition has a name.
- 1initialize arbitrarily,
- 2for each episode do
- 3set and generate an episode with the -greedy policy in
- 4for each first-visited in the episode do
- 5return following that first visit
- 6
- 7incremental mean
- 8return the greedy policy in
The structural weakness of MC is that it needs complete episodes. The return is unknown until termination, so MC cannot update mid-episode, cannot learn in continuing (non-terminating) tasks, and waits a long time on long episodes before any signal propagates.
Temporal-difference learning
Temporal-difference learning removes the wait. Instead of substituting the full sampled return , it substitutes the one-step bootstrap target: one real reward plus the current estimate of the rest. This is the sampled form of the Bellman expectation equation .
The TD error appears in every method that follows: it is the gap between what the agent expected and what one step of experience plus its own forecast now suggest. MC and TD differ only in their target: MC regresses toward the realized , TD toward . Dynamic programming uses the same target as TD but takes a full expectation over instead of sampling one.
The implications are immediate: TD learns online, after every step, from incomplete episodes, and works in continuing tasks where no terminal state exists. It bootstraps, so it can begin propagating value before any episode finishes.
A worked TD(0) update
For example, take and step size . The current table holds and . The agent takes its action and observes reward , landing in . Form the bootstrap target, then the TD error, then the update:
The estimate moves a tenth of the way from toward the target . It did not jump to : a single transition is one noisy sample, and limits how much weight it receives. Had the reward been unluckily large, the target would overshoot and the next transition from would pull the estimate part of the way back; the step size averages these samples over time. Every method in this lesson is a variation on this three-line loop, changing only what fills the target slot.
Bias and variance
TD and MC are both correct in the limit, but they trade bias against variance. The MC target is an unbiased sample of but accumulates the randomness of every reward and transition along the whole trajectory, so its variance is large. The TD target depends on a single random transition, so its variance is small, but it bootstraps off the current estimate , which is wrong early in training, so it is biased until converges.
| Property | Monte Carlo | TD(0) |
|---|---|---|
| Target | full return | |
| Bias | unbiased () | biased (bootstraps off ) |
| Variance | high (whole trajectory) | low (one transition) |
| Needs complete episodes | yes | no |
| Continuing tasks | no | yes |
| Markov property | not required | exploited |
| Initial-value sensitivity | low | high |
The Markov-property row is the deepest distinction. On finite data, MC converges to the values that minimize mean-squared error on the observed returns, whereas TD(0) converges to the values of the maximum-likelihood Markov model fit to the data, the so-called certainty-equivalence estimate. When the environment really is Markov, TD's structural assumption is a feature and it is typically far more data-efficient; when it is not, MC's model-freedom is safer.
On-policy control: SARSA
Control needs action values, and the same TD idea applied to gives SARSA, named for the quintuple that the update consumes. The bootstrap target uses the action that the agent actually takes next under its current policy.
SARSA is on-policy: the target evaluates the very policy generating the data, so as the policy improves, the values it learns are the values of the improving policy. With a GLIE schedule the policy becomes greedy and SARSA converges to .
- 1initialize arbitrarily,
- 2for each episode do
- 3initial state; choose from by -greedy in
- 4repeat for each step of the episode
- 5take , observe and
- 6choose from by -greedy innext action under the policy
- 7
- 8;
- 9until is terminal
- 10return
Off-policy control: Q-learning
Q-learning changes one symbol and the character of the algorithm with it. Its target bootstraps off the greedy action , not the action actually taken. It learns about the optimal policy while behaving by an exploratory one.
This is off-policy: the behavior policy that selects (e.g. -greedy, for exploration) differs from the target policy the update evaluates (greedy). Because the target is a sampled form of the Bellman optimality equation, Q-learning converges to directly under the standard step-size conditions, regardless of the behavior policy, as long as it keeps visiting every pair.
One term separates the two
Line up the two targets and only one factor differs:
SARSA plugs in at the action the behavior policy actually samples next. That action is -greedy, so with probability it is a random, possibly bad action, and its low value is folded into the target. The target therefore describes the value of following the exploratory policy, including its mistakes; SARSA evaluates the policy that generated the data, which is the definition of on-policy. Q-learning replaces with , the value of the best action regardless of what the agent will do next. The erases the behavior policy from the target: whatever exploratory action gets taken, the bootstrap always assumes greedy continuation. That is why the target policy (greedy) is decoupled from the behavior policy (-greedy) — the decoupling that defines off-policy learning. When the sampled action and the greedy action coincide and the two updates become identical; the gap between them is the cost of exploration, which SARSA counts and Q-learning ignores.
- 1initialize arbitrarily,
- 2for each episode do
- 3initial state
- 4repeat for each step of the episode
- 5choose from by -greedy inbehavior policy
- 6take , observe and
- 7greedy target
- 8
- 9until is terminal
- 10return
The on-policy/off-policy gap changes the actual path the agent learns. The canonical demonstration is cliff walking: a gridworld where the bottom edge between start and goal is a cliff that costs and resets the agent, while every other step costs . The optimal path hugs the cliff edge. Q-learning learns exactly that optimal greedy path. SARSA, because it evaluates the -greedy policy it actually follows, accounts for the random exploratory steps that occasionally push it off the cliff, so it learns a safer path one row away from the edge, earning more reward online during -greedy training.
n-step returns and the unified spectrum
MC and TD(0) are the endpoints of a dial. TD(0) bootstraps after one reward; MC after all of them. In between, the -step return takes real rewards and then bootstraps:
At this is the TD(0) target; as (to termination) it is the MC return . The corresponding -step TD update is . Intermediate typically beats both endpoints: enough real reward to cut the bootstrap bias, few enough steps to hold the variance down.
TD() and eligibility traces
Rather than commit to one , TD() averages all of them. The -return is a geometric average of every -step return, weighted by :
The weights sum to one. At all weight collapses onto , recovering TD(0); at the average reduces to the MC return . The single knob sweeps continuously between bootstrapping and full sampling.
The -return as written is a forward view: it looks ahead to future rewards, so like MC it needs the whole episode. The equivalent backward view makes it online and incremental through eligibility traces. Each state keeps a trace that spikes on visit and decays by , marking how recently and how often it was seen. A single TD error is then broadcast to all states in proportion to their trace.
For an offline (whole-episode) update, the backward and forward views compute exactly the same total change, so eligibility traces are a memory-efficient, causal implementation of the -return rather than a different algorithm.
Function approximation and semi-gradient TD
A table is impossible when the state space is huge or continuous, the regime every deep RL agent lives in. We replace the table with a parametric , a linear map or a neural network with weights , and learn by stochastic gradient descent. The natural objective is the mean-squared value error, the value gap weighted by how often the policy visits each state:
where is the on-policy state distribution. The true target is unknown, so we substitute a sampled target. With the MC target this is honest SGD on a sampled return. With the TD target it is not: the target itself depends on , and we deliberately ignore that dependence when taking the gradient.
Dropping that term is what makes it efficient and what makes it dangerous.
The deadly triad
For on-policy linear function approximation, semi-gradient TD converges. But three ingredients, when combined, can make the weights diverge to infinity even on a finite Markov chain.
Each leg alone is safe. On-policy TD with linear approximation converges; tabular off-policy Q-learning converges; MC with any approximator converges (it does not bootstrap). The interaction is the hazard. The simplest divergent example is named after its author.
Geometrically the failure is an expansion. On-policy, the TD update is a contraction in the -weighted norm, so iterates are pulled inward toward a fixed point. Off-policy, the data distribution no longer matches the policy being evaluated; the semi-gradient update can become an expansion, and each step pushes the weights farther out.
The triad is the reason deep RL is hard. Deep Q-networks combine all three legs (a bootstrapped target, off-policy replay, and a neural approximator), and the stabilizing tricks of modern value-based deep RL, target networks and large replay buffers among them, exist precisely to tame this interaction. True-gradient methods that descend the projected Bellman error restore convergence at the cost of a second set of weights.
Putting it together
The whole family is two binary choices: how the target is formed (sample versus bootstrap), and whose policy the target evaluates (behavior versus a different target policy).
| Method | Target | Bootstraps | On/off-policy | Needs model |
|---|---|---|---|---|
| Dynamic programming | full expectation over | yes | n/a | yes |
| Monte Carlo | full return | no | on-policy | no |
| TD(0) prediction | yes | on-policy | no | |
| SARSA | yes | on-policy | no | |
| Q-learning | yes | off-policy | no | |
| TD() | -return | partial | on-policy | no |
The maximization bias
Q-learning's target has a subtle flaw the full reinforcement-learning subject treats in depth and this lesson glossed: taking a over noisy estimates systematically overestimates. Because whenever the are noisy, the greedy target is biased upward even when every action's true value is identical. If two actions both have true value but this sample reads and , the correct target is yet ; averaged over many visits the noise never cancels, because the always picks whichever estimate it happened to inflate.
Double Q-learning fixes it by decoupling selection from evaluation. Keep two independent tables and ; use one to select the greedy action and the other to evaluate it, with target , alternating which is updated. The noise that inflated the selected action in is not the noise in 's estimate of it, so the upward bias cancels in expectation.
Double DQN applies exactly this decoupling to the deep-Q-network of the next lesson, using the online network to select and the target network to evaluate, measurably reducing the overestimation that plagues vanilla DQN.
Takeaways
- Model-free methods estimate or from sampled transitions, never forming the unknown and . Both prediction and control reduce to estimating the return from experience.
- Monte Carlo averages complete-episode returns: unbiased, high variance, and blocked in continuing tasks. First-visit and every-visit variants both converge to .
- TD(0) bootstraps, : online, low variance, biased early, and it exploits the Markov property by fitting the maximum-likelihood model.
- MC control with -greedy exploration converges to under GLIE (infinite exploration, greedy in the limit).
- SARSA () is on-policy and learns a safe path that accounts for its own exploration; Q-learning () is off-policy and learns the optimal greedy path. Cliff walking separates them.
- n-step returns and TD() interpolate the MC-TD spectrum; the -return averages all -step returns, and eligibility traces give an equivalent online backward-view implementation.
- Semi-gradient TD scales value estimation to parametric by SGD on the value error, dropping the target's gradient. Combining bootstrapping, off-policy training, and function approximation, the deadly triad, can diverge, as Baird's counterexample shows. This is the central difficulty of value-based deep RL.
- Maximization bias: the target overestimates because under noise; double Q-learning cancels this by selecting the action with one estimate and evaluating it with an independent one, the idea Double DQN carries into deep RL.
╌╌ END ╌╌