Policy iteration

Recall value iteration:

Vk*(s)← maxa∑s′ P(s′|s,a) (R(s,a,s′)+γVk−1*(s′))

Policy evaluation for a given π(s):

Vkπ(s)← ∑s′ P(s′|s,π(s)) (R(s,π(s),s′)+γVk−1π(s′))

At convergence:

∀s Vπ(s)← ∑s′ P(s′|s,π(s)) (R(s,π(s),s′)+γVπ(s′))

Vπ(s) is the expected discounted return from s when following the same policy π at every step. This evaluates the given policy; its value need not be optimal.

The sum is a probability-weighted average of reward now plus discounted future return. There is no max because π(s) already chooses the action.

At convergence, successive rounds approach the same Vπ, so the iteration index k 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 π(a|s), where π(a|s) 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?

  1. Incorrect

    Vk+1π(s)← maxa∑s′ P(s′|s,a) (R(s,a,s′)+γVkπ(s′))

    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).

  2. Correct

    Vk+1π(s)← ∑s′∑a π(a|s)P(s′|s,a) (R(s,a,s′)+γVkπ(s′))

    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.

  3. Incorrect

    Vk+1π(s)← ∑aπ(a|s)maxs′ P(s′|s,a) (R(s,a,s′)+γVkπ(s′))

    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 πk:

Keep the policy fixed and iterate until convergence:

Vi+1πk(s)← ∑s′ P(s′|s,πk(s)) [R(s,πk(s),s′)+γViπk(s′)]

Here, k counts policy changes and i counts value updates while evaluating the same policy. This step gives Vπk: 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

πk+1(s)← argmaxa∑s′ P(s′|s,a) [ R(s,a,s′) ↑ Reward now +γ Vπk(s′) ↑ Then followπk ]

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?”

“One-step” means only the next transition is expanded explicitly. All later steps are already included in Vπk(s′). The candidate score is Qπk(s,a); 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 nowReward nowNext-state value under the old policyCandidate score
Left151 + 0.9 × 5 = 5.5
Right080 + 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, 0≤γ<1, 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:

  1. 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:

    (number actions)(number states)=|A||S|

    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.

  2. Optimal at convergence

    At convergence, improvement selects the same action as the current policy in every state:

    ∀s πk+1(s)=πk(s)

    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:

    ∀s Vπk(s)= maxa ↑ Current action is best ∑s′T(s,a,s′) [R(s,a,s′)+γVπk(s′)]

    Here, T(s,a,s′)=P(s′|s,a), 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: V*. Since the current policy’s value satisfies that same equation, it must be that fixed point:

    Vπk = Unique fixed point ↓ V*

    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.