Skip to main content
Deep Reinforcement Learning

Comprehensive Examination Revision and Advanced Policy Methods

Published: 2026-08-22
Level: postgraduate
Audience: Postgraduate students in Deep Reinforcement Learning

Prerequisite Knowledge

This lecture builds on the following concepts from earlier lectures. If any feel unfamiliar, review the linked notes before proceeding.

Previously Covered in This Subject

  • Multi-Armed Bandits and Exploration — covered in Lecture 2
  • Markov Decision Processes and Bellman Equations — covered in Lecture 4
  • Dynamic Programming — Policy Evaluation and Policy Improvement — covered in Lecture 6
  • Monte Carlo Methods — On-Policy Prediction and Control — covered in Lecture 8
  • Off-Policy Monte Carlo and Importance Sampling — covered in Lecture 9
  • Temporal-Difference Learning — SARSA, Q-Learning and Expected SARSA — covered in Lecture 10
  • Maximization Bias and Double Q-Learning — covered in Lecture 11
  • Function Approximation and Semi-Gradient Methods — covered in Lectures 11–12
  • Deep Q-Networks — Experience Replay and Target Networks — covered in Lectures 12–13
  • Policy Gradient Methods and REINFORCE — covered in Lecture 14
  • Model-Based Planning and Monte Carlo Tree Search — covered in Lecture 15

16.1 Course Overview and Examination Scope

16.1.1 Lecture Notes as a Superset and What Is Examinable

Hook — why this matters before any equation: You will sit an open-book examination with every algorithm printed in front of you and still get the question wrong if you have not practiced what the symbols mean. The notes contain everything you might ever need — but the examination tests whether you can use what was actually taught.

The lecture notes for this course are a superset — a deliberately larger collection that contains every topic ever covered or intended to be covered in any offering of the course, including material prepared for a future re-alignment where early topics would be compressed and later advanced topics expanded. The watermarked combined document spans 191 pages. Not every page is examinable in the current offering.

The examinable scope follows what was actually delivered in class and in the slide decks, not the full extent of the notes. Where the notes include ambition material for future cohorts, that material is explicitly marked as not required for this examination. Where the notes compress a topic that was taught in detail in class, the slides and the textbook take priority over the notes. In short, the notes are a reference library; the lectures define the examination syllabus.

What "examinable" means in practice: A topic is examinable when it was presented in class with an algorithm or formula, explained line by line or in broad mechanism, and flagged for numerical practice. A topic is enrichment when it appears only in the notes as a pointer to papers or as a compressed survey. The two are intentionally different, and the examination follows the first.

The course as delivered is designed for 16 sessions. One session was contributed by a guest instructor and 15 by the main instructor, and the volume already exceeds a comfortable single-session review. An extra class originally on the calendar was cancelled because the course is on track; a replacement slot early next week is reserved on the calendar and will be used to discuss papers and future directions only if participation warrants it. That slot is enrichment, not remediation.

The examination is open-book. Every relevant algorithm and formula will be available in the notes during the examination. Rote memorization of parameter values or line numbers is not the skill being tested. The skill being tested is understanding what each term means and being able to use the algorithm to solve a problem. Even with the sheet open, confusion over a term such as the incremental weight accumulator will prevent a correct solution unless you have practiced the algorithm beforehand.

Scope — what the open-book format does and does not change: The open-book format removes the burden of memorizing pseudocode, but it raises the bar on comprehension. You must still know the meaning of every symbol, the direction of every loop, and the reason for every early exit. If a numerical problem omits a hyperparameter such as the step size or the discount factor , do not silently assume a value — either ask for the missing information or declare the assumption explicitly on the answer sheet. Declared bookkeeping is part of the answer.

Visual intuition — think of the notes as a city map that shows every road ever planned, including roads not yet built. The delivered lectures trace the route you actually drove, street by street. For the examination you are tested on the route you drove, with the map open on your lap for reference. You still need to know which turns you took and why, because the map alone does not tell you where you went.

The notes were produced by concatenating existing sources into a single file. A watermarked version and a non-watermarked version circulated; the content is identical and any apparent discrepancy is a formatting artifact, not a difference in substance.

Exam note: Prioritize the slides and the textbook alongside the notes. If a topic is marked in this lecture as skippable or as post-examination enrichment, do not spend examination-preparation time on it. Practice the numerics that were flagged as requiring practice — especially the backward incremental weighting in off-policy Monte Carlo and the temporal-difference control loop — because the algorithm sheet will not save you if you have not traced those steps before.

16.1.2 Course Chronology and Conceptual Anchors

Understanding where each topic sits in the story makes the rest of the lecture easier to remember. The course unfolds as a deliberate relaxation of assumptions, starting from full knowledge and moving toward learning from raw experience.

Block Sessions Core idea What it assumes
Foundations: what reinforcement learning is, stateless simplification 1–3 Agent, environment, reward, and the exploration problem without state No state — each decision is independent
Markov decision processes and dynamic programming 4–6 State, transition, reward, and the Bellman optimality equations solved by iterative improvement Full model of transition probabilities and complete state knowledge
Monte Carlo methods Mid-term block Learning and by averaging complete returns from sampled episodes No model, but complete episodes and no bootstrapping
Off-policy Monte Carlo Bridging mid-term to post-mid-term Learning about a target policy from data generated by a different behaviour policy via importance sampling Coverage: whenever
Temporal-difference learning Post-mid-term Combining sampling with bootstrapping: update toward One-step lookahead plus a learned estimate
Function approximation and Deep Q-Networks Following block Replacing tables with parametrized functions Generalization across states, with stability concerns
Policy-gradient and model-based planning Final blocks Direct policy parametrization and decision-time search (MCTS, AlphaGo family) Differentiable policies or a learned/known model

Midterm coverage ended at dynamic programming and on-policy Monte Carlo. The notes distributed at that stage went up to those topics. Off-policy Monte Carlo was partially covered before the midterm but completed after it — no midterm question was drawn from it, but it is included for the comprehensive examination. Everything after the midterm — temporal difference, function approximation, Deep Q-Networks, policy gradients, and the guest material on Monte Carlo Tree Search — is examinable at the level described in each section below. Advanced policy themes introduced in the final sessions — asynchronous methods, generalized advantage estimation, proximal policy optimization, and viewing language models as sequential policies — were presented as a high-level overview.

Two backbones to carry forward: Throughout the second half of the course two ideas keep reappearing. First, dynamic programming as a conceptual backbone — the idea of bootstrapping and iterative improvement shows up in every later family. Second, temporal difference as the practical backbone — understanding why temporal difference is a compromise between dynamic programming and Monte Carlo, and what temporal-difference target and temporal-difference error mean, pays off well beyond the examination because virtually every modern paper uses those terms.

Visual intuition — picture a triangle with dynamic programming at one corner (needs a full model, bootstraps), Monte Carlo at another corner (needs no model, no bootstrapping, waits for the end), and temporal difference in the middle, borrowing bootstrapping from the first and sampling from the second. Later topics — -step methods, function approximation, planning with a learned model — are different ways of sliding along the edges of that triangle or lifting it into higher-dimensional function spaces.

Common pitfall — treating chronology as trivia: Students sometimes memorize the list of topics without connecting the assumption each topic relaxes. If you can say for each transition "what assumption did we drop and what new difficulty did that create," you have understood the course structure. If you can only recite names, you have not.

16.1.3 How to Prepare from the Materials

Two complementary ways of approaching any algorithm in the notes were distinguished, and either succeeds provided the terms are genuinely understood.

Line-by-line understanding — read each statement, identify each symbol, and trace why it appears. This is the safest route for algorithms with a backward sweep or an early-exit condition, where the order of operations matters.

Mechanism understanding plus reference — grasp broadly how the algorithm achieves its correction (for example, how backward incremental weighting corrects for off-policy data), then use the algorithm sheet as a reference to solve a problem by mapping each symbol to its role. This is faster once the mechanism is solid, but it still requires that you can map every symbol.

Either approach succeeds only if the meaning of terms such as the weight accumulator , the cumulative denominator , the return , and the direction of the backward scan are correctly internalized.

A concrete preparation routine that works: Pick one representative algorithm — off-policy Monte Carlo control or one-step SARSA. Write the algorithm on a blank sheet from memory with every symbol defined. Generate a tiny three-step episode on paper with explicit rewards and policy probabilities. Run the algorithm backward by hand, computing each , , , and update, and check the break condition. Compare your trace with the notes version and the slide version. If they differ in phrasing, settle on one and practice consistently with that version. The goal is not to memorize lines but to eliminate surprises when the sheet is open.

A second practical skill was highlighted: assumption-writing and bookkeeping. If a numerical problem omits a hyperparameter such as the step size , the discount factor , or the exploration rate , do not silently assume a value. Either ask for the missing information or declare the assumption explicitly before proceeding, and write every assumption on the answer sheet. Declared assumptions are part of a correct answer; hidden assumptions are a marking risk.

Finally, a note on consistency. The notes as a stitched document concatenate sources that may phrase or summarize the same algorithm differently. For numerical problems, it matters which exact statement you use — the one used in class to solve the worked example and the one summarized in the notes may differ in compression. When in doubt during examination practice, compare the slide version with the notes version for that algorithm, settle on one that is comfortable, and practice consistently with that version. Comfort with a chosen level of detail matters more than switching between variants.

Recap and bridge: This overview sorted the 191-page superset into a delivered syllabus, placed every upcoming topic on a single assumption-relaxation storyline with dynamic programming and temporal difference as persistent backbones, and distinguished two valid preparation styles. The next section begins the examinable technical material with the first post-midterm topic: off-policy Monte Carlo and the importance-sampling correction that makes learning from someone else's experience possible.

16.2 Off-Policy Monte Carlo Methods

16.2.1 What Off-Policy Learning Is and Why Importance Sampling Is Needed

Hook — a question that makes the difficulty visible: You have a log of a thousand episodes produced by an old, cautious warehouse robot that explores randomly 40% of the time. You have designed a new, much greedier policy you would like to deploy. Can you estimate how well the new policy would have performed without running it even once? Off-policy learning says yes — but only if you correct for the fact that you are averaging the wrong experience.

Off-policy learning separates the policy that generates data from the policy being learned about. The behaviour policy is the policy actually followed to produce episodes. The target policy is the policy whose value or we want to estimate or improve. In on-policy Monte Carlo control the two coincide; in off-policy Monte Carlo they are deliberately different.

Intuition and analogy — the movie critic: Imagine a critic who wants to predict how a particular audience (the target) would rate a film, but can only interview people who watched a different cut (the behaviour). If the two audiences differ in who they include, the critic must reweight each interview: an opinion from someone who would rarely be in the target audience counts less, an opinion from someone highly representative of the target counts more. The weight is the ratio of how likely that person-action is under the target versus the behaviour. Where the analogy breaks: In reinforcement learning the reweighting multiplies along a trajectory — each action choice contributes a factor — so the weight is a product, not a single opinion weight. A long trajectory can therefore become extremely light or extremely heavy.

Why off-policy matters. First, the exploration-exploitation dilemma: the behaviour policy can remain soft and exploratory to ensure every state-action pair is visited, while the target policy can be greedy or near-greedy and steadily move toward optimality. Second, data reuse: historical logs from an old recommender, a simulator, or a human demonstrator already exist and should be usable without fresh interaction. The price of this flexibility is that a return observed under has expectation , not . It is the wrong expectation and must be corrected.

Coverage — the assumption that makes correction possible: For off-policy prediction to be well-defined, the behaviour policy must give non-zero probability to every action the target might take. Formally, for every state and action : Here is a state in the finite state set , is an action in , is the target-policy probability of choosing in , and is the behaviour-policy probability. If can choose an action that never tries, no episode generated by can ever give evidence about that target action, and the correction ratio would require dividing by zero.

Visual intuition — picture two overlapping probability clouds over the same set of actions in a state. The behaviour cloud is broad and low (exploratory), the target cloud is peaked (greedy). The importance ratio at each action is the height of the target cloud divided by the height of the behaviour cloud at that point. Actions where the target peak towers above the behaviour cloud receive ratios larger than one; actions the target rarely takes receive ratios smaller than one. A trajectory that happens to follow the target peak throughout accumulates a large product and dominates the estimate.

Scope — when the correction applies and when it strains: The importance-sampling correction assumes episodic, finite-horizon tasks where returns are well-defined, the coverage assumption above holds, and we observe the behaviour-policy probabilities for every taken action. It does not require knowledge of transition dynamics , because those cancel from the ratio (shown in the next subsection). It strains when trajectories are long (the product of many ratios can explode or vanish), when is near-deterministic while is diffuse (ratios become huge for the rare matching trajectory), or when rewards are unbounded. In those regimes variance dominates and weighted variants are preferred.

Keeping the scope in mind, the next habit to build is recognizing the two most frequent mistakes students make when they first apply the correction on paper.

Pitfalls to avoid:

  • Forgetting coverage. Treating an action with as giving ratio zero is correct, but thinking it contributes "a small amount" is wrong — it contributes nothing, and earlier steps whose correction product includes that zero are truncated.
  • Mixing up ordinary and weighted averages. Dividing by the number of visits versus dividing by the sum of weights gives different estimates, different biases, and dramatically different variance. The examination will expect you to know which denominator you are using.
  • Reading the backward sweep forward. The accumulators and build backward from termination. Running them forward mixes up which suffix product belongs to which return.

In the broader field, off-policy Monte Carlo is the simplest instance of a pattern that recurs everywhere: in recommender systems a log from last year's ranker (behaviour) is reweighted to evaluate this year's candidate ranker (target); in healthcare, observational treatment decisions form the behaviour while a proposed protocol is the target. The tabular Monte Carlo instance taught here isolates the core statistical idea that those applied systems all build on.

Exam note: For this topic the essential examination material is the meaning of off-policy, the statement of the coverage assumption, the form of the per-step ratio and its product along a trajectory, and numerical practice with that product and its incremental backward accumulation. Statistical-behaviour derivations about bias and variance are background for understanding, not a source of difficult computation. Application pointers to papers are motivation, not detailed question sources.

16.2.2 Importance Sampling — Mathematical Formulation

Single-step correction — the importance-sampling ratio: For a state and the action actually taken at time , the per-step importance-sampling ratio is where is the target-policy probability of that action in that state, is the behaviour-policy probability, and both are evaluated at the realized pair . When would have chosen that action more often than did, ; when would have chosen it less often, . If the ratio is zero, flagging that this trajectory suffix is inconsistent with the target.

To see why a product appears, write the probability of a trajectory segment. Conditioned on the starting state , the probability under policy of the suffix is

where is the termination time of the episode, is the environment transition probability, and each factor gives the probability of the action choice times the resulting transition. The same segment under behaviour policy has probability

Dividing the two, every transition factor appears identically in numerator and denominator and cancels. The relative probability — the importance-sampling ratio for the segment — therefore depends only on policies, not on the unknown dynamics:

where is the last decision step before termination. This cancellation is why off-policy Monte Carlo can remain model-free: the agent never needs to know or estimate .

The correction property follows directly. Let be the discounted return from time , defined for episodic tasks as , where is the reward on the transition and is the discount factor (here is common for episodic Monte Carlo). Then weighting a -generated return by its segment ratio recovers the -expectation:

where is the expectation over trajectories generated by starting from , and is the true state value under . In words: expand the expectation as a sum over all possible trajectory segments, each trajectory's behaviour probability times its ratio leaves , so the sum becomes the target-policy expectation.

Two estimators — ordinary and weighted: Fix a state and collect all time steps visiting across a batch of episodes. Write for that set, for the return after , and for the ratio from to the termination time of the episode containing . Then is the ordinary importance-sampling (OIS) estimator: a simple average of importance-weighted returns, where is the number of visits to . It is unbiased for the first-visit variant (each first-visit weighted return has expectation ) but can have enormous or infinite variance because a few huge ratios dominate the average.

is the weighted importance-sampling (WIS) estimator: a weighted average normalized by the sum of weights (defined as zero when the denominator is zero). It is biased in finite samples because the denominator is random, but the bias vanishes asymptotically and the variance is usually far smaller — bounded by the range of returns when returns are bounded — so WIS is strongly preferred in practice.

Visual intuition for the variance difference — plot mean-squared error against number of episodes on a log horizontal axis. The OIS curve (weight-unnormalized) starts high and fluctuates wildly: a single trajectory that happens to match receives a huge ratio and pulls the average far above or below the truth. The WIS curve is smoother and lower early on because the same huge ratio appears in both numerator and denominator and partially cancels, keeping the estimate within the range of observed returns.

A classic one-state infinite-variance illustration clarifies the product structure. One non-terminal state has actions left and right. Target always chooses left; behaviour chooses left or right with probability . The left action loops back to with probability (reward ) or terminates with reward with probability ; right terminates immediately with reward . Under , every terminating trajectory has return and . For a trajectory with left-loops before termination the ratio is . The second moment becomes , a geometric series with ratio that diverges to infinity. The estimator is unbiased but its variance is infinite — rare trajectories receive astronomically large weights.

Scope — what to prioritize for the examination: You should be able to write the per-step ratio, form the product along any short trajectory, and compute both OIS and WIS from given and values. You should understand in words why the WIS denominator is random and why that creates finite-sample bias that decays with data. The formal infinite-variance derivation and discounting-aware or per-decision refinements are background — they explain why long episodes are problematic and how advanced methods help, but they are below the focus for computation.

16.2.3 Off-Policy Monte Carlo Prediction and Control — Algorithm

This subsection uses the procedural spine: purpose, inputs and outputs, steps, trace, and cost. The material singled out in class as requiring careful study is the algorithm underlying Section 8 of the off-policy Monte Carlo notes — the incremental weighted-importance-sampling prediction and its extension to control.

The algorithm has a clear purpose that motivates every later detail.

Purpose — what the incremental algorithm solves: The batch WIS formula needs all episodes in memory to form sums over . The incremental form processes episodes one at a time, sweeping backward, maintaining a running estimate that after each episode equals the batch WIS estimate so far. It is the practical bridge from the statistical formula to an episode-by-episode update loop that also underlies off-policy control.

With the purpose clear, the data the algorithm needs can be described precisely.

Inputs and outputs: Inputs are the target policy , the behaviour policy , a discount factor , a state-action value table initialized arbitrarily, and a cumulative-weight table initialized to zero. For control, the target policy is not fixed: it is defined as the greedy policy with respect to the current , updated after each backward step. The output after many episodes is an estimate (prediction) or with (control), learned from -generated episodes.

Symbols used below: is the state, action, reward at step ; is the termination time; is the return built backward as ; is the cumulative importance weight from the suffix already processed; is the sum of weights applied to so far.

With inputs defined, the backward scan that ties them together can be stated step by step.

Steps — the backward incremental loop: The algorithm generates one episode with and then scans it from the end to the beginning. At each step it accumulates the return, updates the weighted average for that state-action, improves the target policy greedily, and checks whether it can continue.

  1. Initialize arbitrarily for all ; set ; set the initial target with ties broken consistently.
  2. For each episode: choose as any soft policy that covers the current greedy ; generate a complete episode using .
  3. Set (return accumulator, built backward) and (suffix weight accumulator, starts as the empty product).
  4. Loop for (backward scan):
  • (a) — extend the return to include this step's reward.
  • (b) — add the current suffix weight to the denominator for this pair.
  • (c) — weighted incremental average: move the estimate a fraction toward the observed return .
  • (d) — improve the target policy greedily (control variant; in prediction stays fixed and this step is omitted).
  • (e) If then break the inner loop — the deterministic target would never have taken this action, so ; every earlier suffix ratio contains this zero factor and contributes nothing further.
  • (f) — extend the weight backward: since is deterministic greedy, for the actions that survived the break test, so the ratio simplifies to . In the prediction case with stochastic , the factor is .

