Unit 6 of 11 · about 4 hours · derive, implement

Matrix-form and iterative policy evaluation

Exact values are the oracle for every later sampler. If iteration and solve disagree, the bug is in the model, not in sampling noise.

You'll be able to

  • Solve as for a small finite policy and state the cubic cost.
  • Implement synchronous iterative evaluation with maximum absolute difference stopping and match the linear solve.
  • Reproduce Example 4.1 Figure 4.1 sweeps and Exercise 4.1 action values.

Covers

Matrix form of finite policy evaluationExact policy evaluation and iterative policy evaluation
1

Read

In this order, only the parts listed

0 of 4 done

  1. Iterative policy evaluation and gridworldReinforcement Learning: An Introduction (2nd ed.) - Chapters 3 and 4

    Chapter 4, Section 4.1 Policy Evaluation with (4.3) to (4.5) and the two-array versus in-place note, Example 4.1 and Figure 4.1 with Exercises 4.1 to 4.3, printed pp. 74 to 76. The authors post the full text free at incompleteideas.net.

  2. Matrix form of the Bellman equationHands-on Modern RL - MDPs, Values and Bellman Equations

    Matrix Form with and and the cubic-cost remark (page read 2026-10-14)

  3. Three-state Bellman verification scriptHands-on Modern RL - MDPs, Values and Bellman Equations

    3-state MDP definition with uniform random policy and manual versus iterative comparison giving 8.714450, 6.817661 and 9.214450

  4. Iterative evaluation updatesStanford CS234 Winter 2026 - Foundations and Planning

    Iterative Algorithm for Computing Value of a MRP (slide 7) and MDP Policy Evaluation, Iterative Algorithm with the Bellman backup note (slide 12)

2

Focus on

  • Matrix solve is exact but cubic in . Iteration costs about per sweep with a known model and no inversion.
  • Two-array synchronous evaluation reads for all successors. In-place reuses new values within the sweep.
  • Terminal value stays 0. Reward is counted on entry, not inside the terminal state.
Common mistakes · 3
  • Inverting with in episodic tasks without absorbing handling. The inverse may not exist. Iteration with proper terminals still works.
  • Forgetting and bootstrapping from the terminal state.
  • Comparing iteration after one sweep to the exact solve and calling the gap a bug. Check the residual, not the first sweep.
3

Try it yourself

Closed-book, before checking anything

On the Hands-on 3-state MDP with uniform random policy and , solve to get 8.714450, 6.817661 and 9.214450 and match iteration to 1e-6. Then reproduce Example 4.1 sweep 1 to sweep 3 tables and Exercise 4.1 answers minus 1 and minus 15.
4

Quiz yourself

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

0 got · 0 missed

  1. 1.What is the cost of the exact solve versus one evaluation sweep?Answer

    Exact solve needs matrix inversion at about . One sweep costs about for a fixed policy with a known model.

  2. 2.What are Exercise 4.1 answers for and ?Answer

    Down from 11 enters the terminal with reward minus 1, so minus 1. Down from 7 reaches 11 with value minus 14, so minus 1 plus minus 14 gives minus 15.

  3. 3.Why does the book mention two arrays?Answer

    Synchronous evaluation must read the old table for every successor. Reusing new values inside the sweep is a different in-place order.

  4. 4.What are the Hands-on 3-state values under the uniform policy?Answer

    8.714450, 6.817661 and 9.214450 for the three states. Manual solve and iteration agree.

5

Practice

You're done when

Your iteration matches the linear solve on the 3-state MDP and your Example 4.1 tables match Figure 4.1 through sweep 3.

Only when you can do this without notes.

Leads to

Notes

Resources · 3 for this unit, 4 more in the section
  • Stanford CS234 Winter 2026 - Foundations and PlanningStanford University · primary

    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 · required

    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.

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

    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.

Also in this section

  • Gymnasium - Time Limits and Episode SemanticsFarama Foundation · required

    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.

  • Deep-ML - Planning ProblemsDeep-ML · support

    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 Control Laboratory - Planning CoreRoadmap-Final · required

    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.

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

    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.