Part XVI — Reinforcement Learning: Bandits, MDPs, Policy Gradients & PPO · Chapter 4

Policy iteration & value iteration

Hook

Last chapter's Bellman optimality equation was checked using VV^* values that were simply recognized — borrowed from a policy already known to be optimal. Real problems don't offer that shortcut. What if all that's known up front is the MDP itself, and every state's value starts out just... wrong?

Intuition
S0V=-1.00
S1V=-1.00
S2V=10.00
S3V=0.00
sweep 1/5

Start every state's value at exactly 00 — a deliberately bad guess. Then, sweep by sweep, replace every state's value with the Bellman optimality backup computed from the previous sweep's numbers. Step forward and watch a wrong guess turn into the exact right answer, purely from applying the same equation over and over.

Formalize

Value iteration turns the Bellman optimality equation into an update rule, applied to every state on each pass:

Vk+1(s)maxa[R(s,a)+γVk(P(s,a))]V_{k+1}(s) \leftarrow \max_a \Big[ R(s,a) + \gamma\, V_k\big(P(s,a)\big) \Big]
  • Vk(s)V_k(s) — the current estimate of state ss's value, after kk sweeps.
  • Vk+1(s)V_{k+1}(s) — the updated estimate, computed from a one-step lookahead using VkV_k.
  1. Every state updates from the same snapshot

    A sweep computes Vk+1V_{k+1} for every state using VkV_k — the previous sweep's values, not values already updated earlier in the same sweep. This is exactly why "sweep 1" and "sweep 2" are meaningful checkpoints: within a sweep, nothing has propagated yet.

  2. Why not just solve it directly, like last chapter did?

    Last chapter reused VV^* from a policy already known to reach the goal by the shortest route — that only worked because moving away from the goal was provably never better. In general an MDP can have cycles (bouncing between states is possible here too, via repeated "left" moves), so there's no safe order to compute states in just once. Iterating to a fixed point sidesteps the ordering problem entirely.

  3. Policy iteration is the other half of dynamic programming

    Instead of iterating on values directly, policy iteration alternates two steps: fully evaluate the current policy's VπV^\pi (sweeping the fixed-policy Bellman equation, no max\max, to its own fixed point), then improve the policy by acting greedily on that VπV^\pi. Repeat until the policy stops changing. Both algorithms provably converge to the same VV^* and π\pi^*.

Play

Every state starts at a flatly wrong 00. Five sweeps later, the values are 6.2,8,106.2, 8, 10 — exactly the VV^* from the previous chapter, recovered without ever being told the optimal policy in advance.

Worked example

With γ=0.9\gamma = 0.9, starting from V0(s)=0V_0(s) = 0 for every state:

  1. Sweep 1 — only the immediate reward is visible

    V1(2)=max(1+0.9(0), 10+0.9(0))=10V_1(2) = \max(-1 + 0.9(0),\ 10 + 0.9(0)) = 10 — the goal's reward reaches state 2 immediately. For states 0 and 1, both the left and right moves land on a neighbor whose V0V_0 is still 00, so both branches of the max collapse to the same number: V1(1)=max(1+0.9(0), 1+0.9(0))=1V_1(1) = \max(-1+0.9(0),\ -1+0.9(0)) = -1 and V1(0)=max(1+0.9(0), 1+0.9(0))=1V_1(0) = \max(-1+0.9(0),\ -1+0.9(0)) = -1 — neither has a neighbor with useful value yet, so both just reflect the cost of a single step.

  2. Sweep 2 — the goal's value takes one more step back

    Using V1V_1: V2(1)=max(1+0.9(1), 1+0.9(10))=8V_2(1) = \max(-1 + 0.9(-1),\ -1 + 0.9(10)) = 8 — now that V1(2)=10V_1(2)=10 exists, state 1 can see it. V2(0)V_2(0) still can't see past state 1's old value: V2(0)=max(1+0.9(1),1+0.9(1))=1.9V_2(0) = \max(-1+0.9(-1), -1+0.9(-1)) = -1.9.

  3. Sweep 3 — every state has settled

    V3(0)=max(1+0.9(8), 1+0.9(1.9))=6.2V_3(0) = \max(-1+0.9(8),\ -1+0.9(-1.9)) = 6.2. Checking sweep 4 against sweep 3 changes nothing at all — the fixed point has been reached in exactly 3 sweeps, and it's the exact VV^* from the previous chapter.

Checkpoint

Sweep forward until a sweep changes nothing — the value function has hit its fixed point.

S0V=-1.00
S1V=-1.00
S2V=10.00
S3V=0.00
sweep 1/5
Sweep forward to try it
Summary
Vk+1(s)maxa[R(s,a)+γVk(P(s,a))]V_{k+1}(s) \leftarrow \max_a \Big[ R(s,a) + \gamma\, V_k\big(P(s,a)\big) \Big]

Value iteration finds VV^* from nothing but the MDP's own definition — no policy needs to be guessed correctly in advance, and no special ordering of states is required, because repeated sweeps converge to the same fixed point regardless of where they started. The catch is what this chapter assumed throughout: RR and PP had to be fully known to compute every backup. The next chapter drops that assumption entirely — learning QQ^* from nothing but experienced transitions, without ever being handed the transition model itself.