Why the break condition appears: Once a non-greedy action is encountered going backward, the importance ratio for every earlier time includes a factor , making all earlier weights zero. There is no point updating earlier states in that episode for a deterministic target.

What the abstract loop does is clearest when traced over two concrete episodes.

Trace — two-episode line-world control: States with terminal exits. Action Exit at gives , at gives ; moves between and give . Behaviour chooses each with in ; discount .

Episode 1 generated by : .

Backward scan: At : , , . At : , , , , . At : , , , , . So after episode 1, .

Episode 2 generated by : .

At : , . At : , becomes , . Now , so remains . But the observed action at was , so the scan stops — no earlier update would be consistent with the greedy target. The target policy stays . Sense-check: The agent explored a poor left move; the off-policy update correctly learned that is bad without dragging the estimate for any still-earlier state down with it, because the break prevents contamination by target-inconsistent prefixes.

Complexity and cost — per episode the backward scan touches each step once: time and memory for the tables. The practical limit is variance: when non-greedy actions are common, many episodes break early and only short suffixes contribute, so early states learn slowly. This "learning from tails" phenomenon is the main motivation for moving from Monte Carlo to temporal-difference methods that can learn from every transition.

When to use this versus alternatives: Use off-policy Monte Carlo control when you have episodic logs, need a greedy target, and can tolerate high variance in exchange for conceptual simplicity and model-freedom. Prefer on-policy Monte Carlo or temporal-difference methods when episodes are long, variance from product ratios is severe, or you need online step-by-step updates before termination. Per-decision and discounting-aware variants reduce variance without changing the idea; temporal-difference learning (next section) removes the need for full-episode weights entirely.

A domain connection that fixes the idea: in a logged recommender, is last quarter's production ranker that generated clicks, is the candidate ranker you want to evaluate, and each slate's ratio reweights the observed click-through return. The tabular algorithm above is the textbook-scale version of that industrial counterfactual evaluation loop.

16.2.4 Worked Perspective on Importance Sampling Numerics

No single exhaustive numeric table was dictated in this session, but the preparation advice was explicit: work at least one small reweighting by hand until the product structure and the incremental backward perspective are automatic. Three compact exercises are provided below at increasing length.

Worked Example A — single three-step trajectory (the ratio product): A trajectory has states and actions : . Let . Then If the observed return from is , the ordinary importance-weighted return is . Interpretation: means this trajectory is more characteristic of the target than of the behaviour — a greedy-biased trajectory sampled by an exploratory behaviour — so its return is up-weighted.

Worked Example B — two returns, ordinary versus weighted: Two episodes starting from give and with (the long-trajectory example from the notes, six steps each). Then OIS is pulled far above both observed returns by the large weight on the first episode; WIS stays within the return range as a proper weighted average. Sense-check: Any WIS estimate with bounded returns must lie between the minimum and maximum observed returns — here between and — which does.

Worked Example C — incremental WIS update arriving weight by weight: Suppose weighted returns for a state arrive as , processed incrementally with using Step 1: . Step 2: . Step 3: . Batch check: , matching the incremental result. Sense-check: The final batch weighted average must equal the incremental value after the last arrival — a useful examination verification.

Pitfalls in numerics:

  • Multiplying discounts into the ratio. The product involves only policy probabilities, never transition probabilities or . Multiplying by powers of or by is a common error.
  • Applying the full ratio to a prefix reward. Plain OIS applies to the whole return . Attaching it only to the first reward underestimates the correction. (Per-decision variants deliberately refine this, but the base algorithm uses the full product — know which form the question asks for.)
  • Forgetting the break condition in control. Continuing the backward scan past a state where adds updates that should have weight zero, corrupting .

Recap and bridge: Off-policy Monte Carlo lets data from one policy speak about another by reweighting each trajectory with the product ; the transition dynamics cancel, the expectation is corrected, but the product's variance can dominate. OIS divides by visit count and is unbiased but volatile; WIS divides by total weight, is asymptotically unbiased and far more stable. The incremental backward algorithm with accumulators and makes the batch estimate online and extends directly to control with a greedy target and an early-exit break. The next section replaces full-episode products with a local, low-variance alternative: temporal-difference learning, which bootstraps from the next estimate instead of waiting for the final return.

16.3 Temporal-Difference Learning

16.3.1 Temporal Difference as the Best of Both Worlds

Hook — the question that motivates everything in this section: If you already know your current estimate is partly wrong, should you wait until the journey ends to correct it, or correct it immediately using your next estimate — even though that next estimate is also imperfect? Temporal-difference learning answers: correct it immediately, and do it in a way that keeps the best of both alternatives.

Temporal-difference learning was framed in class as the method that takes the best of dynamic programming and the best of Monte Carlo. From dynamic programming it borrows bootstrapping — the idea of updating an estimate on the basis of another estimate rather than waiting for the final outcome. From Monte Carlo it borrows sampling and model-freedom — the ability to learn directly from raw experience without requiring a complete model of transition probabilities .

Intuition and analogy — the hill hiker and the driving home story: Picture a hiker in fog who wants to know the height of the hilltop. Dynamic programming is like having a perfect contour map: you can compute the height of any point from the heights of its neighbours, but you need the whole map in advance. Monte Carlo is like walking all the way to the top every time and then averaging the measured heights — no map needed, but each measurement requires the full walk. Temporal difference is like the hiker who walks one step, looks at the new estimated height under her boots plus the step she just climbed, and immediately adjusts the previous height estimate. She still walks (sampling), she still uses estimates of what lies ahead (bootstrapping), but she learns after every step instead of every expedition.

A concrete story used in the textbook makes the same point for prediction. You estimate that driving home will take 30 minutes. After five minutes you see rain and revise the remaining time to 35 minutes, so your total estimate becomes 40. After another 15 minutes you revise again. A Monte Carlo learner waits until you are home and then corrects the original 30 toward the true 43. A TD learner corrects the 30 toward 40 immediately after the rain observation, and later corrects the 40 toward the next estimate. Where the analogy breaks: In reinforcement learning the "remaining time" is not just observed — it is itself a learned value that changes as learning proceeds, so the target moves while you chase it. That moving-target property is why step sizes and convergence conditions matter.

The conceptual comparison that was flagged as deceptively theoretical-looking but genuinely important is best seen as a table.

Dimension Dynamic Programming Monte Carlo Temporal Difference (one-step)
Needs a model Yes — needs full distribution No — learns from sampled episodes No — learns from sampled transitions
Bootstraps (updates an estimate from another estimate) Yes — No — waits for final return Yes —
When it can learn After a full sweep over states Only at episode end After every single transition
Bias / variance tendency Low variance, but model bias if model is wrong Unbiased, high variance (depends on full return) Biased (target depends on current estimate), lower variance than Monte Carlo
Typical use Planning with known model Episodic prediction and control without model Online prediction and control, continuing tasks, long episodes

When to pick which: Use dynamic programming when you have a trustworthy model and need exact sweeps. Use Monte Carlo when you have episodic data and want unbiased estimates without bootstrapping. Use temporal difference when you need online, incremental, model-free learning — especially for long or continuing tasks where waiting for termination is impractical.

Why the "best of both" claim is not just a slogan: Monte Carlo target is an unbiased sample of but has high variance because it sums many random rewards. Dynamic programming target has lower variance but requires the model expectation. Temporal difference replaces the unknown true value with the current estimate and replaces the model expectation with a single sample transition . The result is a model-free, single-step, bootstrapped target that trades a small bias for a large reduction in variance and wait time. Multi-step TD generalizes this trade-off over horizons before falling back to a learned estimate.

Visual intuition — imagine a spectrum drawn horizontally from "full model, full bootstrapping" on the left (dynamic programming) to "no model, no bootstrapping" on the right (Monte Carlo). Mark one-step TD just right of centre: it samples like Monte Carlo but bootstraps after one step like dynamic programming. Further to the right lie -step TD methods that sample rewards before bootstrapping; at they reach Monte Carlo. The diagram shows that all three families are points on one continuum, not separate islands. The professor's visual with exhaustive search at one extreme and TD at the most compact alternative conveys the same width-versus-depth trade-off: TD achieves the best blend.

Scope — when the one-step TD idea applies: The one-step TD prediction update described here assumes a Markov decision process with states , rewards , discount , and a fixed policy being evaluated. It applies to both episodic and continuing tasks. It does not require a model, but it does require that the value estimate be stored for every visited state (tabular case) or parametrized smoothly (function approximation, later section). It breaks down as a reliable estimator if the step size is too large or if the bootstrapped estimate is extremely inaccurate early in learning — the same moving-target issue noted above.

With the scope clear, the practical habits that prevent mistakes become important.

Pitfalls to avoid:

  • Treating TD as "just an approximation to Monte Carlo." It is not an approximation that will converge to the same finite-sample answer. Under batch updating, TD converges to the certainty-equivalence estimate (the value that would be correct if the maximum-likelihood model built from the data were the true environment), while Monte Carlo converges to the minimum mean-squared-error estimate on the training returns. They are answers to different questions.
  • Confusing bootstrapping with cheating. Learning a guess from a guess sounds circular, but the TD target contains fresh information — the real reward and the real next state — that the old estimate did not have. That is what makes the update informative.

In the broader field, one-step TD is the atomic operation inside virtually every modern reinforcement learning paper — from Q-learning to actor-critic to the value head of AlphaGo. Understanding the vocabulary "TD target" and "TD error" introduced here is therefore not just examinable; it is the shared language for reading any contemporary algorithm.

Recap and bridge: Temporal difference sits at the intersection of dynamic programming's bootstrapping and Monte Carlo's sampling, giving model-free, online, low-variance updates at the cost of a transient bias. The next subsection formalizes the two terms that carry that idea — the TD target and the TD error — and extends them to the -step case that will later connect this section to eligibility traces.

16.3.2 Mathematical Formulation — Targets, Errors and Updates

Starting from the Bellman identity makes the TD construction transparent.

The Bellman starting point: For a fixed policy , the true state value is the mean discounted return where is the return, the reward on transitioning , the discount factor, and the termination time. By splitting off the first reward, Here is the state at time , the next state, the immediate reward, and the expectation over the policy and the environment dynamics starting from . The Monte Carlo target estimates the first line by sampling ; the dynamic programming target uses the second line with a model expectation; the TD target samples the second line.

With the Bellman identity in hand, the TD target and error follow directly.

One-step TD target and TD error (tabular prediction): Let denote the current tabular estimate of , with . On observing the transition , define

  • the one-step TD target (also called the one-step return ):

  • the one-step TD error (the quantity universally called ):

Every symbol: is the immediate reward; is the scalar discount factor; is the current estimated value of the next state (defined as if is terminal); is the current estimated value of the current state; is a signed scalar that is positive when the transition turned out better than predicted and negative when it turned out worse. When function approximation is used, becomes parametrized by weight vector , but the form of target and error is identical.

The tabular one-step TD prediction update is then where is the step-size parameter. This is TD(0), the simplest TD method.

The relationship between Monte Carlo error and TD errors clarifies why TD is a decomposition of the same information. Assume for a moment that does not change during the episode (as in batch Monte Carlo). Then by expanding with the identity :

so that

where each is the TD error at step , and for the terminal state. In words: the Monte Carlo error (how far the full sampled return is from the current estimate) equals the discounted sum of one-step TD errors along the trajectory. When is updated online, the identity holds only approximately, with an additional correction for the changing ; the approximation is good when is small. This decomposition is the algebraic reason -step methods can interpolate between TD(0) and Monte Carlo.

Multi-step targets generalize the same idea over real rewards before bootstrapping. For and ,

with the convention when (the window reaches termination and no bootstrap is needed). Here is the reward steps after , the state steps ahead, and the current estimate there. The -step TD error is , and the -step TD update is

The choice recovers TD(0); as (or ) it recovers Monte Carlo. The backup diagram for -step TD is a chain of sampled states, rewards and bootstrapped value — the visual bridge between the one-step TD diagram (one sampled successor) and the Monte Carlo diagram (chain to termination).

For action values, the same construction applies with in place of . With function approximation, becomes and the gradient-based form appears; the semi-gradient subtlety — that the target's dependence on through is ignored when differentiating — belongs to the function-approximation section and is not needed for the tabular derivations here.

Scope — what the formulas assume: The identities above assume the Markov property (the future depends on the present state, not the full history), a well-defined discount , and tabular storage where each can be updated independently. They hold exactly for the batch viewpoint where is frozen during the expansion; online, they describe the direction of the update rather than an exact equality. Convergence of TD(0) to with probability 1 requires the usual stochastic-approximation step-size conditions (, ) and that every state is visited infinitely often — covered formally in later analysis.

Exam note: Be able to write down the one-step TD target , the TD error , and the multi-step target from memory, with every symbol defined. Expect to identify which a given update uses from its form, and to explain why TD(0) bootstraps while Monte Carlo does not. The derivation is the bridge to the next chapter and is worth being able to reproduce.

16.3.3 Worked Examples — Grid World, Random Walks and the Control Loop

This subsection follows the procedural spine: purpose, inputs and outputs, steps, trace, and cost.

Purpose — why worked examples are the core here: Prediction formulas are compact, but control is where students stumble. The grid-world running example and the random-walk extra problems exist to make the abstract loop — choose an action from , observe a transition, form a target, update one entry, and thereby change the policy — concrete and traceable cell by cell.

With that purpose in mind, the data that flow through one control step can be listed explicitly.

Inputs and outputs of one tabular control step: Inputs are a small grid world where each cell is a state , the set of movement actions (typically up, down, left, right), a reward function (for example per step, for reaching a goal, for an undesirable terminal), a discount , a step size , an exploration parameter , and the current action-value table for all state-action pairs with . Output is the single updated entry and, implicitly, the new -greedy policy at state derived from the updated .

Symbols: is the estimated mean return starting from , taking , then following the current policy; is the probability of exploring a non-greedy action; scales the incremental correction.

Once inputs and outputs are clear, the loop that uses them can be stated step by step.

Steps — the representative control loop as narrated in class:

  1. In state , choose action using the policy derived from the current . For -greedy: with probability pick (break ties arbitrarily but consistently); with probability pick uniformly among the non-greedy actions. Consulting all at that state is the entire policy.
  2. Execute , observe reward and next state .
  3. Form the algorithm-specific target:
  • SARSA: where is the action actually taken in under the same -greedy policy.
  • Q-learning: .
  • Mean SARSA: where is the current policy.

Compute and update .

  1. Because changed, the implied policy at automatically changes. Iterating this loop improves both and the policy it implies. No separate "policy update" statement is needed beyond the update — improving is improving the policy.

The phrase emphasized in class — "when I update the -value, I am updating the policy as well" — captures the tight coupling that surprises students who expect an explicit policy table.

Visual intuition — picture the grid with each cell containing a small table of four -values (one per action). An arrow in the cell points toward the greedy action (the largest ). One update changes a single number in one cell's table, which may flip the arrow in that cell. Over many episodes the arrows gradually swing toward the goal, carving a policy path through the grid. -greedy exploration occasionally forces a non-arrow action, which is how new cells get visited.

Worked trace — one step of the grid-world control loop with numbers: Consider a grid where position is the start, is a goal with reward on entry, every other move gives reward , , , . Suppose the current -values at the critical states are: and at the successor state :

SARSA trace: Policy at is -greedy; the greedy action is right (). Suppose exploration does not happen and is chosen. Executing right yields and . Now choose at -greedily — suppose the greedy action up () is chosen. SARSA target . Error . Update . After the update, the -values at become and the greedy arrow at now points to right still, but less strongly — the policy shifted because its underlying numbers did.

Q-learning on the same transition: Target as well (here the actually taken happened to be the maximizing action). If instead had been a non-greedy action, SARSA's target would have used that non-greedy while Q-learning would still use the max — the source of their different behaviour under persistent -greedy exploration, detailed in the next subsection.

Sense-check: Any update must move toward the target. Here was and the target estimate was , so the value correctly moves downward. If a trace moves a away from its target, the sign of was applied incorrectly.

The random-walk extra-practice problems are the prediction-side counterpart. The textbook five-state walk with start at , reward on terminating right and elsewhere, and undiscounted , has true values for the equiprobable random policy. Initializing for all and running TD(0) with , the estimates after 100 episodes closely approach the true values and converge faster in root mean-squared error than constant- Monte Carlo. Under batch updating, Monte Carlo converges to the sample-average returns (minimum squared error on the training set) while TD converges to the certainty-equivalence estimate — unbiased for the maximum-likelihood model of the Markov chain — which often predicts future data better.

Pitfalls in the control loop:

  • Storing a separate policy table unnecessarily. In tabular TD control the policy is the argmax of . Maintaining an independent policy array that you forget to update after changing creates an inconsistency that no longer matches what the algorithm does.
  • Forgetting the terminal condition. or is defined as when is terminal. Leaving the old value in place adds a phantom bootstrap.
  • Mixing up which the examination expects. The notes sometimes summarize a lengthy algorithm for space. For numerics, compare the slide version with the notes version and commit to the one used in the class worked example — they are conceptually identical but may differ in where -greedy action selection appears in the listing.

16.3.4 Three Tabular Control Algorithms — SARSA, Q-Learning and Expected SARSA

Each of the three algorithms should be recognizable on sight from its update target. The table below contrasts them on the dimensions that matter for understanding and for the examination.

Dimension SARSA (on-policy) Q-learning (off-policy) Expected SARSA
Full name / mnemonic State–Action–Reward–State–Action Expectation over next actions under
Update equation
Which next action does the target use? The action actually taken under the behaviour policy The greedy action regardless of what was taken The expected value over all next actions weighted by
On- versus off-policy (why) On-policy: evaluates and improves the same -greedy policy it follows, because the target contains the sampled Off-policy: learns values for the greedy policy while behaving -greedily, because the max decouples behaviour from target Can be either: on-policy when is the behaviour, off-policy when is a different target (then it generalizes Q-learning)
Variance of target Higher — depends on the random Lower target variance from max, but introduces maximization bias Lowest variance — averages over the randomness of
Behaviour under persistent -greedy exploration Learns the value of the exploratory policy; tends to find safer paths (accounts for the fact that exploration will happen) Learns the value of the greedy policy; can find the optimal path in value but may still stumble during online execution because it ignores exploration risk Retains SARSA's safety advantage with less variance; often outperforms both in cliff-walking experiments
Classic illustration Windy gridworld; safer cliff path Optimal cliff-edge path in value; poorer online return while Best interim and asymptotic performance on cliff walking at larger

When to pick which: Use SARSA when online safety under the actual exploratory behaviour matters — robotics with constraints, or any task where a random exploratory action can be costly. Use Q-learning (and its deep extension) when the goal is the optimal greedy value regardless of current exploration. Use Expected SARSA when you want SARSA-like safety with reduced variance, and can afford the small extra cost of summing over actions.

Formal definitions with symbols: In every equation below, is the state, the action, the reward, the next state, the current action-value estimate with , the step size, the discount, and the policy probability. For -greedy, for the greedy and otherwise.

  • SARSA target: where . The quintuple names the algorithm.
  • Q-learning target: . The max makes the update off-policy: the target is greedy even when behaviour is -greedy.
  • Expected SARSA target: . When is greedy this equals the Q-learning target; in general it is the expectation SARSA moves toward in mean.

Visual intuition — the backup diagrams tell the story at a glance. SARSA's diagram is a chain — a sample action node follows the sample state. Q-learning's diagram fans out from to all possible action nodes with an arc across them indicating the max — the target looks at the best branch regardless of which was taken. Expected SARSA's diagram is the same fan-out but weighted by — an average over branches rather than a max.

Worked comparison — same episode, different targets: States and are non-terminal, then terminal. From only action go leads to with reward . From two actions end the episode: safe gives , risky gives . Discount , step size . Current estimates: , , . Observed episode (due to -greedy exploration): , .

