Skip to main content
Every method so far in this chapter is model-free: it learns values or a policy directly from real transitions and uses each transition a few times at most. Dynamic programming in the MDP chapter was the opposite: it never acted at all and computed values from a known model. Model-based RL sits between the two. The agent learns a model of the environment from experience and then improves its values or policy with experience simulated by the model. Simulated experience is cheap, so a good model lets the agent learn from far fewer real interactions. A wrong model leads the agent to optimize for an environment that does not exist.

Models and planning

A model predicts how the environment responds to an action. A distribution model gives the full p(s′,r∣s,a)p(s', r \mid s, a), which is what dynamic programming needs. A sample model only draws one outcome (s′,r)(s', r) at a time, as a simulator does; it is easier to build and is enough for sampling-based methods (Sutton & Barto, 2018). Planning here means any computation that uses a model to improve a policy. One simple form reuses the methods you already know. Draw a state and an action, ask the sample model for (s′,r)(s', r), and apply a Q-learning update to the simulated transition as if it were real. This is Q-planning: Q-learning on simulated experience. With a correct model and enough updates it converges to q∗q_* of the model, for the same reasons Q-learning does.

Dyna-Q

Dyna-Q (Sutton, 1990) runs learning and planning side by side. Every real transition is used three times: for a direct Q-learning update, to update the model, and as one of the transitions that planning can replay later.
With n=0n = 0 this is plain Q-learning. In a gridworld maze, Q-learning extends the learned path back from the goal by roughly one state per episode, because each value only moves when the agent passes through it. With 50 planning steps per real step, Sutton and Barto’s Dyna maze finds the optimal path within the first few episodes: once the goal has been reached once, planning propagates its value back along the remembered transitions without new real experience (Sutton & Barto, 2018).

When the model is wrong

The model above is a table of the last observed outcome, so it is exactly right in a deterministic world that does not change. If the environment changes, for example a shortcut opens in the maze, the model stays wrong until the agent happens to try the changed transition, and the greedy policy gives it no reason to. Dyna-Q+ adds an exploration bonus to simulated rewards, r+κτr + \kappa\sqrt{\tau}, where τ\tau is the number of steps since the state-action pair was last tried in the real environment. Transitions that have not been checked for a long time look more attractive, so the agent tests them and corrects the model.

Prioritized sweeping

Dyna-Q picks planning updates at random, so most of them change nothing, especially early on, when almost all values are still zero. Prioritized sweeping keeps a queue of state-action pairs ordered by how much their value would change. After a value changes, the predecessors of that state, the pairs that the model says lead into it, are queued with a priority equal to the size of their pending update. Planning then works backward from wherever values are actually changing.

Planning at decision time

Dyna plans in the background and stores the result in QQ. Decision-time planning plans from the current state each time the agent must act, and keeps only the chosen action. The simplest version runs rollouts: from the current state, simulate each action followed by some fixed policy many times with the model, and pick the action with the best average return. Monte Carlo tree search (MCTS) builds a search tree from the current state instead. It spends more simulations on the branches that look promising and uses the statistics in the tree to choose the action. AlphaZero combined MCTS with a network that predicts values and action probabilities and learned to play Go, chess and shogi from self-play. MuZero kept the search and replaced the game rules with a learned model, so the same method works where no simulator exists.

Learned world models

For high-dimensional observations, such as images, the model is usually learned in a compressed latent space: an encoder maps the observation to a latent state, a dynamics network predicts the next latent state and the reward from the current one and the action, and a decoder can reconstruct the observation. The policy can then be trained entirely on trajectories imagined in the latent space. Ha and Schmidhuber’s world model (Ha & Schmidhuber, 2018) trained a small controller inside a learned model of a racing game. The Dreamer line of agents learns the actor and the critic from imagined latent rollouts; DreamerV3 (Hafner et al., 2023) uses one set of hyperparameters across Atari, continuous control and Minecraft. The World Models chapter covers these architectures in detail.

Model predictive control

Model predictive control (MPC) is decision-time planning with a model of the dynamics, as used in control engineering. At every step it optimizes a sequence of actions over a short horizon, executes only the first action, observes the new state and optimizes again. The model can be derived from physics or learned from data. With a learned model and a sampling optimizer such as the cross-entropy method, MPC gives a model-based agent that needs no policy network at all; replanning at every step corrects for errors in the model as they show up. Key references: (Sutton & Barto, 2018; Ha & Schmidhuber, 2018; Hafner et al., 2023); Sutton (1990), Integrated architectures for learning, planning, and reacting based on approximating dynamic programming.

References

  • Ha, D., Schmidhuber, J. (2018). World Models. arXiv [cs.LG]. Link
  • Hafner, D., Pasukonis, J., Ba, J., Lillicrap, T. (2023). Mastering diverse domains through world models. arXiv [cs.AI]. DOI
  • Sutton, R., Barto, A. (2018). Reinforcement Learning: An Introduction. Link

Found an error on this page? Report an issue.