Concepts / Value Iteration for Optimal Policies

Value Iteration for Optimal Policies

Policy evaluation can make each policy-iteration step a lengthy computation.

  • Programming

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.

evaluaterepeatrepeatthenCurrent policyState sweepEvaluation passState sweepEvaluation passMore sweepsUntil evaluation stopsPolicy improvement
What sequence of repeated state-value updates can occur before one policy-improvement step is completed?

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.

sweepsweepcontinued sweepsV0Initial estimateV1After a sweepV2After another sweepV*Limiting value function
How do successive value estimates approach the true value function while usually remaining slightly different at finite iterations?

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.

considerconsiderenumeratereturnreturncomparestoreState sAction a1Expected returnAction a2Expected returnAvailable actionsAll action returnsMaximumLargest expected returnV(s)Updated state value
How does a state value change when the algorithm compares every available action and keeps the maximum expected return?

V(s) ← max over a of the sum over s′ and r of p(s′, r | s, a)[r + γ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.

Evaluate actions: The sweep calculates the expected return for each available action.

Compare returns: The algorithm compares 6 and 9 rather than committing to a policy before making the comparison.

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

visit statecompareafter complete sweepchange is not small enoughchange is sufficiently smallΔ = 0Start sweep|v − V(s)|Current state changeLargest changeUpdate ΔΔ compared with θStopping testAnother sweepStopValue function ready
How is the largest change across all state values tracked, and how does it determine whether another sweep is needed?

Δ ← max(Δ, |v − V(s)|)

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.

Record each change: The algorithm compares every state change with the current value of Δ.

Keep the largest change: The largest observed change is 0.07, so Δ becomes 0.07.

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

choosechooseState s1Final value functionAction a1Largest expected return ats1State s2Final value functionAction a2Largest expected return ats2
How does the final value assigned to each state determine which single action the policy chooses there?

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.

Compare actions: Policy extraction examines the expected return of each available action under the final value function.

Identify the maximum: The expected return 12 is larger than 10.

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

evaluatethenupdatetrack Δif neededwhen stopping condition is metPolicyFull evaluation routeValue functionValue iteration routeFull evaluationRepeated sweepsMaximum updateEach sweepPolicy improvementAfter evaluationRepeatUntil Δ is smallDeterministic policyExtracted at the end
How does value iteration update values incrementally instead of waiting for policy evaluation to converge completely before improving the policy?
Full policy evaluationValue 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

  • Treating a small change in one state as sufficient evidence to stop.

    The stopping test uses the largest change across the complete sweep.

    Fix: Track every state change and stop only when the sweep-wide maximum Δ satisfies the stopping condition.

  • Assuming that a stable greedy policy means the value function is exact.

    Exact convergence and policy stability are different ideas.

    Fix: Describe the policy as stable while recognizing that the value estimates may not yet have reached their exact limiting values.

  • Choosing an action before comparing all available actions.

    The update must use the maximum expected return over the available actions.

    Fix: Evaluate each action, compare their expected returns, and retain the maximizing action for policy extraction.

  • Confusing the value stored for a state with the action selected by the policy.

    The value update stores a number, while policy extraction identifies the action that produced that number.

    Fix: Keep the state value and the maximizing action as separate outputs.

Check Your Understanding

MEDIUM

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?

  • Yes, because at least one state changed by less than θ.
  • Yes, because the average change may be small.
  • No, because the largest change is 0.08.
  • No, because value iteration always requires exact convergence.
Reveal answer

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

  1. Policy evaluation can require several complete state sweeps, making one policy-iteration step computationally lengthy.
  2. Exact convergence of values and stability of greedy policy decisions are different conditions.
  3. Value iteration updates each state's value with the maximum expected return over available actions.
  4. The algorithm records the largest value change Δ during each complete sweep and compares it with θ.
  5. After stopping, a deterministic policy selects the maximizing action in each state.

Key Takeaways

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