Simple Algorithm
Reinforcement Learning · Fixed Point · 26 min

Asynchronous & Prioritized Dynamic Programming

In-place sweeps, prioritized sweeping and real-time dynamic programming.

A sweep that updates every state equally often is the least intelligent way to spend computation: most values barely change while a few are far from settled. Asynchronous dynamic programming updates states in any order, prioritized sweeping spends each update where the Bellman error is largest, and real-time dynamic programming updates only the states an agent actually visits. On a 400-cell grid, the right order turns 39 sweeps into two.

What you’ll learn

  • State the convergence theorem for totally asynchronous dynamic programming, including updates that use stale values, and connect it to the convergence of Q-learning.
  • Show on a worked example how the order of updates changes the work by more than an order of magnitude.
  • Design prioritized sweeping with Bellman-error priorities, and bound how one backup changes the errors of other states.
  • State the convergence theorem of real-time dynamic programming with its conditions, and explain how labeling (LRTDP) and heuristic search (LAO*) let it stop.

Asynchronous updates and their guarantee

In asynchronous dynamic programming there are no sweeps. At each time tt some state sts_t is chosen and its value is replaced by its backup, V(st)←(TV)(st)V(s_t)\leftarrow(\mathcal TV)(s_t), with T=Tπ\mathcal T=\mathcal T^\pi for evaluation or T⋆\mathcal T^\star for control; all other values stay put. In-place sweeps, random orders and many processors updating different states at once are all special cases. With several processors, an update may even read values of other states that are out of date.

Bertsekas (1982, 1983) showed that almost nothing about the order matters. The cleanest statement is a general theorem about fixed points.

DerivationWhy the boxes do the work
  1. X(k)={V: ∥V−Vˉ∥∞≤γk∥V0−Vˉ∥∞}=∏s[Vˉ(s)−γkc, Vˉ(s)+γkc],c=∥V0−Vˉ∥∞X(k)=\big\{V:\ \norm{V-\bar V}_\infty\le\gamma^k\norm{V_0-\bar V}_\infty\big\}=\prod_{s}\Big[\bar V(s)-\gamma^k c,\ \bar V(s)+\gamma^k c\Big],\qquad c=\norm{V_0-\bar V}_\infty

    For a γ\gamma-contraction in the max norm, use balls around the fixed point. A max-norm ball is a product of intervals, one per state, so the box condition holds, and one backup of any vector in X(k)X(k) lands in X(k+1)X(k+1):

  2. Suppose that from some time on every value an update reads comes from a vector in X(k)X(k). The next update of state ss then puts V(s)V(s) into its interval of X(k+1)X(k+1), and later updates of ss keep it there. Because the set is a box, each state can move into its new interval on its own schedule: no coordination between states is needed.

  3. Vt∈X(k) for all large t, for every k⟹∥Vt−Vˉ∥∞→0V_t\in X(k)\ \text{for all large }t,\ \text{for every }k\qquad\Longrightarrow\qquad\norm{V_t-\bar V}_\infty\to0

    Once every state has been updated after that time, the whole vector is in X(k+1)X(k+1); once stale reads from before that moment are flushed, all reads come from X(k+1)X(k+1), and the argument repeats. Fairness and eventual refreshing make this happen for every kk, so V→VˉV\to\bar V:

The theorem reaches beyond planning. Tabular Q-learning is asynchronous stochastic approximation of the backup T⋆\mathcal T^\star on action values: each step updates one pair (s,a)(s,a) with a noisy sampled target. Its classical convergence proofs (Tsitsiklis, 1994; Jaakkola, Jordan & Singh, 1994) combine exactly this asynchronous contraction argument with step sizes that average out the noise (Convergence of TD: Stochastic Approximation).

Check your understanding

