Tabular Solution Methods/Planning: Focusing Updates and Decision-Time Search

Lesson 2.102,371 words

Planning: Focusing Updates and Decision-Time Search

Dyna plans by replaying remembered transitions, but sampling them uniformly wastes most of the effort. This lesson sharpens planning: prioritized sweeping works backward from states whose value just changed, expected versus sample updates weigh thoroughness against cost, and trajectory sampling and real-time DP focus updates on the states the policy actually visits.

╌╌╌╌

This builds on Planning and Learning, which showed that planning and learning are the same backup applied to simulated versus real experience, and built the Dyna architecture around that idea. Dyna replays remembered transitions chosen uniformly at random — and most of those replays do no useful work. This lesson makes planning efficient, then turns from background planning to planning done afresh at each decision.

Prioritized sweeping

Dyna-Q starts its simulated transitions at pairs chosen uniformly at random, wasting effort. In the second maze episode only the pair leading into the goal has nonzero value, so an update anywhere else backs up zero onto zero and changes nothing. Under uniform sampling the agent performs many null updates before finding a useful one.

To address this, work backward from states whose value just changed. When changes, the only one-step updates that can do useful work are those on actions leading into ; updating them may change their predecessors, so the frontier of useful updates propagates backward from the change. This is backward focusing. The frontier grows fast, and not every pair matters equally — some values would change by a lot, others barely. Prioritized sweeping orders the work by urgency: keep a queue of state–action pairs keyed by the magnitude of the Bellman error they would incur, and always process the top first.

