Unit 5 of 13 · about 3 hours · explain

On-policy and off-policy learning with behavior and target policies

Every off-policy claim stands or falls on one distinction: which policy generated the data and which policy the update improves. Mixing them up silently redefines the result.

You'll be able to

  • Explain behavior versus target policies and which policy each tabular update evaluates.
  • Explain why Q-learning is off-policy while Sarsa with matched sampling is on-policy.
  • State the coverage requirement that any behavior policy must satisfy.

Covers

On-policy and off-policy learningBehavior policies and target policies
1

Read

In this order, only the parts listed

0 of 3 done

  1. Control without exploring starts and the behavior-target setupReinforcement Learning: An Introduction (2nd ed.) - Chapters 2, 5, 6 and 7

    Chapter 5, Sections 5.4 and 5.5: -soft control and the behavior-target setup with the coverage assumption (printed pp. 100 to 109)

    Read for the policy definitions and the coverage rule; leave the ratio algebra to the next unit.

  2. Sarsa and Q-learning policy rolesReinforcement Learning: An Introduction (2nd ed.) - Chapters 2, 5, 6 and 7

    Chapter 6, Sections 6.4 and 6.5: the Sarsa box and the Q-learning box with rule (6.8) (printed pp. 129 to 132)

    Compare what each box learns versus what generates its data; leave Expected Sarsa and maximization bias to later units.

  3. On-policy versus off-policy framingStanford CS234 Winter 2026 - Policy Evaluation and Q-Learning

    Lecture 4, On and Off-Policy Learning (slide 34), with Q-learning as the off-policy case (slide 35)

    Use the framing only; the derivations live in Sutton.

2

Focus on

  • The behavior policy generates actions. The target policy is the one being evaluated or improved. On-policy means ; off-policy means they differ.
  • Sarsa backs up with the action actually taken, so it evaluates the behavior policy. Q-learning backs up regardless of the next action, so it directly approximates .
  • Coverage requires to imply . Without it some target actions never appear and no weight can repair the gap.
Common mistakes · 3
  • Calling Q-learning on-policy because one policy object acts and updates. The target uses the max, not the behavior action, so the learned values are off-policy even with a single actor.
  • Assuming greedy behavior is safe for Sarsa. Without exploration Sarsa stops updating unvisited pairs and can lock onto a suboptimal policy.
  • Believing more off-policy data always helps. Data from without coverage of adds no information about the missing actions.
3

Try it yourself

Closed-book, before checking anything

Closed-book, classify Sarsa, Q-learning and Expected Sarsa as on-policy or off-policy under behavior policy , and write the coverage condition. Then give a two-action case where picks the unsupported action and state the conclusion: nothing about that action.
4

Quiz yourself

Answer first, then mark it. Missed ones go to Review.

0 got · 0 missed

  1. 1.Why is Q-learning off-policy even when actions come from its own -greedy policy?Answer

    Its target uses the maximum over next actions, not the action the behavior policy will take. It learns about the greedy policy while behaving -greedy.

  2. 2.Suppose action selection is fully greedy with identical initialization and tie-breaking. Do Sarsa and Q-learning behave identically?Answer

    Almost, but not exactly. Sarsa picks before updating , while Q-learning picks its next action after the update, so when the update can change which action is greedy and the two runs diverge. Exercise 6.12 asks exactly this.

  3. 3.Behavior never tries action up in some state. What can off-policy learning say about it?Answer

    Nothing. Coverage fails, so no trajectory carries information about that pair.

  4. 4.Which policy's values does on-policy Monte Carlo control improve?Answer

    The -soft behavior policy it samples from, per Section 5.4. Optimality comes only as exploration decays.

You're done when

You classify each update's learned policy without notes and can spot a coverage failure in a behavior log.

Only when you can do this without notes.

Leads to

Notes

Resources · 2 for this unit, 5 more in the section
  • Reinforcement Learning: An Introduction (2nd ed.) - Chapters 2, 5, 6 and 7Richard Sutton and Andrew Barto · primary

    The authors post the full second edition free at incompleteideas.net; cite the printed page numbers. Study Sections 2.4 and 2.5 (incremental and constant step-size estimates), Chapter 5 without the starred sections (Monte Carlo prediction and control, ordinary and weighted importance sampling), Chapter 6 Sections 6.1 to 6.7 (TD(0), Sarsa, Q-learning, Expected Sarsa, maximization bias) and Chapter 7 Sections 7.1 to 7.3 (n-step methods). Reproduce Example 5.4 (off-policy blackjack), Example 6.2 (random walk) and Example 6.6 (cliff walking), and implement each update from fixed hand-calculated trajectories before training an agent.

  • Stanford CS234 Winter 2026 - Policy Evaluation and Q-LearningStanford University · required

    Study Lecture 3 (tabular policy evaluation) and Lecture 4 (Q-learning) slides and the relevant independent Assignment 1 and 2 written questions. Use the course treatment to state model-access, convergence, coverage and function-approximation assumptions for each update.

Also in this section

  • Hands-on Modern RL - Dynamic Programming, Monte Carlo and TDWalking Labs · support

    Use the DP, MC and TD page and the bandit script as a code companion. Rebuild the algorithms in the shared track schema, and keep the bandit comparison as a seed-sensitivity case: which method wins changes with the seed. Pin commit 9231bab of walkinglabs/hands-on-modern-rl; its code/chapterNN folders do not follow the site chapter numbers.

  • Gymnasium Core APIFarama Foundation · reference

    Use the reset, step, seeding and wrapper documentation as the behavior authority for the installed environment version: reset(seed=...) seeds once, step returns terminated and truncated, and vector environments autoreset on the next step by default. Test observation, reward, terminated, truncated and info fields at the boundary.

  • Deep-ML - Tabular Prediction and Control ProblemsDeep-ML · support

    Use named problems as closed-book checks after your own implementation passes: 272 (first-visit Monte Carlo), 257 (TD error), 273 (n-step TD), 175 (SARSA), 476 (Expected SARSA), 133 (Q-learning) and 518 (cliff walking, SARSA versus Q-learning). Read each problem's tests before trusting its statement.

  • Reinforcement Learning Control Laboratory - Tabular ControlRoadmap-Final · required

    Complete the MC, SARSA and Q-learning requirements with exact trajectory updates, stochastic and exploration-sensitive environments, visitation logs, matched interaction budgets and seeded alignment and bootstrap defects.

  • Reinforcement Learning: An Introduction (2nd ed.) - Starred Sections 5.8 and 5.9 and Chapter 10 Sections 10.3 to 10.5Richard Sutton and Andrew Barto · support

    Study starred Section 5.9 on per-decision importance sampling only for the per-decision estimator, and Chapter 10 Sections 10.3 to 10.5 on average reward and differential values only for the continuing-task unit. Cite printed pages; the authors post the full text free at incompleteideas.net.