Classical RL II: Sampling, Temporal Difference and Control

When a transition model is unavailable, values and policies must be learned from sampled experience. This stage derives every target from a fixed trajectory, separates on-policy from off-policy claims and makes coverage, support and terminal semantics visible.

Section 2 of 12 · 13 units · about 48 hours

0/13

By the end you can Implement Monte Carlo prediction, TD(0), SARSA and Q-learning from blank files, match fixed-trajectory updates, and explain a multi-seed on-policy versus off-policy result using coverage, target and terminal evidence.

Units

Build it

Mini project · about 12 to 16 hours

Tabular sampling with exact trajectory oracles

Extend policylab with tabular Monte Carlo and TD control checked against fixed-trajectory oracles, plus behavior and target policy bookkeeping with support diagnostics. Every update is tested without environment noise before any multi-seed comparison runs.

  1. 1Add tabular/ samplers that emit the shared trajectory record with environment, policy, seed and version identity, and reject records with missing identity before any update runs; evaluate only on held-out seed streams.
  2. 2Build fixed-trajectory oracles for returns, one-step and multi-step targets that cut the bootstrap at termination and keep it at truncation, pass Deep-ML 272, Deep-ML 257 and Deep-ML 273, and catch seeded alignment and bootstrap defects.
  3. 3Implement Sarsa, Expected Sarsa and Q-learning from explicit batches with no hidden environment calls, pass Deep-ML 175, Deep-ML 476 and Deep-ML 133, and label behavior against target policies on exploration-sensitive trajectories including a coverage failure.
  4. 4Compute ordinary, weighted and per-decision importance estimates on fixed trajectories, track effective sample size curves and visitation logs that name uncovered pairs, and refuse estimates where support is missing.
  5. 5Compare constant against decreasing step sizes under matched interaction budgets with visitation logs, and show which schedule tracks drift and which converges.
  6. 6Run the Sarsa against Q-learning cliff comparison across several seeds with independent evaluation streams and matched budgets, pass Deep-ML 518, and derive the average-reward ring rate with its value gaps.
What you hand in
  • Tabular samplers with the versioned trajectory schema and fixed-trajectory update oracles.
  • Tests: return and target boundaries, control updates, importance estimates, support refusal and seeded defects.
  • Matched-budget step-size and cliff comparisons with per-seed raw curves and the ring derivation.
How to check it
How it's graded

Update oracles

Pass: Fixed-trajectory returns and targets match hand computation, and every seeded alignment defect fails loudly.

Great: A live-run mismatch is traced to the update rather than blamed on sampling noise.

Policy labeling

Pass: Behavior and target policies are labeled on every trajectory, and the coverage failure refuses estimation.

Great: The cliff gap is attributed to update distribution rather than tuning.

Support diagnostics

Pass: Visitation logs name uncovered pairs and effective sample size curves mark collapse.

Great: A planted zero-support pair is caught before any estimator runs.

Budget honesty

Pass: Comparisons use matched budgets with all seeds retained and evaluation on separate streams.

Great: A best-seed claim is shown to reverse under the full seed set.

Resources

  • Reinforcement Learning: An Introduction (2nd ed.) - Chapters 2, 5, 6 and 7Richard Sutton and Andrew Barto

    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

    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.

  • Reinforcement Learning Control Laboratory - Tabular ControlRoadmap-Final

    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.

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

    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.

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

    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: An Introduction (2nd ed.) - Starred Sections 5.8 and 5.9 and Chapter 10 Sections 10.3 to 10.5Richard Sutton and Andrew Barto

    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.

  • Gymnasium Core APIFarama Foundation

    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.