Instead of fully evaluating one policy and then improving it, value iteration performs a one-step optimality backup at every iteration. Mathematically, it is fixed-point iteration for the nonlinear equation
\[
V^*=TV^*.
\]
For a finite discounted Markov decision process, \(T\) is a contraction in the sup norm. This gives existence, uniqueness, convergence, computable error bounds, and a clear stopping rule.
11.1 Learning goals
After reading this chapter, students should be able to:
define the optimal Bellman operator for a finite discounted MDP;
prove that the Bellman optimality operator is a contraction in \(\|\cdot\|_\infty\);
implement value iteration from first principles;
distinguish value error, Bellman residual, and greedy-policy error;
derive practical stopping criteria from mathematical error bounds;
explain why large discount factors slow convergence;
interpret value iteration as finite-horizon dynamic programming with a moving horizon;
compare value iteration, policy iteration, and modified policy iteration;
use Python to compute values, residuals, and greedy policies in small finite MDPs;
use AI tools to check derivations, debug code, and critique stopping criteria.
11.2 8.1 Why value iteration?
Policy iteration alternates two steps:
\[
\text{evaluate }\pi_k \quad\longrightarrow\quad \text{improve greedily to obtain }\pi_{k+1}.
\]
Exact policy evaluation can be expensive because it requires solving a linear system
\[
(I-\gamma P_{\pi_k})V^{\pi_k}=r_{\pi_k}
\]
at every outer iteration. Value iteration avoids exact evaluation. It directly applies the optimal Bellman update
\[
V_{k+1}=TV_k.
\]
Each iteration combines two operations:
expectation over next states, using \(P(s'\mid s,a)\);
optimization over actions, using \(\max_a\).
Thus value iteration is both a probabilistic computation and an optimization computation.
Value iteration is the cleanest first example of nonlinear fixed-point computation in reinforcement learning. The nonlinearity comes from the maximum over actions. The contraction comes from discounting.
In finite discounted MDPs, the supremum is achieved by at least one stationary deterministic policy. Therefore it is enough to search over deterministic greedy policies, although randomized policies are still useful for exploration and statistical learning.
11.4 8.3 The optimal Bellman operator
For any vector \(V\in\mathbb R^{|\mathcal S|}\), define
The next figure shows the basic contraction scale \(\gamma^k\). It is not the actual value error for every MDP, but it explains the dominant phenomenon: when \(\gamma\) is close to \(1\), value iteration can need many more iterations.
11.5 8.4 Contraction theorem
The main mathematical fact behind value iteration is that \(T\) is a contraction in the sup norm.
Theorem 8.1: Bellman optimality operator is a contraction. For any \(V,W\in\mathbb R^{|\mathcal S|}\),
\[
\|TV-TW\|_\infty\leq \gamma \|V-W\|_\infty.
\]
Therefore, for \(0\leq \gamma<1\), the operator \(T\) has a unique fixed point \(V^*\) and the sequence \(V_{k+1}=TV_k\) converges to \(V^*\) from every initial vector \(V_0\).
Taking the maximum over \(s\) gives the contraction inequality. The Banach fixed-point theorem gives existence, uniqueness, and convergence to the unique fixed point. \(\square\)
The proof uses two special facts: the transition probabilities are nonnegative and sum to one, and \(\gamma<1\). Without discounting, \(T\) may fail to be a contraction in the ordinary sup norm.
11.6 8.5 The value iteration algorithm
Value iteration starts from an arbitrary vector \(V_0\) and repeats
The update is called a Bellman optimality backup. It replaces the current value of a state by the best one-step expected return plus discounted continuation value.
11.7 8.6 Error bound from contraction
Since \(V^*=TV^*\) and \(V_{k+1}=TV_k\), the contraction property gives
This is a clean theoretical bound but it contains the unknown quantity \(\|V_0-V^*\|_\infty\). For actual computation, we need bounds that can be evaluated from the iterates.
11.8 8.7 Bellman residual and computable stopping rules
For any candidate value vector \(V\), the Bellman residual is
\[
\operatorname{Res}(V)=\|TV-V\|_\infty.
\]
If \(\operatorname{Res}(V)=0\), then \(V\) is a fixed point of \(T\), so \(V=V^*\).
Theorem 8.2: Residual error bound. For any \(V\in\mathbb R^{|\mathcal S|}\),
If the user wants value error at most \(\varepsilon\), a sufficient condition is
\[
\Delta_k\leq (1-\gamma)\varepsilon.
\]
11.8.1 Interactive demonstration: residual bounds
11.9 8.8 Greedy-policy performance bounds
In control, the final goal is not merely a good value estimate; the goal is a good policy. Suppose \(\pi_V\) is greedy with respect to an approximate value vector \(V\). How bad can \(\pi_V\) be?
Theorem 8.3: Performance bound for a greedy policy. Let \(\pi_V\) be any policy greedy with respect to \(V\). Then
which gives the first inequality. The second follows from Theorem 8.2. \(\square\)
The factor \((1-\gamma)^{-2}\) can be large. When \(\gamma\) is close to one, a small Bellman residual may still be needed to guarantee a strong policy-performance bound.
11.10 8.9 Python example: a small finite MDP
Consider an MDP with three states and two actions. The transition array has shape
The greedy policy is extracted after the value vector is close to a fixed point. The last number is the Bellman residual \(\|TV_k-V_k\|_\infty\).
We can evaluate the greedy policy exactly by solving a linear system.
def evaluate_deterministic_policy(policy): P_pi = np.zeros((n_states, n_states)) r_pi = np.zeros(n_states)for s inrange(n_states): a = policy[s] P_pi[s] = P[a, s] r_pi[s] = r[s, a]return np.linalg.solve(np.eye(n_states) - gamma * P_pi, r_pi)V_pi = evaluate_deterministic_policy(greedy)print("V of greedy policy:", np.round(V_pi, 6))print("sup-norm difference between V estimate and V_pi:", np.max(np.abs(V - V_pi)))
V of greedy policy: [7.009368 7.427336 8.346145]
sup-norm difference between V estimate and V_pi: 5.733101993143919e-09
If the greedy policy is optimal, then \(V^{\pi}=V^*\) up to numerical error.
11.11 8.10 Visualizing value iteration on a small gridworld
A gridworld is useful because the value function can be visualized as a surface or heatmap. The following interactive display shows a stylized value function after increasing numbers of value-iteration sweeps.
The purpose of this figure is conceptual: Bellman backups propagate information backward from rewarding terminal or goal states. Early iterations only affect nearby states. Later iterations propagate long-range consequences.
11.12 8.11 Python example: gridworld value iteration
The next example implements value iteration for a small deterministic gridworld. The agent receives a step cost and a positive reward at the goal.
This example is intentionally simple. More realistic gridworlds may include stochastic movement, obstacles, terminal states with negative reward, and absorbing boundaries.
11.13 8.12 Finite-horizon interpretation
When \(V_0\) is interpreted as a terminal value function, the iterates
\[
V_{k+1}=TV_k
\]
can be interpreted as optimal values for problems with one more decision step. For example, if \(V_0(s)=0\), then \(V_1\) is the best expected one-step reward, \(V_2\) is the best expected two-step discounted reward, and so on.
Thus value iteration can be viewed in two equivalent ways:
These bounds can be loose, but they are often enough to sanity-check numerical output.
11.15 8.14 Asynchronous and Gauss-Seidel value iteration
The standard update computes all entries of \(V_{k+1}\) from the old vector \(V_k\). This is a Jacobi-style update. An alternative is to update states one at a time and immediately use the newest available values. This is a Gauss-Seidel-style or asynchronous update.
For a sweep order \(s_1,s_2,\ldots,s_n\), an in-place update replaces
Under standard conditions for finite discounted MDPs, asynchronous value iteration converges if every state is updated infinitely often.
Practical note. In-place value iteration can converge faster in wall-clock time because new information is used immediately. However, the exact sequence of iterates depends on the state update order, so reproducibility requires recording the order.
11.16 8.15 Computational complexity
Suppose there are \(n\) states and \(m\) actions per state. A full Bellman backup requires computing
\[
\sum_{s'}P(s'\mid s,a)V(s')
\]
for each state-action pair. If transitions are dense, one sweep costs approximately
\[
O(mn^2).
\]
If transitions are sparse and each state-action pair has at most \(d\) possible next states, one sweep costs
\[
O(mnd).
\]
The number of iterations needed to achieve a value error of order \(\varepsilon\) scales roughly like
\[
\frac{\log(1/\varepsilon)}{1-\gamma}
\]
when \(\gamma\) is close to one. This explains why high-discount problems are computationally harder.
11.16.1 Interactive demonstration: discount factor and iteration count
11.17 8.16 Value iteration versus policy iteration
Value iteration and policy iteration solve the same optimality problem but take different computational routes.
Method
Main step
Strength
Weakness
Policy iteration
exact or near-exact policy evaluation plus greedy improvement
often few outer iterations
linear system or many evaluation sweeps can be costly
Value iteration
repeated optimal Bellman backups
simple and stable
can be slow when \(\gamma\) is close to one
Modified policy iteration
partial evaluation plus improvement
interpolates between both
requires choosing evaluation depth
A useful mental model is:
\[
\text{value iteration} \approx \text{policy iteration with one-step partial evaluation before improvement}.
\]
This is not an exact identity in every implementation, but it captures the algorithmic relationship.
11.18 8.17 Statistical viewpoint
So far value iteration has assumed that \(P\) and \(r\) are known. In many reinforcement learning problems they must be estimated from data. Suppose we have estimates \(\widehat P\) and \(\widehat r\). The empirical Bellman operator is
Here \(\widehat M\) is the estimated MDP and \(M\) is the true MDP. For MS Statistics students, this decomposition is important: even perfect convergence for the estimated model does not eliminate sampling error.
11.19 8.18 AI-assisted learning components
Modern AI tools can help students learn value iteration, but they should be used to check mathematical reasoning rather than to replace it.
AI prompt: deriving the contraction proof
Ask an AI system:
Prove that the optimal Bellman operator for a finite discounted MDP is a contraction in the sup norm. Make every inequality explicit, especially the step involving the maximum over actions.
Then check whether the proof uses \(\gamma<1\) and whether it correctly handles the maximum operation.
AI prompt: debugging value iteration code
Paste a value-iteration implementation and ask:
Check this code for mathematical and programming mistakes. In particular, verify the shape of the transition array, whether the maximum is taken over actions rather than states, whether the stopping rule uses the correct norm, and whether the greedy policy is extracted from the final value vector.
Then verify the answer with a small hand-computable MDP.
AI prompt: explaining the residual bound
Ask:
Explain why a small Bellman residual implies that a value vector is close to the optimal value function. Derive the factor \(1/(1-\gamma)\) and explain why this factor becomes large when \(\gamma\) is close to one.
A good answer should use the contraction inequality and should not confuse residual error with policy-performance error.
AI prompt: creating examples
Ask:
Construct a three-state, two-action MDP where value iteration converges slowly when \(\gamma=0.99\). Explain which transition structure and rewards make the slow convergence visible.
Then implement the example and compare \(\gamma=0.7\), \(0.9\), and \(0.99\).
11.20 8.19 Common mistakes
Maximizing over the wrong axis. In code, the action dimension must be clear. If \(Q\) has shape (states, actions), use Q.max(axis=1).
Using transition rows that do not sum to one. Every \(P(\cdot\mid s,a)\) must be a probability distribution.
Stopping too early when \(\gamma\) is large. The residual bound divides by \(1-\gamma\).
Confusing value convergence with policy convergence. The greedy policy may stabilize before the value vector is highly accurate, or it may change because of tiny numerical ties.
Ignoring tie-breaking. Deterministic tie-breaking makes results reproducible.
Forgetting terminal-state modeling. Terminal states should be represented consistently, often as absorbing states.
11.21 8.20 Summary
Value iteration is a central dynamic programming algorithm for finite discounted MDPs.
Show that if \(V_0\leq TV_0\), then the sequence \(V_{k+1}=TV_k\) is monotone nondecreasing.
11.24 8.23 Computational exercises
Implement value iteration for the three-state MDP in Section 8.9. Plot \(\|V_{k+1}-V_k\|_\infty\) versus iteration number on a log scale.
Repeat the experiment with \(\gamma=0.5,0.8,0.95,0.99\). How does the number of iterations change?
Modify the gridworld so that one state has a negative terminal reward. How does the greedy policy change?
Implement Gauss-Seidel value iteration. Compare the number of sweeps with standard value iteration.
Add random transition noise to the gridworld: with probability \(0.8\) the intended action occurs, and with probability \(0.2\) a random action occurs. Recompute the value function and policy.
Estimate \(P\) and \(r\) from simulated samples, run value iteration on the estimated MDP, and compare the result with the true model-based solution.
11.25 8.24 AI-assisted exercises
Ask an AI system to write value iteration code for a finite MDP. Identify at least three possible bugs or ambiguous modeling assumptions in the code.
Ask an AI system to prove the contraction theorem. Rewrite the proof in your own words and check every inequality.
Ask an AI system to explain the difference between Bellman residual and policy loss. Provide a counterexample or numerical example showing that the two are not identical.
Ask an AI system to design a small MDP where tie-breaking matters. Implement it and test two different tie-breaking rules.
Ask an AI system to propose a stopping tolerance for \(\gamma=0.99\) and desired value error \(0.01\). Check whether the proposed tolerance follows the residual bound.
11.26 8.25 Notes for instructors
For MA Applied Math students, emphasize:
nonlinear contraction mappings;
fixed-point iteration;
monotone operators;
sup-norm estimates;
computational complexity.
For MS Statistics students, emphasize:
conditional expectations inside the Bellman backup;
plug-in estimation of \(P\) and \(r\);
model error versus optimization error;
residual diagnostics and uncertainty.
A good lecture sequence is:
derive \(T\) from one-step optimal lookahead;
prove contraction;
implement value iteration on a three-state MDP;
discuss residual stopping rules;
visualize value propagation in a gridworld;
compare with policy iteration.
11.27 References
Classic references for this chapter include Bellman’s dynamic programming principle, Puterman’s treatment of Markov decision processes, Bertsekas’s dynamic programming texts, and Sutton and Barto’s reinforcement learning presentation. The contraction and residual arguments are also standard in numerical analysis through the Banach fixed-point theorem.