Classical RL I: MDPs, Bellman Equations and Planning

Classical RL supplies the exact objects that every later deep or language-policy method approximates. This stage makes the environment contract, value definitions and planning oracles executable so later learning curves can be checked against something stronger than apparent reward improvement.

Section 1 of 12 · 11 units · about 42 hours

0/11

By the end you can Formulate an unfamiliar finite decision process, derive both Bellman equations, implement policy and value iteration, and make exact values, simulation estimates and stopping error agree while exposing one plausible reward or terminal bug.

Units

Build it

Mini project · about 10 to 14 hours

Exact planning oracles for small finite MDPs

Build the policylab foundation: versioned transition records, small finite MDPs and exact planning oracles that later samplers and networks must match. The project turns Bellman equations into tested code with seeded defects, so every later learning claim has an exact reference.

  1. 1Create policylab with schema/, envs/, oracles/, tabular/, deep/, offline/, mbrl/, llm/, agents/, systems/, eval/, ledger/, faults/, tests/ and reports/, and record one versioned transition schema plus a small finite MDP with known dynamics in envs/.
  2. 2Implement matrix-form exact evaluation and synchronous iterative evaluation in oracles/, prove their agreement on your MDP, and run the same oracle through the Stanford CS234 Assignment 1 bellman_backup and policy_evaluation functions on RiverSwim.
  3. 3Implement policy iteration and value iteration with a fixed tie rule, check policy against value agreement on RiverSwim, pass Deep-ML 467, Deep-ML 157 and Deep-ML 164, and set the stopping tolerance from the residual over rather than a fixed sweep count.
  4. 4Seed tie-switching, unreachable-state and terminal-bootstrap defects in faults/, show each failing test before its repair, and prove truncation still bootstraps while true termination cuts the target.
  5. 5Write the MDP contract with state sufficiency, action authority, reward components, termination, discount and evaluation policy, then seed one reward or terminal defect and keep a reward-hacking probe where the proxy optimum differs from the intended behavior.
  6. 6Evaluate the greedy policy on several held-out seed streams with no training exploration, keep per-seed raw records in ledger/ and reports/, and state what the optimal-policy claim does and does not establish.
What you hand in
  • The policylab layout with the versioned schema, finite MDPs and exact planning oracles.
  • Tests: oracle agreement, RiverSwim policy and value match, residual stopping and seeded defect regressions.
  • The MDP contract with the evaluation policy, hacking probe and multi-seed greedy evaluation report.
How to check it
How it's graded

Oracle agreement

Pass: Iterative evaluation matches the matrix solve on your MDP, and policy and value iteration agree on RiverSwim.

Great: Agreement holds under several sweep orders and tie rules, with the residual bound predicting the remaining error.

Stopping discipline

Pass: Tolerance comes from the residual bound, and values and policy convergence are reported separately.

Great: A premature stop is shown to leave value error while the policy looks stable, or the reverse.

Defect regressions

Pass: Each seeded tie, terminal and reward defect fails before its repair and passes after.

Great: One defect survives a naive fix and needs a second repair with its own regression test.

Formulation honesty

Pass: The contract names the evaluation policy, and the hacking probe shows the proxy optimum missing the intent.

Great: Two competing formulations predict different optimal policies, and evaluation separates them.

Resources

  • Stanford CS234 Winter 2026 - Foundations and PlanningStanford University

    Study Lecture 1 (lecture1pre.pdf and lecture1post.pdf) and Lecture 2 on tabular MDP planning (lecture2pre.pdf and lecture2post.pdf under https://web.stanford.edu/class/cs234/slides/). Work Assignment 1 independently: the written MDP, horizon and Bellman-operator questions and the vi_and_pi.py planning code on RiverSwim (NumPy only). Do not copy or publish course solutions.

  • Reinforcement Learning: An Introduction (2nd ed.) - Chapters 3 and 4Richard Sutton and Andrew Barto

    The authors post the full second edition free at incompleteideas.net; cite the printed page numbers. Study Chapter 3 (Sections 3.1 to 3.7, finite MDPs, returns, Bellman equations and optimality) and Chapter 4 (Sections 4.1 to 4.7, policy evaluation, improvement, policy and value iteration, asynchronous DP and GPI). Reproduce Example 4.1 and Figure 4.1 exactly, then Example 4.3 (the gambler), and write exact tests for stochastic transitions, terminals, ties and stopping error.

  • Gymnasium - Time Limits and Episode SemanticsFarama Foundation

    Read the termination, truncation and "importance in learning code" sections, then the vector autoreset note at https://farama.org/Vector-Autoreset-Mode (next-step autoreset is the default in Gymnasium 1.x). Build a wrapper test that distinguishes termination from truncation and proves which cases bootstrap before using any third-party environment.

  • Reinforcement Learning Control Laboratory - Planning CoreRoadmap-Final

    Complete Milestone A planning requirements: an explicit finite MDP, exact policy evaluation, value iteration, policy iteration, simulator agreement and seeded reward, transition, terminal and tie defects.

  • Hands-on Modern RL - MDPs, Values and Bellman EquationsWalking Labs

    Use the value and Bellman page and the value experiment page (code/chapter03_mdp/bellman_equation_verify.py and gridworld_q_learning.py run on CPU in seconds) as a code companion. Check every equation against Sutton and Barto before adopting it. Pin commit 9231bab of walkinglabs/hands-on-modern-rl; its code/chapterNN folders do not follow the site chapter numbers.

  • Deep-ML - Planning ProblemsDeep-ML

    Use named problems as closed-book checks after your own implementation passes: 157 (Bellman equation for value iteration), 164 (the gambler's problem by value iteration) and 467 (policy iteration). Read each problem's tests before trusting its statement.

  • Reinforcement Learning: An Introduction (2nd ed.) - Chapter 2 banditsRichard Sutton and Andrew Barto

    Read Section 2.9, Associative Search (Contextual Bandits), printed p. 41, with Exercise 2.10 as the context versus no-context check. Use only this section from Chapter 2.