Level 0: Foundation
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.Working backwards from the goal
To plan a route through a maze, start at the exit: the squares next to it are good, the squares next to those are a little less good, and so on. Writing these scores into every square, again and again until they stop changing, gives a map that tells you the best move everywhere. This is value iteration. Policy iteration does it the other way round: it picks a plan, checks how good it is everywhere, improves it, and repeats.
Satellite navigation, inventory planning and robot path planning all use versions of dynamic programming.
- 1. Value iteration spreads scores outward from…
- 2. Policy iteration repeatedly…
- 3. Dynamic programming needs…
Level 1: Beginner
★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.By hand
- Value iteration (VI): V_(k+1) = T*V_k; stop when the change is small; act greedily on the result.
- Policy iteration (PI): evaluate V^π exactly (solve a linear system), set π ← greedy(V^π), repeat until π stops changing.
- Policy improvement theorem: the greedy policy with respect to V^π is at least as good as π in every state.
- Modified policy iteration (MPI): evaluate the policy only approximately, with m sweeps of V ← r_π + γP_πV, then improve. m = 1 is value iteration; m = ∞ is policy iteration.
- In-place (Gauss–Seidel) updates: use new values as soon as they are computed; a good state ordering speeds things up.
- Stopping rule: if ||V_(k+1) − V_k|| < ε(1 − γ)/γ then ||V_(k+1) − V*|| < ε.
- 1. Policy iteration stops when…
- 2. Modified policy iteration with m = 1 is…
- 3. The greedy policy of V^π is…
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.Value iteration and policy iteration
Exercise 1.
- A 4×4 gridworld: the intended move succeeds with probability 0.8 and slips sideways otherwise; the goal (bottom right) pays +1, four pits pay −1, both end the episode.
- Value iteration to a tolerance of 1e-8, and policy iteration with exact evaluation, at γ = 0.95.
- Check that both reach the same values and that the policy-iteration policy attains them.
Practice.
- Use policy iteration for small and medium problems: few iterations, each a linear solve.
- Use value iteration or modified policy iteration for large ones, where solving the linear system is too expensive.
- Stop on the policy, not only on the values: the greedy policy is often optimal long before the values converge.
- Break ties consistently in the improvement step, or policy iteration can cycle between equally good policies.
- Exploit structure: sweep states backwards from the goal, or prioritise states whose values changed most.
- Tools: NumPy and SciPy for tabular problems; mdptoolbox; the same backups appear inside planning with learned models.
def value_iteration(P, R, gamma, tol=1e-8):
V = np.zeros(len(R))
while True:
V2 = (R + gamma * np.einsum("sat,t->sa", P, V)).max(1)
if np.max(np.abs(V2 - V)) < tol * (1 - gamma) / gamma:
return V2
V = V2- 1. For large state spaces prefer…
- 2. The greedy policy often becomes optimal…
- 3. Policy iteration can cycle if…
Level 3: Advanced
★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.Theory
Policy improvement theorem. Let π’ be greedy with respect to V^π. Then T^(π’)V^π = TV^π ≥ T^πV^π = V^π. Applying the monotone operator T^(π’) repeatedly gives V^(π’) = lim (T^(π’))^k V^π ≥ V^π. If nothing improves, V^π = TV^π, so V^π = V*.
Convergence. Policy iteration visits a sequence of strictly improving deterministic policies, of which there are finitely many (|A|^|S|), so it terminates; in practice it needs very few iterations. Value iteration converges geometrically at rate γ; with terminal states the effective rate is faster, because probability mass leaves the system.
Cost. One VI sweep costs O(|S|²|A|) with a dense model (O(|S||A|) here, since each move reaches at most three states). One PI iteration costs a linear solve, O(|S|³) dense, plus a greedy sweep. Modified PI trades between the two.
- 1. Policy iteration terminates because…
- 2. Value iteration converges at rate…
- 3. A dense policy evaluation by linear solve costs…
Level 4: Expert
★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.How does the work of value iteration, policy iteration and modified policy iteration grow with the size of the grid and the discount factor, and how early is the greedy policy already optimal?
History.
- R. Bellman (1957) introduced value iteration; R. A. Howard (1960) introduced policy iteration.
- M. L. Puterman and M. C. Shin (1978) proposed modified policy iteration.
- Y. Ye (2011) proved that policy iteration is strongly polynomial for a fixed discount factor; B. Scherrer (2016) improved the bounds.
- A. W. Moore and C. G. Atkeson (1993) introduced prioritised sweeping.
Exercise 2.
- Random N×N grids with 10% pits, slip 0.2, N = 5, 10, 20, γ = 0.9 and 0.99; tolerance 1e-6.
- Value iteration (also recording the sweep after which the greedy policy is optimal for good), policy iteration with exact evaluation, and modified policy iteration with 10 evaluation sweeps.
- Work in backups: one VI sweep = |S||A|, one evaluation sweep of a fixed policy = |S|.
Seed 0:
| grid, γ | VI sweeps | VI policy optimal after | PI iterations | MPI(10) improvements | VI backups | MPI backups |
|---|---|---|---|---|---|---|
| 5×5, 0.9 | 37 | 16 | 7 | 8 | 3,700 | 2,550 |
| 5×5, 0.99 | 137 | 16 | 6 | 16 | 13,700 | 5,350 |
| 10×10, 0.9 | 101 | 17 | 6 | 12 | 40,400 | 15,800 |
| 10×10, 0.99 | 177 | 32 | 7 | 21 | 70,800 | 28,400 |
| 20×20, 0.9 | 96 | 42 | 9 | 16 | 153,600 | 85,600 |
| 20×20, 0.99 | 343 | 155 | 13 | 35 | 548,800 | 192,000 |
- Policy iteration needed only 6 to 13 iterations in every case, growing slowly with the grid.
- Value iteration’s policy was optimal long before its values converged: at 20×20 and γ = 0.99 after 155 of 343 sweeps, at 5×5 after 16 of 137.
- Modified policy iteration did 1.5 to 2.9 times less work than value iteration, the most on the 20×20 grid at γ = 0.99, where cheap evaluation sweeps replace many expensive improvement sweeps.
- Value iteration needed far fewer sweeps than the worst-case bound (about 1,400 for γ = 0.99 and ε = 1e-6), because the pits and the goal end episodes and drain probability mass.
- Seeds 1 and 2, 20×20 and γ = 0.99: VI 291 and 300 sweeps (policy optimal after 107 and 111), PI 13 and 17 iterations.
Dynamic programming in practice
- Real problems rarely come with a model: the rest of this section learns values from experience (Monte Carlo, temporal-difference learning) using the same Bellman backups.
- Curse of dimensionality: the number of states grows exponentially with the number of state variables; approximate dynamic programming replaces tables by function approximators.
- Planning with learned models (Dyna, MuZero) runs dynamic-programming-like backups inside a learned model.
- Linear programming is a third exact method: V* is the smallest V with V ≥ T*V componentwise.
References
- R. Bellman (1957). Dynamic Programming. Princeton University Press.
- R. A. Howard (1960). Dynamic Programming and Markov Processes. MIT Press.
- M. L. Puterman and M. C. Shin (1978). “Modified policy iteration algorithms for discounted Markov decision problems.” Management Science.
- Y. Ye (2011). “The simplex and policy-iteration methods are strongly polynomial for the Markov decision problem with a fixed discount rate.” Mathematics of Operations Research.
- A. W. Moore and C. G. Atkeson (1993). “Prioritized sweeping: reinforcement learning with less data and less time.” Machine Learning.