Silver RL·Lecture 5·Lecture Notes

Lecture 5 · Model-Free Control

Updated 2026-08-30·EN

Slides: David Silver, UCL Course on Reinforcement Learning (2015), CC BY-NC 4.0. Some slide content is from third parties and is outside that licence.

Slides: David Silver - RL Course (UCL 2015) · Previous: Lecture 4 · Model-Free Prediction · Next: Lecture 6 · Value Function Approximation

Read this instead of watching. Each slide is embedded below with only what the slide itself does not say — the reasoning, the caveats, and the questions worth being able to answer.


The one idea

Lecture 4 answered "given π\pi, how do I estimate vπv_\pi?" Lecture 5 drops that estimator into the generalized policy iteration (GPI) loop to find q∗q_*. Everything else is a variation on which estimator goes in which slot.

Policy evaluation ↑ Policy improvement ↓ Algorithm
Dynamic programming (L3) iterative policy evaluation greedy policy iteration
Monte-Carlo MC evaluation of QQ ϵ\epsilon-greedy GLIE MC control
Temporal-difference Sarsa ϵ\epsilon-greedy Sarsa, Sarsa(λ\lambda)
TD, off-policy Q-learning greedy target, ϵ\epsilon-greedy behavior Q-learning

Two substitutions make the whole lecture work.

Substitution 1 — use QQ, not VV

