Learning route — change the target, then change the representation
Bring: The Bellman backup and policy/value distinction from Lecture 7.
First pass
What to do
Follow the idea
MC/TD evaluation → control → behavior versus target → DQN/Double DQN
Work without the solution
Update one action value from a measured temperature transition.
Return later
Proof details and the wider deep-RL catalogue are references.
For the temperature thread: predict → calculate → reveal and check → change one condition. Complete the core calculation before reading the research extensions.
Q1. Fix a policy. With no P and no R, how good is it?
ACT 1Evaluation without a modelLecture 8
The arena — from MDP to experience
Q1 Evaluate?Q2 Improve?Q3 Explore?Q4 Scale?
We no longer query a model. We act, and a stream comes back:
s1,a1,r2,s2,a2,r3,s3,…,sT(one episode)
the agent chooses at=π(st) — decision,
the environment returns rt+1,st+1 — the only window onto P,R,
from this stream we must recover Q∗ and act on it — learning.
Start with the humblest sub-task: prediction. Fix a policy π; estimate its value Vπ. No control yet — just: how good is this behavior? Everything harder is built on getting this right.
Monte Carlo prediction — average what actually happened
Visit st, watch the episode finish, collect the realized return Gt=rt+1+γrt+2+⋯+γT−t−1rT. Then nudge:
V(st)←V(st)+α[targetGt−V(st)]
Unbiased.E[Gt]=Vπ(st) exactly — the target is the real thing, not a guess.
No model, no bootstrap. Each state's estimate stands alone; we never lean on neighbors.
The price: must wait for the terminal state (no online updates), and the return of a long episode is a high-variance single draw — one unlucky tail corrupts the estimate.
MC also wastes the structure of the MDP: it learns each state separately and never reuses the fact that s leads to s′. That wasted structure is exactly what TD reclaims.
One episode can visit a state twice — define the Monte Carlo sampleMake the averaging convention explicit
Consider an illustrative episode A→B→A→terminal with rewards 1,2,3 and γ=1. The two returns observed after visiting A are 6 and 3.
Estimator of Vπ(A)
Contributions from this episode
First-visit Monte Carlo
use 6, from the first visit to A
Every-visit Monte Carlo
use 6 and 3; their average for this episode is 4.5
Across episodes, keep the count of included visits and update the running average. Neither estimate from this single episode is guaranteed to equal the true value.
A Monte Carlo target is a sampled return after a specified visit. State values are averages over repeated experience, not a rule that every visit has the same realised return.
The target contains V(st+1) — our own current estimate. It need not be better on every individual transition. This is bootstrapping.
Online, incremental, model-free. One step is enough — ideal for long or non-terminating tasks.
Often lower variance, possible bias. The target depends on one reward plus a learned value, not a whole noisy trajectory — but it inherits whatever error V(st+1) currently carries.
TD can learn faster in many tasks; neither method dominates for every reward process, initialization, and step size.
Five states, a random walk from C, reward 1 only on exiting right — so Vπ(s)=i/6. MC and TD see the identical stream and differ only in the target. Watch TD's low-variance target settle while MC's realized returns keep jittering; then raise α and watch MC degrade faster.
Monte Carlo waits for the episode to end and averages the actual return; TD updates after one step using its own estimate of what follows. What is the trade?
MC's target is a real sampled return — correct in expectation, but carrying the noise of every step that followed. TD's target r+γV(s′) leans on a current estimate, importing whatever error that estimate has while discarding all the downstream noise. Bootstrapping is the trade at the heart of the lecture, and in Act 4 it turns out to be one of the three ingredients that can make learning diverge.
The Lecture 7 dance is unchanged — evaluate, improve, repeat — but each half is now sampled.
Evaluate (sampled)Q→Qπ via MC / TD
Improveπ→ε-greedy(Q)
One subtlety the model-based version never faced: to estimate Qπ(s,a) from data, every(s,a) must actually be tried. A purely greedy policy never tries the actions it currently dislikes — and so never learns they were good.
Improvement now requires exploration. That is the new tax.
The tax, paid — ε-greedy, and the bandit underneath
The simplest way to keep trying everything:
at={argmaxaQ(st,a)a random actionwith prob. 1−ε(exploit)with prob. ε(explore)
This is the exploration–exploitation trade-off of the n-armed bandit, now living inside every state. The bandit was RL with the dynamics deleted; here the dynamics are back, but the same dilemma — spend on what you know, or pay to learn more — governs every step.
Decay ε→0 (e.g. ε=1/t) and, with every (s,a) visited infinitely often, the greedy policy in the limit is optimal.
Hold ε fixed and you keep a permanently-cautious, permanently-curious agent — sometimes exactly what a real system needs.
Two Q-learning agents, identical but for ε. The greedy one locks onto the near +1 it stumbled into first and stops looking — read its coverage figure: the actions it dislikes are never tried, so their values are never corrected. The exploring one pays a little return per episode and finds the far +5.
Monte Carlo control — evaluate an episode, then improve the policyAlgorithm between prediction and TD control
Generate a complete episode using the current exploratory policy.
Work backwards to compute Gt=rt+1+γGt+1.
Average the selected returns for each visited (st,at) into Q(st,at).
Make the policy ε-greedy with respect to the updated Q values.
For four actions and ε=0.2, a unique greedy action gets probability 0.85 and each other action gets 0.05.
Exploring starts assumes we can start episodes in every relevant state-action pair. When that is impractical, use an exploratory policy to collect coverage. A fixed positive ε keeps the executed policy stochastic.
Assume tabular Q-learning satisfies its convergence conditions. With ε=0.1 fixed, what happens to its behaviour?
Under adequate state–action coverage and diminishing step sizes, tabular Q-learning can converge to Q∗ while its behavior remains exploratory. With two actions and one unique best action, ε=0.1 chooses the best with probability 0.9+0.1/2=0.95, not 0.9. Exploration can choose the best action too.
Q3. The data comes from an exploring policy. Which policy's value does the update actually estimate?
ACT 3Whose value are we learning?Lecture 8
Two control rules, one tiny difference
Q1 Evaluate?Q2 Improve?Q3 Explore?Q4 Scale?
Put TD evaluation of Q together with ε-greedy improvement. Two natural updates appear, differing in one term:
SARSA — on-policy
Q(s,a)←Q(s,a)+α[r+γQ(s′,a′)−Q(s,a)]
a′ is the action actually taken next.
Q-learning — off-policy
Q(s,a)←Q(s,a)+α[r+γa′maxQ(s′,a′)−Q(s,a)]
max over all next actions, taken or not.
S, A, R, S′, A′ — SARSA literally uses the next action it sampled. Q-learning replaces that sampled a′ with the best possiblea′. For these two algorithms, that substitution reveals the distinction: the target policy need not be the policy that generated the data.
Let Q(s,a)=2, reward r=1, γ=0.9, and α=0.2. At the next state, the two action values are 5 and 1. Exploration actually selects the action worth 1.
update
continuation used
target
new estimate
SARSA
actual next action: 1
1+0.9(1)=1.9
2+0.2(1.9−2)=1.98
Q-learning
greedy next action: 5
1+0.9(5)=5.5
2+0.2(5.5−2)=2.70
The reward and transition are identical. The difference is what behavior we assume after arriving. This is what the cliff experiment will make visible.
Cross the two forks of the whole lecture — bootstrap? and whose policy?
Non-bootstrap (MC)
Bootstrap (TD)
On-policy
MC control
SARSA
Off-policy
off-policy MC
Q-learning
On-policy: the policy that generates the data is the policy we evaluate. SARSA learns the value of the very (exploring, ε-greedy) behavior it is running.
Off-policy: the behavior policy and the target policy differ. Q-learning behavesε-greedily but learns the value of the pure-greedy optimal policy — it studies one policy while living as another.
Look at what each update assumes about the next step.
SARSA's target uses Q(s′,a′) where a′∼πbehavior — the real next action, exploration and all. It is honest about the policy it runs.
Q-learning's target uses maxa′Q(s′,a′) — it pretends the next action will be greedy, regardless of the a′ actually taken. The behavioral a′ is collected, then ignored.
The clean extremeact with ε=1, i.e. fully random
SARSA learns the value of acting randomly. Q-learning learns the value of the optimal policy — while acting randomly.
This convergence statement is tabular: finite stationary MDP, bounded rewards, γ<1, every state–action pair visited infinitely often, and Robbins–Monro step sizes per pair. Random actions alone do not guarantee visits to unreachable states.
Temperature thread — learn from one measured transitionshared teaching example · predict before revealing the calculation
The model probabilities from Lecture 7 are now unavailable to the learner. Observe a heating transition from x=−2 to x′=−1, with reward −2. Let Q(−2,heat)=−4, maxaQ(−1,a)=−1, γ=0.9 and step size 0.5.
Predict: Should this observation raise or lower the old estimate −4?
Calculate and check. The target is −2+0.9(−1)=−2.9. The TD error is −2.9−(−4)=1.1, and the updated estimate is −4+0.5(1.1)=−3.45.
The update uses one measured outcome. Lecture 7 instead averaged outcomes using a known transition model.
Try it — the observed heating step failswork independently · reveal only after writing an answer
Start again from Q = −4. This time the next state remains −2, the measured reward is −5 and its next maximum Q is −3. Keep γ = 0.9 and step size 0.5. Calculate the update.
Check your answer. Target =−5+0.9(−3)=−7.7; TD error =−3.7; new Q =−4+0.5(−3.7)=−5.85.
One good or bad observation does not identify the transition probability. Repeated data and an appropriate update schedule matter.
The original windy gridworld — learn the transition through experienceFour-action version, redrawn
Start S, goal G. The numbers below the columns give upward wind strength; grid boundaries clip the resulting position.
What SARSA learns
An intended move and the resulting displacement differ. For this convention, the wind at the departure column acts with the chosen move.
From row 3, column 3, moving right with wind 1 ends at row 2, column 4. Rows increase downward; indices start at 0.
Use reward −1 until arrival at G. SARSA learns from the actual next state and the next exploratory action, without being handed the wind model.
The source's preceding page 57 depicts the random-walk prediction example; page 58 is the windy control task. Prediction of a fixed policy and learning a control policy are different experiments.
The original six-room example — follow the actual numerical updatesInitial Q values 0, step size 0.5, discount 0.8
Original door connectivity. Here F ends the episode, as stated on source pp. 70 and 72. Entering F pays 100; other moves pay 0.
Three source updates
Observed transition
Update
New Q
B → F
0+0.5(100−0)
50
D → B
0+0.5(0+0.8(50)−0)
20
B → F again
50+0.5(100−50)
75
Only the visited entry changes. The reward at F starts affecting actions taken before reaching F through bootstrapping.
The target on a terminal transition is the immediate reward. The next slide separates this episodic rule from the source's different continuing-state table.
Terminal versus continuing — why the source also shows a value of 500source pp. 68 and 73 use a rewarded F self-loop; pp. 70–72 terminate at F
Those conventions define different MDPs. They must not share the same claimed converged Q table.
Convention
Value after reaching F
Limiting Q(B,F)
Terminal F: episode ends
V(F)=0
100+0.8(0)=100
Continuing F: staying pays 100 each step
V(F)=100+0.8V(F)=500
100+0.8(500)=500
With terminal F, the best D → B → F continuation has Q∗(D,B)=80, and C → D → B → F has Q∗(C,D)=64. These are limits, unlike the intermediate values 50, 20 and 75 on the previous slide.
A terminal mask is part of the problem definition. Changing it changes the correct answer, even when the room diagram and discount remain the same.
Q-learning learns the optimal path — along the edge — but it actsε-greedily, and the occasional random step plunges it off the cliff: higher reward in theory, worse online. SARSA accounts for its own exploration and learns a cautious detour. Neither is "better" — the cliff teaches the design choice.
SARSA updates toward r+γQ(s′,a′) using the action actually taken next; Q-learning uses r+γmaxa′Q(s′,a′). Why does that one difference make Q-learning off-policy?
SARSA evaluates the policy that is driving, exploration and all — on the cliff it learns the safe path, because it accounts for the chance of stepping off while exploring. Q-learning evaluates the greedy policy regardless of who is driving, so it learns the optimal edge-hugging path and then keeps falling off it. Neither is wrong; they are answers to different questions.
Q4. Everything so far stores one number per (s,a). What happens when the state is an image?
ACT 4Scaling past the tableLecture 8
The wall — a table cannot hold the world
Q1 Evaluate?Q2 Improve?Q3 Explore?Q4 Scale?
Everything so far stores one number per (s,a). Then comes Atari:
state=four 84×84 grayscale frames⇒∣S∣≈25684×84×4
more configurations than atoms in the universe. A Q-table is impossible three times over: too many states to visit, too many to store, and — fatally — no generalization: a table says nothing about a state it has never seen.
The machine-learning answer: stop storing, start approximating.
Q(s,a)≈Q^(s,a;w),e.g. Q^(s,a;w)=w⊤ϕ(s,a) or a neural net
Now "learning" means fitting w — and similar states share answers.
Why DQN stacks frames — position alone may hide velocityRepresentation is part of the state definition
Two situations can have the same current image but require different actions:
Previous ball position
Current position
Inferred horizontal motion
10
20
moving right
30
20
moving left
A single frame at position 20 cannot distinguish them. DQN's input stacks four recent 84 × 84 grayscale frames, and a convolutional network extracts spatial features from that stack.
The network approximates Qafter a state representation has been chosen. Frame stacking supplies short-term motion information; it does not guarantee a Markov state in every environment.
It is called a semi-gradient method for an honest reason: we differentiate the prediction Q^(s,a;w) but treat the target as fixed, even though it too depends on w. We are chasing a target that moves when we move.
In the tabular world that chase still converged. With function approximation, it can diverge. Tabular Q-learning's guarantees do not survive the jump — and we must understand why before trusting a network.
The deadly triad — why naive deep Q-learning blows up
These three ingredients together create an important source of instability. Their absence is not a universal safety guarantee for arbitrary algorithms or step sizes.
Function approximationerrors spread across states
Bootstrappingtarget built from its own moving estimate
Off-policydata from a policy = the one evaluated
Q-learning with a neural net has all three. The data are also strongly correlated (consecutive frames) and the target shifts on every update. Plain SGD on L(w) fights itself.
The breakthrough was not a new objective — it was two engineering tricks that tame the triad.
Two states, every reward 0, so the true value is 0 everywhere. With all three switches on, ∣V(s1)∣ grows without bound. Turn any one of them off — use a table, use the return instead of a bootstrap, or update on-policy — and the same algorithm collapses to 0. (Tsitsiklis & Van Roy, 1997)
DQN — the two tricksMnih et al., 2013; Nature 2015
Keep Q-learning's update. Add two stabilizers.
Experience replay. Store transitions (s,a,r,s′) in a buffer D; train on random minibatches from it. This reduces temporal correlation within minibatches and reuses experience; the finite replay data are not independent samples from a fixed environment distribution.
Target network. Compute the target with a frozen copy w−, synced to w only every C steps:
For each stored transition, the target is fixed between target-network updates. This helps stability but does not restore a general convergence guarantee.
Result: one architecture, one set of hyperparameters, human-level play across dozens of Atari games from raw pixels. The Bellman equation, untouched; the model, never learned; the table, replaced by a convnet.
DQN as regression — freeze the label, fit the prediction
For one stored nonterminal transition, let r=1, γ=0.9, and the target network's next values be 5 and 1. The label is y=1+0.9(5)=5.5.
If the current network predicts 2:
21(y−Qw(s,a))2=21(5.5−2)2=6.125.
The derivative with respect to that prediction is 2−5.5=−3.5, so gradient descent pushes the prediction upward. Do not differentiate through the label.
Store a terminal flag d and use y=r+γ(1−d)maxa′Qw−(s′,a′). For a true terminal transition, y=r. A time-limit truncation may still need bootstrapping.
Trace the lineage of each box: act ε-greedy (Act 2's exploration tax), the max in the target (Act 3's off-policy Q-learning), bootstrap target (Act 1's TD), buffer + frozen w− (Act 4's triad fixes). One loop holds the whole lecture.
Double DQN — select with one estimate, evaluate with anothervan Hasselt, Guez & Silver · AAAI 2016 · one nonterminal target calculation
At the next state, suppose the two networks give:
Action
Online Qw
Target Qw−
A
8
4
B
7
6
For immediate reward 1 and discount 0.9:
yDQN=1+0.9max(4,6)=6.4.
Double DQN selects a∗=argmaxaQw(s′,a)=A, then evaluates that action with the target network:
yDouble=1+0.9Qw−(s′,A)=1+0.9(4)=4.6.
Separating selection and evaluation reduces a source of overestimation; neither number is guaranteed correct. This is different from TD3's minimum of two critics in Lecture 10. Double DQN
The two tricks opened a decade of refinements, each patching a named flaw:
Double DQN — the max over-estimates; decouple action-selection from evaluation. (van Hasselt et al., 2016)
Dueling networks — split Q^ into state-value + advantage; learn "which states matter" separately. (Wang et al., 2016)
Prioritized replay — sample high-error transitions more often. (Schaul et al., 2016)
Rainbow — combine them; the combination improved the reported Atari benchmark results. (Hessel et al., 2018)
Every one keeps the same skeleton: sampled Bellman backup+Q for model-free greed+a stabilizer. None brings back the model — and their standard finite-action versions cannot simply enumerate a continuous action space. The maximization then needs extra structure or an optimizer, motivating an actor.
That wall — the max over a continuum — is exactly where Lecture 9 begins.
The deadly triad names three things that together can make value learning diverge. Which set?
All three together can send an estimate to infinity even when all rewards and true values are zero. Removing a leg helps in the displayed example; it does not prove every remaining algorithm converges. DQN's two tricks are best read as attacks on this: a replay buffer decorrelates the updates and a frozen target network weakens the bootstrap. Neither removes the third leg, which is why deep RL remains fragile.
Lecture 7 could solve the Bellman equation, because it owned the world. Lecture 8 learned to solve it.
by sampling the expectation, storing Q instead of V, and replacing the table with a network whose stability and performance must be checked.
Questions?
From a windy gridworld to human-level Atari with one update rule — the distance between knowing the dynamics and never needing to. What stays fixed through all of it is the equation Bellman wrote; we only ever changed what we were allowed to look up.
APPENDIX
Backup slides
Complete arguments, kept out of the narrative.
APPENDIXBackup slidesLecture 8
Reading guide — from a tabular target to a learned value functionone main idea to explain, one comparison, one application
Why separate selecting an action from evaluating its value?
Apply
The original windy gridworld, six rooms and Atari examples
Which issue is about the target, and which is about state representation?
Use Sutton–Barto Chapters 5–6 for MC and TD prerequisites. DQN is the main research case; Double DQN explains a specific failure. Dueling, prioritized replay and Rainbow remain a brief extension map.
Both estimate Vπ(s)=Eπ[Gt∣st=s] from samples; they differ in what they sample.
Monte Carlo target Gt=∑kγkrt+k+1
Bias: none — E[Gt]=Vπ(st) exactly.
Variance: high — a function of many random rewards and transitions along the whole episode.
TD(0) target rt+1+γV(st+1)
Bias: present — uses the current (imperfect) estimate V(st+1); unbiased at the true Vπ (and sometimes when errors cancel in expectation).
Variance: often lower — depends on one reward and one successor estimate; no universal ordering holds for arbitrary estimates.
The bridge — n-step and TD(λ)
Interpolate by bootstrapping after n steps, Gt(n)=rt+1+⋯+γn−1rt+n+γnV(st+n); n=1 is TD(0), n=∞ is MC. TD(λ) averages all n geometrically. The whole family is one dial between low-bias / high-variance and higher-bias / low-variance.
Claim(Watkins & Dayan, 1992): in a finite stationary MDP with bounded rewards and 0≤γ<1, tabular Q-learning converges to Q∗ with probability 1, provided
every state–action pair (s,a) is visited infinitely often (the role of exploration, e.g. ε>0), and
for each state–action pair, its update step sizes satisfy the Robbins–Monro conditions ∑tαt=∞, ∑tαt2<∞.
Why it holds (sketch). The Bellman optimality operator (TQ)(s,a)=Es′[r+γmaxa′Q(s′,a′)] is a γ-contraction in the sup-norm, so it has a unique fixed point Q∗. The Q-learning update is a stochastic approximation of T: each step replaces the expectation by one sample. Robbins–Monro step sizes average out the sampling noise; infinite visitation guarantees every entry keeps being corrected. Together they drive Q→Q∗.
What breaks under approximation. Replace the table by Q^(⋅;w) and the update is no longer a contraction in any norm the parameters respect — the projection onto the function class can expand distances. That is the formal root of the deadly triad, and the reason DQN needs its two crutches.
In vector form w←w+αδϕ(s,a) — the tabular update is the special case ϕ(s,a)=e(s,a) (a one-hot indicator), which is why tabular RL is "just" function approximation with the most local possible features. For a neural net, ϕ becomes ∇wQ^(s,a;w) and the same line holds.
Backup 4 — model-based RL, the alternative we set aside
The branch we acknowledged in Act 0 and walked away from. Estimate the model from the same stream of experience:
P^(s′∣s,a)=#(s,a)#(s,a,s′),R^(s,a,s′)=mean of r over (s,a,⋅,s′)
Then solve the estimated MDP with any Lecture 7 method (value / policy iteration).
Pro — sample efficiency: a learned model can be "replayed" indefinitely; each real transition informs the value of many states through planning.
Con — model bias: errors in P^,R^ compound through planning; you optimize for a world that is slightly wrong.
Con — cost: estimating a full kernel is far more than estimating the Q∗ we actually act on.
This is why model-free dominated the deep-RL era — and why Lecture 11 returns to model-based methods only once it can make the learned model carry its weight (planning, Dyna, differentiable control).
The translation table — our coordinate system for today
Every object of Lecture 7 has a sampled counterpart. Keep this in sight.
Lecture 7 (model-based)
Lecture 8 (sampled)
What replaces the model
expectation ∑s′P(s′∣s,a)[⋯]
one transition (s,a,r,s′)
a sample average / a bootstrap
policy evaluation (solve with P,R)
MC or TD prediction
returns, or a one-step estimate
greedy on V: argmaxa∑s′P[⋯]
greedy on Q: argmaxaQ(s,a)
store Q, not V
value iteration
Q-learning
the max inside a sampled backup
full backup (all successors)
sample backup (one successor)
the law of large numbers
tabular, exact
function approximation (DQN)
a network Q(s,a;w)
Read column 3. Nothing here is a new principle — it is the same Bellman backup, with the one piece we don't own quietly swapped out. The art is in what we swap it for without the whole thing collapsing.
The most literal idea: estimate P,R from data, then run Lecture 7.
P^(s′∣s,a)=#(s,a)#(s,a,s′),R^(s,a,s′)=average r over (s,a,⋅,s′)
Plug in, solve the MDP. This is model-based RL, and it is perfectly valid.
But notice the waste: to choose actions we only ever need Q∗, yet here we first estimate a whole transition kernel — vastly more parameters than the thing we actually use. Why estimate P and R at all,
when we could estimate Q∗ directly?
That question — skip the model, estimate the value — is the entire model-free programme. The rest of today walks it. (The model returns, deliberately, in Lecture 11.)