SARSA: Update uses the taken next action risky: target . New . Update : target , new . Interpretation: because exploration forced risky, SARSA pulls the value of go downward to reflect what actually happens under the behaviour.

Q-learning: Update uses the greedy next action at : target . New . Update is the same . Interpretation: Q-learning ignores the exploratory risky in the target and backs up the optimistic greedy continuation.

Expected SARSA (with , two actions): , if safe is greedy. Target for . New — between SARSA and Q-learning, with less variance than SARSA. Sense-check: Any Expected SARSA target must lie between the SARSA target (worst single sample) and the Q-learning target (best) when the same are used — here , which holds.

Pitfalls distinguishing the three:

  • Calling Q-learning "on-policy because it uses -greedy for action selection." Action selection is behaviour; the target's use of max is what makes it off-policy. Behaviour can be -greedy in all three algorithms — the difference is only in the target.
  • *Forgetting that Expected SARSA with a greedy is Q-learning.* When puts probability 1 on , the expectation collapses to the max. This is why the text says Expected SARSA subsumes Q-learning.
  • Using the wrong sum in Expected SARSA. The expectation is over next actions at weighted by , not over current actions. Summing over is a common transcription error.

16.3.5 Maximization Bias and Double Q-Learning

Hook — the statistical trap hidden inside the max: Suppose every action at a state is truly worthless — true value zero — but your estimates are noisy, some above zero, some below. If you take the maximum of those noisy estimates, will you get zero? No. You will get something positive, because the noise that happens to push an action upward is the noise that gets selected. Q-learning does exactly this on every update, and the bias accumulates.

Maximization bias — why the max is systematically optimistic: Consider a single state where many actions have true value but estimated values are uncertain, distributed around zero — some above, some below. The true maximum is . The estimated maximum is the largest of those noisy samples, which is almost surely positive. In general, , with equality only when the maximizer is known with certainty. Because Q-learning's target contains , this positive bias propagates: sampling noise makes the maximizing action look better than it truly is, Q-learning reinforces that optimism, and the agent can confidently prefer actions that are not in fact optimal — especially early in learning when estimates are noisiest. This is not a rare corner case; it is the reason Q-learning can be overoptimistic in stochastic environments.

A clean demonstration is the MDP used in the textbook. State has two actions: right goes directly to terminal with reward ; left goes to state with reward , from which many actions all terminate with reward drawn from — mean , variance . Any trajectory starting with left therefore has expected return , so left is always the wrong choice at . Yet Q-learning with -greedy (, , ) initially chooses left far more often than the 5\% minimum exploration rate, and even at asymptote takes left about more often than optimal. The cause is maximization bias at : among the many noisy actions, one will by chance have a large positive sample that the max selects.

Double Q-learning removes the bias by decoupling selection from evaluation. Two action-value functions and are maintained, each an independent estimate of . On each transition a coin is flipped: with probability update using to evaluate the action that selected, and otherwise the reverse.

Double Q-learning — algorithm: Initialize arbitrarily with . Behaviour is -greedy with respect to (average or sum). On each step :

  • With probability :

  • Otherwise:

Every symbol: are the two independent estimators; is the action considers best at (selection), provides its value (evaluation), and vice versa. Here is , is , is , is , the step size, the discount. Only one table is updated per step, so memory doubles but computation per step does not.

Because the action is selected using one noisy estimate and evaluated using an independent noisy estimate, the upward selection bias in the first is not reinforced by the second — the evaluation is unbiased in expectation for the selected action. Swapping roles keeps the two tables symmetric.

On the same MDP, Double Q-learning is essentially unaffected by maximization bias: the fraction of left actions from stays near the exploration floor, matching the optimal policy's preference for right. Analogous double versions exist for SARSA and Expected SARSA.

Scope — when Double Q-learning matters: The bias is most harmful when the action set at a state is large, rewards are stochastic, and early estimates are noisy — all conditions where the max has many candidates to be optimistic about. In near-deterministic, low-noise tasks the bias is small and single Q-learning works well. Double Q-learning does not change the on/off-policy character; it is a bias-reduction refinement that can be combined with any of the three algorithms above.

A domain connection: in financial trading, auction bidding, or any recommender where many actions have similar true values but noisy realized rewards, a vanilla Q-learner will systematically overvalue the apparent best action and may deploy it with misplaced confidence. Double estimators are used precisely to keep that optimism in check.

Exam note: Be able to explain in words why the max causes a systematic positive bias (same samples used to select and to evaluate) and how Double Q-learning fixes it by using one estimator to select and the other to evaluate. The MDP with Gaussian rewards at is the canonical illustration. You should also be able to write the Double Q-learning update with the selection and evaluation roles correctly assigned.

16.3.6 Student Questions and Answers on Temporal Difference

Q: How do I know what policy to use when the algorithm says "choose action from state using the policy derived from "? A: Look at the current -values for exactly that state . For each action available in there is a number . The greedy action is the with the largest ; with -greedy that greedy action is taken most of the time and a non-greedy action is explored with probability . Concretely, if is the number of actions and , then and for every other . Knowing the -values and knowing is sufficient to determine the full action-selection distribution — no additional policy object needs to be stored separately.

The next question shifts from how to select an action to what happens to the policy when values change.

Q: When I update , am I also updating the policy or is there a separate policy-update step? A: The update to is itself a policy update. Because the policy at is defined as the maximizer (or -soft maximizer) of , any change to immediately changes which action the derived policy prefers at , or with what probability. There is no separate "now update the policy" line in the SARSA or Q-learning pseudocode beyond the greedy improvement implied by the new . Iteratively improving entry by entry is how the policy improves — this tight coupling is why the class emphasized "when I update the -value, I am updating the policy as well."

A final practical question concerns which printed algorithm to trust when sources differ in length.

Q: The algorithm block in the notes for SARSA or Q-learning looks shorter than the one in the slides. Which one should I use for numerics? A: The notes sometimes summarize a lengthy algorithm for space — for example collapsing the -greedy selection or the terminal-state handling into fewer lines — because a fully expanded listing would be long. For solving problems, what matters is that the algorithm you actually apply matches the one used to produce the class worked example. Compare the notes version and the slides version for that algorithm, decide on one, and stay consistent when you solve examination-style numerics. The three targets — SARSA's sampled , Q-learning's , and Expected SARSA's — must be exactly as practiced, because the arithmetic depends on which target you use.

Recap and bridge: This section built the TD target and error , showed how the control loop turns a single update into a policy improvement, distinguished the three tabular control algorithms by their targets, and explained why the max in Q-learning creates a systematic overestimation that Double Q-learning removes by separating selection from evaluation. With tabular TD in hand, the next section asks what happens when the state space is too large for a table and the value function must be approximated — the step from tables to parametrized functions that leads toward deep methods.

16.4 On-Policy Prediction with Function Approximation

16.4.1 Why Function Approximation and the Textbook Summary Image

Hook — what if your table has more rows than atoms in the universe? Backgammon has about states, Go about , and a robot camera sees a new image every frame. A table that stores one number per state cannot even be allocated, let alone filled. How do you learn a value function when you can never visit most states?

Function approximation answers by replacing a separate table entry for every state with a single parametrized function that generalizes across states. Instead of with one independent parameter per , you maintain where with is a shared weight vector and is a feature representation of . Updating on one state changes the estimated value of many other states that share features — that is the entire point and the entire risk.

Intuition and analogy — painting a landscape with a small palette: Think of true values as a detailed landscape with a height at every location. Tabular learning is like setting the height of each location independently with a separate peg — exact but impossible when there are billions of locations. Function approximation is like painting the landscape with a limited set of brush strokes (the features) blended by adjustable weights. One brush stroke affects a region, not a single point, so you can paint the whole landscape quickly, but you can never match every bump exactly. The question becomes: which regions should match best? That weighting is the state distribution introduced below. Where the analogy breaks: A painter can add more colors freely; an approximator with fixed has a permanent capacity limit, and the interaction of bootstrapping, off-policy data, and approximation can even cause divergence — a painting never diverges no matter how you mix.

The textbook image reproduced in both the slides and the notes makes the same point from the search perspective. Picture a two-dimensional trade-off diagram.

Visual intuition — imagine a square whose horizontal axis is breadth (how many actions you sample at a frontier) and vertical axis is depth (how far you follow a trajectory before evaluating). The bottom-right corner is exhaustive search — the full tree expansion familiar from classical AI search where every branch is enumerated to terminal depth. The top-left corner is one-step temporal-difference learning — the most compact alternative that samples one action, observes one reward, and bootstraps immediately. The two interior quadrants prioritize breadth-first sampling versus depth-first rollout. Temporal-difference achieves the best blend: it samples like Monte Carlo but bootstraps like dynamic programming, sitting closest to the ideal of low computation per update and rapid propagation of information. The professor highlights this image because it connects the classical search intuition from the earlier AI course to the compact backup used throughout reinforcement learning.

Scope — when the on-policy prediction formulation applies: The objective and algorithms in this section assume on-policy data — states are encountered by following the same policy whose value is being estimated, and the state-weighting is the on-policy distribution (stationary distribution for continuing tasks, normalized visitation frequency for episodic tasks). The approximator must be differentiable in . State features are assumed given. The theory in this section does not guarantee convergence for off-policy bootstrapping with approximation — that failure mode belongs to the next chapter's divergence examples.

That scope sets up the practical mistakes that follow — misreading the image or misjudging feature capacity can cost more than a missed derivation.

Pitfalls to avoid:

  • Assuming "more features always helps." With linear methods, too many overlapping features can make the matrix in the TD fixed-point analysis ill-conditioned; with nonlinear networks, too much capacity invites overfitting to recent experience and poor generalization to unseen states.
  • Forgetting that the image is a conceptual map, not a performance ranking. Exhaustive search is not "worse" in principle — it is exact when feasible. Temporal-difference is not "better" universally — it is the most data-efficient trade-off when the model is unknown or the state space is huge.

Recap and bridge: Function approximation is forced by large state spaces and works by sharing parameters across states via features. The summary image places every method on a breadth-versus-depth spectrum, with temporal-difference at the most compact, best-blended point. The next subsection makes that sharing concrete — first in the linear form used for all class numerics, then as a stand-in for deep networks.

16.4.2 Approximation Architecture — Linear and Non-Linear Forms

