Level 0: Foundation
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.Practising in your head
A model-free learner only improves from what actually happens to it. A model-based learner also builds a mental map of how the world works and rehearses in its head: once it has found the goal, it can replay the route many times without walking it again. The catch is that the map can be wrong, especially if the world changes, so a good model-based learner also checks its map from time to time.
MuZero mastered Go, chess, shogi and Atari with a learned model, and Dreamer learns to control robots by imagining thousands of trajectories in a learned world model.
- 1. A model-based agent learns…
- 2. Planning with a model lets the agent…
- 3. The main risk of a model is that it…
Level 1: Beginner
★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.By hand
- Model: an estimate of the transitions and rewards, P̂(s′|s, a) and R̂(s, a), or a sampler that produces (s′, r) from (s, a).
- Planning: any computation that improves a policy or value function from the model rather than from new experience; value iteration (topic L1-5) is planning with a known model.
- Dyna-Q (Sutton 1990): after each real step, (1) a Q-learning update, (2) a model update, (3) n planning updates, each a Q-learning update on a transition replayed from the model at a previously seen (s, a).
- Prioritised sweeping: plan first where the values are changing most, and work backwards through predecessors.
- Dyna-Q+: add an exploration bonus κ√τ for transitions not tried for τ steps, so the agent re-checks parts of the model that may have gone stale.
- Learned latent models: MuZero learns a representation, a dynamics function and value and policy heads, and plans with Monte Carlo tree search; Dreamer learns a recurrent world model and trains an actor-critic entirely on imagined rollouts.
- 1. Planning means improving the policy from…
- 2. Dyna-Q's planning updates replay transitions from…
- 3. Dyna-Q+ adds a bonus for transitions…
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.Dyna-Q on the Dyna maze
Exercise 1.
- The 6 × 9 maze of Sutton and Barto with seven wall cells; start on the left, goal at the top right; reward 1 at the goal, 0 otherwise; the shortest path takes 14 steps.
- A deterministic tabular model that remembers the last outcome of every (s, a) tried.
- Dyna-Q with α = 0.1, ε = 0.1, γ = 0.95 and n planning updates per real step, each from a uniformly chosen previously seen (s, a).
Practice.
- Use a model when real experience is expensive (robots, user interactions) and computation is cheap.
- Keep imagined rollouts short: model errors compound with the horizon (MBPO uses rollouts of a few steps from real states).
- Use ensembles of learned models to estimate uncertainty and avoid exploiting model errors (PETS, MBPO).
- Plan where it matters: prioritised sweeping and trajectory sampling focus updates on states the agent will actually visit.
- Revisit the model: bonuses for staleness or uncertainty keep it honest in changing environments.
- Tools: DreamerV3 and MuZero reference implementations (JAX), MBRL-Lib, and LightZero for MCTS-based agents.
for _ in range(n_plan):
ps, pa = seen[rnd.randrange(len(seen))] # a previously tried (s, a)
ps2, pr, pd = model[(ps, pa)] # what happened last time
target = pr + (0 if pd else gamma * max(Q[ps2]))
Q[ps][pa] += alpha * (target - Q[ps][pa]) # Q-learning on imagined experience- 1. Imagined rollouts should be short because…
- 2. Ensembles of models help to…
- 3. Prioritised sweeping updates first where…
Level 3: Advanced
★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.Theory
Planning is learning from simulated experience. A Q-learning update on a transition sampled from a correct model has the same expected effect as one on a real transition. With n planning updates per step, Dyna-Q performs n + 1 updates per real step; with a perfect deterministic model and enough planning it converges to the same Q* as Q-learning, with far fewer real steps.
Certainty equivalence. Planning with a maximum-likelihood model treats the estimates as if they were exact. With n samples per (s, a), the model error is of order 1/√n, and the resulting value error can be amplified by up to γ/(1 − γ)² by the simulation lemma: ‖V^π − V̂^π‖∞ ≤ γ ε_P R_max/(1 − γ)² + ε_R/(1 − γ), with ε_P and ε_R the largest transition (total variation) and reward errors.
Compounding errors. A k-step imagined rollout accumulates one-step errors: for linear dynamics x′ = ax with an estimate â, the k-step prediction error is |a^k − â^k||x₀|, which grows roughly k times faster than the one-step error when |a| ≈ 1.
Stale models. A model that was right becomes wrong when the environment changes. If the change makes things worse, acting on the model reveals it; if it makes things better (a new shortcut), a greedy agent never visits the changed part and never learns about it. Dyna-Q+’s bonus κ√τ makes long-untried transitions attractive in planning, so the agent goes and checks.
- 1. With a perfect model, a planning update has the same expected effect as…
- 2. The simulation lemma bounds value error by model error times…
- 3. A greedy agent misses a new shortcut because…
Level 4: Expert
★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.How much real experience does planning save on the Dyna maze, and what happens when the maze changes after the model has been learned?
History.
- R. S. Sutton (1990, 1991) introduced Dyna and Dyna-Q+.
- A. Moore and C. Atkeson (1993) introduced prioritised sweeping.
- M. Kearns and S. Singh (2002) analysed planning with estimated models (the simulation lemma).
- J. Schrittwieser and colleagues (2020) introduced MuZero; D. Hafner and colleagues introduced Dreamer (2020) and DreamerV3 (2023).
- M. Janner, J. Fu, M. Zhang and S. Levine (2019) introduced MBPO, with short model rollouts from real states.
Exercise 2.
- Planning: Dyna-Q with 0, 5 and 50 planning updates per real step on the Dyna maze, 10 runs of 50 episodes each.
- Changing maze: the shortcut maze of Sutton and Barto (Example 8.3): a wall across row 3 with a gap on the left (shortest path 16 steps); at step 3,000 a gap opens on the right (shortest path 10 steps). Dyna-Q against Dyna-Q+ (κ = 0.001, which also plans with untried actions), 50 planning updates, 6 runs of 6,000 steps.
Seed 0, Dyna maze (mean steps per episode over 10 runs):
| planning updates per step | episode 2 | episodes 2–10 | episodes 41–50 | first episode averaging ≤ 20 |
|---|---|---|---|---|
| 0 (Q-learning) | 953.8 | 361.6 | 17.7 | 25 |
| 5 | 147.0 | 39.3 | 16.6 | 5 |
| 50 | 43.2 | 20.3 | 17.1 | 3 |
Seed 0, shortcut maze:
| agent | reward by step 3,000 | reward in steps 5,001–6,000, each run |
|---|---|---|
| Dyna-Q | 99.3 | 56, 54, 86, 56, 55, 57 |
| Dyna-Q+ | 88.8 | 83, 83, 78, 83, 73, 71 |
- Planning saved most of the experience: with 50 planning updates, episodes averaged at most 20 steps from episode 3, against episode 25 for Q-learning (episodes 26 and 29 on seeds 1 and 2; 6 and 6 for 5 planning updates; 3 and 3 for 50).
- All three reached the same final behaviour, 16.6 to 17.7 steps per episode: planning changes how fast the values propagate, not what they converge to.
- Dyna-Q missed the shortcut: in 17 of 18 runs over three seeds its reward in the last 1,000 steps stayed at 52 to 57, the rate of the old 16-step path. Its model still said the right side was a wall, and a greedy agent had no reason to check.
- Dyna-Q+ found it in all 18 runs (71 to 85 in the last 1,000 steps), at the price of less reward before the change (88.8 against 99.3 by step 3,000 on seed 0; 82.7 against 123.7 and 98.5 against 115.0 on seeds 1 and 2), spent re-checking stale transitions.
- Exercise 1: over 5 runs, episode 2 took 748.6 steps without planning and 48.4 with 50 planning updates.
From Dyna to learned world models
- MuZero never predicts observations: its model predicts only rewards, values and policies in a learned latent space, which is all that tree search needs (topic L6-2 for MCTS).
- Dreamer learns a recurrent state-space model of observations, then trains an actor-critic on imagined latent rollouts of about 15 steps.
- MBPO and PETS use ensembles of neural dynamics models; MBPO mixes short model rollouts with real data for SAC.
- Classical control often has a physics model already: LQR and MPC (topics L6-3 and L6-4) plan with it directly.
References
- R. S. Sutton (1990). “Integrated architectures for learning, planning, and reacting based on approximating dynamic programming.” ICML.
- A. W. Moore and C. G. Atkeson (1993). “Prioritized sweeping: reinforcement learning with less data and less time.” Machine Learning.
- M. Kearns and S. Singh (2002). “Near-optimal reinforcement learning in polynomial time.” Machine Learning.
- J. Schrittwieser and colleagues (2020). “Mastering Atari, Go, chess and shogi by planning with a learned model.” Nature.
- D. Hafner, J. Pasukonis, J. Ba and T. Lillicrap (2023). “Mastering diverse domains through world models.” arXiv:2301.04104.