Greedy improvement on VV needs one-step lookahead, π′(s)=arg⁡max⁡a(Rsa+γPss′aV(s′))\pi'(s)=\arg\max_a\big(\mathcal{R}^a_s+\gamma\mathcal{P}^a_{ss'}V(s')\big), and that lookahead is a model. With QQ it collapses to π′(s)=arg⁡max⁡aQ(s,a)\pi'(s)=\arg\max_a Q(s,a) — no model at all.
QQ is a cache of the lookahead. Storing values per action is what buys model-freedom.

Substitution 2 — use ϵ\epsilon-greedy, not greedy

DP swept every state. Here you only see what you visit, so a greedy policy can lock onto a wrong belief it will never revisit. Perpetual exploration is not a refinement — it is a correctness requirement.

Contents


1 · Why model-free control

p.4 · Uses of Model-Free Control ⏱ 2:17

Lecture 5 Model-Free Control, slide 4
Lecture 5 Model-Free Control, slide 4

Model-free applies in two situations, and the second is the one people forget:

  1. The MDP model is unknown.
  2. The model is known but too large to use, except by sampling.

Real-world physics is case 2. You could in principle write down the dynamics, but no one wants to integrate over every atom — you sample instead. So model-free is not only a response to ignorance; it is a response to lookahead being more expensive than experience. → Model-Free vs Model-Based RL

p.5 · On- and Off-Policy Learning ⏱ 3:47

Lecture 5 Model-Free Control, slide 5
Lecture 5 Model-Free Control, slide 5

  • On-policy — learn on the job. Sample from π\pi, evaluate π\pi.
  • Off-policy — look over someone's shoulder. Sample from μ\mu, evaluate π\pi.

The off-policy goal is stronger than imitation. Watching a human teleoperate an arm, you do not want to copy the trajectory — you want to conclude "you could have collected more reward by going this other way."


2 · Making GPI model-free

p.6–7 · Generalized Policy Iteration ⏱ 5:18

Lecture 5 Model-Free Control, slide 6
Lecture 5 Model-Free Control, slide 6

Up = evaluate, down = act greedily. Convergence of this cycle was settled in L3 → Contraction Mapping & Bellman Convergence. The only question now is what goes in each slot.

Lecture 5 Model-Free Control, slide 7
Lecture 5 Model-Free Control, slide 7

Plug MC evaluation straight into GPI. What breaks?

Three things, in order of depth.

  1. Improvement is not model-free. Acting greedily w.r.t. VV needs the transition model. → fixed on p.8 by switching to QQ.
  2. Exploration is not guaranteed. A greedy policy may never visit large parts of the state space, so those values stay wrong forever. → fixed on p.11 by ϵ\epsilon-greedy.
  3. It is slow. Full MC evaluation costs many episodes per improvement step. → fixed on p.14 (improve every episode) and p.19 (switch to TD).

p.8–9 · Model-Free Policy Iteration Using Q ⏱ 9:54

Lecture 5 Model-Free Control, slide 8
Lecture 5 Model-Free Control, slide 8

π′(s)=arg⁡max⁡a∈A(Rsa+γ∑s′Pss′aV(s′))⏟needs a modelπ′(s)=arg⁡max⁡a∈AQ(s,a)⏟model-free\underbrace{\pi'(s)=\arg\max_{a\in\mathcal{A}}\Big(\mathcal{R}^a_s+\gamma\textstyle\sum_{s'}\mathcal{P}^a_{ss'}V(s')\Big)}_{\text{needs a model}} \qquad \underbrace{\pi'(s)=\arg\max_{a\in\mathcal{A}}Q(s,a)}_{\text{model-free}}

Lecture 5 Model-Free Control, slide 9
Lecture 5 Model-Free Control, slide 9

Problem 1 is now gone. Problem 2 is still open — the down-arrow is still fully greedy.


3 · Exploration and ε-greedy

p.10 · Example of Greedy Action Selection ⏱ 12:56

Lecture 5 Model-Free Control, slide 10
Lecture 5 Model-Free Control, slide 10

A two-armed bandit. Open the left door once, see 00, and greedy behavior never opens it again — even though a single sample says almost nothing about its true value.

The failure is not "greedy is suboptimal." It is that you get trapped inside a belief you have no mechanism to correct. Full treatment in L9.

p.11 · ε-Greedy Exploration ⏱ 15:13

Lecture 5 Model-Free Control, slide 11
Lecture 5 Model-Free Control, slide 11

π(a∣s)={ϵ/m+1−ϵif a∗=arg⁡max⁡a∈AQ(s,a)ϵ/motherwise\pi(a|s)=\begin{cases} \epsilon/m+1-\epsilon & \text{if } a^*=\arg\max_{a\in\mathcal{A}}Q(s,a)\\[4pt] \epsilon/m & \text{otherwise} \end{cases}

Flip a coin: explore uniformly with probability ϵ\epsilon, act greedily otherwise. The extra ϵ/m\epsilon/m on the greedy action accounts for picking it by chance during exploration.

Naive as it looks, it is surprisingly hard to beat in practice.

p.12 · ε-Greedy Policy Improvement ⏱ 17:31

Lecture 5 Model-Free Control, slide 12
Lecture 5 Model-Free Control, slide 12

The whole proof rests on one inequality — a max dominates any convex combination:

max⁡aqπ(s,a)  ≥  ∑awa qπ(s,a),wa≥0, ∑awa=1\max_{a}q_\pi(s,a)\;\ge\;\sum_{a}w_a\,q_\pi(s,a),\qquad w_a\ge 0,\ \textstyle\sum_a w_a=1

The trick is the choice of weights. Take

wa=π(a∣s)−ϵ/m1−ϵw_a=\frac{\pi(a|s)-\epsilon/m}{1-\epsilon}

and the 1−ϵ1-\epsilon factors cancel, the terms collapse, and what remains is exactly ∑aπ(a∣s)qπ(s,a)=vπ(s)\sum_a \pi(a|s)q_\pi(s,a)=v_\pi(s). Hence qπ(s,π′(s))≥vπ(s)q_\pi(s,\pi'(s))\ge v_\pi(s).

That is a one-step result. Extending it to vπ′≥vπv_{\pi'}\ge v_\pi reuses the telescoping argument from the L3 policy improvement theorem — not re-derived here.

What this theorem does not give you

It says nothing about how much to explore or how fast ϵ\epsilon should decay. Monotone improvement holds for any fixed ϵ\epsilon. Choosing a schedule is a separate problem, answered by GLIE.


4 · GLIE Monte-Carlo control

p.13–14 · Monte-Carlo Policy Iteration → Control ⏱ 22:04

Lecture 5 Model-Free Control, slide 13
Lecture 5 Model-Free Control, slide 13

Both slots are now replaced: evaluation = MC on QQ, improvement = ϵ\epsilon-greedy. The down-arrow no longer reaches a deterministic policy, and that residual stochasticity is what keeps exploration alive.

Lecture 5 Model-Free Control, slide 14
Lecture 5 Model-Free Control, slide 14

There is no reason to evaluate a policy to convergence before improving it — the same argument as in DP. Push it to the limit: improve after every single episode.

The principle that runs through the rest of the lecture

Always act greedily with respect to the freshest estimate you have. Waiting to collect more data before improving means generating that data with a policy you already know is stale. This is why the loop tightens from batch of episodes → one episode → one time-step.

p.15 · GLIE ⏱ 25:15

Lecture 5 Model-Free Control, slide 15
Lecture 5 Model-Free Control, slide 15

Greedy in the Limit with Infinite Exploration — two conditions, each doing distinct work:

Condition Why it is needed
lim⁡k→∞Nk(s,a)=∞\lim_{k\to\infty}N_k(s,a)=\infty Unvisited pairs keep wrong estimates forever
lim⁡k→∞πk(a∣s)=1 ⁣(a=arg⁡max⁡a′Qk(s,a′))\lim_{k\to\infty}\pi_k(a\mid s)=\mathbf{1}\!\left(a=\arg\max_{a'}Q_k(s,a')\right) The Bellman optimality equation contains a max⁡\max. A policy that stays soft satisfies the expectation equation for that soft policy — you converge to some qπq_\pi, not to q∗q_*

ϵk=1/k\epsilon_k=1/k satisfies both. It is a valid schedule, not a good one.

p.16 · GLIE Monte-Carlo Control ⏱ 28:17

Lecture 5 Model-Free Control, slide 16
Lecture 5 Model-Free Control, slide 16

N(St,At)←N(St,At)+1,Q(St,At)←Q(St,At)+1N(St,At)(Gt−Q(St,At))N(S_t,A_t)\leftarrow N(S_t,A_t)+1,\qquad Q(S_t,A_t)\leftarrow Q(S_t,A_t)+\frac{1}{N(S_t,A_t)}\big(G_t-Q(S_t,A_t)\big)
This is not an i.i.d. mean

The returns being averaged come from a sequence of different policies, since π\pi improves as you go. It is only GLIE that rescues this: as πk\pi_k approaches greedy, the early samples from bad policies are progressively dominated, and the average converges on the quantity you actually care about.

Does the initialization of QQ matter?

With a 1/N1/N step size, not at all. On the first visit to a pair, N=1N=1, so the update is Q←Q+1⋅(Gt−Q)=GtQ\leftarrow Q+1\cdot(G_t-Q)=G_t — the initial value is overwritten exactly, in theory and in practice.
With a constant α\alpha it matters a great deal, because every update only moves a fraction of the way from wherever you started. That applies to Sarsa and Q-learning below, not to this algorithm.

Implementation note. Do not store π\pi. Keep QQ, and when it is time to act, flip a coin against the current ϵk\epsilon_k. The policy is implicit in QQ plus the schedule.

p.17–18 · Blackjack ⏱ 34:39

Lecture 5 Model-Free Control, slide 18
Lecture 5 Model-Free Control, slide 18

L4 asked "how much do I lose with this fixed policy?" (prediction). Same problem, now control: "how should I actually play?" The plots show v∗v_* rather than QQ — the action dimension is collapsed for legibility; internally the algorithm holds QQ.

The learned policy is not a simple threshold on your own hand. It sticks on low totals precisely where the dealer's upcard makes the dealer likely to bust — optimal play sometimes means declining to act and letting the opponent lose. A usable ace shifts the whole boundary toward hitting, since counting it as 1 or 11 removes the downside.


5 · Sarsa

p.19 · MC vs. TD Control ⏱ 38:26

Lecture 5 Model-Free Control, slide 19
Lecture 5 Model-Free Control, slide 19

Lower variance, online, works on incomplete sequences — plus a fourth advantage the slide omits: TD is what makes off-policy learning viable at all (see p.33).

p.20–21 · The Sarsa Update ⏱ 39:57

Lecture 5 Model-Free Control, slide 20
Lecture 5 Model-Free Control, slide 20

Q(S,A)←Q(S,A)+α(R+γQ(S′,A′)−Q(S,A))Q(S,A)\leftarrow Q(S,A)+\alpha\big(R+\gamma Q(S',A')-Q(S,A)\big)

The name is the update's data dependency, and it involves two different kinds of sampling:

Step Sampled from
S,A→R,S′S,A \rightarrow R,S' the environment
S′→A′S' \rightarrow A' your own policy

Lecture 5 Model-Free Control, slide 21
Lecture 5 Model-Free Control, slide 21

The GPI loop now runs at every time-step: update one cell of QQ, immediately improve. In a looping environment this means that when you return to a state you already behave differently.

p.22 · Sarsa Algorithm ⏱ 44:29

Lecture 5 Model-Free Control, slide 22
Lecture 5 Model-Free Control, slide 22

QQ is a lookup table, arbitrarily initialized (zeros are fine — but see the constant-α\alpha caveat above). The outer loop is over episodes; the loop that matters is over steps.

Where does A′A' come from, and why is it legitimate to bootstrap from an action you have not been rewarded for yet?

S′S' comes from the environment; A′A' you draw from your current policy, and you then carry it forward as the next step's AA — one policy sample per step.

The target R+γQ(S′,A′)R+\gamma Q(S',A') is a sample of the Bellman expectation equation for qπq_\pi, whose right-hand side splits in two:

  • RR and S′S' — an expectation over the environment;
  • Q(S′,A′)Q(S',A') — an expectation over your own policy, from S′S' onward.

That second term is precisely the thing being estimated. So the action must be drawn from the policy under evaluation for the target to be valid.

Sarsa is therefore on-policy by construction, not by convention. Breaking that constraint is exactly what Q-learning does, and it needs a different Bellman equation to stay valid.

p.23 · Convergence of Sarsa ⏱ 48:14

Lecture 5 Model-Free Control, slide 23
Lecture 5 Model-Free Control, slide 23

GLIE policies, plus Robbins-Monro step sizes:

∑t=1∞αt=∞(you can travel arbitrarily far from a bad initial estimate)\sum_{t=1}^{\infty}\alpha_t=\infty \quad\text{(you can travel arbitrarily far from a bad initial estimate)}
∑t=1∞αt2<∞(the updates must eventually vanish, or noise keeps rattling the policy)\sum_{t=1}^{\infty}\alpha_t^2<\infty \quad\text{(the updates must eventually vanish, or noise keeps rattling the policy)}
Theory vs. practice — stated outright in the lecture

In practice people commonly ignore both conditions, run a fixed α\alpha and a fixed ϵ\epsilon, and Sarsa still works. That is an empirical observation, not a theorem — and the very next example does exactly this.

p.24–25 · Windy Gridworld ⏱ 49:46

Lecture 5 Model-Free Control, slide 25
Lecture 5 Model-Free Control, slide 25

Read the axes carefully — this is the most misread plot in the lecture

The x-axis is time steps, not episodes. The y-axis is cumulative episodes completed. So the slope is 1/(episode length)1/(\text{episode length}), and a steeper curve means shorter episodes.

  • The first episode takes about 2,000 steps — an undirected walk, biased upward by the wind, stumbling onto the goal by luck.
  • After the first success the curve bends sharply: once there is any signal, bootstrapping compounds it.
  • The final slope corresponds to a near-optimal path length. It never becomes perfectly straight because ϵ\epsilon is not decayed, so exploratory actions keep being injected.

6 · Sarsa(λ)

p.26 · n-Step Sarsa ⏱ 53:40

Lecture 5 Model-Free Control, slide 26
Lecture 5 Model-Free Control, slide 26

qt(n)=Rt+1+γRt+2+⋯+γn−1Rt+n+γnQ(St+n),Q(St,At)←Q(St,At)+α(qt(n)−Q(St,At))q_t^{(n)}=R_{t+1}+\gamma R_{t+2}+\dots+\gamma^{n-1}R_{t+n}+\gamma^{n}Q(S_{t+n}),\qquad Q(S_t,A_t)\leftarrow Q(S_t,A_t)+\alpha\big(q_t^{(n)}-Q(S_t,A_t)\big)

n=1n=1 is Sarsa, n=∞n=\infty is Monte-Carlo. Same spectrum as L4, now on QQ.

Changing nn changes how the target is built, never what is being estimated. The quantity is always the full return qπ(s,a)=Eπ[Gt∣St=s,At=a]q_\pi(s,a)=\mathbb{E}_\pi[G_t\mid S_t=s,A_t=a]; an nn-step target simply measures the first nn rewards explicitly and compresses the infinite remainder into one QQ. Keep this straight — the same distinction returns in L6, where function approximation changes the representation of QQ without touching what QQ means.

p.27 · Forward View ⏱ 56:43

Lecture 5 Model-Free Control, slide 27
Lecture 5 Model-Free Control, slide 27

qtλ=(1−λ)∑n=1∞λn−1qt(n),Q(St,At)←Q(St,At)+α(qtλ−Q(St,At))q_t^{\lambda}=(1-\lambda)\sum_{n=1}^{\infty}\lambda^{n-1}q_t^{(n)},\qquad Q(S_t,A_t)\leftarrow Q(S_t,A_t)+\alpha\big(q_t^{\lambda}-Q(S_t,A_t)\big)

(1−λ)(1-\lambda) is only a normalizer making the geometric weights sum to 1 — do not read meaning into it. λ=0\lambda=0 recovers Sarsa, λ=1\lambda=1 recovers MC, and in between is a bias-variance dial.

The defect: qtλq_t^{\lambda} cannot be computed until the episode ends, so this is not online — and some problems have no episode boundary at all.

p.28–29 · Backward View ⏱ 1:00:30

Lecture 5 Model-Free Control, slide 28
Lecture 5 Model-Free Control, slide 28

Et(s,a)=γλEt−1(s,a)+1(St=s,At=a)E_t(s,a)=\gamma\lambda E_{t-1}(s,a)+\mathbf{1}(S_t=s,A_t=a)
δt=Rt+1+γQ(St+1,At+1)−Q(St,At),Q(s,a)←Q(s,a)+α δt Et(s,a)  ∀(s,a)\delta_t=R_{t+1}+\gamma Q(S_{t+1},A_{t+1})-Q(S_t,A_t),\qquad Q(s,a)\leftarrow Q(s,a)+\alpha\,\delta_t\,E_t(s,a)\ \ \forall (s,a)

The eligibility trace is a credit assignment device: when a reward finally arrives, which state-action pairs deserve the blame or the credit? Two heuristics, combined — recency and frequency. Note the trace decays by γλ\gamma\lambda, not λ\lambda alone.

Lecture 5 Model-Free Control, slide 29
Lecture 5 Model-Free Control, slide 29

The asymmetry that trips people up in implementation

Increment the trace for the one pair you visited. Decay and update every pair in the table, visited or not. Reset E=0E=0 at the start of each episode.
Memory cost: EE is an ∣S∣×∣A∣|\mathcal{S}|\times|\mathcal{A}| table, the same size as QQ — and in L6 both get replaced by function approximators.

p.30 · Sarsa(λ) Gridworld ⏱ 1:06:40

Lecture 5 Model-Free Control, slide 30
Lecture 5 Model-Free Control, slide 30

With QQ initialized to zero, Sarsa(0) makes almost no progress on the first episode: at every step before the goal, both your estimate and the bootstrapped next estimate are 00, so δt=0\delta_t=0. Only the final transition carries information. Reward knowledge crawls backward one cell per episode.

Sarsa(λ\lambda) has a trace laid along the entire trajectory, so the moment the reward arrives, the whole path updates at once, scaled by each pair's eligibility.

λ\lambda defeats the tyranny of the time step

Halve your time-step and Sarsa(0) needs twice as many episodes to propagate the same information. λ\lambda lets you set how far back credit flows in real time rather than in step count, decoupling the algorithm from your discretization choice.

What this figure does not demonstrate

The advertised benefit of the backward view is that it is online — no waiting for the episode to end. This figure cannot show that, because with a single terminal reward there is genuinely no information to propagate earlier; the updates are running every step, they are just multiplied by δt=0\delta_t=0.
The real behavior: with rewards mid-episode, every informative event immediately updates the whole trailing path, without any episode boundary. → Forward and Backward Views of TD Lambda

MC averaged returns explicitly. Where is the average in Sarsa?

There is none. Bootstrapping is a different mechanism for estimating the same expectation — you nudge toward the TD error instead of accumulating a sample mean.
Even substituting 1/N1/N for α\alpha would not make it a true mean, because the targets themselves keep changing as QQ improves. It is a non-stationary average by construction.


7 · Off-policy learning

p.31 · Why bother ⏱ 1:19:42

Lecture 5 Model-Free Control, slide 31
Lecture 5 Model-Free Control, slide 31

Four motivations, increasing in ambition:

  1. Learn from observing others — humans or other agents — and conclude how to do better than what you observed.
  2. Reuse experience from old policies. GPI marches through π1,π2,…\pi_1,\pi_2,\dots; discarding that data is wasteful. This is the reason off-policy learning is used in the Atari/DQN line of work.
  3. Explore while learning the optimal policy. The best-known use: behave as exploratorily as you like, learn about the deterministic optimum anyway.
  4. Learn about many policies from one stream. "I only get this one stream of data that we call life, and I want to learn about all of these other policies." Answering many counterfactual questions in parallel off a single trajectory.

p.32–33 · Importance Sampling, and why it fails for MC ⏱ 1:25:01

Lecture 5 Model-Free Control, slide 32
Lecture 5 Model-Free Control, slide 32

EX∼P[f(X)]=∑XQ(X)P(X)Q(X)f(X)=EX∼Q ⁣[P(X)Q(X)f(X)]\mathbb{E}_{X\sim P}[f(X)]=\sum_X Q(X)\frac{P(X)}{Q(X)}f(X)=\mathbb{E}_{X\sim Q}\!\left[\frac{P(X)}{Q(X)}f(X)\right]

Lecture 5 Model-Free Control, slide 33
Lecture 5 Model-Free Control, slide 33

Gtπ/μ=π(At∣St)μ(At∣St)⋅π(At+1∣St+1)μ(At+1∣St+1)⋯π(AT∣ST)μ(AT∣ST)  GtG_t^{\pi/\mu}=\frac{\pi(A_t|S_t)}{\mu(A_t|S_t)}\cdot\frac{\pi(A_{t+1}|S_{t+1})}{\mu(A_{t+1}|S_{t+1})}\cdots\frac{\pi(A_T|S_T)}{\mu(A_T|S_T)}\;G_t
Why ordinary episode-wise off-policy MC becomes impractical

The product does not merely become small. If π\pi is deterministic, one action that π\pi would never take makes the whole weight zero, while rare fully matching trajectories receive huge weights. The expectation identity remains valid under the support condition, but variance can grow catastrophically.
Silver's “just useless” is a practical verdict for long, substantially different policies, not a theorem that every off-policy MC estimator always fails. Short horizons, similar policies, and weighted or per-decision variants can help. For this lecture's main line, the problem motivates bootstrapping.

p.34 · Importance Sampling for Off-Policy TD ⏱ 1:27:18

Lecture 5 Model-Free Control, slide 34
Lecture 5 Model-Free Control, slide 34

V(St)←V(St)+α(π(At∣St)μ(At∣St)(Rt+1+γV(St+1))−V(St))V(S_t)\leftarrow V(S_t)+\alpha\left(\frac{\pi(A_t|S_t)}{\mu(A_t|S_t)}\big(R_{t+1}+\gamma V(S_{t+1})\big)-V(S_t)\right)

Only one correction is needed, because everything past the bootstrap point is already summarized by VV. Far lower variance than the MC version — but still capable of blowing up when the two policies disagree on that single step.

Why does the MC ratio product become a rare-event estimator, and why does Q-learning need no ratio? → Importance Sampling in Off-Policy RL

8 · Q-learning

p.35–36 · Off-policy without importance sampling ⏱ 1:28:51

Lecture 5 Model-Free Control, slide 35
Lecture 5 Model-Free Control, slide 35

Q(St,At)←Q(St,At)+α(Rt+1+γQ(St+1,A′)−Q(St,At)),At+1∼μ(⋅∣St+1),A′∼π(⋅∣St+1)Q(S_t,A_t)\leftarrow Q(S_t,A_t)+\alpha\big(R_{t+1}+\gamma Q(S_{t+1},A')-Q(S_t,A_t)\big), \qquad A_{t+1}\sim\mu(\cdot|S_{t+1}),\quad A'\sim\pi(\cdot|S_{t+1})

The move is to split the action you take from the action you bootstrap from:

Symbol Drawn from Used for
At+1A_{t+1} behavior policy μ\mu actually executed in the environment
A′A' target policy π\pi the bootstrap term only — never executed

Nothing is stored or replayed; both are sampled on the spot. No importance sampling is required because the Bellman equation for QQ never asked for it — you are simply sampling a different equation.

Successor-state indexing

The slide conditions At+1A_{t+1} and A′A' on StS_t, but both are successor actions associated with the bootstrap state St+1S_{t+1}. The equations here use St+1S_{t+1} accordingly.

Lecture 5 Model-Free Control, slide 36
Lecture 5 Model-Free Control, slide 36

The algorithm everyone calls "Q-learning" is the special case π=\pi= greedy, μ=ϵ\mu=\epsilon-greedy, with both improving over time. Substituting the greedy target collapses the expression:

γQ(St+1,arg⁡max⁡a′Q(St+1,a′))=γmax⁡a′Q(St+1,a′)\gamma Q\big(S_{t+1},\arg\max_{a'}Q(S_{t+1},a')\big)=\gamma\max_{a'}Q(S_{t+1},a')

p.37 · Q-Learning Control Algorithm ⏱ 1:33:27

Lecture 5 Model-Free Control, slide 37
Lecture 5 Model-Free Control, slide 37

Q(S,A)←Q(S,A)+α(R+γmax⁡a′Q(S′,a′)−Q(S,A))Q(S,A)\leftarrow Q(S,A)+\alpha\Big(R+\gamma\max_{a'}Q(S',a')-Q(S,A)\Big)

Silver's own name for it is the "Sarsamax" update — S,A,R,S′S,A,R,S', then a max over a′a'. It converges to q∗q_* because it samples the Bellman optimality equation, whereas Sarsa samples the expectation equation and converges to qπq_\pi.


9 · The DP–TD correspondence

p.41–42 ⏱ 1:34:13

Lecture 5 Model-Free Control, slide 41
Lecture 5 Model-Free Control, slide 41

The single sentence this lecture compresses to

A TD target is a sample of the right-hand side of a Bellman equation. DP expands the expectation (full backup); TD samples it (sample backup).

Bellman equation Full backup (DP) Sample backup (TD)
expectation for vπv_\pi iterative policy evaluation TD learning
expectation for qπq_\pi Q-policy iteration Sarsa
optimality for q∗q_* Q-value iteration Q-learning

Lecture 5 Model-Free Control, slide 42
Lecture 5 Model-Free Control, slide 42

x← α y≡x←x+α(y−x)x \xleftarrow{\ \alpha\ } y \quad\equiv\quad x \leftarrow x+\alpha(y-x)

So Sarsa vs. Q-learning is not a matter of algorithmic taste — it is a matter of which Bellman equation you chose to sample. This table is the joint between L3 and L5. → Markov Decision Process (MDP) · Model-Free Prediction


Study checklist

Answer these without the notes before moving on to L6. Each item links back to where it is worked out; open the toggle only after you have tried.

1. Why does greedy improvement on VV require a model, and why does QQ not?
→ p.8–9 · Model-Free Policy Iteration Using Q ⏱ 9:54

Answer

Greedy on VV is π′(s)=arg⁡max⁡a(Rsa+γ∑s′Pss′aV(s′))\pi'(s)=\arg\max_a\big(\mathcal{R}^a_s+\gamma\sum_{s'}\mathcal{P}^a_{ss'}V(s')\big) — the one-step lookahead is R\mathcal{R} and P\mathcal{P}, i.e. a model. QQ already stores the value of each action separately, so it is a cache of that lookahead: π′(s)=arg⁡max⁡aQ(s,a)\pi'(s)=\arg\max_a Q(s,a) needs nothing but the table.

2. State the ϵ\epsilon-greedy improvement theorem. Which weights make the proof work, and what does the theorem not tell you?
→ p.12 · ε-Greedy Policy Improvement ⏱ 17:31

Answer

For any ϵ\epsilon-greedy policy π\pi, the ϵ\epsilon-greedy policy π′\pi' with respect to qπq_\pi satisfies vπ′≥vπv_{\pi'}\ge v_\pi.
The proof is one inequality — a max dominates any convex combination — and the weights that make it collapse are wa=π(a∣s)−ϵ/m1−ϵw_a=\dfrac{\pi(a|s)-\epsilon/m}{1-\epsilon}. With those, the 1−ϵ1-\epsilon factors cancel and the remainder is exactly ∑aπ(a∣s)qπ(s,a)=vπ(s)\sum_a\pi(a|s)q_\pi(s,a)=v_\pi(s).
What it does not give you: any guidance on how much to explore or how fast ϵ\epsilon should decay. Monotone improvement holds for any fixed ϵ\epsilon — and a fixed ϵ\epsilon never reaches q∗q_*. That is GLIE's job, not this theorem's. It is also a one-step result; vπ′≥vπv_{\pi'}\ge v_\pi needs the L3 telescoping argument on top.

3. What are the two GLIE conditions, and what specifically goes wrong if you drop the second?
→ p.15 · GLIE ⏱ 25:15

Answer

(i) lim⁡k→∞Nk(s,a)=∞\lim_{k\to\infty}N_k(s,a)=\infty — every pair is visited infinitely often, or its estimate stays wrong forever.
(ii) lim⁡k→∞πk(a∣s)=1(a=arg⁡max⁡a′Qk(s,a′))\lim_{k\to\infty}\pi_k(a|s)=\mathbf{1}\big(a=\arg\max_{a'}Q_k(s,a')\big) — the policy becomes greedy in the limit.
Drop (ii) and you still converge, just to the wrong thing: a permanently soft policy satisfies the Bellman expectation equation for that soft policy, so you get qπq_\pi of your ϵ\epsilon-soft policy. The optimality equation contains a max⁡\max, and only a policy going greedy in the limit samples it.

4. Why is the MC control average not an i.i.d. mean, and why does it converge anyway?
→ p.16 · GLIE Monte-Carlo Control ⏱ 28:17

Answer

The returns being averaged into Q(St,At)Q(S_t,A_t) come from a sequence of different policies — π\pi improves after every episode — so they are not identically distributed.
GLIE rescues it: as πk\pi_k approaches greedy, the early samples generated by bad policies are progressively dominated by the later ones, and the running average converges on q∗q_*.

5. Why is Sarsa on-policy by construction rather than by convention?
→ p.22 · Sarsa Algorithm ⏱ 44:29

Answer

The target R+γQ(S′,A′)R+\gamma Q(S',A') is a sample of the Bellman expectation equation for qπq_\pi, whose right-hand side is two expectations: R,S′R,S' over the environment, and Q(S′,A′)Q(S',A') over your own policy from S′S' onward. That second term is the quantity being estimated, so A′A' must be drawn from the policy under evaluation or the target is not a sample of the right thing.
Breaking that constraint is exactly what Q-learning does — and it has to switch to a different Bellman equation to stay valid.

6. Why does Sarsa(0) propagate reward information only one cell per episode?
→ p.30 · Sarsa(λ) Gridworld ⏱ 1:06:40

Answer

With QQ initialized to zero and a single terminal reward, every step before the goal has Q(S,A)=0Q(S,A)=0 and Q(S′,A′)=0Q(S',A')=0, so δt=0\delta_t=0 — the update runs but multiplies by nothing. Only the final transition carries information, so episode 1 updates exactly one pair. Each subsequent episode moves that frontier back by one cell.
Sarsa(λ\lambda) has a trace laid along the whole trajectory, so when the reward arrives the entire path updates at once, scaled by each pair's eligibility.

7. What does "λ\lambda defeats the tyranny of the time step" mean concretely?
→ p.30 · Sarsa(λ) Gridworld ⏱ 1:06:40

Answer

Sarsa(0) propagates credit one cell per step count, so halving your discretization doubles the number of episodes needed to move the same information the same real distance — the algorithm's behavior is hostage to an arbitrary modeling choice.
The trace decays by γλ\gamma\lambda per step, so λ\lambda sets how far back credit flows in real time, and you can hold that horizon fixed while changing the time-step.

8. Why is off-policy MC with importance sampling unusable, and what does that force you to do instead?
→ p.32–33 · Importance Sampling, and why it fails for MC ⏱ 1:25:01

Answer

The weight is a product of per-step ratios over the entire episode. If π\pi is deterministic, a single action it would never take zeroes the whole weight, while the rare fully matching trajectories get enormous weights — a rare-event estimator whose variance can grow catastrophically. (The identity itself stays valid under the support condition; "useless" is a practical verdict for long, substantially different policies, not a theorem.)
It forces you to bootstrap: TD needs only one ratio per step (p.34), and Q-learning removes the ratio entirely. → Importance Sampling in Off-Policy RL

9. Why does Q-learning need no importance sampling?
→ p.35–36 · Off-policy without importance sampling ⏱ 1:28:51

Answer

Because it never reweights anything. It splits the action taken from the action bootstrapped from: At+1∼μA_{t+1}\sim\mu is executed, A′∼πA'\sim\pi appears only in the target and is sampled on the spot. You are not correcting μ\mu's samples into an expectation under π\pi — you are sampling a different Bellman equation, the optimality equation, whose right-hand side asks for max⁡a′Q(St+1,a′)\max_{a'}Q(S_{t+1},a') and nothing about μ\mu.

10. Reconstruct the DP–TD table from memory.
→ 9 · The DP–TD correspondence

Answer

A TD target is a sample of the right-hand side of a Bellman equation. DP expands the expectation (full backup); TD samples it (sample backup).

Bellman equation Full backup (DP) Sample backup (TD)
expectation for vπv_\pi iterative policy evaluation TD learning
expectation for qπq_\pi Q-policy iteration Sarsa
optimality for q∗q_* Q-value iteration Q-learning

Gaps to close on your own

Slides p.38–40 are skipped in the lecture

Lecture 5 Model-Free Control, slide 40
Lecture 5 Model-Free Control, slide 40

The video jumps from p.37 straight to the summary, leaving three slides unexplained — the Q-learning pseudocode, the demo, and Cliff Walking.
Cliff Walking is the standard demonstration of the practical difference between Sarsa and Q-learning: the on-policy learner walks the safe route away from the edge, the off-policy learner learns the optimal edge-hugging path but performs worse online because ϵ\epsilon occasionally knocks it off. Working through it is the fastest way to make the on/off-policy distinction concrete.

  • Windy Gridworld move set — the lecture is ambiguous about whether the figure uses the four standard moves or king's moves (diagonals). Sutton & Barto Example 6.5 is the reference; confirm there before quoting the numbers.
  • Forward/backward equivalence for the control case is asserted, not proved. The L4 proof is said to carry over → Forward and Backward Views of TD Lambda.
  • Function approximation — everything here is a lookup table, which does not scale. That is L6, and it applies to EE as well as QQ.

Language notes

Phrasings worth stealing for your own technical writing and talks:

Expression Use
learn on the job / look over someone's shoulder naming on- vs off-policy without formalism
vanishingly small a quantity decaying toward zero, informally but precisely
let me back off that retracting a claim mid-sentence without losing authority
it defeats the tyranny of the time step a design choice removing a dependence on an arbitrary parameter
a thorny problem genuinely hard and unresolved, not merely difficult
get the best of both worlds a method inheriting the advantages of two extremes
this is naive but surprisingly hard to beat conceding simplicity while defending a baseline
rlsilver-courselecture-notesmodel-free-controlsarsaq-learning