Linear value approximation — the workhorse of every class numeric: For a state with feature vector and weight vector , Here is the feature vector (each is one feature's response at ), is the weight vector learned by the algorithm, and is the scalar approximate value. A constant bias term is included by adding a feature so that acts as an intercept. The gradient that will drive learning is exceptionally simple in the linear case: That is, each weight's influence is exactly its feature's activation.

Why does the course use this form almost exclusively in numerics even though the field has moved to deep networks? The professor's answer is direct: linearity is a pedagogical stand-in. Everywhere the notes write you may substitute a neural network that maps the same feature vector through one or more hidden layers with nonlinear activations to a scalar output. The deep case, the shallow nonlinear case, and the linear case share the same prediction objective and the same gradient-descent template; only the mapping and its gradient change.

In the linear case the function class is a -dimensional hyperplane over feature space, which makes convergence analysis tractable and lets a single numeric be worked with pen and paper. In the nonlinear case the function class is far richer — a one-hidden-layer sigmoid network can approximate any continuous function on a compact region, and a deep convolutional network can learn hierarchical features end-to-end — but the same weight-update line applies, now with computed by backpropagation rather than read off as .

Visual intuition — picture feature space as a gallery of detectors: one detector fires for "left side of room," another for "near the goal," another for "high velocity." A state lights up a pattern of detectors; the value is the weighted vote of the lit detectors. Tile coding makes those detectors square tiles; radial basis functions make them soft Gaussian bumps; a deep network learns what detectors to build in its hidden layers.

Scope — linearity as a teaching device, not a restriction: The linear exposition is not a claim that linear models are sufficient in practice. It is the clearest vehicle for teaching the objective, the semi-gradient distinction, and the feature-construction ideas. When an examination problem says "assume ", it is specifying the arithmetic to use, not restricting the concept to that form. If a problem instead says "a neural network approximator," the same conceptual steps apply with in place of .

Exam note: Know the linear form by heart and know that its gradient is the feature vector. Then rehearse the sentence: "wherever the notes write , a neural network may be substituted without changing the conceptual structure." That single sentence closes the gap between the examination arithmetic and the deployed deep systems.

16.4.3 Prediction Objective — Mean Squared Value Error — and Gradient Descent

Hook — what should "good" mean when you cannot be good everywhere? With a table you can eventually match every true value exactly. With approximation you have far fewer weights than states (), so improving the estimate at one state inevitably worsens it at another. You must declare which states matter most before you can say what learning should minimize.

The declaration is a state distribution with that weights how much the squared error at each state counts.

Mean Squared Value Error (MSVE) — the prediction objective: Let be the true value of state under policy (the expected discounted return from ), the approximate value with weights , and the state-weighting distribution. Then Here ranges over states, is fixed (unknown to the learner), varies with , and averages squared error according to how often each state matters. The root MSVE is often plotted as a more interpretable scale. Under on-policy training, is the on-policy distribution: the stationary distribution under for continuing tasks, or the normalized expected visitation frequency for episodic tasks. In practice the expectation is sampled — on each visit to a state you incur squared error weighted implicitly by how often you visit .

A sampled stochastic form often written in notes is where is the return sampled from as an unbiased replacement for , and the factor is a convenience that cancels the from differentiation. Different texts omit or include the ; the concept — squared error averaged over the on-policy visitation — is what matters.

With an objective defined, the optimizer is gradient descent, and in reinforcement learning specifically stochastic gradient descent (SGD). The reason is not just computational convenience but the nature of the data: experience arrives as a stream of states, targets are nonstationary (they depend on the current weights when bootstrapping), and waiting to collect a full batch before updating would waste data and react slowly to a changing policy.

Stochastic-gradient and semi-gradient updates: Let be an update target for the visited state — for example the Monte Carlo return or the one-step TD target . With step size , the general SGD prediction update is Here is the weight vector before the update, is a scalar error (how far the target is from the current estimate), points in the direction that would most increase the estimate at , and scales the step. In the linear case this becomes the especially simple

True gradient versus semi-gradient: When (Monte Carlo), does not depend on — it is a sample return — so the update is a true stochastic gradient of the MSVE. When (one-step temporal difference), does depend on through , but the standard derivation ignores that dependence and treats the target as if it were fixed when differentiating. Because only part of the gradient is included, it is called a semi-gradient method. Concretely, the true gradient of would contain a term ; semi-gradient TD(0) drops that term and keeps only . The resulting temporal-difference error is therefore the error that drives the semi-gradient update .

Two pairings of optimizer and estimator were flagged as "certainly know" material: Monte Carlo gradient-based prediction (true gradient, unbiased target, higher variance, must wait to episode end) and semi-gradient TD(0) (biased target due to bootstrapping, lower variance, online after every step). Structurally they look identical — both are — but the error they use is the entire distinction. Under linear function approximation and on-policy sampling, gradient Monte Carlo converges to the global minimum of the MSVE, while semi-gradient TD(0) converges to a nearby fixed point whose MSVE is within a bounded expansion of the optimum — a subtlety captured formally by the bound in the continuing case.

Visual intuition — imagine descending a bowl (the MSVE surface) by taking steps in the direction that most reduces error at the current state. True-gradient Monte Carlo steps point toward the bowl's bottom. Semi-gradient TD steps point toward a slightly shifted aim — toward where the bowl would be if the bootstrap target were nailed down — so they converge quickly but not quite to the same point.

Assumptions and scope: SGD convergence assumes small or decreasing according to stochastic-approximation conditions and that states are sampled according to . Semi-gradient TD guarantees hold for the on-policy distribution with linear approximation; switching to an off-policy distribution or to nonlinear approximation without additional machinery can cause divergence. The expectation in the MSVE is not over a fixed dataset — it shifts as the policy or the weights change, which is why full-batch gradient descent is poorly suited and SGD's incremental sampling is preferred.

That distinction also creates the most frequent beginner mistakes — getting the names and roles of the error terms wrong.

Pitfalls to avoid:

  • Calling semi-gradient TD "gradient descent." It is not — it ignores the target's dependence on . That omission is why it can be combined with bootstrapping while true gradient methods cannot without additional corrections.
  • Confusing the two roles of . In the episodic return and the TD target, discounts future rewards. In the SGD step it has no relation to ; they are separate scalars that happen to multiply in the update.
  • Forgetting that defines "good." Under weighted MSVE, an approximator that is excellent on frequently visited states and poor on rare states is considered better than one with the reverse property — the objective bakes in the visitation frequency.

Worked example — one SGD step with linear approximation: Consider two states with features , and current weights , so , . Let , .

Monte Carlo step: Visit , observe return . Error . Update . Only the first component moves because only the first feature was active.

Semi-gradient TD(0) step: Visit , observe transition with . TD target . TD error . Update . The bootstrap target was smaller than the Monte Carlo return, so the weight moves less. Sense-check: In both cases the weight for the active feature moves toward the target — positive error increases the weight, negative error would decrease it — and inactive features do not move.

Recap and bridge: The prediction objective is MSVE weighted by the on-policy distribution; SGD is the optimizer suited to streaming, nonstationary reinforcement-learning data; the same SGD template yields true-gradient Monte Carlo and semi-gradient TD depending on the target, and that target choice is the key conceptual distinction. With the objective and optimizer in hand, the remaining design choice is how to build the features that the approximator consumes.

16.4.4 Feature Construction — Coarse Coding, Tile Coding and Radial Basis Functions

Feature construction is how raw states — positions, velocities, pixels — are mapped to the vectors that the linear approximator blends. Three classical families illustrate the spectrum from binary to smooth representations.

Coarse coding groups states into overlapping receptive fields — for example intervals on a line or circles in a plane — and represents a state by the set of fields covering it. Each field is a binary feature (1 if the state lies inside, 0 otherwise). Generalization is controlled by overlap width: wide fields make nearby states share many active features and generalize broadly; narrow fields share few and discriminate finely. The textbook's illustration of overlapping circles of three sizes shows that different overlap widths change the shape of generalization but, with enough fields, the asymptotic accuracy can still be fine-grained — breadth of generalization and fineness of approximation are partly separable when coverage is dense.

Tile coding is the computationally efficient form of coarse coding for modern digital computers. Each tiling is a partition of the state space into non-overlapping tiles (often squares or rectangles in two dimensions). A state activates exactly one tile per tiling. Multiple tilings, each offset by a fraction of a tile width, together give coarse coding: a state activates one feature per tiling, so total active features equals number of tilings (for example four tilings produce four active features out of perhaps ). Because every state activates the same number of features, the step size can be set intuitively — for example gives one-step convergence on a single example. Tile coding gains efficiency from binary features ( is just the sum of weights of active tiles) and from a hashing trick that collapses large tilings into compact memory. Irregular tilings, stripe tilings, and multi-resolution tilings let the designer inject prior knowledge about which dimensions should generalize together.

Radial basis functions (RBFs) generalize coarse coding to continuous-valued features. Rather than 0 or 1, each feature responds with a graded activation that decays with distance to a centre : where is the centre of the -th RBF, controls its width, and is a distance metric chosen for the task. Gaussian RBFs produce smooth, differentiable approximate value functions, whereas tile coding produces piecewise-constant ones. Learning can also adjust and , which moves the approximator into the nonlinear regime.

Visual intuition — coarse coding is like overlapping spotlights on a stage: where spotlights overlap the light is strongest; tile coding is like stacking several transparent grids offset by half a square — the exact combination of squares covering a point encodes its position; RBFs are like heat sources — each source warms its neighborhood smoothly, strongest at its centre, fading with distance.

Scope — what the notes versus the textbook cover: Class time on feature construction was deliberately kept to what is needed for the examination — the classical families above at the level illustrated in the slides. The notes contain a more expanded survey that includes deep-learning-based feature extraction (for example convolutional layers that learn from pixels). For examination preparation, follow the level of detail established in class and prioritize the textbook and slides over the notes for this block. The reason is not that the notes are wrong but that they intentionally compress classical methods and expand deep-learning feature extraction to serve both the current offering and a planned future emphasis where early material would be compressed. For post-course study, the notes' expanded deep-learning survey is the recommended next reading.

With scope clear, the two most common mistakes are easy to name — treating features as neutral and confusing one tiling with coarse coding.

Pitfalls to avoid:

  • Treating feature design as neutral. The choice of tilings or RBF centres injects strong inductive bias. Poorly chosen features can make even a perfectly optimized linear approximator incapable of representing the true value function — no amount of SGD tuning can fix a representational limitation.
  • Forgetting that tile-coding features are binary and conjunctive. A single tiling is just state aggregation (one active feature). Coarse coding only appears when multiple offset tilings are used together.

In the broader field, feature construction is the bridge between raw sensor data and value prediction. Every deployed system that values states — from a warehouse robot estimating time-to-goal from lidar features to a game agent estimating win probability from board features — makes a feature-construction choice before any weight is learned. Deep networks automate part of this choice by learning features end-to-end, but the classical families remain the clearest way to reason about generalization.

Recap and bridge: Coarse coding gives intuition, tile coding gives efficiency, and RBFs give smoothness — all three map raw states to vectors that linear weights blend. With architecture, objective, optimizer, and features established, the on-policy prediction loop with approximation is complete, and the section closes with the question students most often ask about the linear form itself.

16.4.5 Student Questions and Answers on Approximation

Q: If everything in the exercises is linear , does that mean approximation only works for linear models? A: No — linearity is a pedagogical stand-in, not a restriction. Everywhere the notes write you may substitute a neural network that maps to a scalar value, for example a one-hidden-layer network or a deep convolutional stack for pixel inputs. The approximation property that matters — that different states share parameters and therefore generalize — holds for linear and nonlinear parametrizations alike, and the same MSVE objective and SGD template apply with in place of . The linear case is used in class because it makes the arithmetic tractable and the generalization mechanism visible; the notes deliberately retain it as the clearest teaching vehicle, with the understanding that a network can replace the linear form wherever it appears.

The underlying doubt is natural: when every worked calculation multiplies a weight vector by a feature vector, it looks as if the theory depends on that multiplication. It does not. The theory depends on differentiability and on sharing parameters across states — both properties hold for deep networks, whose expressive power strictly contains the linear class.

Recap and bridge: This section established why large state spaces force approximation, how linear approximation and its deep-network substitution share the same MSVE objective and SGD machinery distinguished by true versus semi-gradient errors, and how feature construction controls generalization. The next section applies the same function-approximation machinery to control — replacing tabular with a deep network that approximates optimal action values from high-dimensional inputs.

16.5 Deep Q-Networks

16.5.1 How Deep Learning Helps Q-Learning

Hook — what changes when the board becomes a photograph? Tabular Q-learning stores one number for every pair and updates it from one transition. An Atari frame is numbers changing 60 times per second. No table can list those states, and two successive frames differ by a handful of pixels — updating one table entry teaches almost nothing about the next frame. How does the same temporal-difference control loop survive when the state is an image?

The answer is to keep the control loop and replace the table with a learned function that generalizes across images.

Deep Q-Network — definition and scope: For a discrete action set and a state representation (for example a stack of four grayscale frames), a Deep Q-Network parametrizes the action-value function as where collects all network weights. The network takes as input and outputs a vector with one entry per action. The optimal value is the maximum expected discounted return with discount . The DQN architecture that realizes this mapping in the 2015 Nature paper is a convolutional stack: input , first hidden layer 32 filters stride 4 with rectifier, second layer 64 filters stride 2, third layer 64 filters stride 1, followed by a fully connected layer of 512 rectifier units, then a linear output layer with one unit per action. Earlier 2013 variants used two convolutional layers and 256 hidden units; every element of the 2013 design is contained in the 2015 design, so studying the 2015 version subsumes the 2013 version.

Every symbol: is the (possibly history-based) state, a discrete action, the vector of network weights, the predicted action value, the optimal value, the number of actions, the discount, and the loss below averages over a behaviour distribution over states and actions encountered during training.

With that mapping, the temporal-difference machinery carries over with one architectural change — a single forward pass now produces all values at once, whereas a history-action network that concatenates as input would need forward passes.

Bellman target, loss, and gradient for DQN: The optimal action-value function satisfies the Bellman optimality equation where denotes the environment dynamics that generates next state and reward from . DQN turns this identity into an iterative regression. At iteration with frozen target weights , define the target and the loss Differentiating gives the gradient used for stochastic updates, In the practical minibatch form, the outer expectations are replaced by samples and a single gradient step is taken. The 2015 DQN stabilizes this further with two engineering choices: an experience replay buffer that supplies from many past policies, and a target network with parameters that are copied from only every steps, so that uses rather than and does not chase a target that moves on every gradient step.

Visual intuition — picture the tabular backup as updating one isolated cell in a giant spreadsheet. The DQN backup is pulling a rope attached to many cells at once: the network's shared weights mean that moving toward for a single sampled nudges the values of visually similar states in the same direction. The convolutional filters are what define "visually similar" — they learn to detect paddles, balls, and enemies directly from reward, rather than relying on hand-crafted colour channels or background subtraction used in pre-DQN Atari work.

Class time devoted more than one full lecture to this question precisely because the idea is simple but the reason it works is not. All architecture details, discount values, network sizes, and training schedules are provided open-book; the assessment tests whether you can explain the role of each component, not whether you can recite its number.

Scope — what "DQN" means for this examination: Study the 2015 Nature/Atari DQN with experience replay and a periodically updated target network. The 2013 NIPS workshop version is subsumed by it and need not be studied separately. Double DQN is the one-line change that selects the maximizing action with the online network and evaluates it with the target network — know that it addresses the overestimation caused by the in the target. No paper year, layer count, or hyperparameter needs to be memorized.

The scope above implies concrete mistakes that follow — mischaracterizing DQN as on-policy or misjudging its architecture.

Pitfalls to avoid:

  • Calling DQN on-policy because its behaviour is -greedy. The learning target uses regardless of which action was actually taken next, so the value being learned is for the greedy policy even while data are gathered -greedily — that decoupling is what makes DQN off-policy and what licenses replay.
  • Assuming a separate forward pass per action. With the architecture, one forward pass returns all action values. The older history-action architecture that inputs jointly is not the DQN evaluated here.

In the broader field, this single change — as a deep convolutional mapping from pixels — bridged high-dimensional vision and sequential decision making for the first time at scale, demonstrating one network, one algorithm, and one hyperparameter set succeeding across 49 Atari games from raw pixels and score alone. That demonstration re-ignited the combination of deep learning and reinforcement learning after earlier divergence concerns with nonlinear approximators.

Recap and bridge: Deep Q-Networks keep the Q-learning temporal-difference target but replace the table with that outputs all action values from one state in a single forward pass, trained against a periodically frozen target via squared-error regression. The component that makes that regression stable and data-efficient is experience replay, which is the deepest examinable point and the focus of the next subsection.

16.5.2 Experience Replay — Purpose Beyond the Three Bullet Points

Hook — why would you ever throw away a hard-won transition after using it once? In tabular Monte Carlo you must — the return after that state will be different next time you visit it. With a deep network each gradient step is tiny, and a single transition can still teach the network after the first pass. Insisting on learning on-policy discards that opportunity and forces the optimizer to learn from a correlated, shifting stream.

Three textbook phrases — reuse, decorrelation, distribution smoothing — name the purposes, but the examination asks you to reason beyond the phrases.

Experience replay — mechanism: Each environment step produces a transition , where is the state, the action taken, the reward, and the next state, with a flag for terminal . A replay buffer stores the last transitions pooled over many episodes, typically frames in the Atari experiments, and overwrites the oldest when full. Training draws minibatches of size 32 uniformly at random, , and for each element computes and a gradient step on . Because samples come from many past policies, the update is off-policy by necessity — the current differs from the that generated most of the buffer.

Every symbol: is the buffer, its capacity, the online weights, the target weights frozen between copies, the discount, and the uniform distribution over stored transitions.

Reuse, decorrelation, and smoothing each repair a distinct weakness of the naive online stream.

Reuse means a transition survives beyond its creation step and contributes to many gradient updates. With function approximation the gradient only conveys reliable direction in a small neighbourhood of the current ; a transition whose target error is large may need many small steps to be fully exploited. Reusing it amortizes the cost of gathering it — important when data are generated by slow environment interaction rather than by cheap dataset iteration. The uniform minibatch of 32 from a million-entry buffer typically contains experience from dozens of episodes and many stages of learning.

Decorrelation means random sampling breaks the strong temporal correlation of consecutive frames. Successive Atari frames differ by a few pixels; consecutive transitions and share almost the same image and produce almost the same gradient. Training on them in order feeds the optimizer a sequence of nearly identical directions, violating the independent-samples assumption behind stochastic gradient descent and inflating variance. Shuffling through restores an approximately independent and identically distributed stream and therefore reduces the variance of updates. Without it, a modern optimizer can oscillate or diverge even on simple games.

Distribution smoothing means averaging over the buffer smooths the non-stationary, non-uniform distribution of states that a single episode or a single policy phase induces. Early in training the buffer is filled with poor play; later it contains expert play; at any fixed time a single episode visits only a narrow slice of the state space. Sampling from mixes those phases and slices, producing a more stationary and better-covering training distribution that averages over many previous behaviours. That averaging prevents the feedback loop where the current policy's preference for "move left" biases the training distribution toward the left side of the screen, which then reinforces moving left even when the policy would otherwise change.

The class exhortation is to be able to argue these effects for a new scenario: replay helps most when data are precious, frames are visually correlated, and the state distribution shifts as the policy improves — all true for Atari. It would help less if transitions were already independent random draws from a fixed distribution and data were free.

Visual intuition — imagine the online trajectory as a narrow, winding river that cuts one groove through state space. Each gradient step digs that groove deeper. Replay is a reservoir that collects water from many rivers cut at different times; drawing buckets uniformly from the reservoir irrigates the whole plain rather than deepening a single trench.

Scope — assumptions and limits: Replay assumes discrete actions where is computed by enumeration; it is not directly applicable to continuous actions without a different maximization method. The buffer does not differentiate important transitions — uniform sampling gives equal importance to all stored experience, and finite capacity means older transitions are eventually overwritten. A more sophisticated variant prioritizes transitions with larger temporal-difference error, but uniform replay is the examinable base.

Given that scope, three misconceptions tend to follow — reciting phrases without mechanism, expecting replay to cure all instability, and forgetting it forces off-policy learning.

Pitfalls to avoid:

  • Reciting the three phrases without the mechanism. "Reuse, decorrelation, smoothing" earns little without being able to name the stored tuple , the buffer size and minibatch size, and why consecutive samples violate the independent-samples assumption.
  • Treating replay as a cure for all instability. Replay smooths the behaviour distribution but does not by itself remove correlation between and its target ; that second correlation is what the frozen target network addresses. The learning curves in the DQN Nature paper show divergence when replay or the target network is removed.
  • Forgetting that replay forces off-policy learning. Because the buffer contains data from past policies, the learned must be for the greedy policy defined by the current , not for the behaviour distribution — which is why the target uses rather than the action actually taken next.

In production, replay is the template for every value-based agent that learns from high-dimensional observations — from game agents that bank millions of frames to robotics stacks that bank real-world transitions because robot time is expensive and correlated.

Exam note: Be ready to explain, for any scenario, which of the three purposes would or would not help and what would go wrong without replay — mere recitation of the three bullet points is not the standard. That reasoning is also how you should read the learning-curve figure that plots average score (noisy) versus average predicted (smoother) over training epochs.

16.5.3 Worked Example — Scope and Limits

Worked forward computation — putting numbers into the DQN expressions: Consider a tiny DQN that flattens a single -pixel state and uses a one-hidden-layer network with two hidden rectifier units and two discrete actions. Let weights be , bias , and output weights , . The forward pass is:

Hidden pre-activation: . Rectifier .

Outputs: . So , ; the greedy action is .

Now sample a transition where for the target network predicts . With , the DQN target for this non-terminal transition is . If the target network is the same as the online network in this tiny example (no lag), the squared error for the taken action is , and the gradient step moves to reduce that gap via . With experience replay this same transition would be sampled again in later minibatches, contributing to many such steps.

Sense-check: The target exceeds either because it adds the immediate reward plus discounted optimistic next value; the loss is positive and larger when the network underestimates the return, which is the typical early-training case.

The pedagogical role of the textbook's own DQN numeric was qualified in class: it puts numbers into the expressions above and carries one forward computation to a result, but it does not by itself convey deep insight beyond confirming that the expressions can be evaluated mechanically. Once the concepts — what represents, why is the target, why a frozen stabilizes it, and why sampling from is required — are understood, the arithmetic follows without surprise. That is why the examination rewards conceptual reasoning over numeric substitution here.

Scope — what not to spend time on: For Deep Q-Networks, material from Section 10 onward in the DQN notes — extended surveys of individual games as solved by DQN — can be ignored for examination preparation. Those sections are examples for curiosity, not examinable content. Section 13 of the DQN notes is labelled as an ambition for the next offering; it was not delivered in class, is not part of this assessment, and should be assumed out of scope. The discussion of bias in DQN in that later section is therefore also out of scope.

Recap and bridge: How deep learning helps Q-learning is the mapping that scales temporal-difference control to images; why experience replay matters is the triple effect of reuse, decorrelation, and distribution smoothing that makes stochastic gradient descent on that mapping stable; how the numeric works is a forward pass producing all values, a target , and a squared-error step sampled from replay. With value-based deep control established, the next section switches families to directly parametrizing and improving a stochastic policy for continuous control.

16.6 Policy Gradient Methods and the Lane-Keeping Control Problem

16.6.1 Policy Gradient Theorem — Statement, Intuition and What to Skip

Hook — what if you stopped learning values and learned the driving itself? Value-based methods learn how good each lane position is and then derive steering from those values. Policy-gradient methods skip the middleman: they directly adjust the steering distribution so that good steers become more probable and bad steers become less probable, guided by the return those steers actually produced.

That direct parametrization is the shift in viewpoint. Two networks were shown side by side in class to make it tangible.

Intuition and analogy — the coach who only moves the mean: Imagine a coach who controls a dart thrower whose throws scatter around an aim point with a fixed spread. The coach cannot change the scatter, only the aim. After each throw the coach sees where the dart landed and whether it scored. If a throw slightly left of aim still scored well because the target was left, the coach nudges the aim a little left — "keep more of that direction." Over many throws the aim drifts toward the region that scores. Policy-gradient learning is that coach: the aim is , the scatter is , and the score is the return . Where the analogy breaks: In dart throwing the score depends only on where the dart lands; in reinforcement learning the score depends on the whole future trajectory, so the credit for a good outcome must be assigned to every action in the episode, not just the last throw — hence the weighting that discounts later steps when viewed from the start.

With that picture, the theorem that makes the update principled can be stated cleanly.

Policy gradient theorem — examinable statement (proof not required): Let be a stochastic policy differentiable in , let be the expected discounted return over trajectories , and let be the state distribution and the action-value under . Then Here is the policy parameter vector, the probability (or density) of action in state , its logarithmic logarithm, the score-function gradient, and the expected return from that state-action. In the REINFORCE instantiation the expectation over is replaced by a single sampled return from the episode, giving the sampled gradient .

A useful equivalent form collects the time steps: The textbook and the slides differ only in whether the per-step discount is written explicitly outside the sum or absorbed into ; both are the same estimator.

Visual intuition — picture two adjacent training loops. The value network loop predicts , compares to a target , computes squared error, and backpropagates mean-squared error. The policy network loop samples an action , observes the downstream return , and nudges in the direction scaled by . One loop minimizes prediction error; the other follows the gradient of expected return. That is why class asked "which network should use the policy-gradient theorem and which should use gradient descent on mean-squared error" — the value head uses the second, the policy head uses the first.

Scope — when the theorem applies and what was flagged to skip: The theorem assumes a Markov decision process with states , actions , rewards , discount , a stochastic policy that is differentiable in , and the ability to sample trajectories under (on-policy). It holds for both discrete and continuous actions and for episodic and continuing tasks with appropriate . The statement and the ability to use it to derive REINFORCE, baseline, and actor-critic updates are examinable. The proof of the theorem does not appear in the notes and is explicitly not examinable. For post-examination study the book Grokking Deep Reinforcement Learning was recommended because its proof is accessible, but that pointer is not part of the examinable material.

That scope distinction causes two recurring mistakes — mixing the two losses and studying the proof for credit that does not exist.

Pitfalls to avoid:

  • Confusing the value-network loss with the policy objective. Minimizing learns a value; maximizing via learns a policy. Swapping their gradients is a common transcription error — the policy update never contains a squared error, and the value update never contains .
  • Treating the proof as required. Spending examination time reconstructing the proof trades points for no credit. Know the implication — that sampling an action and weighting by return yields an unbiased gradient estimate — and move on to using it.

Recap and bridge: Policy-gradient methods follow via the score function weighted by return or advantage, rather than deriving a policy from values. The theorem statement above is the contract; the next subsection turns it into the concrete REINFORCE algorithm and derives the log-derivative trick that makes it computable. Exam note: Be able to write the theorem, name every symbol, and explain that sampling and scaling by estimates the true gradient.

16.6.2 REINFORCE — Algorithm and Update in Words and Mathematics

Purpose — the Monte Carlo policy gradient: REINFORCE generates an episode under the current policy, computes the return from each visited state, and moves in the direction that would make the actions actually taken more likely in proportion to how good their consequences turned out to be. It is Monte Carlo because each is the full sampled return, not a bootstrapped estimate.

With that purpose clear, the concrete mathematics that realizes it can be stated without ambiguity.

REINFORCE update — mathematics: With differentiable policy , step size , discount , and an episode where is the state at time , the action, the immediate reward, and the termination time, the textbook REINFORCE processes the episode as

for each time step : Here is the discounted return from step , the scalar step size, the additional discount that progressively down-weights later steps when viewed from the start of the episode, and the score-function gradient for the realized state-action. The professor's verbal parsing — "alpha gamma power " for , "one is that is return," and "the other one is the gradient part" — maps directly to the three multiplied factors. In some textbook presentations is absorbed into the definition of ; the arithmetic is identical.

The gradient factor is not a postulate — it follows from a short, examinable derivation known as the log-derivative trick.

Log-derivative trick — complete derivation (no skipped algebra): Let be a probability mass or density differentiable in and let be any scalar function not depending on . Then The identity is the log-derivative trick. Applying it with a full trajectory, the trajectory probability, and the total return gives Writing and taking logs, all environment dynamics terms have zero -gradient and drop, leaving . Distributing and using causality (return before is unaffected by action at ) replaces by term by term, yielding the REINFORCE estimator and its discounted form . This is why sampling one episode and summing estimates the true gradient.

Visual intuition — imagine as a hilly surface over . You cannot evaluate the whole surface, but at your current you can sample a trajectory, compute at each step, and that vector points on average uphill. Repeating the sample-and-step moves the policy toward higher expected return.

Scope — assumptions and what does: REINFORCE assumes stochastic, differentiable and on-policy sampling — the trajectory must be generated by the same that is being updated. The factor is not an extra hyperparameter; it is the textbook's per-step discounting that reduces the influence of later updates when viewed from time zero. If a problem statement gives , it disappears. Common hyperparameter values cited in class are or and for the simplest one-step episode; a specific examination problem will state its values.

Two errors follow directly from that scope — misplacing the extra discount and trying to differentiate the environment's reward.

Pitfalls to avoid:

  • Dropping or applying it to twice. already contains inside the sum. The outer is the additional weighting from the start of the episode, not a correction to itself.
  • Trying to differentiate directly. Rewards come from the environment and are not differentiable in ; the log-derivative trick is how influences return — through the action distribution, not through the reward function.

Recap and bridge: REINFORCE is Monte Carlo policy gradient with update ; the log-derivative trick derives that gradient from without differentiating rewards. Once is known, the rest is mechanical — so the hard part, if the examination changes , is computing that logarithmic derivative, which is exactly what the Continuous-action derivation in the next two subsections practices.

16.6.3 The Lane-Keeping Assistance Problem — Full Specification

Hook — the car that must stay in the middle between the gutters: An assistance system steers a car that is somewhere in its lane. If the car is already in the centre it should stay there; if it has drifted left it should steer right, and vice versa. The reward is simple — plus one when the car ends up in the centre, zero otherwise — but the steering command is continuous, so the policy cannot be a discrete choice. This is the running example that makes every policy-gradient variant concrete with the same states, features, and episode.

States, features, and actions: The lane is discretized to three positions Each state is encoded by a one-hot feature vector : Here is the feature extraction of state , written in the lecture as " of ." The mapping is explicit: " of is left represented as , centre is , right is ."

The steering action is a continuous real number where is full left, is full right, and intermediate values are proportional (for example is almost fully left, almost fully right). The policy must therefore output a distribution over this interval from which a steering value is sampled.

The reward structure is In words: "you get plus one if the car is in the centre, you get zero if the car is in left or right." The objective is to stay in centre.

Gaussian policy parametrization for continuous actions: Because the action is continuous, a softmax over finitely many actions is not applicable. Instead the network outputs the parameters of a Gaussian from which the steering command is sampled.

Conceptually two heads share the same input features : Here is the mean-network parameter vector, parametrizes the standard deviation, and the lecture's shallow-network assumption "assume the network is a very simple, very shallow network doing only theta transpose of " makes the linear form the operative model. In the simplified numerical example only the mean network is learned; the standard-deviation network is fixed to so the policy is a narrow Gaussian centred at with variance . The learner updates only ; the lecture frames this as "you are only learning mean and you are not learning sigma; sigma is assumed." Initial parameters are with hyperparameters step size (cited as in the worked episode and in variant illustrations — the problem statement gives the value to use) and discount (taken as in the simplest episode). The advice given is: if or are missing from a problem statement, ask or declare the assumed value explicitly.

Visual intuition — draw a road from above with three lanes: left, centre, right. Above each lane position plot a narrow bell curve: centred at over left (leaning left), at over centre (straight), at over right (leaning right). Sampling a steering command means dropping a dot under the bell for the current lane — most dots fall near the centre of that bell. Learning slides each bell's centre so that dots increasingly land where the reward lives.

Scope — when this specification applies: The one-hot encoding and constant are the examinable simplification for lane keeping. The general case would learn both and as functions of state with richer features (for example lane offset and heading angle). The discrete-action alternative — discretizing steering into bins and using a softmax policy — is a different parametrization not required for numerics here; it was noted as straightforward for anyone familiar with discrete softmax but not covered technically.

That fixed-variance choice is exactly what students most often misread — confusing the mean with the sample and trying to learn when it is frozen.

Pitfalls to avoid:

  • Treating as the action. The mean is where the distribution is centred; the action is a single sample from . Confusing the two makes the gradient collapse to zero.
  • Forgetting that is fixed here. Its gradient is not computed and its value does not update. A problem that instead says "learn " would require an additional derivative.

Recap and bridge: Lane keeping is three states with one-hot features, continuous steering in , reward for centre and elsewhere, and a Gaussian policy with initial and fixed . The next subsection evaluates what that initial actually means for each lane position.

16.6.4 Means for Each State Under the Initial Parameters

With the one-hot encoding, computing is a table lookup — it selects one coordinate of .

Worked computation — all three states: Let .

  • Left: ,

The policy's centre is significantly left — negative is left.

  • Centre: ,

The policy's centre is straight ahead.

  • Right: ,

The policy's centre is significantly right.

These three numbers are the starting distribution centres before any learning. Intuition: being in the left lane already biases steering left, being on the right biases it right, and being centred biases it straight — the initial parametrization encodes a naive corrective tendency that learning will refine. Sense-check: Each mean equals exactly one entry of because one-hot features pick out one weight; if the encoding were not one-hot, would be a blend of weights.

Scope and pitfall: This lookup property depends on the one-hot choice. With richer features (for example two-dimensional features including lane offset and heading), would interpolate between weights rather than selecting one. For examination numerics, keep the one-hot rule: , , under the initial .

Recap and bridge: Initial means are for left, for centre, for right — each is one coordinate of . Those means parametrize the Gaussian whose log-density and derivative are needed for the update, which is the next derivation.

16.6.5 Policy Density, Log-Policy and Its Gradient for the Gaussian

The quantity that enters REINFORCE is not the density but its logarithm and the logarithm's gradient — the highlighted derivative that multiplies . The derivation is three short steps with no skipped algebra.

Step 1 — Gaussian density: With and fixed , the policy density for steering command is Here is the realized steering value, the state-dependent mean, the fixed standard deviation, and the parameter vector. The lecture's phrase "the probability of an action given a state is this, because we assumed if I know mu and sigma I go to the normal distribution expression to plug these values" is this line.

Step 2 — log-policy: Taking the natural logarithm, Here the first term is a constant in (since is fixed) and the second term carries the -dependence through . The lecture isolates this as "first you take the pi, apply the log."

Step 3 — gradient with respect to : Differentiate, using so : So the boxed result that "is going to come in this great important" place — the factor that multiplies in the REINFORCE update — is With , ; with one-hot , the gradient has only one nonzero coordinate. This is the Gaussian "score" — it points in the feature direction, with magnitude proportional to how far the sampled action was from the current mean, scaled by precision .

Visual intuition — the bell curve is steep near its centre. If you sampled to the right of the mean (), the gradient points toward increasing the weight for that state's feature, which will slide the bell rightward. Sampling left of the mean pushes it left. The narrower the bell (smaller ), the same distance produces a larger push because is larger — a confident narrow policy updates more sharply from each sample.

Scope — what changes if the policy form changes: The three-step pattern — write , take , differentiate with respect to — is universal. If the examination gives a different (for example a Bernoulli or a different continuous density), apply the same two operations; the resulting derivative replaces in the update, and every other piece (, , addition to ) remains identical. That replacement is the only non-mechanical part of the REINFORCE computation.

Those two steps are mechanical, but two transcription slips routinely break them — dropping the feature factor and misplacing the variance.

Pitfalls to avoid:

  • Forgetting the chain rule through . The gradient is with respect to , not . The factor comes from ; omitting it collapses a vector gradient to a scalar.
  • Mixing up and . The density has in the normalization and in the exponent denominator . After logging and differentiating, only remains in the gradient denominator. Writing instead of is a factor-of-five error when .

Recap and bridge: The Gaussian log-policy is and its gradient is — that vector is the boxed quantity that scales the REINFORCE step. With all pieces defined, the next subsection puts numbers into that gradient for a one-step episode.

16.6.6 Worked Example — REINFORCE on a One-Step Episode

Worked example — the simplest possible episode carried end to end: The episode is a single transition that ends immediately, so every return and discount collapses to one number.

Setup: Current state with . Current mean from the previous subsection. Fixed so . Sampled action (slightly left of straight; negative is left). Reward because the action lands the car in centre. Next state ; episode terminates.

Return: With and only one reward, The lecture's phrasing "since there is only one episode you know your is plus , correct? There is only one thing to sum" is this line.

Log-policy gradient at this transition: Using , , , Multiplying by the feature vector, With the stated the active coordinate is . (A value of would correspond to , i.e. ; the problem as specified uses .)

Parameter update: With step size and for the first step, Substituting , , , gradient , Only the left-state coordinate moves, from to ; the centre and right coordinates are unchanged because their feature entries are zero for this transition. The lecture's stated result "the answer comes to minus " matches this arithmetic.

Interpretation: The current mean says "turn significantly left" (); the good outcome ( for reaching centre) was achieved with a slightly less left action (), so the update relaxes the left bias toward — "don't keep that much effort left, slightly relax, come to centre." Accumulated over many episodes this small shift centres the steering policy.

Extension to longer episodes: For a three-step episode the same five-step mini-algorithm from the textbook applies: form for each , compute , multiply by , and add to . Later steps are discounted by when viewed from the start. Sense-check: Every update moves toward the sampled action when and away when ; here and is to the right of , so the mean correctly shifts right (less negative).

The full written update the professor walked through — "new theta is old theta plus alpha gamma power times times the gradient" — is exactly the displayed equation used above.

Scope — hyperparameters to watch: The value here is the one used in the spoken walk-through for this episode; other lanes or problems may specify . The episode length, , and will be stated. If any is missing, declare the assumption before computing.

Pitfalls to avoid:

  • Applying the gradient to all three coordinates. Only the state actually visited contributes; the gradient entries for centre and right are zero because those feature entries are zero. Updating all three is the most common arithmetic error.
  • Using reward instead of return when the episode is longer. For a one-step episode they coincide, but for a multi-step episode sums discounted future rewards, not just the immediate .

Exam note: If the form of is changed, the only non-mechanical part is recomputing and ; forming , scaling by , and adding to remains identical. Master the Gaussian derivative above and the rest of any lane-keeping numeric is bookkeeping.

16.6.7 REINFORCE with Baseline — What Changes

REINFORCE with baseline keeps every piece of REINFORCE scaffolding except the scalar that multiplies the gradient. The change is one subtraction.

Baseline update — the single-term substitution: Let , written in the lecture as " cap of ," be an estimated state value (a baseline) that may be learned separately or given. The per-step update becomes Here is the usual sampled return from step , the baseline value for the visited state, and the advantage-flavoured scalar that replaces bare . Every other factor — and — is unchanged from the REINFORCE calculation. The lecture's guidance "you have in place minus the value of ; everything is same except that minus cap" is this line.

Why it helps: Subtracting a state-dependent constant does not bias the expected gradient (because , so ), but it reduces variance — the gradient estimate fluctuates less because the baseline recentres the return around its typical value for that state. The theory behind that variance reduction was covered analytically before the numerics; for the examination numeric the operational change is the subtraction.

Worked continuation of the same one-step episode with a baseline: Keep , , , , gradient , . Suppose the given baseline values are , , (illustrative values of the kind the notes state for each lane position).

Baseline-corrected scalar: Update: The mean still shifts right but by less ( instead of ) because part of the return was already expected by the baseline. If instead (return worse than expected), the scalar would be negative and the mean would shift away from the sampled action. Sense-check: Baseline does not change the gradient direction — only its magnitude and potentially its sign via .

Pitfalls to avoid:

  • Subtracting instead of . The baseline is for the current state's value, not the next state's. The actor-critic variant in the next subsection is the one that uses both.
  • Learning the baseline from the same without a separate update. The baseline is typically trained to minimize via its own gradient step; plugging into both the policy and the baseline without that separation conflates two objectives.

Recap and bridge: REINFORCE with baseline replaces the scalar by and is otherwise identical to REINFORCE — one extra lookup and subtraction before the multiplication. The next variant goes one step further and replaces the Monte Carlo quantity entirely.

16.6.8 Actor-Critic (One-Step) — Replacing with the TD Error

The actor-critic variant replaces the sampled return with a bootstrapped one-step temporal-difference error that needs no wait to episode end.

One-step actor-critic — the second substitution: In place of or , the one-step actor-critic uses the TD error called "advantage" and "one-step TD error" interchangeably in this context. The policy update becomes Here is the immediate reward, the estimated value of the next state, the estimated value of the current state, the discount, and the same score-function gradient as before (for the Gaussian, ). The lecture's phrasing "in place of you are actually using delta" is this substitution; the gradient factor is unchanged, only the scalar weighting it changes from a full return to a one-step bootstrapped error. A separate critic update trains toward the TD target, typically with its own step size .

The three lane-keeping numerics in the notes share the same episode and feature representation so that the variants can be compared by inspecting one scalar.

Worked continuation — same one-step lane keeping episode as actor-critic: Keep , , , , gradient , . Let the given estimates be and (the lecture cites "point four something" for centre).

TD error: Policy update: If instead (overestimate), then and the update would be , pushing the mean away from the sampled action because the transition turned out worse than the critic expected. Sense-check: When bootstrapping is accurate, is centred and lower-variance than ; when the critic is wrong, the bias in biases the policy step — the cost of not waiting for the full return.

Side-by-side, the only difference across the three lane-keeping numerics is the scalar:

Variant Scalar weighting Needs full episode? Bias / variance
REINFORCE Yes — wait to Unbiased, high variance
REINFORCE with baseline Yes — still needs Unbiased, lower variance
One-step actor-critic No — one transition Biased (depends on ), lowest variance, online

When to pick which: Use REINFORCE when you need unbiased Monte Carlo and can afford episode-length waits. Add a baseline whenever a value estimate is available — it is a free variance reduction. Use actor-critic when episodes are long or continuing and you need updates after every step; that is the control loop that scales to driving, robotics, and language-model fine-tuning.

Scope — what the notes label not required: The discretization-with-softmax alternative (Section 11 of the policy-gradient notes, "if steering is discretized, a softmax alternative") and the optional session from Section 13 onward are explicitly not required for examination preparation; they were not covered technically. They are straightforward for anyone familiar with discrete-action softmax but should not consume examination-preparation time.

Pitfalls to avoid:

  • Replacing with alone. The actor-critic scalar is the TD error , not the raw reward. The bootstrap and the baseline are both essential.
  • Updating with but forgetting the critic update. The critic must be updated toward ; otherwise the same biased persists and the policy converges to the wrong point.

Recap and bridge: The three lane-keeping numerics share the same episode, features, and ; they differ only in the scalar — , , or . Understanding one numeric and applying the single-term substitution for each of the other two is the recommended preparation path. The section closes with the two questions students most often ask when a continuous-action Gaussian is used.

16.6.9 Student Questions and Answers on Policy Gradients

Q: I missed how the continuous action is actually selected if the network only outputs a mean. A: The mean together with the fixed standard deviation defines a full Gaussian . Action selection samples a single number from that Gaussian and uses it as the steering command — for example with after the update, the policy draws and steers by that . Learning the mean shifts the centre of the sampling distribution; sampling from the updated Gaussian automatically produces actions closer to the rewarded region more often. The spread stays constant here, so exploration does not collapse but also does not adapt — that is the simplification that keeps the numeric to one parameter vector.

A practical follow-up often arises: what if the policy were not Gaussian at all?

Q: What if the examination gives me a different policy form than the Gaussian? A: Apply the same two operations, no new machinery: take the natural logarithm of the given and differentiate the result with respect to . That derivative replaces the boxed Gaussian term in the update. Every other piece — forming (or or ), scaling by , updating — remains identical. For example, if the problem instead gave a discrete softmax , then and would be the softmax log-derivative (indicator minus probability times feature), and that vector would multiply exactly as the Gaussian gradient did. If the calculus is solid, the remainder is mechanical.

Recap and bridge: Continuous actions under a Gaussian are sampled from and learned by moving ; any alternative policy is handled by the same log-and-differentiate step, with only the gradient factor changing. With policy-gradient numerics — REINFORCE, baseline, and actor-critic — established on the lane-keeping problem, the next section turns to model-based planning where a learned model guides search before acting.

16.7 Model-Based Planning — MCTS, AlphaGo, MuZero and Planet

16.7.1 Why Model-Based Learning and Decision-Time Planning

Hook — thinking before you move: Picture a Go board where your opponent has just played. You have almost two minutes before you must reply. You could blurt out the first move that looks plausible, or you could spend those two minutes mentally trying moves, following their consequences with the rules of Go in your head, and only then commit. That deliberate use of time to search with a model is exactly what this block is about.

Model-free methods learn a policy or a value that maps the current state directly to an action, with no explicit look-ahead at decision time. Model-based methods learn or are given a model of the environment and then plan with it — they simulate what would happen if actions were taken, evaluate those futures, and choose after the search.

Model and what planning means: Let be the state set, the action set, and let a model be a function that predicts the next state and immediate reward from , i.e. . Planning is any computation that uses to improve a policy or value before acting in the real environment. Background planning improves the policy offline from simulated experience; decision-time planning runs search from the current state at the moment a move is required.

The classic analogy used in class makes the operational difference concrete.

Intuition and analogy — two examinations: In a closed-book examination you must answer from memory alone — that is the model-free policy: state goes in, action comes out. In an open-book examination you arrive well prepared, and when a hard scenario question appears you flip through your notes, refresh the mental model, test perspectives against each other, and only then write. The ability to enter well prepared, then search the notes before committing, is decision-time planning. The Go clock gives the same story in game terms: after the opponent moves you have up to two minutes not to recall a memorized line but to systematically explore using the rules of the game as the model. Where the analogy breaks: Notes can be re-read at leisure, but a game clock is finite and the branching factor is enormous. Brute-force search of every continuation is impossible — planning must be selective, sampling promising lines more deeply than unpromising ones, which is precisely what Monte Carlo Tree Search does.

Not every problem benefits equally from decision-time planning. The slide that enumerates when it helps can be read as three conditions: the state space or branching factor is too large to have an optimal policy tabulated for every state; the decision is not required in a few milliseconds, so thinking time can be invested; and a model of the environment is available or can be learned accurately enough to simulate. When those hold, evaluating many possible actions by looking ahead and gathering evidence before choosing systematically outperforms committing to the first output of a reactive policy.

Visual intuition — imagine two pipelines side by side. On the left, a single arrow from state through a network to an action ; the network has done all its work during training and contributes nothing at decision time. On the right, the state is the root of a growing tree; each edge is a simulated action using the model, each child is a predicted next state, and a search algorithm expands that tree for as many iterations as the clock allows, scores the branches, and finally returns the most promising root action. The left pipeline is fast but blind to this specific position's subtleties; the right pipeline pays time to get evidence about this position.

Scope — what is examinable here and what is not: Examinable are the motivation for model-based learning and the precise meaning of decision-time planning versus a reactive policy. Examinable at the level used in the guest session is the search algorithm itself — its four stages and the rule that drives its selection. Deep recall of every engineering choice, network architecture, or training hyperparameter in each historical paper is explicitly not required. Section 15 of the notes lists ambitious future topics beyond the 16-session scope; only apprenticeship learning (DAgger) will be covered in depth there — see 16.7.4.

That scope is where students most often mis-allocate time — either memorising paper pseudocode or ignoring the planning concept entirely.

Pitfalls to avoid:

  • Conflating planning with learning the model. Planning assumes a model already exists (given as rules or learned). Learning the model and using it to plan are two distinct steps; this block tests the second — how search produces a decision — not the derivation of model-learning losses.
  • Treating decision-time planning as background replay. Background planning updates a global value or policy from simulated experience for later use. Decision-time planning is local to the current state and its value is specific to the move now required, even though the statistics it builds may be discarded afterwards.

Comparison at a glance:

Dimension Background planning (e.g. Dyna) Decision-time planning (MCTS)
When Between real actions, offline At decision time, from
Root Many simulated starts Single current state
Output Improved global or for future states Best for this state
Cost Amortised over many states Paid per move, bounded by clock

Recap and bridge: Model-based learning uses a model to simulate futures. Decision-time planning invests thinking time from the current state to evaluate actions before committing — the open-book examination, the Go two-minute clock. When branching is huge but time exists, selective search beats a blind reactive choice. The next subsection makes that selective search procedural: the four stages that define Monte Carlo Tree Search and the confidence-bound rule that steers it.

16.7.2 Monte Carlo Tree Search — The Four Stages and the UCT Formula

Hook — how do you search a tree you cannot finish? Go has about 250 legal moves per position and games last ~150 moves; exhaustive search is astronomically larger than chess. Monte Carlo Tree Search (MCTS) answers by growing the tree selectively: it keeps statistics at every edge, always extends the most promising but least explored branches first, and backs up the results of fast random play-outs to refine those statistics. Time, not depth, determines when to stop.

MCTS interleaves four stages on every iteration, starting from the root that represents the current real state . The guest session devoted significant time to these stages and the ability to trace them is the examinable core.

The four stages — procedural definition:

  • 1. Selection. Starting at the root, repeatedly descend by choosing the child that maximizes the UCT score (defined below) until a leaf node — a node with at least one untried action — or a terminal game position is reached. Selection is the tree policy; it balances exploiting high-valued children against exploring rarely visited ones.
  • 2. Expansion. Create one or more child nodes for an untried action from the selected node and attach them to the tree. The newly added node represents the predicted state after that action under the model.
  • 3. Simulation (rollout). From the newly expanded node, play out to a terminal state (or a fixed truncation depth) using a fast rollout policy — often uniform random or a lightweight learned policy — collecting the outcome (win/loss or scored return). The rollout need not be strong; it must be fast enough to be repeated thousands of times within the clock.
  • 4. Backup (backpropagation). Propagate back up the path visited in this iteration. For each ancestor node and edge on the path, increment visit counts and by one and update the edge's mean value toward the observed result, e.g. .

The score that drives selection is UCT — the Upper Confidence bound applied to Trees — the tree analogue of the classic UCB bandit rule. The instructor's comment that "the expression does not really differ from your classic UCB, you just take this UCT expression and you look at your good old UCB expression; they are not much different, you are doing primarily the same thing" reconstructs to:

Here is the empirical mean value of action from state averaged over rollouts through so far, is the visit count of parent state , is the visit count of the child edge (with for the formula to be defined; untried actions are given priority), and is the exploration constant that trades exploitation of currently good-looking moves (large ) against exploration of less-visited moves (large second term). larger favours broader search; smaller favours deeper exploitation of the current best line. UCT applies the UCB principle at every internal node of the tree, so confidence bounds are composed down the path.

Visual intuition — draw the root with two children. Each incident edge is labelled with a pair and each node with . Selection follows the bold edge whose UCT is larger; expansion adds a new leaf dangling from that edge; simulation shoots a dashed line from the new leaf straight to a terminal outcome; backup colours the entire visited path and ticks every count. After many iterations the tree is broad near the root where many alternatives have been tried, and deep along the few lines whose UCT remained highest — exactly selective growth.

Worked example — two-iteration trace with real numbers: Consider root with two legal actions and exploration constant (the common choice). Visits and means are maintained as . Untried actions have UCT and are taken before any visited action.

Initial state before any iteration: , no children expanded.

Iteration 1 — Selection finds has untried actions, so it picks one, say , without using UCT. Expansion creates node for . Simulation from with the rollout policy returns (win for the player to move). Backup updates the visited path: Root statistics now record one win down the branch and nothing yet for .

Iteration 2 — Selection at . Child is still untried, so its UCT is infinite and it is selected regardless of . No UCT arithmetic is needed to see this — starvation of an unvisited edge dominates. Expansion creates for . Simulation from returns (loss). Backup:

What the next selection would do (illustrative iteration 3): Now both children have been visited, so UCT governs. With , So iteration 3 would select again, expand a child beneath , simulate, and back up, deepening the more promising branch while the exploration bonus for will grow slowly as increases. Sense-check: After iteration 2 the means are 1.00 and 0.00 — the algorithm has seen one win and one loss. UCT correctly keeps both lines in contention because visit counts are still tiny; as counts grow the term shrinks for heavily visited edges, forcing the tree to eventually return to less-explored branches.

Why the two numerics flagged in class matter: the guest instructor's live trace shows how the narration maps to the four verbs — "I am selecting, now expanding, now simulating, now backing up" — while the compact notes numerical provides a self-contained table of UCT calculations and backup arithmetic that can be reproduced on paper. Preparatory advice is to be able to do what the box above does: given a small tree with visit counts and means, compute UCT for competing children, pick the maximizer, expand the untried edge, assume a rollout outcome, and back up counts and means along the visited path.

Relationship to the bandit UCB: at each node MCTS faces a bandit problem whose arms are the legal moves from that state. UCT is literally UCB1 re-applied at every node, which is why the formula looks identical except for the state-conditioning .

Concept UCB (bandit) UCT (tree)
Arm Action Edge conditioned on node
Mean for that node's subtree
Count total pulls, per arm node visits, edge visits
Scope One decision Every internal node, composed along the path

Assumptions and scope: MCTS assumes a generative model that can sample next states and outcomes quickly enough for thousands of simulations within the clock, a finite action set at each node so that children can be enumerated, and the ability to define a rollout policy and a terminal evaluation. It does not require a perfect value function in advance — the tree and rollout outcomes are the evaluation. For the examination, being able to state the four stages in order, write UCT with all symbols defined, and trace one or two iterations with numbers is sufficient; convergence proofs and alternative selection rules beyond UCT are out of scope.

Two slips break otherwise correct traces:

Pitfalls to avoid:

  • Forgetting in the numerator or swapping it with . The confidence width grows with (parent visits) and shrinks with (child visits). Writing or changes the exploration rate dramatically.
  • Treating a rollout as an evaluation of the parent instead of the new leaf. Simulation starts from the newly expanded node, not from the root or the selected node before expansion. Backing up to the wrong path assigns credit to branches that were never traversed.

Recap and bridge: MCTS repeats selection by , expansion of an untried action, fast simulation to a terminal outcome, and backup of visit counts and mean values. UCT is UCB on a tree. Tracing two or three iterations with arithmetic — computing UCT, expanding the winning edge, simulating a 1 or 0, and incrementing counts — is the mechanical skill to practice. The next subsection shows how four landmark game-playing systems all use that same loop, differing only in what model they search with.

16.7.3 AlphaGo, AlphaZero, MuZero and Planet — What to Know and What Not to Memorize

Hook — four systems, one search backbone: From 2016 to 2019 a single research thread produced a sequence where each system did more with less — less hand-craft, less privileged access to the real environment, more learned structure — yet played stronger. What never changed was the backbone: Monte Carlo Tree Search at decision time. What changed was the model that MCTS searched over.

The notes title enumerates MCTS, AlphaGo, AlphaZero, MuZero and Planet as a lineage. Read chronologically they show decision-time planning carried progressively further by learning better models.

At-a-glance lineage — milestones and what improved:

System Year Model MCTS searches Training signal Key advance over predecessor Strength signal
AlphaGo (Fan / Lee) 2016 Given rules + supervised policy/value nets + rollout policy Human expert games + self-play RL + value regression First superhuman Go with MCTS guided by deep nets Defeated European champion Fan Hui 5–0, Lee Sedol 4–1
AlphaGo Zero 2017 Given rules + single net (policy + value) Pure self-play from scratch, no human games Removed human data; one network trained entirely by self-play Defeated AlphaGo Lee version 100–0
AlphaZero 2017–18 Given rules (general game) + single net Pure self-play Generalised the Zero method beyond Go to chess and shogi with identical architecture and minimal game-specific knowledge Superhuman in three games with one algorithm
MuZero 2019 Learned latent dynamics model (no given rules) Self-play + latent model learning (reward, value, policy) Plans in a learned abstract state, not the real rules; needs only reward and action interface Matches AlphaZero on Go/chess/shogi and exceeds on Atari without seeing the simulator
Planet (and Dreamer lineage) 2018+ Learned latent world model for continuous control Model-based RL in latent space Demonstrates the same idea — learn dynamics, then plan with search — outside board games, in visual control Sample-efficient control from pixels via latent planning

Across the entire lineage the pattern is invariant: MCTS is the decision-time planner; the networks supply the prior policy that biases selection, the value that truncates and evaluates leaves, and (from MuZero on) the dynamics that replace the given simulator.

In more detail, AlphaGo combined MCTS with two deep convolutional networks produced by supervised learning on human games and reinforcement learning from self-play: a policy network to propose moves and a value network to evaluate positions, plus a fast rollout policy for simulations. AlphaGo Zero collapsed those into a single network and removed the human phase — the only input was the board and the rules. AlphaZero showed that collapse was not Go-specific. MuZero removed the last crutch: instead of the true transition model, it learned a latent dynamics function that predicts rewards, values and policies in an abstract state, and MCTS searches entirely inside that learned latent space. Planet applies the same principle — learn a latent world model from pixels and plan inside it — to continuous visual control, showing that the idea extends beyond perfect-information board games.

Visual intuition — imagine the planner's tree gradually detaching from the real board. In AlphaGo the edges of the tree are legal Go moves and nodes are real board positions. In MuZero the tree's nodes are abstract latent states that the model learned to make search work, and edges are actions whose consequences are predicted rather than simulated by the true rules; the real environment is only consulted for the root state and the rewards that train the latent model. Planet does the same but the leaves are video frames compressed to latent vectors.

What to know versus what not to memorize:

Know and be able to write a few sentences on each: what the system did (its milestone), what the technical improvement over its predecessor was, and how MCTS is used inside it (as the decision-time search guided by learned policy/value and, where applicable, a learned model). A compact lineage table like the one above plus one sentence per system is the right granularity.

Do not memorize: algorithm pseudocode, network depths, layer counts, training hours, or specific parameter values from any paper. Slides contain slightly more detail than the notes; either source at that high level suffices. No numerical of the Alpha family was flagged for mechanical practice comparable to the lane-keeping numerics — conceptual lineage is the preparation goal.

That expectation mirrors the open-book analogy from 16.7.1: even for a high-level description, having refreshed the notes pages that summarize each paper's contribution before writing makes the answer precise.

Pitfalls to avoid:

  • Saying MCTS disappeared in later systems. It did not — later systems strengthened MCTS by pairing it with a stronger learned model, not by replacing it. "MCTS is the planner; the model is what improved" is a safe summary sentence.
  • Listing milestones without the improvement direction. An answer that names four systems but cannot say what AlphaZero removed relative to AlphaGo, or what MuZero learns that AlphaZero was given, reads as memorised names rather than understood progression.

Recap and bridge: AlphaGo (human data + MCTS), AlphaGo Zero (zero human data + single net + MCTS), AlphaZero (general game + same method), MuZero (learned latent model + MCTS in latent space), Planet (latent world model for visual control) — one search backbone, progressively more learned. Know milestone, improvement, and MCTS role; skip pseudocode and parameters. The final subsection maps what from this rich landscape the course will pursue further and what it will deliberately defer.

16.7.4 Roadmap Items Deferred — Section 15 and Imitation Learning

Hook — a course cannot cover everything it names: The combined notes span 191 pages and were designed as a superset for multiple offerings. Section 15 lists a set of frontier topics that is explicitly too ambitious for 16 taught sessions at the depth used elsewhere. Naming the deferred items is part of keeping the examinable scope honest.

Section 15 enumerates, among others, imitation learning and the DAgger (Dataset Aggregation) algorithm, inverse reinforcement learning (also called reward modeling), multi-agent reinforcement learning, and safety in reinforcement learning. The stated plan is that a future re-alignment of the course would compress some early material to create room to cover more of these topics in depth.

What will be covered versus deferred:

Topic in Section 15 Coverage in this offering What to understand
Imitation learning / DAgger ~1 hour in depth What imitation learning is, why it matters when expert demonstrations exist, how DAgger (Dataset Aggregation) iteratively collects states under the learner's policy but labels them with the expert to fix distribution shift, and what class of problems it addresses
Inverse RL / reward modeling Introductory only That the reward function itself can be learned from preferences or demonstrations; the idea that appears directly in preference-optimization methods for language models
Multi-agent RL Introductory only That multiple learners interact, so the environment is non-stationary from any single agent's perspective; models joint or adversarial dynamics
Safety in RL Introductory only That constraints and guarantees are needed before deploying learned policies in the physical world

Imitation learning is included because it connects directly to planning: when a high-quality policy or human expert is available, the cheapest way to get good sequential behaviour can be to imitate rather than discover from scratch via reward search, provided distribution shift is handled (the problem DAgger addresses). The other three topics will be introduced only to the level of "what the topic is, what class of applications it models, and where it connects to material already seen." Concretely, inverse reinforcement learning as reward modeling appears in direct-preference-optimization style algorithms; multi-agent RL as the extension where multiple learners co-adapt; safety as the family of constraints needed for real-world deployment.

Scope — examination level for deferred topics: Imitation learning and DAgger may be examined for understanding of what imitation is, why it matters, how DAgger works, and what problem class it addresses. Inverse RL / reward modeling, multi-agent RL, and safety will be presented at an introductory what-it-is level, not as a source of numerical or proof-style examination material. No deep paper recall is required for any deferred topic.

Recap and bridge: Section 15 is a roadmap, not all of it examinable: DAgger will be treated in an hour in depth; inverse RL, multi-agent, and safety will be introduced as landscape. Together with the MCTS lineage, this completes the model-based planning thread — from why to plan at decision time, through the four-stage algorithm and its confidence-bound rule, through the Alpha-family that shows the idea scaling, to what comes next. The following section stays with policy methods but turns to how advantages and trust regions make that learning stable and sample-efficient.

16.8 Advanced Policy Methods — Asynchronous Methods, Generalized Advantage Estimation and Proximal Policy Optimization

16.8.1 Asynchronous Advantage Actor-Critic (A3C) and Synchronous Advantage Actor-Critic (A2C)

Hook — why train one agent when you can train ten at once? A single actor-critic collecting one trajectory at a time learns slowly and sees highly correlated data — frame after frame of the same game. If ten copies of the same agent play ten copies of the game in parallel, each seeing a different part of the state space, and all contribute to one shared brain, the brain learns faster and more stably. That shared-brain, many-workers design is what this block organizes.

Both A3C and its synchronous variant A2C start from the single-instance actor-critic: an actor with policy parameters that outputs and a critic with parameters that outputs . The goal in both parallel variants is to learn the parameters of the shared master network — the global and global — while workers do the data collection.

Master, workers, and the five-step cycle: Let be the global actor parameters and the global critic parameters held in the master network. Let there be workers (the lecture uses as the running example) each with a local copy and . Each worker repeats:

  1. Copy. Synchronize local parameters from the master: , .
  2. Roll out. Interact with the environment for a trajectory of length (or until termination) using the local policy , producing .
  3. Compute. Form parameter updates from that rollout — typically -step advantage actor updates and value-regression critic updates. If the trajectory is long, multiple -step windows are taken inside the same rollout; for example a 100-step rollout with yields 10 incremental advantage computations.
  4. Accumulate. Aggregate the resulting incremental deltas locally (a worker sums its roughly 5–10 gradient contributions before communicating).
  5. Apply. Push the accumulated update to the master parameters .

Here is the -step horizon, the immediate reward, the discount, and the advantage (defined in 16.8.2) weights the actor gradient . The cycle is the same for A3C and A2C; what differs is the synchronization of step 5.

Intuition and analogy — submitting notebooks without a roll call: Picture 30 students sent to solve a task at their own desks. In the asynchronous room, each student works at their own pace and walks up to hand in their notebook the moment they finish — whoever finishes first submits first, regardless of roll number or start order, and the shared grade sheet is updated immediately on each arrival. In the synchronous room, everyone works for a fixed interval, then all notebooks are collected together into one stack and the grade sheet is updated once from the whole stack. The first room is A3C; the second is A2C. The asynchronous room tolerates staleness for speed, the synchronous room pays coordination for a cleaner, batched gradient. Where the analogy breaks: Students do independent work, but workers share parameters that drift while a worker is still collecting data — so an asynchronous worker's gradient may have been computed under a policy slightly older than the master it updates, which is why locking and staleness were active research considerations before the synchronous variant became standard.

The distinction is therefore not in what is computed but in how step 5 is applied.

In A3C the application is asynchronous and lock-free: each worker pushes its accumulated update to the master as soon as it finishes, without waiting for other workers and without a global barrier. Updates interleave in arrival order — the order in which workers happen to complete, which depends on varying trajectory lengths and computation times. The master evolves incrementally after every worker's push.

In A2C the collection is synchronized: multiple environments still run in parallel and each collects a planned number of steps under the same current policy, but their data are assembled into a single batch. One joint gradient is computed from the batch and one synchronized update is applied to the master. Concretely the operational difference is independent rollouts with unlocked pushes versus synchronized rollouts with a batched update.

Visual intuition — draw one central book labelled Master with spokes to worker desktops. Each worker's spoke is a loop: copy down from the centre, orbit the environment for a few steps, sum gradients locally, then arrow back to the centre. In the A3C diagram those back-arrows arrive at random times, interleaved; in the A2C diagram they all land together, are summed in the middle of the diagram into one thick arrow, and a single update is applied.

Dimension A3C (asynchronous) A2C (synchronous)
Step-5 synchronization Unlocked, per-worker push on completion Barrier, batched joint update
Arrival order First-come, first-applied (notebook analogy) Synchronized collection, single batch
Gradient staleness Mild staleness possible (local policy slightly behind master) No staleness within the batch
Implementation today Historically influential, less common now Modern default; aligns with batched GPU computation
When preferred Many CPU workers, minimal coordination overhead Batched accelerators, cleaner optimization semantics

Assumptions and scope: Both methods assume on-policy data — each worker's rollout is generated by the policy whose gradient it computes (or, in the asynchronous case, by a very recent copy). They assume a parametrized stochastic policy differentiable in and a learned state-value critic . The five-step cycle is examinable at the operational level — be able to list the five steps and explain the asynchronous-versus-synchronized difference. Specific distributed-system details, lock implementations, or throughput numbers are not examinable. The notes identify A2C as the variant that aligns with more recent engineering; the asynchronous-versus-synchronized contrast is the takeaway.

The usual transcription error is to describe the difference as "A3C has no master" or "A2C has no workers" — both have the same master and workers; only the timing of step 5 changes.

Pitfalls to avoid:

  • Saying A3C has no shared network. It does — the master is the point of A3C. Asynchrony is about when pushes happen, not about whether a shared target exists.
  • Forgetting the accumulate step. Each worker does not push after every single transition; it aggregates several -step deltas (for example 10 windows inside a 100-step rollout) and pushes the sum. Describing the cycle as copy-rollout-push skips the accumulation that makes the update stable.

Recap and bridge: A3C and A2C share one master and workers that each copy, roll out, compute -step advantages, accumulate, and apply — they differ only in whether step 5 is unlocked per-worker (A3C, notebooks arrive as finished) or synchronized into one batch (A2C, stack collected together). That batched collection is what modern implementations use. The quality of what workers compute depends on the advantage estimator they use, which is the subject of the next subsection.

16.8.2 Advantage Estimation — From One-Step and -Step to Generalized Advantage Estimation

Hook — judging an action fairly: Suppose a chess engine evaluates your position as winning and you play a move that keeps it winning but slightly less so — was that move good or bad? The raw return says "still winning" (positive), but relative to how good the position already was, the move lost value. The advantage captures exactly that relative judgment: how much better the action was than the state's average. Actor-critic methods weight the policy gradient by this relative signal, not by the absolute return, which is why its estimation matters so much.

Advantage — definition: For a policy , let be the action value and the state value, where is the discounted return with discount . The advantage is Here measures how much better action is than the policy's average behaviour in ; its expectation under is zero, . In practice and are estimated by a learned critic and rollout rewards, so denotes an estimator.

Rather than learning and separately, modern actor-critic learns only and combines it with sampled rewards to estimate .

One-step and -step advantage — mathematics: Let be the current critic, the discount, and the immediate reward. The one-step TD error advantage is The -step advantage generalizes over real rewards before bootstrapping: Here is the horizon, the -step estimator, and the bootstrapped tail. Special cases: recovers ; as reaches the episode end the bracket becomes the full Monte Carlo return and .

Why two extremes are not enough: The Monte Carlo advantage is unbiased for the true advantage but varies widely from episode to episode because sums many random rewards — high variance, low bias. The one-step advantage depends heavily on the possibly biased critic and is myopic — low variance but higher bias. The -step family trades these properties discretely via ; Generalized Advantage Estimation blends them continuously.

The continuous blend is what GAE formalizes — an exponential weighting of the whole -sequence rather than a hard horizon cut.

Generalized Advantage Estimation — the -weighted blend: Let be the one-step TD error at time with discount as above, and let be the GAE weighting parameter. Then Here is the GAE Advantage at time , each is a one-step TD error, discounts for time, and controls the exponential down-weighting of distant TD errors. When only survives and (high bias, low variance). When the telescoping sum recovers the Monte Carlo advantage (low bias, high variance). Intermediate smoothly interpolates — "every subsequent step is discounted down and down to give lesser and lesser importance" by an extra factor per step.

Derivation intuition in one line: expanding the definition of shows ; GAE is the exponentially weighted average with , which collapses to the compact form.

Visual intuition — picture a timeline from to the right, each position holding a block . The -step estimator with stacks the first three blocks with weights . GAE stacks all blocks but dims each successive block by an extra factor — the contribution fades exponentially. Small keeps only the first few bright blocks (short-horizon, critic-heavy); large keeps many dim blocks out to the horizon (long-horizon, reward-heavy).

Worked example — GAE by hand with short numbers: Take discount and GAE parameter , so . Suppose a short trajectory with learned values and rewards:

Step 1 — one-step TD errors:

Step 2 — GAE as exponentially weighted sum (truncate after for illustration): Since ,

For comparison:

  • One-step advantage .
  • Two-step advantage .
  • Monte Carlo advantage (three steps here) .

GAE with gives , close to the Monte Carlo but with variance reduced because distant rewards are softly down-weighted rather than fully included. If the answer would be ; if it would be the Monte Carlo (with exact ). Sense-check: is strongly negative because the value dropped from 11.0 to 9.0 unexpectedly; GAE with intermediate dilutes that surprise relative to the pure one-step, but not as harshly as truncating at .

Bias–variance trade-off at a glance:

Estimator Uses Bias Variance / regime
One-step heavily Higher (depends on critic) Lower ,
-step rewards + tail Decreases with Increases with Hard cutoff at
GAE Exponentially weighted 's Decreases with Increases with Soft blend,
Monte Carlo Full return Lowest (unbiased for ) Highest (episodic variation) ,

Assumptions and scope: GAE assumes a learned state-value critic , discount , and the ability to compute along a trajectory. The finite-horizon implementation truncates the infinite sum at the end of the trajectory and bootstraps with or zero at termination. The idea-step and GAE as bias-variance controls, what does, and which extreme each recovers — is examinable. Detailed numeric sensitivity to is not the focus of examination computation. GAE was flagged as required at this high level because it appears pervasively in contemporary papers, including PPO.

Two confusions break GAE answers:

Pitfalls to avoid:

  • Writing GAE as or omitting . GAE sums TD errors , not raw rewards or returns. Summing rewards directly is the -step return, not GAE.
  • Treating as the discount. discounts future reward for the objective; discounts how far into the future the advantage looks for variance control. They multiply as but play distinct roles — is part of the problem, is an estimator design choice.

Recap and bridge: The advantage judges actions relative to the state's average. Its -step estimator and its exponentially smoothed form trade bias against variance — is one-step biased but stable, is Monte Carlo unbiased but noisy. That blended advantage is the signal PPO will reuse and clip — the next subsection's subject.

16.8.3 Proximal Policy Optimization (PPO) — Motivation, Ratio, and Clipped Objective

Hook — data are precious, but reusing them is dangerous: In on-policy learning the usual cycle is collect a rollout with , use it for one gradient step, discard it, collect again with the new . When a rollout contains a rare success, discarding it after a single use is wasteful. PPO asks: can we squeeze several mini-batch updates out of the same rollout before discarding it, without letting the policy drift so far that the old data misleads it? The clipping mechanism is the guardrail that makes that reuse safe.

The on-policy cycle without reuse is: generates an episode, the episode is used once to update , the old episode is thrown away, generates fresh data, repeat. The motivating observation for PPO is that this is sample-inefficient when good experience is rare; the desire is to "reuse the rollout again and again for controlled mini-batch updates; once you have reused your rollouts enough number of times you discard and collect again." The risk of naive reuse is that may move far from the that actually produced the data, so gradients computed from old state-action frequencies become misleading and can cause a large, destabilizing jump — the "huge change of mind" that should not dominate the loss.

The drift is what must be measured before it can be bounded.

Probability ratio — the drift measure: Let be the old policy that generated the rollout and the current policy being updated, with the actor parameters and the snapshot at data-collection time. For the state-action in the rollout, define Here is the likelihood ratio, the probability the old policy assigned to the action actually taken, and the probability the current policy assigns to that same action. Interpretation: means today and yesterday agree on this action; means the current policy emphasizes this action more than the old policy did; means it de-emphasizes it. Naively maximizing would let large deviations of drive large updates.

Once drift can be measured, it can be bounded — the clipped objective is that bound.

Clipped objective — the guardrail: Let be the advantage estimate for (typically the GAE value from 16.8.2) and let , usually , be the clipping parameter. Define the clipped ratio which constrains the effective ratio to the interval . The PPO clipped objective is Here the expectation is over time steps in the rollout batch, weights whether the action should be made more or less likely, and the implements a pessimistic bound: when the unclipped term would improve the objective more than the clipped term allows, the clipped term is taken, removing the incentive for to leave the neighbourhood . When is inside the interval, both terms inside the are equal and clipping has no effect.

Clipping intuition is easiest with the numbers quoted in class. Take so the allowed interval is . The box below works three regimes with that interval.

Worked clipping arithmetic — three cases with :

Case 1 — modest increase, stays inside: Yesterday , today . Since , . Clipping does nothing; both terms in the are . A increase is tolerated.

Case 2 — large increase, hits the ceiling: Yesterday , today . Since , . If advantage is positive, say , The objective is capped at ; the extra from pushing to is ignored. The "huge change of mind" from 0.5 to 0.9 is not allowed to dominate.

Case 3 — large decrease, hits the floor: Yesterday , today . Since , . If advantage is negative, say , Here again picks the more pessimistic (more negative) value, preventing the large drop from being exploited. Sense-check: Clipping is not symmetric in its effect — it always takes the worse of the clipped and unclipped terms, which is why is a lower bound on the unclipped surrogate. When , clipping caps how much can help; when , clipping caps how much can help — in both cases it removes the incentive to move far outside .

The training cycle that this objective supports was described procedurally: collect a fresh rollout (a sequence of interactions), compute advantages for that rollout (typically via GAE), then reuse the same rollout for several controlled mini-batch epochs — for example 4 epochs of mini-batches — optimising each time, and only then discard the rollout and collect again with the now-updated policy. The earlier performance measure from tabular policy gradients expressed the same "want to improve" intention; PPO translates it into this clipped surrogate, with the sign convention flipped to a loss to be minimized or an objective to be maximized via gradient steps on .

Visual intuition — imagine a leash of length between today's policy and yesterday's policy for each state-action. The ratio is how far the dog has pulled; inside the leash is slack and the dog moves freely; at the boundary the leash goes taut and further pulling in that direction does not move the owner — the gradient from that term is clipped. Positive advantage pulls toward larger , negative toward smaller , but neither pull matters beyond the leash length.

How reuse differs Naive reuse of on-policy data PPO clipped reuse
Objective unbounded in bounded
Large when Encouraged without limit Capped at
Small when Encouraged without limit Capped at
Effect of No guardrail Trust region of radius around

Assumptions and scope: PPO assumes on-policy rollouts (data from ), a differentiable policy , and an advantage estimator . The ratio and clipping interval with typically are the core mechanics. The idea — why PPO wants to reuse data, what , , mean, what clipping does, and the rollout → advantages → mini-batch reuse → discard cycle — is examinable at the conceptual level introduced. The lecture explicitly says detailed PPO numerics are not required for the examination; the simplified worked illustration in the notes is recommended as a clearer entry point than the original papers when studying in free time.

A frequent misreading is to treat PPO as fully off-policy because it reuses old data.

Pitfalls to avoid:

  • Calling PPO off-policy. The data are generated by but reused only within the proximal neighbourhood and only for a few epochs before being discarded. True off-policy methods learn indefinitely from arbitrary behaviour policies; PPO is better described as controlled reuse of on-policy rollouts.
  • Applying clipping to the advantage instead of the ratio. Clipping acts on , not on . Writing or misplaces the guardrail; the quantity bounded is how far the policy's probability for the taken action may move.

Recap and bridge: PPO reuses a fresh rollout for several mini-batch epochs before discarding it, but guards that reuse with clipped to via . Inside the interval matters normally; outside, the removes the incentive to push further — a huge change of mind from yesterday to today cannot dominate the loss. With the A3C/A2C cycle, GAE blending, and PPO clipping in place, the remaining questions are the two students most often ask about off-policy reuse and what "middle ground" really means.

16.8.4 Student Questions and Answers on Advanced Policy Methods

Q: If PPO reuses old data for multiple updates, does that not make it off-policy? A: The data are indeed generated by an older policy while updates are applied to the current , so there is a mismatch. PPO acknowledges that mismatch through the ratio and the clipping constraint . Reuse is allowed only within the proximal neighbourhood and only for a small, fixed number of epochs (for example 3–4) before the rollout is discarded and fresh on-policy data are collected with the new . That controlled, short-horizon reuse distinguishes PPO from fully off-policy methods that would learn indefinitely from a fixed replay buffer under an arbitrary behaviour policy. The right description is reuse of on-policy rollouts with a trust-region guardrail, not off-policy learning.

Why GAE is repeatedly called the middle ground was the second point students asked to hear again.

Q: Why is GAE described as a middle ground, and what does actually control? A: Because it blends many one-step TD errors rather than committing to a single horizon . With near the blend is dominated by the first few 's — it inherits their low variance but also the bias of the critic , behaving like the myopic one-step advantage. With near the blend reaches far into the future and recovers the Monte Carlo advantage — nearly unbiased but with the high variance of full returns. Intermediate trades the two: each successive is multiplied by another factor , so its contribution is progressively down-weighted. Formally , with the problem discount and the estimator design knob. That soft, exponential weighting — versus the hard cutoff of a fixed -step — is why GAE is called a soft choice.

Exam-facing synthesis for this section:

Question that appears on the paper What a good answer shows
Contrast A3C and A2C operationally Five-step cycle (copy, roll out, compute, accumulate, apply) and whether step 5 is asynchronous unlocked or synchronized batched; A2C is the modern batched variant
Write an advantage estimator One-step , -step , and GAE with and bias-variance interpretation
Explain PPO at idea level Data are precious but on-policy data would be discarded after one use; PPO reuses a rollout for several mini-batch epochs, guarding drift via clipped to and the pessimistic objective

Recap and bridge: A3C versus A2C is asynchronous unlocked pushes versus synchronized batched pushes of the same five-step worker cycle; GAE is the exponential blend that soft-trades bias for variance between the myopic and the noisy ; PPO makes reuse safe by measuring drift as and clipping it to inside a pessimistic . No detailed PPO numerics are required for the examination — the ratio, the interval, the , and the rollout-advantages-minibatch-reuse-discard cycle are the ideas to carry forward. Together with the decision-time planning of 16.7, these policy methods complete the transition from single-trajectory actor-critic to the large-scale, stable training that underpins contemporary applications — including, as the next section shows, viewing a language model itself as a sequential policy.

16.9 Language Models Viewed as Sequential Policies

This closing perspective reframes a familiar system — a language model — in the vocabulary built across the lecture. What looked like next-word prediction becomes a policy, a trajectory, and an optimization problem identical in form to lane keeping and game playing.

16.9.1 A Language Model as a Sequential Policy

Hook — the language model as an agent that acts by writing: A chatbot does not answer in one shot. It chooses a word, sees the sentence so far, chooses the next word, sees the updated sentence, and continues until it decides to stop. Each word is an action that changes what the model sees next. That incremental, state-dependent choice is exactly what a sequential policy does.

The intuition is conversation as trajectory. A conversation starts with an initial context — the user's prompt and system instruction. The model emits a first token, the context grows by that token, the model emits a second token conditioned on the longer context, and so on. The full response is not scored word by word in isolation; the final quality — helpfulness, correctness, tone — is judged after the sequence is complete. In reinforcement-learning language, the sequence of contexts and tokens is a trajectory and the final judgement is a return that credits every token choice.

Language model distribution: Let prompt be the initial context (for example "write a program that sorts a list"), let vocabulary be the finite token set, and let with each be the generated response. Let be the model parameters. The model defines a conditional distribution over full responses where may vary across responses and termination is signalled by a special end-of-sequence token or a length limit.

This joint distribution is not parametrized directly over exponentially many sequences. It is factorized autoregressively.

Chain-rule factorization — 16.9.formula.1: By the chain rule of probability applied to the token sequence, where denotes with empty, each factor is the next-token distribution given the prompt and all earlier tokens, and for every prefix. Taking logarithms gives the sum used in training, Each factor is produced by the same network conditioned on a growing context, so generating a response is sampling a trajectory one factor at a time.

In reinforcement-learning terms each factor is already a policy. Writing for the context before step and for the token chosen at that step, so the factorization reads . The probability of a full response is the product of policy decisions along its trajectory — identical in form to the trajectory probability that appears in REINFORCE.

Visual intuition — draw a horizontal timeline of steps. At step a box holds the current state — the prompt plus the prefix built so far, for example "write a program" "write a program: def". An arrow labelled fans out to the vocabulary, one token is sampled and appended, producing . Repeating the loop builds the full sequence. Below the timeline the product accumulates to . A terminal EOS token caps the trajectory; before EOS the process is open, after EOS the episode ends.

Illustration — a three-token response with the factorization visible: Take prompt "complete: Hello". Suppose the model generates in three steps: If the three factors are , , and , then and . Changing to increase any factor increases the joint probability of the responses that contain it — exactly how a policy update shifts probability toward rewarded trajectories.

What is not being claimed: This view does not change how the language model is architecturally implemented. The same transformer that was trained to predict the next token is reinterpreted as a policy; no new network is introduced by the reinterpretation. The benefit is vocabulary: optimization ideas from earlier sections — REINFORCE's , baselines, actor-critic TD errors, GAE, and PPO's clipped reuse — can be applied to language-model fine-tuning by substituting with the elements above.

16.9.2 Mapping Reinforcement-Learning Elements to Language-Model Elements

Complete mapping: The correspondence is one-to-one between the MDP vocabulary of Sections 16.2–16.8 and the language-model vocabulary:

MDP element Symbol Language-model element Concrete instance
State Prompt plus all tokens generated so far Instruction "write a program" concatenated with the code emitted up to the current position
Action Next token chosen from the vocabulary Choosing "def" from among keywords and subword tokens
Policy Next-token distribution the model outputs at step Softmax over conditioned on the growing context
Transition Deterministic concatenation Appending the sampled token to the context
Episode / trajectory One completed response User asks for a letter, model generates token by token until or length limit
Reward or Quality of the response Human thumbs-up, pairwise preference, or score from a reward model; typically sparse and given at the end
Reward model Learned evaluator of response quality Model trained on human comparisons that maps to a scalar score used as the optimization signal

Here is the prompt, the vocabulary, the end-of-sequence token, and the reward-model parameters (distinct from policy parameters ). The transition is deterministic — choosing fully determines — so all stochasticity is in the policy.

This mapping clarifies where the reward comes from. In classical control the environment returns a numeric reward; in language, quality is a human judgement. In practice the judgement is distilled into a reward model trained from multiple signals — ratings, comparisons, or pairwise preferences — that evaluates how useful or appropriate a response was. The lecture's phrasing that quality "can be inferred from multiple places" and that "what you actually do is to learn a model, a reward model, which will evaluate various parameters and tell you how good this response was" refers to this object. Once is available, it supplies the scalar reward for policy optimization.

Real-world — RLHF and DPO as policy optimization on this MDP: Reinforcement learning with human feedback (RLHF) collects human comparisons between responses, trains a reward model to predict the preferred response, and then fine-tunes to maximize with a policy-gradient method — often PPO — regularized to stay close to the original model. Direct preference optimization (DPO) reaches a similar end by optimizing the policy directly from preferences without an explicit scalar reward model. Both frame the same problem: state is prompt plus prefix, action is next token, policy is the next-token distribution, and trajectory quality is preference. This is why the A3C/A2C, GAE, and PPO machinery of Section 16.8 reappears in contemporary language-model training.

The view is unifying rather than expansive: it does not add a new algorithm to memorize but shows that the states, actions, policies, episodes, and rewards defined for grid worlds, lane keeping, and game planning already organize language-model fine-tuning.

Recap: A language model defines where each factor is a policy over next tokens, state is prompt plus prefix , action is the next token, transition is concatenation, an episode is a completed response ending at or length limit, and reward is response quality typically supplied by a learned reward model . That identification lets the policy-gradient, advantage-estimation, and PPO ideas of earlier sections transfer to RLHF and DPO for language models.

Exam Guidance Summary

This appendix consolidates every explicit scope and study instruction issued during the session. It does not add new material; it organizes what is examinable, what is background only, and how to use the open-book format. Keep the algorithm sheets flagged for quick reference and treat this page as the checklist for revision.

How to use this summary: The lecture notes are a 191-page superset spanning all ambitions for the course across offerings. Only topics actually delivered in class and at the depth delivered in class are examinable at this offering; ambition material earmarked for future re-alignment is not. The slides and the textbook are authoritative companions to the notes — where the notes compress what was taught in detail, follow the slides and textbook. The examination is open-book; no parameter values, paper years, or line-by-line algorithm text need to be memorized, but the ability to interpret and apply the material is essential.

Scope by topic — what to prioritize

General scope. Notes are a 191-page superset; examinable scope follows delivered content only. Slides and textbook are the authoritative companions where notes are compressed.

Foundations (classes 1–6) and dynamic programming. As previously covered for the midterm, these remain background that every later topic builds upon. No change in scope; treat as assumed knowledge for all later numerics.

Off-policy Monte Carlo. Examinable: definition of off-policy learning, the importance-sampling ratio and its product form, and its numerical use (basic sections and the numerical), and the off-policy Monte Carlo prediction and control algorithm of the notes' Section 8. For understanding and post-course enrichment only: statistical-behaviour derivations and the application survey. Practice the backward incremental sweep involving and .

Temporal-difference learning. Examinable: what temporal difference is, how it takes the best of dynamic programming and Monte Carlo, the meaning of temporal-difference target and temporal-difference error (one-step and its multi-step generalization), the grid-world running example, the control loop (initial , -greedy policy derived from , update that simultaneously improves and policy), and the three algorithms SARSA, Q-learning and Expected SARSA — including which parts of their update targets differ. Maximization bias and how double Q-learning addresses it are important to understand irrespective of a guarantee that a question will appear on them. Recommended practice: random-walk extra problems. For numerical precision, commit to one exact algorithm statement (notes versus slides) and use it consistently.

On-policy prediction with approximation. Examinable: mean squared value error as the objective, stochastic gradient descent as the optimizer and when to use it, the semi-gradient distinction, and the two pairings (Monte Carlo versus temporal difference with approximation). The textbook summary image (exhaustive search versus temporal difference, width versus depth trade-off) is examinable. Feature construction (coarse coding, tile coding, radial basis functions) is examinable at the class-taught level; the notes' expanded deep-learning feature-extraction survey is lower priority for this examination and higher priority for post-course reading. For this block, prioritize the textbook and slides over the notes.

Deep Q-Networks. One-plus class of coverage; the 2015 version plus the incremental Double DQN idea are sufficient — the 2013 version need not be studied separately because its content is contained in the 2015 version. Experience replay is the deepest examinable point: be able to explain reuse, decorrelation and distribution smoothing beyond the one-line definitions, and to argue why replay helps or would not help in a new scenario. Not examinable: sections from Section 10 onward in the DQN notes and the games-solved-by-DQN surveys. Entirely out of scope: Section 13 of the DQN notes — marked as ambition for the next offering — including bias in DQN there.

Policy-gradient methods. Examinable: the policy-gradient theorem statement and its implication (gradient involves ) — the proof is explicitly not examinable (post-examination pointer: Grokking Deep Reinforcement Learning for an accessible proof). Examinable at the conceptual level and through the lane-keeping numerics: REINFORCE, REINFORCE with baseline, and actor-critic with one-hot states, , constant, , and given, and versus versus weighting the same . The Gaussian log-policy derivation and the substitution are expected; changing 's form changes only that derivative, the rest remaining mechanical. Not required: Section 11 of the policy-gradient notes (softmax alternative for discretized steering) and the optional Section 13 onward. The shared intermediate notes on lane keeping are provided for practice and verification but are not themselves examination material.

MCTS / AlphaGo / AlphaZero / MuZero / Planet — guest session. Examinable: motivation for model-based learning, meaning of decision-time planning, and MCTS at the four-stage level (selection, expansion, simulation, backup) with the UCT rule understood as UCB on a tree, including the ability to trace a couple of iterations through the two numerics flagged (guest's class example and the small notes numerical). For AlphaGo, AlphaZero, MuZero and Planet, examinable at a high level: what each work accomplished, its key technical improvement, and how it uses MCTS. Explicitly not expected: specific pseudocode and parameter values from those papers.

Advanced policy themes — A3C/A2C, GAE, PPO, and language models as policies. Examinable at the operational level: the A3C/A2C five-step worker cycle and the asynchronous-versus-synchronized distinction. Examinable at the trade-off level: generalized advantage estimation — -step versus one-step versus GAE as a -weighted sum of TD errors , with the bias–variance interpretation. Examinable at the idea level: PPO's cycle — collect a fresh rollout, compute advantages, reuse the same rollout for controlled mini-batch updates before discarding, the ratio and the meaning of / / , and clipping to to prevent large changes of mind from dominating the loss; detailed PPO numerics were explicitly marked as not required (use the simplified notes illustration when free as an easier entry point than the research papers). Viewing a language model as a sequential policy — state as prompt plus generated prefix, action as next token, policy as next-token distribution, episode as a completed response ending with EOS or length limit, and reward via a reward model — was introduced as a unifying application perspective; it consolidates rather than extends the assessed material and is examinable at the mapping level above. From Section 15: the promised imitation-learning session (DAgger, about one hour) is the only topic that will be covered in depth; inverse reinforcement learning and reward modeling (as used in DPO), multi-agent reinforcement learning, and safety in reinforcement learning will be introduced only at a what-it-is and what-it-models level.

Practical conduct

Open-book discipline: Have the algorithm sheets cleanly flagged for quick reference. Write all assumptions explicitly. Show work in tables where applicable; a tabular layout is easier to grade than scattered prose. If any hyperparameter or definition is missing from a problem statement, ask or declare an explicit assumption rather than guessing silently.

Recap — revision priority in one scan: Foundations are assumed background. Off-policy Monte Carlo, temporal difference (including SARSA, Q-learning, Expected SARSA, and double Q-learning), function approximation, DQN with replay, policy gradients through lane-keeping numerics, MCTS with UCT, and the A3C/A2C–GAE–PPO chain plus the language-model-as-policy mapping are examinable at the depths named above. Statistical derivations, application surveys, and ambition sections are enrichment unless explicitly listed. The proof of the policy-gradient theorem and detailed PPO numerics are not required; the theorem statement, REINFORCE mechanics, and PPO's ratio-clipping idea are.

Key Industry Applications

This appendix maps each major method from the lecture to a named industry domain that uses the same structure. It does not introduce new examination material; it shows where the ideas reappear in production systems.

How to read this appendix: Each entry names a domain, the lecture concept it instantiates, and the concrete transfer. The same state–action–policy–episode–reward vocabulary organizes all of them — from tree search to language-model alignment.

Planning and search — game playing and logistics optimization. The exhaustive-search versus temporal-difference spectrum is not merely a pedagogical diagram — the same trade-off appears in production planning where full tree expansion is infeasible and sampling-based planning (MCTS-style) or learned value heuristics are used instead. The width–versus–depth choice the textbook image makes visible governs how logistics, scheduling, and game-playing systems allocate computation.

Value prediction with generalization — recommendation and large-scale state evaluation. Function approximation with as a linear precursor to deep-network approximation underpins every modern value-prediction system that generalizes across states. The substitution of a deep network wherever the notes write the linear form is how deployed reinforcement-learning systems scale from textbook grid worlds to high-dimensional inputs such as user–item contexts in recommendation and content ranking.

Deep reinforcement learning from high-dimensional observations — game AI and visual control. Deep Q-Networks as scaled Q-learning with function approximation, together with experience replay for decorrelation and sample efficiency, are the template behind game-playing agents that operate directly on high-dimensional observations — the notes' games-solved-by-DQN surveys point to that class of application, which extends to visual navigation and simulated control where observations are images rather than compact states.

Continuous control — robotics and lane-keeping assistance. The stochastic policy parametrized as a Gaussian with is the standard continuous-control parametrization in industrial control problems; the lane-keeping assistance problem is a representative instantiation — keeping a vehicle centred in a lane with continuous steering in and a reward for centre — of the same class that includes robotic manipulation, autonomous driving, and industrial process control.

Decision-time planning — the Alpha family of game-playing systems. Decision-time planning via Monte Carlo Tree Search, with the UCT rule balancing exploration and exploitation in the tree, is the search backbone behind the Alpha family — AlphaGo, AlphaZero, MuZero and Planet — each of which applies MCTS over a learned model with progressively less reliance on hand-crafted knowledge and progressively more on learned dynamics. The pattern transfers wherever a simulator or learned world model is available for lookahead.

Distributed training — large-scale reinforcement learning infrastructure. Parallel actor-critic architectures — A3C with asynchronous unlocked updates and A2C with synchronized batched rollouts — are the design pattern for distributed reinforcement-learning training, where many workers explore independently and contribute to a shared master policy. The same coordinator–worker structure underpins data-centre-scale training for games, robotics fleets, and language-model fine-tuning.

Stable large-scale policy optimization — RLHF and DPO pipelines. Generalized advantage estimation as a bias–variance-controlled blend of TD-error signals and proximal policy optimization as a clipped, reuse-aware on-policy updater are the current default combination for training large-scale policies, including the reinforcement-learning-with-human-feedback (RLHF) and direct-preference-optimization (DPO) pipelines that fine-tune language models. PPO's ratio and interval are what make reuse of on-policy rollouts safe at that scale.

Language models as sequential decision-makers — conversational AI and code generation. Viewing a language model as a sequential policy with state as prompt plus prefix, action as next token, episode as a completed response, and reward supplied by a learned reward model is how modern RLHF and DPO systems frame language-model alignment — the same MDP vocabulary that organizes grid-world control now organizes the training of conversational and code-generation models.

Data efficiency — sample-efficient learning in any sequential-data system. Experience replay's three purposes — reuse, decorrelation and distribution smoothing — generalize to any data-driven system where sequential correlations would otherwise bias learning and where carefully curated historical data improve efficiency, from offline reinforcement learning on logged interactions to continual learning from production traces.

Recap: Grid worlds illustrate tabular control; approximation and deep Q-networks scale that control to high-dimensional domains such as recommendations and game AI; Gaussian policies instantiate continuous control in robotics and driving; MCTS with UCT powers the Alpha family; A3C/A2C, GAE, and PPO supply the distributed, variance-controlled, reuse-safe training behind today's RLHF and DPO language-model pipelines; and the language-model-as-policy view unifies all of them under one vocabulary of states, actions, policies, episodes, and reward models.

DRL Lecture 16 notes · Comprehensive Examination Revision and Advanced Policy Methods

Deep Reinforcement Learning· postgraduate· 2026-08-22

Sections Breakdown

1Course Overview and Examination Scope

The 191-page notes are a superset; the examinable syllabus follows delivered lectures and slides, with an open-book examination that tests comprehension of every algorithm term rather than memoriza...

2Off-Policy Monte Carlo Methods

Off-policy Monte Carlo reweights episodes from a behaviour policy b to estimate values for a different target policy pi via the product importance-sampling ratio; ordinary and weighted estimators a...

3Temporal-Difference Learning

One-step TD combines dynamic-programming bootstrapping with Monte Carlo sampling via the target R+gamma V(S') and error delta; SARSA, Q-learning and Expected SARSA differ by their targets, and Doub...

4On-Policy Prediction with Function Approximation

Function approximation replaces a per-state table with a shared parametrized function vhat(s,w) trained to minimize MSVE under the on-policy distribution via SGD; the same template yields true-grad...

5Deep Q-Networks

DQN replaces tabular Q(s,a) with a convolutional network Q(s,a;theta) trained off-policy against the Bellman target r+gamma max Q(s',a';theta-) via squared-error regression, stabilized and made dat...

6Policy Gradient Methods and the Lane-Keeping Control Problem

Policy gradients follow nabla log pi(a|s;theta) weighted by return via the log-derivative trick; REINFORCE, its baseline variant (G - Vhat), and one-step actor-critic (delta = R+gamma Vhat(s')-Vhat...

7Model-Based Planning — MCTS, AlphaGo, MuZero and Planet

Decision-time planning uses a model to search from the current state before acting; MCTS makes this practical via iterative selection by UCT, expansion, fast rollout simulation, and backup, and the...

8Advanced Policy Methods — Asynchronous Methods, Generalized Advantage Estimation and Proximal Policy Optimization

Parallel actor-critic (A3C async vs A2C sync) scales the same five-step worker cycle; n-step and GAE advantage estimators trade bias for variance via horizon n or exponential weighting by lambda; P...

9Language Models Viewed as Sequential Policies

Reframes a language model as an autoregressive sequential policy via the chain rule p(y|x)=prod p(y_t|x,y_{\lt t}>); each factor is pi(a_t|s_t) with state s_t=(x,y_{\lt t}>), action next token, deterministic...

10Exam Guidance Summary

Appendix consolidating all examinable scope: 191-page notes are a superset — only delivered content is examinable; off-policy MC, TD/SARSA/Q-learning/Expected SARSA/double Q, function approximation...

11Key Industry Applications

Appendix mapping each method to a named domain: planning/search to logistics optimization, approximation to recommendation, DQN+replay to game AI/visual control, Gaussian policy to robotics and lan...

Postgraduate students in Deep Reinforcement Learning

Exam Revision Notes

Below is the distilled, exam-ready core. Every entry comes from the full explanation above. Use this section for rapid review; return to the main notes when a point needs more context.

Course Overview and Examination Scope

Must-know: Notes are a superset — examinable scope follows delivered lectures and slides, not the full 191 pages; open-book means every algorithm is available but you must know what each symbol and step means and declare any assumed hyperparameters.

⚠️ Top pitfall: Treating the notes superset as the syllabus, or assuming hidden hyperparameters without declaring them on the answer sheet.

Self-check: What are the two valid preparation styles for any algorithm, and why does comfort with a chosen level matter more than memorizing line numbers?

Connects to: 16.2, 16.3, 16.4

Off-Policy Monte Carlo Methods

Must-know: Coverage requires b(a|s)>0 whenever pi(a|s)>0; per-step ratio rho_t=pi/b product along trajectory corrects the expectation because dynamics cancel; WIS divides by sum of weights, is biased finite-sample but low variance.

⚠️ Top pitfall: Multiplying discount gamma or transition p into rho; dividing by visit count when the question asks for WIS; forgetting the break when At != pi(St) in control.

Self-check: Given pi(L|X)=0.8 and b(L|X)=0.5 for one step, what is rho_t, and does it up-weight or down-weight that transition?

Connects to: 16.3, 16.6, 16.8

Temporal-Difference Learning

Must-know: TD target is R+gamma V(S') and TD error is that minus V(S); SARSA uses sampled Q(S',A'), Q-learning uses max_a Q(S',a) (off-policy), Expected SARSA uses sum_a pi(a|S')Q(S',a); Double Q-learning decouples max selection from evaluation to remove positive bias.

⚠️ Top pitfall: Calling Q-learning on-policy because its behaviour is epsilon-greedy; maintaining a separate policy table instead of deriving it from Q; forgetting Q(terminal)=0 bootstrap.

Self-check: Does updating Q(S,A) also update the policy at S, and why does Expected SARSA with a greedy pi collapse to Q-learning?

Connects to: 16.2, 16.4, 16.5

On-Policy Prediction with Function Approximation

Must-know: MSVE = E_{S~mu}[(v_pi(S)-vhat(S,w))^2] is the objective; linear vhat=w^T x(s) has gradient x(s); Monte Carlo update uses error G_t - vhat (true gradient) while TD(0) uses delta = R+gamma vhat(S')-vhat(S) as semi-gradient ignoring target dependence on w; linearity is a pedagogical stand-in for a neural network.

⚠️ Top pitfall: Calling semi-gradient TD true gradient descent; forgetting that d << |S| forces trade-offs weighted by mu(s); assuming more features always helps.

Self-check: Why is the TD(0) update called semi-gradient and what target does it ignore when differentiating?

Connects to: 16.3, 16.5

Deep Q-Networks

Must-know: 2015 DQN subsumes 2013; Q(s,a;theta) outputs all K action values from one state in a single forward pass and is trained against y=r+gamma max Q(s',a';theta-); experience replay's three purposes are reuse, decorrelation, and distribution smoothing and must be argued beyond the three phrases.

⚠️ Top pitfall: Calling DQN on-policy because behaviour is epsilon-greedy; reciting reuse/decorrelation/smoothing without naming the tuple, buffer size, and violation of the i.i.d. assumption.

Self-check: Why must DQN be off-policy and why does uniform sampling from a million-entry buffer reduce variance?

Connects to: 16.3, 16.4, 16.6

Policy Gradient Methods and the Lane-Keeping Control Problem

Must-know: Policy gradient theorem gives nabla J = E[Q pi nabla log pi]; REINFORCE is theta <- theta + alpha gamma^t G_t nabla log pi with log-derivative trick; Gaussian log pi gradient is (a-mu)/sigma^2 x(s); baseline uses G-Vhat and actor-critic uses delta=R+gamma Vhat(s')-Vhat(s); lane-keeping has three one-hot states, sigma=0.2, theta0=[-0.5,0,0.5], worked left-state update to -0.45.

⚠️ Top pitfall: Treating mu(s) as the action instead of a sample from N(mu,sigma^2); updating all theta coordinates instead of only the visited state's one-hot coordinate; writing sigma instead of sigma^2 in the gradient denominator.

Self-check: Derive the Gaussian nabla log pi from pi -> log pi -> gradient and compute the left-state REINFORCE update for a=-0.3, sigma=0.2, G=1, alpha=0.01.

Connects to: 16.4, 16.5, 16.8

Model-Based Planning — MCTS, AlphaGo, MuZero and Planet

Must-know: Model-based vs model-free and decision-time vs background planning; MCTS four stages in order (selection, expansion, simulation/rollout, backup); UCT as UCB on a tree with exploration constant c; ability to trace 2 iterations computing UCT, expanding, simulating, and backing up counts/means; Alpha-family lineage at high level — milestone, improvement over predecessor, and how MCTS is used; DAgger in depth vs inverse RL / multi-agent / safety at intro level.

⚠️ Top pitfall: Swapping log N(s) with N(s) or N(s,a) in the UCT numerator; starting simulation from the root instead of the newly expanded leaf; conflating planning (using a model to search) with learning the model.

Self-check: Given root N(s0)=2, children (N=1,Xbar=1.0) and (N=1,Xbar=0.0), c=1.4, compute both UCT values and state which child selection picks; then expand the untried edge, assume rollout G=1, and write the updated N and Xbar along the visited path.

Connects to: 16.5, 16.6, 16.8

Advanced Policy Methods — Asynchronous Methods, Generalized Advantage Estimation and Proximal Policy Optimization

Must-know: A3C/A2C five-step worker cycle and async unlocked vs sync batched step-5 difference; n-step advantage and GAE A^GAE=sum (gamma lambda)^l delta_{t+l} with lambda in [0,1] bias-variance trade; PPO motivation (precious data, reuse), ratio r=pi/pi_old meaning r=1/>1/<1, clipping to [1-eps,1+eps] (eps 0.1-0.2), L_CLIP=E[min(rA, clip(r,1+-eps)A)], and rollout-advantages-minibatch reuse-discard cycle. No detailed PPO numerics required.

⚠️ Top pitfall: Saying A3C has no master network; writing GAE over raw rewards instead of delta; clipping the advantage instead of the ratio r; calling PPO fully off-policy rather than controlled reuse of on-policy rollouts.

Self-check: List the 5 worker steps and say which step differs between A3C and A2C; write GAE and state what lambda=0 and lambda=1 recover; given pi_old=0.5, pi=0.9, eps=0.2 compute r and clip(r,0.8,1.2) and say which term min() picks when A>0.

Connects to: 16.6, 16.7, 16.9

Language Models Viewed as Sequential Policies

Must-know: Chain rule factorization p(y|x)=prod p(y_t|x,y_{\lt t}}) and log sum; RL mapping: s_t=(x,y_{\lt t}}), a_t=y_t, pi=p(y_t|x,y_{\lt t}}), episode ends at EOS/length, reward via learned reward model hat{r}_phi.

⚠️ Top pitfall: Treating p(y|x) as a single joint table instead of product of policy factors; confusing state (prompt+prefix) with prompt alone; expecting per-token reward instead of sparse end-of-episode preference.

Self-check: Write p(y|x) as product over t, map each symbol to s_t/a_t/pi, and name where RLHF and DPO use the same MDP elements.

Connects to: 16.6

Exam Guidance Summary

Must-know: Notes are a superset; only delivered depth is examinable; slides/textbook authoritative where notes are compressed; open-book — no memorization of values or verbatim algorithms, but ability to interpret and compute is essential.

⚠️ Top pitfall: Revising ambition sections (e.g. DQN Section 13, games surveys, Section 11 softmax alternative) or memorizing paper pseudocode/parameters explicitly marked not expected.

Self-check: List each block's examinable boundary and one item explicitly marked out-of-scope for this offering.

Connects to: 16.2, 16.3, 16.4, 16.5, 16.6, 16.7, 16.8, 16.9

Key Industry Applications

Must-know: Each method's deployed counterpart: exhaustive-vs-TD trade-off, approximation generalization, DQN replay, Gaussian continuous control, MCTS+UCT, distributed actor-critic, GAE+PPO for RLHF/DPO, and LM as sequential policy.

⚠️ Top pitfall: Treating industry entries as new material to memorize rather than the same MDP vocabulary — state, action, policy, episode, reward — instantiated in a different domain.

Self-check: Name the domain for each method and state which MDP element it instantiates.

Connects to: 16.4, 16.5, 16.6, 16.7, 16.8, 16.9

Was this lecture useful?

Loading comments…
🤖

BitsNotes AI Assistant

Subject Notes Assistant

Configure AI Chat

Choose how to access the chatbot
Have your own API key?

Switch to "Bring Your Own Key" tab above for unlimited access with any OpenAI-compatible provider.

🔑 Enter API key above to fetch live models from provider, or enter model name manually.
OpenAI-Compatible API Support

Choose any provider preset (Gemini, DeepSeek, Kimi, GLM, MiniMax, Qwen, OpenAI, Groq, Ollama, etc.) or enter a custom endpoint URL.

Security & Privacy First

Your API key is sent directly from your browser to your specified provider. BitsNotes servers never store or see your key.