Value iteration
Solve the Bellman optimality equation by repeated backups; extract the optimal policy greedily.
Animated explanation
The idea
Value iteration skips the separate evaluation step of policy iteration. It simply applies the Bellman optimality backup to every state, over and over: the new value of a state is the best, over actions, of the expected immediate reward plus the discounted value of where you land.
Think of the goal's reward spreading backwards through the grid like ripples, one step per sweep, each step discounted by . Because the backup is a contraction, the values converge to the optimal values from any starting guess, and acting greedily on is optimal. It is a few lines of code and the cleanest example of dynamic programming in RL.
Why it converges
The backup operator satisfies . By the Banach fixed-point theorem it has a unique fixed point () and the iterates approach it geometrically. In practice, stop when the largest change in a sweep is below ε; the greedy policy is usually optimal well before the values have fully converged.
Variants
In-place (Gauss–Seidel) updates use new values immediately and converge faster. Prioritised sweeping updates states whose values are changing most. Asynchronous DP updates states in any order. With function approximation, the same idea becomes fitted value iteration, the ancestor of DQN.
The algorithm, step by step
- 1Initialise for all states.
- 2Repeat: for every non-terminal state, ; track the largest change Δ.
- 3Stop when Δ < ε.
- 4Output the greedy policy .
The maths
Backup
Contraction
Stopping bound
Strengths and weaknesses
Strengths
- Very simple; each sweep is cheap
- Guaranteed convergence to V*
- Basis for fitted and deep value methods
Weaknesses
- Needs the full model
- Many sweeps when γ is close to 1
- Enumerates the whole state space
Reach for it when…
Check your understanding
Lambdian Lab
Value iteration
Using the provided gridworld:
- bellman_backup(V, s, gamma): of the expected one-step look-ahead.
- value_iteration(gamma, tol): synchronous sweeps (compute the new V from the old one) until the max change < tol; return (V, sweeps).
- greedy_policy(V, gamma): dict state → best action (ties → lowest index).
- bellman_residual(V, gamma): max over states of |backup − V|.