Policy iteration
Recall value iteration:
Policy evaluation for a given :
At convergence:
is the expected discounted return from when following the same policy at every step. This evaluates the given policy; its value need not be optimal.
- is the action chosen by the policy in the current state.
- is the probability of reaching each possible next state.
- is the immediate reward for that transition.
- is the discounted return from the next state, continuing with the same policy.
The sum is a probability-weighted average of reward now plus discounted future return. There is no because already chooses the action.
At convergence, successive rounds approach the same , so the iteration index disappears and can be read as equality. There is one equation per state, and the unknown values are linked through the possible next states.
Exercise: Stochastic Policy Evaluation
Consider a stochastic policy , where is the probability of taking action a when in state s. Which of the following is the correct update to perform policy evaluation for this stochastic policy?
-
Incorrect
max over a chooses the action with the largest expected return. It replaces the current action choice and ignores the given policy’s action probabilities. Policy evaluation must average actions according to π(a|s).
-
Correct
There are two sources of randomness: the policy chooses a with probability π(a|s), and the environment then reaches s′ with probability P(s′|s,a). Their product is the probability of this combined outcome. The two sums include every outcome and compute its probability-weighted reward plus discounted future value.
For finite sums, the order of the two summations can be swapped without changing the answer.
-
Incorrect
This averages over actions correctly, but max over s′ keeps only the largest single probability-weighted next-state contribution. The other outcomes are left out. An expectation must add the weighted contributions of all possible next states.
For example, suppose there is one action and two possible next states, each with probability 0.5 and reward plus discounted future value of 10. The correct expectation is 0.5 × 10 + 0.5 × 10 = 10. Option 3 takes max(5, 5) = 5.
One iteration of policy iteration:
1. Policy evaluation for current policy :
Keep the policy fixed and iterate until convergence:
Here, k counts policy changes and i counts value updates while evaluating the same policy. This step gives : the expected return from each state when continuing with the current policy.
2. Policy improvement: find the best action according to one-step look-ahead
At state s, compare every available action a. For each candidate, ask: “If I take this action now, then follow the old policy from the next state onward, what return should I expect?”
- is the reward for the candidate action now.
- includes all later rewards when following the old policy, discounted by one step. These values come from evaluation and stay fixed while comparing actions.
- The sum with averages over all possible next states.
- arg max returns the action with the largest expected return. Store that action as . Do this for every state to build the new policy.
“One-step” means only the next transition is expanded explicitly. All later steps are already included in . The candidate score is ; it uses the current policy’s future return, which may still be below the optimal return.
Example
Suppose the current policy chooses Left at s, the transitions are deterministic, and γ = 0.9. Evaluation gives a value of 5 for the state reached by Left and 8 for the state reached by Right:
| Action now | Reward now | Next-state value under the old policy | Candidate score |
|---|---|---|---|
| Left | 1 | 5 | 1 + 0.9 × 5 = 5.5 |
| Right | 0 | 8 | 0 + 0.9 × 8 = 7.2 |
arg max chooses Right, so the new policy chooses Right at s. Its lower immediate reward is outweighed by the larger future return. The score 7.2 assumes the old policy after this first action; evaluate the new policy in the next round to find its value.
Repeat until the policy converges
Alternate evaluation and improvement. The old action is among the candidates, so the chosen action’s score is at least the current value. For a finite discounted MDP with exact evaluation, making these greedy choices in every state gives a new policy whose value is at least as high in every state. One improvement step need not produce the optimal policy.
If improvement leaves the policy unchanged, it is optimal. Keep the current action when it ties for the best score, so ties do not cause unnecessary switches. Policy iteration can converge in fewer outer iterations than value iteration under some conditions; each outer iteration also includes policy evaluation.
Policy Iteration Convergence
Theorem. Policy iteration is guaranteed to converge and at convergence, the current policy and its value function are an optimal policy and the optimal value function.
Assume a finite MDP with bounded rewards, , and exact policy evaluation. The policies here are deterministic: one chosen action in each state. Keep the current action whenever it ties for the best score.
Proof sketch:
-
Guarantee to converge
Each improvement round either leaves the policy unchanged and stops, or produces a policy with values at least as high in every state and strictly higher in at least one state. This means a previously visited policy cannot be encountered again: returning to it would return to the same value function, undoing a strict improvement.
There are only finitely many deterministic policies. Each state has a choice of action, so the number of possible policies is at most:
For example, 2 actions in each of 3 states give 2 × 2 × 2 = 8 possible policies. Each policy is a complete list of choices, one per state. Since policy iteration cannot repeat a policy, it cannot keep changing forever. The count is an upper bound; the algorithm may stop much earlier.
-
Optimal at convergence
At convergence, improvement selects the same action as the current policy in every state:
Evaluation tells us the return of the current action followed by the current policy. Improvement compares that action with every alternative. If it stays unchanged, the current action already achieves the maximum. Therefore, for every state:
Here, , using the slide’s transition notation.
This is the Bellman optimality equation. The discounted Bellman optimality update is a contraction, so it has exactly one fixed point: . Since the current policy’s value satisfies that same equation, it must be that fixed point:
The current policy therefore achieves the optimal return from every state. The optimal value function is unique, although several policies can achieve it when actions tie.