Value Iteration
Prerequisites
- Markov Decision Processes — MDP definition, Bellman equations, optimal value functions
🎯 Learning Objectives
- Understand the dynamic programming approach to solving MDPs
- Implement the value iteration algorithm step by step
- Explain the Bellman backup operator and its contraction property
- Determine convergence using ‖Vk+1 − Vk‖ < ε
- Extract the optimal policy from converged value function
- Analyze the computational complexity O(|S|²|A|) per iteration
1. Dynamic Programming for MDPs
Dynamic Programming (DP) methods solve MDPs by computing optimal value functions using the Bellman optimality equations. They require a complete model of the environment — i.e., full knowledge of the transition function P(s′|s,a) and reward function R(s,a,s′).
📚 Model-Based vs Model-Free
Model-based methods (like value iteration and policy iteration) require complete knowledge of the MDP. Model-free methods (like Q-learning) learn directly from experience without knowing P and R.
The key idea: turn the Bellman optimality equation into an iterative update rule.
2. Value Iteration Algorithm
Algorithm: Value Iteration
function VALUE-ITERATION(MDP, ε):
Input: MDP = ⟨S, A, P, R, γ⟩, threshold ε > 0
Output: Optimal value function V*, optimal policy π*
Initialize V(s) = 0 for all s ∈ S
repeat:
Δ ← 0
for each state s ∈ S:
v ← V(s) // save old value
V(s) ← max_a ∑_{s'} P(s'|s,a) [R(s,a,s') + γ V(s')]
Δ ← max(Δ, |v - V(s)|)
until Δ < ε
// Extract optimal policy
for each state s ∈ S:
π*(s) ← argmax_a ∑_{s'} P(s'|s,a) [R(s,a,s') + γ V(s')]
return V, π*
💡 Core Update Rule
The heart of value iteration is a single line:
Vk+1(s) = maxa ∈ A ∑s′ P(s′|s,a) [R(s,a,s′) + γ Vk(s′)]
Each iteration applies the Bellman optimality equation as an assignment rather than an equality. The subscript k denotes the iteration number.
3. Bellman Backup Operator
📚 Bellman Optimality Operator T
Define the operator T that maps a value function to a new value function:
(TV)(s) = maxa ∑s′ P(s′|s,a) [R(s,a,s′) + γ V(s′)]
Value iteration is simply: Vk+1 = TVk
🔧 Contraction Property
The Bellman operator T is a γ-contraction in the max-norm:
‖TV − TV′‖∞ ≤ γ ‖V − V′‖∞
Since γ < 1, this means applying T brings any two value functions closer together by a factor of γ. By the Banach fixed-point theorem, T has a unique fixed point V* and repeated application converges to it from any starting V0.
💡 Convergence Rate
After k iterations: ‖Vk − V*‖∞ ≤ γk ‖V0 − V*‖∞
This means the error decreases exponentially with each iteration. For γ = 0.9, the error is halved approximately every 7 iterations (since 0.97 ≈ 0.48).
4. Convergence Criterion
We stop when the maximum change in any state’s value falls below a threshold ε:
‖Vk+1 − Vk‖∞ = maxs |Vk+1(s) − Vk(s)| < ε
🔧 Error Bound After Convergence
When value iteration terminates with ‖Vk+1 − Vk‖∞ < ε, the actual error from the true optimal is bounded:
‖Vk+1 − V*‖∞ < εγ / (1 − γ)
For γ = 0.9 and ε = 0.01: true error < 0.09. To guarantee the policy is optimal, we need ε < Rmax(1−γ) / (2γ).
⚠ Common GATE Pitfall
The stopping criterion Δ < ε does NOT mean the value function is within ε of V*. The actual bound involves the factor γ/(1−γ) which can be large when γ is close to 1.
5. Computational Complexity
| Aspect | Complexity | Notes |
|---|---|---|
| Per-iteration cost | O(|S|² · |A|) | For each of |S| states, try each of |A| actions, sum over |S| next states |
| Number of iterations | O(|S| · |A| · log(1/ε) / log(1/γ)) | Depends on required precision and discount factor |
| Space | O(|S|) | Store one value per state (can use in-place updates) |
| Sparse transitions | O(|S| · |A| · B) | B = max non-zero transitions per (s,a) pair |
💡 In-Place vs Synchronous Updates
Synchronous: Compute all new Vk+1(s) using Vk values, then replace. Requires storing two arrays.
In-place (asynchronous): Update V(s) immediately and use the updated values for subsequent states. Often converges faster in practice and uses less memory.
6. Complete Worked Example: 3×3 Grid World
📝 Grid Setup (same as MDP chapter)
Grid: 3×3, γ = 0.9, deterministic transitions
(0,0) (0,1) (0,2)
(1,0) [PIT] (1,2) PIT: reward -1, terminal
(2,0) (2,1) [GOAL] GOAL: reward +1, terminal
Living penalty: -0.04
Terminal states remain at V=0 after being visited
Iteration 0: V0
Initialize all values to 0:
V0: 0.000 0.000 0.000
0.000 [PIT] 0.000
0.000 0.000 [GOAL]
Iteration 1: V1
For each non-terminal state, compute maxa [R + γV0(s′)]:
State (2,1): Best action = Right → GOAL. V1(2,1) = +1 + 0.9×0 = +1.0
State (1,2): Best action = Down → GOAL. V1(1,2) = +1 + 0.9×0 = +1.0
State (0,2): Best action = Down → (1,2). V1(0,2) = −0.04 + 0.9×0 = −0.04
State (0,1): Best action = Right → (0,2). V1(0,1) = −0.04 + 0.9×0 = −0.04
State (0,0): Best action = Right → (0,1). V1(0,0) = −0.04 + 0.9×0 = −0.04
State (1,0): Best action = Up → (0,0). V1(1,0) = −0.04 + 0.9×0 = −0.04
State (2,0): Best action = Right → (2,1). V1(2,0) = −0.04 + 0.9×0 = −0.04
V1: -0.040 -0.040 -0.040
-0.040 [PIT] +1.000
-0.040 +1.000 [GOAL]
Iteration 2: V2
Now we use the V1 values:
State (0,2): Down → (1,2) with V1=1.0. V2(0,2) = −0.04 + 0.9×1.0 = +0.860
State (0,1): Right → (0,2) with V1=−0.04. V2(0,1) = −0.04 + 0.9×(−0.04) = −0.076
State (2,0): Right → (2,1) with V1=1.0. V2(2,0) = −0.04 + 0.9×1.0 = +0.860
State (1,0): Up → (0,0) with V1=−0.04. V2(1,0) = −0.04 + 0.9×(−0.04) = −0.076
State (2,1): already near GOAL. V2(2,1) = +1 + 0.9×0 = +1.0
State (1,2): V2(1,2) = +1 + 0.9×0 = +1.0
State (0,0): Best = Right → (0,1). V2(0,0) = −0.04 + 0.9×(−0.04) = −0.076
V2: -0.076 -0.076 +0.860
-0.076 [PIT] +1.000
+0.860 +1.000 [GOAL]
The values near the goal are growing, and value information is propagating backward through the grid. Continuing iteration, all V values converge to V*.
Converged Values (approximate)
V*: +0.509 +0.650 +0.795
+0.399 [PIT] +1.000
+0.509 +1.000 [GOAL]
Optimal Policy:
→ → ↓
↑ [PIT] ↓
→ → [GOAL]
7. Extracting the Optimal Policy
After convergence, the optimal policy is obtained by acting greedily with respect to V*:
π*(s) = argmaxa ∑s′ P(s′|s,a) [R(s,a,s′) + γ V*(s′)]
💡 Policy May Converge Before Values
In practice, the greedy policy πk often becomes optimal long before Vk has fully converged. This observation motivates policy iteration (next topic), which interleaves policy evaluation and improvement.
8. Variants and Optimisations
8.1 Gauss-Seidel (In-Place) Value Iteration
Update V(s) immediately and use updated values for subsequent states in the same sweep. Often converges in fewer iterations (sometimes 2× faster).
8.2 Prioritised Sweeping
Instead of sweeping all states in order, maintain a priority queue and update states whose value is likely to change the most first. This focuses computation where it matters.
8.3 Real-Time Dynamic Programming (RTDP)
Only update states that are visited during simulated trajectories. Useful when the state space is too large for full sweeps.
Summary
- Value iteration applies the Bellman optimality equation as an iterative update
- The Bellman operator T is a γ-contraction, guaranteeing convergence
- Convergence is checked via ‖Vk+1 − Vk‖∞ < ε
- Per-iteration cost: O(|S|²|A|)
- The optimal policy is extracted greedily from V*
- In-place updates and prioritised sweeping can speed convergence
References
- Sutton & Barto, RL: An Introduction, Chapter 4.4
- Russell & Norvig, AIMA, Chapter 17.2