Policy Improvement
Policy improvement upgrades a policy by switching each state to the action with the best action value, with a theorem guaranteeing no state gets worse.
Why Does This Exist?
Policy evaluation measures a policy but never changes it. Something must turn those measurements into better decisions. The naive move, tweaking actions by gut feel, can backfire because one changed action reroutes every trajectory that passes through its state.
The policy improvement theorem removes the gamble. It says: if an action looks better under your current values, adopting it everywhere can only help, from every state. That guarantee turns policy search into a steady climb and powers policy iteration, which alternates this step with evaluation until nothing changes.
Think of It Like This
Replacing one bus route after a full audit
A bus company audits its whole network under the current timetable and learns exactly what each stop earns. One audit line stands out: swapping diesel for electric on route 7 earns more even if every other route stays exactly as it is.
So they swap route 7 permanently. Buses that never touch route 7 still earn more, because breakdowns and detours occasionally land them on it. One local swap, verified against the full audit, lifts the entire network. That is greedification: change what the numbers favor, keep the proof that nothing else suffers.
The analogy stops at stationarity: it assumes traffic never adapts to the new buses. The theorem needs the same, a fixed environment that does not fight back.
How It Actually Works
Start from evaluated values , the expected return from under current policy . For any candidate action , the action value is what you would earn by taking once and following after:
Here is the environment model and the discount factor. The new policy picks the winner in each state:
The theorem: if everywhere, then everywhere. Proof sketch: unroll the inequality one step at a time, each successor satisfying the same inequality, until the discounted tail vanishes and only returns remain. If nothing changes anywhere, the values satisfy the Bellman optimality equation and the policy is optimal.
Worked example
Two depots, discount . Depot 1 offers cautious or bold ; depot 2 has one fixed action. Under baseline with , solving the Bellman system gives and .
Score the candidates in depot 1 against those values. Staying cautious reproduces the baseline: . Going bold gives:
Since , greedify: . Re-evaluating under the new policy gives and . Depot 2 kept its action yet gained , because detours keep landing its buses on the improved depot 1. That ripple is the diagram's right panel.
Code
This snippet replays the greedification with plain arithmetic over the two depots.
def q_value(transitions, values, gamma=0.9): """One-step lookahead: sum over p * (r + gamma * V).""" return sum(p * (r + gamma * values[s]) for p, s, r in transitions)
v = {"s1": 18.18, "s2": 22.73}a1 = [(0.8, "s1", 1.0), (0.2, "s2", 1.0)]a2 = [(0.9, "s2", 0.0), (0.1, "s1", -1.0)]q1 = q_value(a1, v)q2 = q_value(a2, v)print(round(q1, 2))print(round(q2, 2))print("a2" if q2 > q1 else "a1")Watch Out For
Greedifying on half baked values
The guarantee assumes exact . Act on noisy or half converged estimates and the "better" action may be worse, so the policy degrades instead of climbing.
Symptom: values fall after an improvement step that the numbers promised would help. Fix: converge evaluation tightly before greedifying in exact settings, and use conservative or trust region updates once values are approximated from samples.
Breaking ties at random
When two actions tie, flipping between them each round stops the outer loop from ever settling, even with fully converged values.
Symptom: the policy oscillates forever while values sit still. Fix: keep the current action on ties within tolerance, and order any remaining ties by a fixed rule. Stability of the policy, not just the values, is the stopping signal.
The Quick Version
- Policy improvement sets using current values.
- The theorem guarantees from every state, never just on average.
- Gains ripple: here depot 2 rose from 22.73 to 26.76 without changing its own action.
- No change anywhere means Bellman optimality, so the policy is optimal.
- Exact values and deterministic ties are the two conditions that keep the guarantee honest.