skip to content

What is the difference between value iteration and policy iteration on the same MDP?

level: middleimportance: should knowfreq 58%

answer

  1. where does the maximum sit
  2. evaluate fully, or only once
  3. few expensive rounds versus many cheap sweeps
  4. one evaluation sweep gives the other algorithm
  5. same fixed point either way

basics

~20 s

Policy iteration evaluates the current policy to convergence, then makes it greedy, repeats. Value iteration folds both into one sweep that takes the maximum over actions. Both reach the same optimal values, trading cost per round against number of rounds.

solid answer

~50 s

They are two points on the same spectrum. Policy iteration runs many evaluation sweeps under a fixed policy — no maximum in the backup — then a single greedy improvement pass, and repeats; it needs very few outer rounds, often under ten, but each round is expensive. Value iteration performs one sweep in which the maximum over actions is taken as part of the update, so there is no separate evaluation phase; each sweep is cheap but you need many more of them. For a maintenance MDP with a modest number of states, policy iteration's evaluation can be solved directly as a linear system, which makes it very attractive. When the state space is large and the action set small, value iteration's cheap sweeps usually win on wall-clock time. Running exactly one evaluation sweep per improvement in policy iteration *is* value iteration; anything in between is modified policy iteration.

go deeper

for a junior

Know the shape of each: policy iteration is evaluate-then-improve in a loop, value iteration is a single sweep with a maximum built in. Both end at the same optimal policy.

for a middle

Explain where the maximum sits in each backup and the cost trade: few expensive rounds versus many cheap sweeps. Be able to say that one evaluation sweep per improvement is exactly value iteration.

for a senior

Reason about which to reach for given the size of the state and action sets and the discount factor, and mention solving evaluation as a linear system when the state count is small.

for a principal

Own the framing that these are two settings of one knob, and argue for the granularity and stopping rule that match the accuracy the downstream decision actually needs rather than chasing value convergence.

## The two algorithms side by side **Policy iteration** ``` repeat: evaluate: v(s) <- sum_s' P(s'|s, pi(s)) [ r + gamma v(s') ] # sweep until settled improve: pi(s) <- argmax_a sum_s' P(s'|s,a) [ r + gamma v(s') ] # one pass until pi stops changing ``` **Value iteration** ``` repeat: v(s) <- max_a sum_s' P(s'|s,a) [ r + gamma v(s') ] # one sweep, maximum inside until the largest change < theta then read off pi(s) = argmax_a ... once at the end ``` The structural difference is *where the maximum sits*. In policy iteration it appears only in the improvement pass, and the evaluation sweeps use the policy's own action. In value iteration it is inside every update, so the values being computed are never the values of any particular policy along the way — they are estimates of the optimal values. ## Cost analysis With dense transitions, one full backup of one state costs about `|S|` operations (summing over successors). - A **value-iteration sweep** does that for every state and every action: about `|S| * |A| * |S|`. - A **policy-evaluation sweep** does it for every state and only the policy's action: about `|S| * |S|`, that is `|A|` times cheaper — but you run many of them per round. - A **policy-improvement pass** costs the same as one value-iteration sweep. So the trade is: policy iteration needs far fewer outer rounds (each improvement uses fully converged values, so it takes bigger jumps), while value iteration needs many more sweeps, each cheaper and simpler. There is no universal winner; the crossover depends on `|A|`, on `gamma` (a discount close to one slows value iteration badly, because the number of sweeps needed grows with the effective horizon `1/(1-gamma)`), and on how exactly the evaluation is done. **The linear-solve option.** Because `v_pi` satisfies a linear system of `|S|` equations, policy iteration can solve evaluation exactly in roughly `|S|^3` work instead of sweeping. For a few thousand states this is often the fastest route to an exactly optimal policy, and it is a strong argument for policy iteration on small, dense problems such as a machine replace-or-repair MDP with a few hundred condition states. ## Same destination Both converge to the same optimal value function and an optimal policy. The optimal values are the unique fixed point of the maximising backup, and both methods are driving towards that fixed point — one by contracting directly, the other by climbing through a finite sequence of improving policies. Neither is an approximation of the other in terms of the answer; they differ only in the path and the cost. ## A practical fact about value iteration The greedy policy implied by the values usually becomes optimal **long before the values themselves converge**. The values keep creeping toward their fixed point while the ranking of actions in each state has already stabilised. If you only need the policy, you can often stop far earlier than a tight value tolerance suggests — and a common practical check is to watch whether the greedy policy has changed over the last several sweeps rather than watching the value delta alone. When you do stop on a value tolerance, the useful guarantee is: if the largest change over a sweep is below `theta`, the greedy policy's value is within about `2 * gamma * theta / (1 - gamma)` of optimal. That factor blows up as `gamma` approaches one, which is the quantitative reason long-horizon problems are hard to plan precisely. ## The spectrum between them Nothing forces evaluation to be either "one sweep" or "run to convergence". **Modified policy iteration** runs `k` evaluation sweeps per improvement: - `k = 1` is value iteration, - `k -> infinity` is policy iteration, - moderate `k` is often the fastest of the three in practice. The umbrella term for the pattern — evaluation and improvement chasing each other at any granularity — is **generalized policy iteration**, and seeing the two named algorithms as endpoints of one idea is exactly the insight an interviewer is checking for. ## How to choose Ask three questions. How many actions per state? Many actions make value-iteration sweeps expensive relative to evaluation sweeps, favouring policy iteration. How large is the state space? A small one lets policy iteration solve evaluation exactly; a large one makes cheap, simple value-iteration sweeps attractive and easier to parallelise. How close is `gamma` to one? A long effective horizon punishes value iteration's sweep count more than it punishes policy iteration's round count.

  • Which of the two converges in fewer outer iterations, and why?
    Policy iteration, usually within a handful of rounds. Each improvement is computed against fully converged values, so it makes a large jump in policy space, and the number of deterministic policies it can pass through is finite. The cost is that every round contains a whole evaluation loop, or a linear solve, rather than a single sweep.
  • How do you decide when to stop value iteration?
    Stop when the largest change to any state value in a sweep falls below a threshold `theta`. The greedy policy read off those values is then within roughly `2 * gamma * theta / (1 - gamma)` of optimal. In practice the greedy policy often stabilises well before that bound is tight, so monitoring whether the policy has changed is a cheaper stopping signal.
  • Is there anything between the two algorithms?
    Yes: modified policy iteration, which runs a fixed number `k` of evaluation sweeps per improvement pass. `k = 1` reduces to value iteration and very large `k` to policy iteration, with intermediate values often fastest. Generalized policy iteration is the general name for interleaving the two processes at any granularity.

saying these in an interview costs you the question

  • Claims the two converge to different optimal policies
  • Says value iteration has no policy at all
  • Puts a maximum over actions in policy evaluation
  • Asserts value iteration is always faster in wall-clock time
  • Cannot connect the two as endpoints of one spectrum

context