Value Iteration for Optimal Policies
Policy evaluation can make each policy-iteration step a lengthy computation.
The Hidden Work Inside Policy Iteration
Policy iteration is often described as a repeating outer process: evaluate a policy, then improve it. The important detail is that policy evaluation is itself a computation. It may require several sweeps through the entire state set before the value estimates approach their limiting values. Therefore, one apparently simple policy-iteration step can contain much more work than the outer loop suggests.
This nested computation explains why policy iteration can be lengthy. The outer loop may appear to make one decision at a time, but the evaluation phase can repeatedly update values for every state before the policy-improvement phase is allowed to use them.
Exact Values and Stable Decisions
Iterative policy evaluation reaches the exact limiting value function only in the limit. Successive sweeps improve the estimates, but at a finite point the estimates may still differ from their exact limiting values. Exact convergence and policy stability are therefore different ideas.
A policy decision depends on which available action has the greatest expected return. That ordering can become stable before every value estimate has reached its exact limit. Truncating evaluation means stopping before exact convergence when later sweeps no longer affect the corresponding greedy policy. The source example reports that evaluation iterations after the first three had no effect on the corresponding greedy policy. This observation motivates a method that avoids waiting for unnecessary full evaluation.
One Value-Iteration Sweep
Value iteration avoids waiting for a separate policy-evaluation phase to reach exact convergence. It begins with an arbitrary value assigned to each state and repeatedly improves the value function. During each sweep, the algorithm visits states, examines the available actions, and replaces a state's value with the greatest expected return among those actions.
- 1For the current state s, consider each available action a.
- 2For a selected action, combine each transition and reward possibility using p(s′, r | s, a).
- 3For each possibility, add the immediate reward r to the discounted value γV(s′) of the resulting state.
- 4Sum these terms to obtain the expected return for that action.
- 5Take the maximum expected return across actions and use it as the new value V(s).
Choosing a value for one state
Suppose a state has two available actions. The first action has an expected return of 6 under the current value function, and the second has an expected return of 9.
- 1Evaluate actions
The sweep calculates the expected return for each available action.
- 2Compare returns
The algorithm compares 6 and 9 rather than committing to a policy before making the comparison.
- 3Update the state
The larger expected return becomes the updated value for the state.
The updated value is 9, and the second action is the maximizing action for this state under the current value function.
Tracking the Largest Change
Value iteration does not stop merely because one state changed by a small amount. At the start of each sweep, the algorithm sets Δ to zero. For every state, it saves the old value, performs the update, and compares the old and new values. The sweep records the largest absolute change seen anywhere.
- 1v is the value calculated for the current state before it is stored.
- 2V(s) is the state's old value.
- 3|v − V(s)| is the size of the current state's change.
- 4max compares that change with the largest change already observed during the sweep.
- 5After all states have been visited, Δ is the largest change anywhere in the complete sweep.
- 6The algorithm compares Δ with θ to determine whether another sweep is needed.
Why the whole sweep matters
During one sweep, three states change by amounts 0.02, 0.07, and 0.03. The stopping threshold θ is 0.05.
- 1Record each change
The algorithm compares every state change with the current value of Δ.
- 2Keep the largest change
The largest observed change is 0.07, so Δ becomes 0.07.
- 3Apply the stopping test
Because the largest change is greater than the threshold 0.05, the sweep is not sufficiently stable to stop.
Another sweep is required, even though two of the three states changed by less than the threshold.
From Values to Actions
After the value function reaches the stopping condition, value iteration extracts a deterministic policy. For each state, it evaluates the same expected-return expression used during the value update and selects the single action that produced the largest expected return.
The value update and policy extraction are closely connected. During the update, the algorithm stores the maximum expected return as the state's value. During extraction, it identifies which action produced that maximum and assigns that action to the state. Because one maximizing action is selected for each state, the resulting policy is deterministic.
Extracting one policy decision
For a particular state, the final value function gives action left an expected return of 12 and action right an expected return of 10.
- 1Compare actions
Policy extraction examines the expected return of each available action under the final value function.
- 2Identify the maximum
The expected return 12 is larger than 10.
- 3Assign the action
The policy assigns left to this state.
The deterministic policy chooses left in that state.
Incremental Improvement Instead of Waiting
Full policy evaluation waits for value estimates to reach their limiting values before the policy-improvement phase uses them. Value iteration instead repeatedly applies the maximum-over-actions update while the value function is being improved. This directly addresses the motivation from truncated evaluation: later evaluation sweeps may no longer change the greedy policy even though they would continue changing the numerical values.
| Full policy evaluation | Value iteration |
|---|---|
| Evaluates a policy through repeated state sweeps before policy improvement. | Updates values using the maximum expected return over actions. |
| Can wait for exact convergence of the current policy's value estimates. | Stops after a complete sweep produces a sufficiently small maximum change. |
| Policy improvement follows the evaluation phase. | The policy is extracted from the final value function. |
The two procedures organize value updates and policy decisions differently.
Mistakes to Avoid
Common mistake Treating a small change in one state as sufficient evidence to stop.
What it looks likeOne state changes by less than θ, but another state changes by more than θ.
Why it failsThe stopping test uses the largest change across the complete sweep.
Do this insteadTrack every state change and stop only when the sweep-wide maximum Δ satisfies the stopping condition.
Common mistake Assuming that a stable greedy policy means the value function is exact.
What it looks likeLater evaluation sweeps change numerical values but do not change which action is greedy.
Why it failsExact convergence and policy stability are different ideas.
Do this insteadDescribe the policy as stable while recognizing that the value estimates may not yet have reached their exact limiting values.
Common mistake Choosing an action before comparing all available actions.
What it looks likeUsing the first action examined as the policy decision.
Why it failsThe update must use the maximum expected return over the available actions.
Do this insteadEvaluate each action, compare their expected returns, and retain the maximizing action for policy extraction.
Common mistake Confusing the value stored for a state with the action selected by the policy.
What it looks likeCalling the maximum expected return the policy itself.
Why it failsThe value update stores a number, while policy extraction identifies the action that produced that number.
Do this insteadKeep the state value and the maximizing action as separate outputs.
Check Your Understanding
Explain why value iteration can stop without first obtaining the exact limiting value function of a policy. In your answer, describe the role of the greedy action, the sweep-wide maximum change Δ, and the final deterministic policy.
Hints
- Separate numerical convergence from policy stability.
- Remember that Δ summarizes the largest change across all states in one complete sweep.
- The final policy selects the action with the largest expected return under the final value function.
What do you think happens?
During a sweep, one state changes by 0.01 and another changes by 0.08. If θ is 0.05, should value iteration stop after this sweep?
Reveal answer
No, because the largest change is 0.08.
The stopping test uses the maximum change across the complete sweep. Since 0.08 is greater than θ = 0.05, another sweep is needed.
Key Takeaways
- 1Policy evaluation can require several complete state sweeps, making one policy-iteration step computationally lengthy.
- 2Exact convergence of values and stability of greedy policy decisions are different conditions.
- 3Value iteration updates each state's value with the maximum expected return over available actions.
- 4The algorithm records the largest value change Δ during each complete sweep and compares it with θ.
- 5After stopping, a deterministic policy selects the maximizing action in each state.
At a glance
- Policy evaluation is an inner computation that may require many sweeps before policy improvement can occur.
- A greedy policy may become stable before the value estimates reach exact convergence.
- Value iteration repeatedly replaces each state value with the maximum expected return over actions.
- The largest change across a complete sweep determines whether another iteration is required.
- The final deterministic policy chooses the action that maximizes expected return in each state.