Value iteration and generalised policy iteration
Value iteration finds the optimal value function by repeatedly applying the Bellman optimality operator (a contraction for discounted, finite MDPs); generalised policy iteration (GPI) describes the interaction of policy evaluation and policy improvement that underlies value iteration, policy iterati
Drafted with Aria, reviewed by the AiCanCode.org team · Updated . How we write and check our notes. Spotted an error? Use Give Feedback at the bottom of the page.
Why it matters
Value iteration and generalised policy iteration (GPI) are core algorithms for computing optimal behaviour in a Markov decision process (MDP). An engineer uses them to compute optimal policies for planning problems (robot path planning, resource allocation, simple games) when a model (transition and reward probabilities) is available.
Key ideas
Start with definitions (simple language). Define every term before use.
Markov decision process (MDP): a tuple (S, A, p, r, γ) where S is a finite set of states, A is a finite set of actions, p(s', r | s, a) is the probability of moving to state s' and receiving reward r when taking action a in state s, and γ ∈ [0,1) is the discount factor. We assume the MDP is finite (finite S and A) and γ < 1 for the main convergence results below. We also assume rewards are bounded (|r| ≤ R_max) so value functions are finite.
Policy (π): a mapping from states to actions (deterministic) or to action probabilities (stochastic). For deterministic π, write π(s) ∈ A.
State-value function (vπ): for policy π, vπ(s) is the expected discounted return starting from s and following π: vπ(s) = Eπ[∑{t=0}∞ γ^t R{t+1} | S0 = s]. Return is the sum of discounted future rewards.
Action-value function (qπ): qπ(s,a) = E[∑{t=0}∞ γ^t R{t+1} | S0 = s, A0 = a, then follow π].
Optimal value function (v): v(s) = maxπ vπ(s). Similarly q* is the maximum action-value.
Bellman expectation operator (Tπ): given a candidate v, Tπ[v] produces the one-step expected return under π followed by v for next state. Formally Tπv = ∑_{s',r} p(s',r|s,π(s)) [ r + γ v(s') ].
Bellman optimality operator (T): Tv = max_{a} ∑_{s',r} p(s',r|s,a) [ r + γ v(s') ]. This operator encodes one-step lookahead plus greedy choice.
Important theorems and assumptions used in exams (state clearly):
Policy evaluation fixed point: For any policy π and γ ∈ [0,1), Tπ is a contraction mapping in the sup norm on the space of bounded value functions. Therefore Tπ has a unique fixed point vπ and iterative policy evaluation v_{k+1} = Tπ[v_k] converges to vπ for any starting v0. Here ||·||∞ denotes the sup norm: ||v||∞ = max_s |v(s)|.
Bellman optimality and contraction: For γ ∈ [0,1), the Bellman optimality operator T is a γ-contraction in sup norm: ||T[v] − T[w]||∞ ≤ γ ||v − w||∞. Therefore T has a unique fixed point v* and iterating v_{k+1} = T[v_k] (value iteration) converges to v*.
Policy improvement theorem: If vπ is the value of π and define π' by greedy improvement: π'(s) ∈ argmax_a ∑_{s',r} p(s',r|s,a) [ r + γ vπ(s') ], then vπ' ≥ vπ (elementwise). Repeating improvement yields non-decreasing value sequences and eventual optimality (in finite MDPs after finite improvements).
Generalised Policy Iteration (GPI): any algorithm that alternates (possibly interleaves) policy evaluation (making v closer to vπ) and policy improvement (updating π to be greedy w.r.t current v) is GPI. Policy iteration (complete evaluation then improvement) and value iteration (single sweep of T, i.e., truncated evaluation then improvement) are special cases.
Standard derivations asked in exams:
Derive Bellman optimality equation: v*(s) = max_a E[ R_{t+1} + γ v*(S_{t+1}) | S_t = s, A_t = a ]. Write out expectation as sum over s',r using p(s',r|s,a).
Prove contraction of T: start from definition and use properties of max and triangle inequality to get factor γ. This gives uniqueness and convergence (sketch given below in Worked examples).
Diagrams to draw in exams (describe exactly):
- Draw a horizontal axis labelled "iteration k" and vertical axis labelled "v(s)"; plot curves for v_k(s) for 2–3 states showing approach to v*(s) (monotone only if rewards are nonnegative and v0 is a lower bound on v*). Label the final horizontal line v*(s).
- For GPI, draw two boxes labelled "policy evaluation" and "policy improvement" with arrows forming a loop; annotate that evaluation makes v closer to vπ and improvement makes π greedy w.r.t v.
Formulas
vπ(s) = Eπ[ ∑_{t=0}∞ γ^t R_{t+1} | S0 = s ] — vπ(s): value of state s under policy π, unit: (units of reward). Applies for any policy π and γ in [0,1).
v*(s) = maxπ vπ(s) — v*(s): optimal state-value, unit: (reward units). Applies for finite MDPs.
Tπ[v](s) = ∑_{s',r} p(s',r|s,π(s)) [ r + γ v(s') ] — Bellman expectation operator; p in probability (unitless), r in reward units, γ unitless.
T[v](s) = max_a ∑_{s',r} p(s',r|s,a) [ r + γ v(s') ] — Bellman optimality operator. Applies when taking one-step greedy lookahead.
v_{k+1} = T[v_k] — value iteration update. Applies when performing synchronous updates (all states each sweep) for finite MDP with γ<1. A practical stopping rule: stop when max_s |v_k(s) − v_{k-1}(s)| ≤ ε(1−γ), which guarantees ||v_k − v*||∞ ≤ ε.
π(s) = argmax_a ∑_{s',r} p(s',r|s,a) [ r + γ v(s') ] — greedy policy extraction from v. If ties, any tie-breaking is allowed.
||T[v] − T[w]||∞ ≤ γ ||v − w||∞ — contraction property (sup norm). Applies for γ ∈ [0,1).
Worked examples
Example 1 — small deterministic MDP (numerical value iteration)
MDP: S = {s1, s2}. Actions A = {a1, a2} available in both states. Transitions and rewards (deterministic):
- From s1: a1 -> s1 with r = 1; a2 -> s2 with r = 0.
- From s2: a1 -> s1 with r = 0; a2 -> s2 with r = 2. Discount γ = 0.9. Start v0(s1)=v0(s2)=0.
Step 1: apply T to v0.
v1(s1) = max(1 + 0.9·v0(s1), 0 + 0.9·v0(s2)) = max(1, 0) = 1.
v1(s2) = max(0 + 0.9·v0(s1), 2 + 0.9·v0(s2)) = max(0, 2) = 2.
Step 2: apply T to v1.
v2(s1) = max(1 + 0.9·1, 0 + 0.9·2) = max(1.9, 1.8) = 1.9.
v2(s2) = max(0 + 0.9·1, 2 + 0.9·2) = max(0.9, 3.8) = 3.8.
Step 3: apply T to v2.
v3(s1) = max(1 + 0.9·1.9 = 2.71, 0 + 0.9·3.8 = 3.42) = 3.42.
v3(s2) = max(0 + 0.9·1.9 = 1.71, 2 + 0.9·3.8 = 5.42) = 5.42.
After many iterations this converges to the optimal values. We can solve the Bellman optimality equations exactly by observing optimal actions: in s2, staying (a2) yields v*(s2) = 2 + 0.9 v*(s2) ⇒ v*(s2) = 2/(1−0.9) = 20. In s1, the two options give values 1/(1−0.9)=10 (stay) or 0 + 0.9·v*(s2) = 0.9·20 = 18 (go to s2). Greedy choice is 18. So final optimal values: v*(s1) = 18, v*(s2) = 20. Bold final answers: v(s1) = 18, v(s2) = 20, with optimal policy: from s1 choose a2 (go to s2), from s2 choose a2 (stay).
Example 2 — proof sketch required in exams: contraction of T and convergence of value iteration
Goal: show ||T[v] − T[w]||∞ ≤ γ ||v − w||∞ for any bounded v,w. Steps:
- For each state s, write Tv − Tw = max_a Q_v(s,a) − max_a Q_w(s,a), where Q_x(s,a) = ∑_{s',r} p(s',r|s,a) [ r + γ x(s') ].
- Use the property |max_a u_a − max_a v_a| ≤ max_a |u_a − v_a| to get |Tv − Tw| ≤ max_a |Q_v(s,a) − Q_w(s,a)|.
- But |Q_v(s,a) − Q_w(s,a)| = | ∑{s',r} p(s',r|s,a) γ (v(s') − w(s')) | ≤ γ ∑{s',r} p(s',r|s,a) |v(s') − w(s')| ≤ γ ||v − w||∞.
- Combine: |Tv − Tw| ≤ γ ||v − w||∞ for all s, hence taking sup over s gives the contraction bound.
- By Banach fixed-point theorem (on finite-dimensional bounded space) T has a unique fixed point v* and repeated application v_{k+1}=T[v_k] converges geometrically to v*.
This is the standard exam derivation; be precise about using sup norm and that γ < 1.
Common mistakes
- Thinking value iteration must evaluate a policy exactly; it only applies T (one-step lookahead) repeatedly.
- Mixing up v and q forms; when extracting policy ensure you use q or compute one-step returns correctly.
- Numerical errors: not carrying γ multiplication and reward units in stepwise calculations.
For your exam
Question types you will see:
- Definitions: define MDP, policy, vπ, Bellman equation, contraction mapping.
- Short notes: explain value iteration algorithm and why it converges (state theorem + assumptions).
- Derivation: prove contraction of T or derive Bellman optimality equation step-by-step.
- Numericals: run value iteration for 2–4 state MDP with given transitions and γ and compute v* and greedy π.
- Diagrams: draw iteration vs v(s) plots or the GPI loop.
What full-marks answers include:
- Clear assumptions stated (finite S,A; γ < 1 or episodic case explained).
- Exact Bellman equations written down and explained.
- Correct proof sketch for contraction (use sup norm), or correct stepwise numeric iterations with units and convergence criterion.
- If asked, description of GPI and how value iteration and policy iteration are special cases.
Quick check
- State the Bellman optimality equation for v*(s).
- What condition on γ ensures T is a contraction in the sup norm?
- In GPI, what two operations are repeated or interleaved?
Answers: 1) v*(s) = max_a ∑_{s',r} p(s',r|s,a) [ r + γ v*(s') ]. 2) γ < 1 (or γ ∈ [0,1) for infinite-horizon discounted MDPs). 3) Policy evaluation (or partial evaluation) and policy improvement.
Finished this topic? Mark it so your progress, study plan and readiness keep up.
Stuck on something here?