An adversary chooses which state asynchronous value iteration (γ<1\gamma<1) updates next, and each update may read values up to 1,000 steps out of date. The adversary must update every state infinitely often. Does the algorithm converge to V⋆V^\star?

  1. No: an adversarial order can make the values cycle
  2. Only if the states are updated in a fixed cyclic order
  3. Yes: fairness plus bounded staleness is enough for a max-norm contraction
  4. Only if each update reads fresh values
Show the answer

C. Yes: fairness plus bounded staleness is enough for a max-norm contraction

The boxes X(k)X(k) shrink by γ\gamma, and with delays bounded by 1,000 steps, old information is eventually discarded. Every fair schedule eventually moves the iterate from one box into the next. The order affects speed, never the limit.

Order matters: a 400-state example

Take an open 20×20 grid with the goal in one corner. Moves are deterministic, bumping into the edge leaves you in place, entering the goal pays +1+1 and ends the episode, γ=0.95\gamma=0.95, and V0=0V_0=0. The optimal value of a cell at distance dd from the goal is γd−1\gamma^{d-1}, and the farthest cell is 38 steps away. Compare four ways of running value iteration until a pass changes nothing.

Predict before you look

Run in-place sweeps row by row, starting from the goal's corner and moving away from it, so that each cell is updated after its neighbors on the goal side. How many sweeps until a sweep changes nothing?

Show the answer

2

When a cell is updated, its goal-side neighbors already hold their final values, so the first sweep computes every value exactly. The second sweep changes nothing and confirms convergence. A synchronous sweep moves information only one step per sweep, so it needs 39.

ScheduleSweepsBackups
Synchronous (Jacobi)3915,561
In place, starting at the far corner and moving toward the goal3915,561
In place, starting at the goal's corner and moving away2798
Prioritized sweeping (largest Bellman error first)no sweeps399, plus 1,990 Bellman-error checks (399 to fill the queue, 1,591 of predecessors)
Exact counts for this grid (399 non-goal cells). After kk synchronous sweeps, exactly the cells within kk steps of the goal have their final values; sweep 39 confirms. Sweeping toward the goal reads each goal-side neighbor before updating it, so it is no better than Jacobi. Prioritized sweeping backs up each cell exactly once, in order of distance.

The same two in-place orders differ by a factor of 20, and nothing in the algorithm tells you which one you are using. Good orders follow the flow of value backward from where rewards are. In this deterministic problem, largest-Bellman-error-first processes the cells in order of their distance from the goal, which is Dijkstra's shortest-path algorithm in disguise. It finds that order without being told, at the price of a priority queue and of checking errors, first of every cell to fill the queue and then of each backed-up cell's predecessors (the cell itself included when it borders the edge): about 2,400 backup-sized operations in all, roughly a sixth of synchronous value iteration's 15,561.

Prioritized sweeping

Prioritized sweeping (Moore & Atkeson, 1993; Peng & Williams, 1993, who called it queue-Dyna) keeps a priority queue of states keyed by the size of their pending update. After backing up a state it re-examines only the states whose backups read it: its predecessors. The key fact is local.

text
PRIORITIZED-SWEEPING(model, V, θ):
    for each state s:  push s with priority |(T V)(s) − V(s)| if it exceeds θ
    while the queue is not empty:
        s ← pop the state with the highest priority
        V(s) ← (T V)(s)                          # one backup
        for each predecessor p of s:              # P(s | p, a) > 0 for some a
            e ← |(T V)(p) − V(p)|                  # its new Bellman error
            if e > θ: push p with priority e (or raise its priority to e)
    return V                                       # every Bellman error ≤ θ

The priority can be the Bellman error itself, as here, or a cheaper upper bound from the theorem, γmax⁡aP(s∣p,a)∣Δ∣\gamma\max_aP(s\mid p,a)\abs\Delta. With a learned model the same loop runs inside Dyna, between real steps (Dyna: Learning, Planning & Acting).