Prioritized sweeping. A value change at a state (right) makes its predecessors candidates for update; each is pushed onto a priority queue keyed by the size of its expected change, and the queue is processed most-urgent first, so the effect of a change propagates backward until it dies out.
Algorithm:Prioritized-Sweeping\textsc{Prioritized-Sweeping} — deterministic environment
  1. 1
    Q(s,a),Model(s,a)Q(s,a), \mathit{Model}(s,a) \gets arbitrary; PQueuePQueue \gets empty
  2. 2
    loop
    forever
  3. 3
    SS \gets current (nonterminal) state
  4. 4
    Aε-greedy(S,Q)A \gets \varepsilon\text{-greedy}(S, Q)
  5. 5
    take action AA, observe RR, SS'
  6. 6
    Model(S,A)R,S\mathit{Model}(S,A) \gets R, S'
  7. 7
    PR+γmaxaQ(S,a)Q(S,A)P \gets \lvert R + \gamma \max_a Q(S',a) - Q(S,A) \rvert
  8. 8
    if P>θP > \theta then
  9. 9
    insert S,AS,A into PQueuePQueue with priority PP
  10. 10
    repeat nn times while PQueuePQueue is nonempty
  11. 11
    S,Afirst(PQueue)S,A \gets \first(PQueue)
  12. 12
    R,SModel(S,A)R, S' \gets \mathit{Model}(S,A)
  13. 13
    Q(S,A)Q(S,A)+α[R+γmaxaQ(S,a)Q(S,A)]Q(S,A) \gets Q(S,A) + \alpha\big[R + \gamma \max_a Q(S',a) - Q(S,A)\big]
  14. 14
    for each Sˉ,Aˉ\bar S, \bar A predicted to lead to SS do
  15. 15
    Rˉ\bar R \gets predicted reward for Sˉ,Aˉ,S\bar S, \bar A, S
  16. 16
    PRˉ+γmaxaQ(S,a)Q(Sˉ,Aˉ)P \gets \lvert \bar R + \gamma \max_a Q(S,a) - Q(\bar S, \bar A) \rvert
  17. 17
    if P>θP > \theta then
  18. 18
    insert Sˉ,Aˉ\bar S, \bar A into PQueuePQueue with priority PP

On maze tasks prioritized sweeping reaches the optimal policy with 5-to-10 times fewer updates than unprioritized Dyna-Q, and the advantage widens with the grid size. It extends to stochastic environments by keeping transition counts and using expected updates over all possible successors — which is also its main limitation, since expected updates can waste computation on low-probability transitions. That tension is the next topic.

Expected vs. sample updates

A backup can be computed two ways. An expected update considers all possible next states and rewards, weighting each by its probability; a sample update considers a single sampled successor. For the action-value with a distribution model , the expected update is

while the sample update, given one sampled , is the Q-learning form

The expected update is thorough but slow (it visits every successor); the sample update is cheap but noisy (it visits one). Under a fixed compute budget, which wins?

They coincide when the environment is deterministic (one successor, ). With many successors they diverge: the expected update is exact — its new is limited in error only by the errors at the successors — while the sample update carries sampling error. So an expected update yields the better estimate but costs more. Let be the branching factor, . One expected update costs about times as much computation as one sample update.

Backup trees for the two updates. The expected update (left) fans out to every possible successor and averages exactly; the sample update (right) follows one sampled transition. An expected update costs about b sample updates, where b is the branching factor.

If there is time to finish an expected update its estimate is generally better. But with large , the units of compute for one expected update instead buy sample updates spread over pairs, improving each a little. The RMS error of sample updating falls roughly as

after sample updates, so for moderately large the error drops to within a few percent of the expected result after only a small fraction of sample updates. On large stochastic problems with many state–action pairs, spreading cheap sample updates across many pairs beats spending the same effort on a few exact ones; and because the successor estimates become accurate sooner, later backups off those successors compound the advantage.1

Trajectory sampling and real-time DP

A second axis governs not what an update looks like but which states get updated. Classical DP sweeps the whole state space, updating every state once per pass. On large tasks this is hopeless: most states are irrelevant — visited only under poor policies or with tiny probability — yet the sweep spends equal effort on them. The alternative is to draw states from the on-policy distribution: follow the current policy in simulation and update the states it visits. This is trajectory sampling, and it needs no explicit representation of the distribution — the trajectory generates it for free. Empirically it speeds early planning, at some risk of neglecting the rest of the space in the long run.

Real-time dynamic programming (RTDP) is the on-policy trajectory-sampling version of value iteration: it applies expected value-iteration updates to the states visited along real or simulated trajectories, in whatever order those visits occur. RTDP is a form of asynchronous DP — no systematic sweeps, updates in trajectory order — and it has a strong guarantee. On stochastic optimal-path problems (undiscounted episodic tasks with an absorbing goal, zero goal value, negative step rewards, and a policy guaranteed to reach the goal), RTDP converges to a policy optimal on the relevant states — those reachable from a start state under some optimal policy — without ever visiting the irrelevant ones, and sometimes without visiting some relevant states at all. On a racetrack task with over 9,000 reachable states, RTDP reached near-optimal control with about half the updates that sweep-based value iteration needed, leaving a large fraction of states barely touched or untouched.2

Beyond the table: model-based deep reinforcement learning

Dyna's claim — that a learned model plus replayed simulated experience extracts more policy improvement from scarce interaction — is the founding idea of model-based deep RL, and the modern versions keep the Dyna skeleton while replacing its tabular pieces with neural networks.

Prioritized sweeping, generalized. Moore and Atkeson's prioritized sweeping, the backward-focusing method above, predates Dyna's tabular limits and was designed precisely for reinforcement learning with less data and less time.3 Its priority-queue idea survives in deep RL as prioritized experience replay: sample stored transitions in proportion to their TD error rather than uniformly, so the network spends gradient steps where the TD error — and thus the learning signal — is largest.4

Learned models you can plan in. Ha and Schmidhuber's World Models trained a recurrent latent dynamics model from pixels and then trained a controller almost entirely inside that model's dream, transferring the result back to the real environment — Dyna's indirect route with a deep generative model as the sample model.5 Hafner and colleagues' Dreamer line made this a strong general method: learn a latent world model, then optimize the policy by backpropagating value gradients through imagined (simulated) trajectories rolled out in the model, achieving state-of-the-art data efficiency on continuous control and, in DreamerV3, across a wide span of domains with fixed hyperparameters.6

Planning in a learned model at decision time. MuZero closes the loop with the decision-time methods below: it learns a latent dynamics model and runs Monte Carlo tree search over it, with no access to the environment's rules, matching AlphaZero on Go, chess, and shogi and setting records on Atari.7 The Dyna picture — experience improves a model, the model generates simulated experience, and the same backups improve the policy — is intact; every box is now a network.

Dyna's descendants in deep RL. The tabular Dyna loop (experience trains a model; the model generates simulated experience; shared backups improve the policy) survives with each piece replaced by a neural network: World Models and Dreamer learn latent dynamics and plan by imagined rollouts; prioritized replay is prioritized sweeping's focus; MuZero plans in a learned model at decision time.

Planning at decision time

Everything so far is background planning: use simulated experience to improve a policy or value function over all states ahead of time, so that when arrives its action is already cached and reading it off is trivial. Planning is not focused on the current state; it has already happened.

The alternative is decision-time planning: on encountering , run a planning computation whose only output is the single action , then discard the values it produced and start over at . The values and policy are specific to and its likely successors — usually wasteful to save (you rarely revisit the exact state soon), but concentrating all computation on the decision at hand.

Background planningDecision-time planning
Whenahead of time, over all stateson demand, for the current
Outputglobal policy / value functionone action
Action selectioncheap table lookupdeep focused lookahead
Reusedyesdiscarded after the move
Suitslow-latency controlseconds–minutes per move (board games)

Heuristic search and rollouts

Heuristic search is the classical decision-time method from artificial intelligence. At each state it builds a large tree of continuations, applies a stored approximate value function at the leaves, and backs those values toward the root exactly as the expected / updates do throughout this course — then picks the best root action and discards the rest. Deeper search improves action selection by pushing the imperfect value function further from the decision; if the search reaches terminal states, the value-function error vanishes entirely. Its main advantage is focus: the tree concentrates on the states and actions that might immediately follow , so computation and memory are spent where they most affect the imminent decision.

Rollout algorithms are decision-time planners built on Monte Carlo control. At state , for each candidate action the algorithm simulates many trajectories that start with and thereafter follow a fixed rollout policy, estimating by the mean of the sampled returns. It then plays

This is one step of policy improvement: by the policy improvement theorem, acting greedily w.r.t. at and following after yields a policy at least as good as . A rollout algorithm does not learn an optimal value function; it improves over on the fly, then discards the estimates. Better rollout policies and more trajectories give better decisions, at more computation per move.

Monte Carlo Tree Search (MCTS) is a rollout algorithm with memory. Plain rollouts throw away every simulated trajectory; MCTS accumulates the value estimates from successive simulations to steer later ones toward high-reward parts of the space. It is the method that carried computer Go from weak amateur in 2005 to grandmaster by 2015, and, combined with a deep neural network, it is the search inside AlphaGo and AlphaZero.8

MCTS maintains a tree rooted at the current state, holding Monte Carlo value estimates for the state–action pairs most likely to be reached in a few steps. Inside the tree it selects actions by an informed tree policy (e.g. -greedy or a UCB rule) that balances exploration and exploitation — a UCB tree policy selects

with the edge visit count and ; outside the tree it falls back to the simple rollout policy. Each iteration runs four steps, repeated until the move-time budget is exhausted.

One iteration of Monte Carlo Tree Search. Selection descends the tree by the tree policy to a leaf; expansion adds a child; simulation rolls out to a terminal state under the rollout policy; backup carries the return up the traversed edges. Iterations repeat until time runs out, then the root's action is chosen by visit count or value.
Algorithm:MCTS\textsc{MCTS} — one move from root state StS_t
  1. 1
    initialize tree with root StS_t
  2. 2
    repeat until time budget exhausted
  3. 3
    // 1. Selection
  4. 4
    ss \gets root
  5. 5
    while ss is in the tree and nonterminal do
  6. 6
    aa \gets tree-policy(ss); ss \gets successor of s,as, a
  7. 7
    // 2. Expansion
  8. 8
    if ss is nonterminal then add ss as a new leaf
  9. 9
    // 3. Simulation
  10. 10
    GG \gets return of a rollout-policy episode from ss to termination
  11. 11
    // 4. Backup
  12. 12
    for each edge (s,a)(s',a') traversed by the tree policy this iteration do
  13. 13
    N(s,a)N(s,a)+1N(s',a') \gets N(s',a') + 1
  14. 14
    Q(s,a)Q(s,a)+1N(s,a)[GQ(s,a)]Q(s',a') \gets Q(s',a') + \tfrac{1}{N(s',a')}\big[G - Q(s',a')\big]
  15. 15
    return argmaxaN(St,a)\arg\max_a N(S_t, a)
A single MCTS state–action estimate keeps running statistics — a visit count and a mean return — updated on backup. High-count, high-value edges pull future selections down the same branch, so simulations concentrate on promising continuations.

The root action is chosen by accumulated statistics — usually the largest visit count (robust to outliers) or the largest . The environment then advances, and MCTS runs again, reusing the surviving subtree and discarding the rest.

MCTS is a decision-time rollout algorithm, so it inherits online, incremental, sample-based value estimation and the policy-improvement guarantee of acting greedily on Monte Carlo estimates. Beyond that, by saving edge statistics and expanding along high-return trajectories, it grows a partial action-value table concentrated on the initial segments of promising trajectories — the benefit of a learned without approximating a value function globally, while still using past experience to guide exploration.

Finally, the leaf-node evaluation and the rollout policy need not stay simple. Replace the hand-written rollout with a deep neural network that evaluates leaf positions and suggests moves, train that network by self-play, and MCTS becomes the search inside AlphaGo and AlphaZero — the subject of the deep-RL case studies. The tree search supplies the deep, focused lookahead; the network supplies the value and policy priors that make the search tractable.

Footnotes

  1. Sutton & Barto, §8.4–§8.5 — Prioritized Sweeping (backward focusing, the priority-queue algorithm) and Expected vs. Sample Updates (equations 8.1–8.2, branching factor , and the error analysis of Figure 8.7).
  2. Sutton & Barto, §8.6–§8.7 — Trajectory Sampling and Real-time Dynamic Programming: on-policy vs. uniform update distributions, RTDP as asynchronous value iteration, and its convergence on relevant states for stochastic optimal-path problems (racetrack example).
  3. Moore, A. W., & Atkeson, C. G. (1993), Prioritized Sweeping: Reinforcement Learning with Less Data and Less Time, Machine Learning 13(1):103–130 — the priority-queue backward-focusing method, reaching optimality with far fewer updates than uniform Dyna-style planning.
  4. Schaul, T., Quan, J., Antonoglou, I., & Silver, D. (2016), Prioritized Experience Replay, ICLR — sampling stored transitions in proportion to TD-error magnitude, the deep-RL analogue of prioritized sweeping's priority queue.
  5. Ha, D., & Schmidhuber, J. (2018), World Models, NeurIPS — a learned recurrent latent dynamics model in which a compact controller is trained largely inside the model's simulated rollouts before transfer to the real environment.
  6. Hafner, D., Lillicrap, T., Ba, J., & Norouzi, M. (2020), Dream to Control: Learning Behaviors by Latent Imagination, ICLR (Dreamer); and Hafner, D., et al. (2023), Mastering Diverse Domains through World Models, (DreamerV3) — optimizing policies by backpropagating value gradients through trajectories imagined in a learned latent world model.
  7. Schrittwieser, J., et al. (2020), Mastering Atari, Go, Chess and Shogi by Planning with a Learned Model, Nature 588:604–609 (MuZero) — learning a latent dynamics model and running Monte Carlo tree search over it, without access to the environment's true rules.
  8. Sutton & Barto, §8.8–§8.11 — Planning at Decision Time, Heuristic Search, Rollout Algorithms, and Monte Carlo Tree Search: the four steps selection/expansion/simulation/backup (Figure 8.10), the tree and rollout policies, and the extension to AlphaGo in §16.6.

╌╌ END ╌╌