Dynamic Programming in RL
Policy evaluation, improvement and iteration.
Value iteration and policy iteration are the two ends of a spectrum. Between them lies most of practical reinforcement learning: evaluate a little, improve a little, repeat, in whatever order and with whatever errors your samples and function approximators impose. This lesson makes the spectrum precise: modified and asynchronous policy iteration, why any fair interleaving still converges, and what approximation errors cost, including why the famous bound is tight and how to beat it.
What you’ll learn
- State generalized policy iteration, and prove that modified policy iteration from a pessimistic start improves monotonically and is never behind value iteration.
- Prove that asynchronous value iteration converges whenever every state is backed up infinitely often, and explain Gauss–Seidel ordering, prioritized sweeping and real-time dynamic programming.
- Derive the error bounds of approximate value iteration and approximate policy iteration, and explain their tightness and the improvement from non-stationary policies.
- Show how least-squares fitted value iteration can diverge, which approximators are safe, and how concentrability coefficients replace sup-norm assumptions.
Generalized and modified policy iteration
Sutton and Barto call the common pattern generalized policy iteration (GPI): an evaluation process pulls toward , an improvement process makes greedy for , and the two interleave at any granularity. Value iteration improves after a single backup, policy iteration after exact evaluation, and actor–critic methods and Q-learning interleave the two sample by sample. Modified policy iteration (MPI; Puterman & Shin, 1978) turns the granularity into a parameter : evaluate the current greedy policy with backups.
function MODIFIED-POLICY-ITERATION(MDP, m, V0): # require T V0 ≥ V0, e.g. V0 = min r / (1 − γ)
V ← V0
repeat
π ← a greedy policy for V # improvement: T^π V = T V
repeat m times: V ← T^π V # partial evaluation
until the largest change in V is small
return π, V
# m = 1 is value iteration; m → ∞ is policy iterationAn iteration costs one greedy step, , plus backups of a fixed policy, each and less with sparse transitions. A moderate often beats both extremes.
Invariant: . Suppose it holds at . Greediness gives , and the monotone map propagates the inequality along its iterates, which therefore increase:
Then , so the invariant passes to . The same chain shows that one MPI iteration does at least as much as one value-iteration sweep:
Lower bound: by induction and the monotonicity of , . Upper bounds: the iterates of from increase to their fixed point , and the iterates of from increase to :
The rate follows from and the contraction of . From an arbitrary start MPI still converges, but not monotonically, and with approximate evaluation, policy iteration with very partial ("optimistic") evaluation can oscillate (Bertsekas & Tsitsiklis, 1996).
Asynchronous dynamic programming
Nothing forces a sweep to update every state from the same old values. Gauss–Seidel value iteration updates states in place, so later updates in a sweep already use new values. Asynchronous DP updates one state at a time in any order, possibly on parallel processors with stale information (Bertsekas, 1982). Such schedules converge under a minimal fairness condition.
Let . An update at reads the current vector, and , so the new error at is at most , while all other states are untouched:
So never increases. Within an interval that updates every state, each state's error after its last update is at most times the maximal error at that moment, hence at most , and states are untouched otherwise. At the end of the interval every state has been updated:
If every state is updated infinitely often, infinitely many such intervals exist, so . Only the sup-norm contraction was used, so the argument covers , soft backups and Q-value backups alike, and with bounded delays it extends to stale information.
A deterministic chain of 20 states leads to a goal that pays 1 on entry, and all values start at 0. How many synchronous (Jacobi) sweeps of value iteration pass before the state farthest from the goal has a nonzero value?
Show the answer
20
After synchronous sweeps, exactly the states within steps of the goal have nonzero values, so the farthest state needs 20. A Gauss–Seidel sweep that visits the states from the goal backward carries the reward along the whole chain in one sweep. Ordering along the flow of value is what makes backward and prioritized sweeps fast, although in the worst case a Gauss–Seidel sweep still contracts by only .
Two refinements choose which states to update. Prioritized sweeping (Moore & Atkeson, 1993) keeps a priority queue keyed by each state's pending Bellman error and, after updating a state, raises the priority of its predecessors, so computation follows the changes. Real-time dynamic programming (RTDP; Barto, Bradtke & Singh, 1995) updates only the states visited by greedy trajectories from the start. For stochastic shortest-path problems with an optimistic (admissible) initial value function, RTDP converges to optimal values on the states reachable under optimal policies, possibly without ever touching the rest of the state space. Its deterministic special case is Korf's LRTA* (1990), which ties dynamic programming to heuristic search (Weighted, Anytime & Real-Time Search).
Asynchronous value iteration updates one state per step. Which schedules are guaranteed to converge to ?
- Any schedule, even one that eventually stops updating some state
- Only the fixed cyclic order
- Any schedule that updates every state infinitely often
- Only schedules that update states in decreasing order of their current values
Show the answer
C. Any schedule that updates every state infinitely often
Each update shrinks that state's error to at most times the current maximal error, and the maximal error never grows, so every interval that touches all states shrinks it by a factor . Fairness is all that is needed; a state that is never updated again keeps its error forever.
Approximate dynamic programming: what errors cost
In large problems every backup is approximate: a regression fits to sampled targets for , or a learned critic evaluates the current policy. The question is how per-iteration errors propagate to the quality of the policies produced.
(a) Contraction plus the per-iteration error, then unroll the recursion:
The greedy-loss bound of MDPs: Value & Policy Iteration multiplies in the second horizon factor. (b) Write , , and with . Greediness for , , yields near-monotone improvement:
Greediness also gives , hence . Split the loss through these two facts:
Since , taking sup norms gives a contraction with a constant input, whose limit is the bound:
One factor accumulates errors over iterations, the other is the greedy step's sensitivity. Scherrer and Lesner (2012) argued that the guarantee is tight for stationary policies, and removed a factor by giving up stationarity: executing the last greedy policies in a periodic loop improves the guarantee toward as grows. With and that is the difference between a worst-case loss of about 200 and about 2.
When fitted value iteration diverges
Sup-norm error bounds are an idealization. Function approximators fitted by least squares control an average error, and composing a least-squares projection with the Bellman operator can fail outright.
Two states with one feature each, and , so the approximate values are and . State 1 moves to state 2; state 2 stays put with probability and terminates otherwise; every reward is 0, so , which represents exactly. Each iteration fits by least squares, with equal weights, to the backed-up targets (Sutton & Barto, §11.2):
Setting the derivative to zero, , gives a linear recursion:
For , for example with , the weight grows geometrically from any , although every exact backup is a contraction and the target function is representable. The projection is a non-expansion in the uniform norm, the backup is a contraction in the sup norm, and their composition contracts in neither.
Two repairs are known. Averagers (Gordon, 1995), approximators whose output is a fixed convex combination of target values (state aggregation, -nearest-neighbor averaging, interpolation on a grid), are sup-norm non-expansions, so fitted value iteration with them remains a contraction.
More generally, error propagation replaces the sup norm by weighted norms. If every regression has error at most in under a sampling distribution , the final policy's loss measured in is bounded by a term of the form , plus one that vanishes with the number of iterations (Munos, 2007). The concentrability coefficient measures how much more probability the state distributions reachable by policies can put on a state than does, so it is finite only if the data cover everything those policies can reach. Finite-sample versions (Munos & Szepesvári, 2008) turn regression error into sample complexity, and fitted Q-iteration with trees or neural networks (Ernst, Geurts & Wehenkel, 2005; Riedmiller, 2005) is the batch template that DQN's target network runs online (Deep Q-Networks).
Key takeaways
- Generalized policy iteration interleaves evaluation and improvement at any granularity. Modified policy iteration with backups interpolates between value iteration () and policy iteration (), and from a pessimistic start satisfies .
- Asynchronous dynamic programming converges whenever every state is updated infinitely often; good orderings (backward Gauss–Seidel, prioritized sweeping, RTDP from an admissible start) can save most of the work.
- A per-iteration error costs up to in policy value for both approximate value and policy iteration. The bound is tight for stationary policies, and periodic non-stationary policies remove one horizon factor.
- Least-squares fitted value iteration can diverge even when the target is representable; averagers are safe, and bounds with concentrability coefficients make the role of data coverage explicit.
Check yourself
In the interactive lesson these are scored with your confidence, and what you miss comes back for review.
Modified policy iteration evaluates each greedy policy with backups. Which algorithms are the cases and ?
- Policy iteration and value iteration
- Value iteration and policy iteration
- Q-learning and Monte Carlo evaluation
- Gauss–Seidel and Jacobi value iteration
Show the answer
B. Value iteration and policy iteration
With , one backup of the policy greedy for is : value iteration. With , , exact evaluation: policy iteration. Everything in between is generalized policy iteration with partial evaluation.
Approximate value iteration at makes a sup-norm error of at most in every backup. What limiting loss does the error-propagation theorem guarantee for the greedy policies?
Show the answer
C.
. The values themselves are within , and the greedy step multiplies by another . Both factors are worst cases.
In the two-state counterexample, least-squares fitted value iteration diverges although the true values are representable and each exact backup is a contraction. What goes wrong?
- The rewards are too large
- The least-squares projection is a non-expansion only in an norm, the backup contracts only in the sup norm, and their composition can expand
- The feature matrix is rank-deficient
- The discount factor exceeds 1
Show the answer
B. The least-squares projection is a non-expansion only in an norm, the backup contracts only in the sup norm, and their composition can expand
Contraction is a property relative to a norm, and two maps that are well behaved in different norms need not compose well. Here the composition multiplies by . Averagers, which are sup-norm non-expansions, or on-policy weighting, under which the backup contracts in the matching norm, avoid the problem.
error bounds for fitted value iteration involve a concentrability coefficient . When is small?
- When the sampling distribution covers, with comparable probability, every state that policies can drive the system to
- When the function class is small
- When the discount factor is small
- When the rewards are sparse
Show the answer
A. When the sampling distribution covers, with comparable probability, every state that policies can drive the system to
compares the state distributions that policies induce with the data distribution ; if some reachable state is rarely or never sampled, regression error there is unconstrained, and is large or infinite. It is the formal reason offline data must cover the behavior one hopes to evaluate or improve.
Further reading
- D. P. Bertsekas & J. N. Tsitsiklis, Neuro-Dynamic Programming (Athena Scientific, 1996).
- M. L. Puterman & M. C. Shin, "Modified policy iteration algorithms for discounted Markov decision problems," Management Science (1978).
- A. G. Barto, S. J. Bradtke & S. P. Singh, "Learning to act using real-time dynamic programming," Artificial Intelligence 72, 81–138 (1995).
- R. Munos, "Performance bounds in -norm for approximate value iteration," SIAM Journal on Control and Optimization (2007).
- B. Scherrer & B. Lesner, "On the use of non-stationary policies for stationary infinite-horizon Markov decision processes," NeurIPS (2012).