On returning, every Bellman error is at most θ\theta, so the values are within θ/(1−γ)\theta/(1-\gamma) of the fixed point. Wingate and Seppi (2005) combined prioritization with partitioning the state space and reordering variables, and report speedups of value and policy iteration by several orders of magnitude on many problems while keeping their convergence guarantees. In deep RL, prioritized experience replay (Schaul et al., 2016) applies the same idea to sampled transitions: replay the ones with large TD errors more often (Experience Replay in Depth).

Check your understanding

A backup has just changed V(s)V(s) by Δ\Delta. Whose Bellman errors can have changed as a result?

  1. Only those of ss's predecessors, by at most γmax⁡aP(s∣p,a)∣Δ∣\gamma\max_aP(s\mid p,a)\abs\Delta each, plus that of ss itself
  2. Only those of the successors of ss
  3. Those of every state, by up to γ∣Δ∣\gamma\abs\Delta
  4. None: ss is now consistent, so nothing else is affected
Show the answer

A. Only those of ss's predecessors, by at most γmax⁡aP(s∣p,a)∣Δ∣\gamma\max_aP(s\mid p,a)\abs\Delta each, plus that of ss itself

A backup at pp reads V(s)V(s) only if some action of pp can lead to ss. Those predecessors' backups shift by at most γmax⁡aP(s∣p,a)∣Δ∣\gamma\max_aP(s\mid p,a)\abs\Delta; ss's own error changes because V(s)V(s) moved. Everything else is untouched, which is why prioritized sweeping needs the predecessor lists.

Real-time dynamic programming

Real-time dynamic programming (RTDP; Barto, Bradtke & Singh, 1995) chooses which states to update by acting. It runs trials: from a start state, follow the policy that is greedy for the current values, back up each state you visit, and stop at a goal. Korf's (1990) LRTA* is its deterministic special case. RTDP is usually stated for stochastic shortest-path problems, in which an agent pays a cost c(s,a)>0c(s,a)>0 per step until it reaches a goal, and the values J(s)J(s) are expected costs to go.

An initial value function is admissible if J0≤J⋆J_0\le J^\star: it never overestimates the remaining cost. Admissible values are optimistic, and optimism drives the greedy policy toward actions that have not been ruled out yet.

The proof combines the asynchronous convergence argument with optimism. Admissible values stay admissible under backups, so an action that looks cheap is tried until its estimate rises to its true cost; an action that looks expensive has been shown to be so. Irrelevant states are never needed to certify the optimal policy, so RTDP can solve problems whose full state space is far too large to sweep. Two weaknesses remain: RTDP has no stopping rule, and states that are relevant but rarely visited converge slowly.

Labeled RTDP (LRTDP; Bonet & Geffner, 2003) fixes both. A state is labeled solved when every state reachable from it under the greedy policy has a Bellman residual below ε\varepsilon; trials stop at solved states, and the algorithm stops when the start state is solved. It terminates after finitely many trials with ε\varepsilon-consistent values on the greedy policy's reachable states. LAO* (Hansen & Zilberstein, 2001) comes from heuristic search: it grows a partial solution graph from the start state, expanding its unexpanded tips, and runs value or policy iteration only on the states whose values the expansion can change. With an admissible heuristic it returns an optimal policy for the start state, typically after visiting a fraction of the states.

MethodWhich states it updatesWhen it stops
Synchronous value iterationAll, every sweepLargest change below a threshold
Prioritized sweepingLargest Bellman error first; then predecessorsQueue empty: every error below θ\theta
RTDPStates on greedy trials from the startNo built-in rule; converges on relevant states
LRTDPGreedy trials, skipping solved statesThe start state is labeled solved
LAO*The expanded part of the best partial solutionThe best solution graph has no unexpanded tips and its values have converged

