Skip to content
BIASED

Q-learning and temporal-difference learning

Exploration, Monte Carlo vs TD(0), SARSA and Q-learning, cliff walking, and tabular convergence.

From a model to samples

Games and Monte Carlo tree search still needed a model: rules, a simulator, or experience from which to learn one. Value iteration needs PP and RR explicitly. Most agents have neither. They act, see one transition (St,At,Rt+1,St+1)(S_t,A_t,R_{t+1},S_{t+1}), and must improve from that. Reinforcement learning estimates the Bellman expectations by averaging samples: estimate ← estimate + α \alpha\,(target − estimate).

Exploration and bandits

Strip the MDP to one state: a multi-armed bandit. Greedy can stick forever on a bad first sample. ε\varepsilon-greedy explores forever and pays linear regret. UCB1 pulls

At=arg⁡max⁡a[Qt(a)+cln⁡tNt(a)]A_t=\arg\max_a\Big[Q_t(a)+c\sqrt{\frac{\ln t}{N_t(a)}}\Big]

and achieves logarithmic regret. At t=100t=100, Q=(1.2,1.0,0.3)Q=(1.2,1.0,0.3), N=(80,15,5)N=(80,15,5), c=2c=2, the scores are 1.6801.680, 2.1082.108, 2.2192.219 — UCB tries the worst-looking arm. On the 10-armed testbed, late reward: greedy 1.021.02, ε=0.1\varepsilon=0.1 1.371.37, UCB 1.481.48.

Monte Carlo and TD(0)

Monte Carlo prediction waits for GtG_t: unbiased, high variance, only at episode end. TD(0) bootstraps after one step:

V(St)←V(St)+α δt,δt=Rt+1+γV(St+1)−V(St).V(S_t)\leftarrow V(S_t)+\alpha\,\delta_t,\qquad \delta_t=R_{t+1}+\gamma V(S_{t+1})-V(S_t).

Key idea. A value must be consistent with itself: one reward plus the next state’s value. TD moves estimates toward that consistency without waiting for the true return. On the random walk A–E (true values 1/6,…,5/61/6,\ldots,5/6), if V(C)=0.50V(\mathrm{C})=0.50, V(D)=0.60V(\mathrm{D})=0.60, a step C→D with R=0R=0 and α=0.1\alpha=0.1 yields V(C)=0.51V(\mathrm{C})=0.51. The Monte Carlo error equals the discounted sum of TD errors along the episode.

SARSA and Q-learning

Control needs QQ, so greedy improvement is arg⁡max⁡aQ(s,a)\arg\max_a Q(s,a) without PP. SARSA is on-policy: target Rt+1+γQ(St+1,At+1)R_{t+1}+\gamma Q(S_{t+1},A_{t+1}) with At+1A_{t+1} from the behaviour policy. Q-learning is off-policy: target Rt+1+γmax⁡aQ(St+1,a)R_{t+1}+\gamma\max_a Q(S_{t+1},a) — a sample of the Bellman optimality equation — and learns Q⋆Q^\star while exploring.

Cliff walking

On cliff walking (ε=0.1\varepsilon=0.1), Q-learning’s greedy path hugs the edge (return −13-13), but ε\varepsilon-greedy behaviour on that path averages −45.8-45.8. SARSA learns the safer upper path; the best ε\varepsilon-greedy policy averages −20.7-20.7. One edge update: Q-learning target −7-7; SARSA’s expected target −9.775-9.775 because a random fall costs extra. If exploration will stop, prefer Q⋆Q^\star; if the agent must keep exploring while acting, prefer SARSA’s caution.

Convergence and next

With Robbins–Monro steps ∑α=∞\sum\alpha=\infty, ∑α2<∞\sum\alpha^2<\infty and infinite visits, TD(0) → VπV^\pi, Q-learning → Q⋆Q^\star; SARSA needs GLIE exploration too. Tables do not generalize: Atari screens never repeat. Next: replace the table by a network — deep Q-networks, with replay and a target network to survive the deadly triad.

Check your understanding

The same questions as in Pulse. Answers are shared between modes.

Go deeper — optional

Code and labs do not count toward the main percentage or the certificate.

  • One Q-learning updateoptional

    Apply Q(s,a) ← Q + α[r + γ max Q(s',·) − Q] on a 2×2 table; match the new value.

    ~20 min · easier on a computer · The matching course topic has been read.

    Self-check in the notebook — not part of mastery or the certificate.

Full notes

Answers are saved on the server and tied to this browser until you sign in.