Key takeaways

  • Asynchronous dynamic programming converges under any schedule that updates every state infinitely often, even with stale but eventually refreshed values; the box structure of max-norm balls is the reason, and it also underlies Q-learning's convergence.
  • Order changes the work, not the limit: on a 20×20 grid, sweeping in the direction value flows needs 2 sweeps instead of 39, and prioritized sweeping finds such an order by itself.
  • Prioritized sweeping backs up the state with the largest Bellman error and re-examines only its predecessors, whose errors change by at most γmax⁡aP(s∣p,a)∣Δ∣\gamma\max_aP(s\mid p,a)\abs\Delta.
  • RTDP updates only states visited by greedy trials and, from admissible values, converges on the relevant states; LRTDP adds a solved-labeling stopping rule, and LAO* brings the same idea to heuristic search.

Check yourself

In the interactive lesson these are scored with your confidence, and what you miss comes back for review.

Question 1

Which condition is enough for asynchronous value iteration with γ<1\gamma<1 to converge to V⋆V^\star?

  1. Every state is updated infinitely often, and stale values are eventually refreshed
  2. States are updated in decreasing order of their current values
  3. All states are updated equally often
  4. Each update reads only values computed in the current sweep
Show the answer

A. Every state is updated infinitely often, and stale values are eventually refreshed

That is the totally asynchronous condition. The max-norm boxes around V⋆V^\star make the order irrelevant to the limit, though not to the speed.

Question 2

On the 20×20 grid, prioritized sweeping backed up each of the 399 cells exactly once, yet did about 2,400 backup-sized operations in total. Where did most of the rest go?

  1. Into backing up the goal state repeatedly
  2. Into re-checking the Bellman errors of predecessors after each backup
  3. Into an initial synchronous sweep that is required for correctness
  4. Into sorting all states by value before starting
Show the answer

B. Into re-checking the Bellman errors of predecessors after each backup

After each backup the algorithm computes the Bellman error of every predecessor of the updated cell, each check as costly as a backup: 1,591 checks here, on top of the 399 that filled the queue at the start. Prioritization saves backups but adds bookkeeping, and pays off when the right order is not known in advance.

Question 3

RTDP with admissible values runs on a problem where half the states cannot be reached from the start under any optimal policy. What happens to their values?

  1. They converge to J⋆J^\star like all the others
  2. RTDP diverges unless they are initialized exactly
  3. They may stay wrong forever, while the greedy policy from the start becomes optimal
  4. They are set to infinity
Show the answer

C. They may stay wrong forever, while the greedy policy from the start becomes optimal

RTDP updates states only when greedy trials visit them, and once values on the relevant states are accurate, the greedy policy avoids the irrelevant ones. Their values are not needed to act optimally from the start, which is exactly the saving.

Question 4

When does Labeled RTDP mark a state as solved?

  1. When it has been visited at least once
  2. When its own Bellman residual falls below ε\varepsilon
  3. When its value equals the heuristic
  4. When every state reachable from it under the greedy policy has a residual below ε\varepsilon
Show the answer

D. When every state reachable from it under the greedy policy has a residual below ε\varepsilon

Its own residual is not enough: its value depends on the states it can reach. Requiring all of them to be ε\varepsilon-consistent makes the label safe, and once the start state is labeled the algorithm can stop.

Further reading

  • D. P. Bertsekas & J. N. Tsitsiklis, Parallel and Distributed Computation: Numerical Methods (Prentice Hall, 1989).
  • A. W. Moore & C. G. Atkeson, "Prioritized sweeping: reinforcement learning with less data and less time," Machine Learning 13, 103–130 (1993).
  • A. G. Barto, S. J. Bradtke & S. P. Singh, "Learning to act using real-time dynamic programming," Artificial Intelligence 72, 81–138 (1995).
  • B. Bonet & H. Geffner, "Labeled RTDP: improving the convergence of real-time dynamic programming," ICAPS (2003).
  • E. A. Hansen & S. Zilberstein, "LAO: a heuristic search algorithm that finds solutions with loops," Artificial Intelligence* 129, 35–62 (2001).