Unit 4 of 11 · about 4 hours · implement, measure

Dyna-style imagined experience and imagined versus real accounting

Dyna is the oldest recipe for turning a model into data. Its loop and its accounting rules recur in every modern imagined-data method.

You'll be able to

  • Implement tabular Dyna-Q from its boxed steps, including the planning-sampling rule for states and actions.
  • Reproduce the Dyna maze rank order (more planning steps reach near-optimal behavior in fewer episodes) as the book reports it.
  • Account imagined and real updates separately, and state the sample budget both ways.

Covers

Dyna-style real and imagined experienceImagined versus real sample and compute accounting
1

Read

In this order, only the parts listed

0 of 3 done

  1. Chapter 8, Section 8.2: DynaReinforcement Learning: An Introduction (2nd ed.) - Chapter 8

    Section 8.2, printed pp. 161 to 165: Figure 8.1 (Dyna architecture), the Tabular Dyna-Q box (printed p. 164), Example 8.1 with Figures 8.2 and 8.3

    Steps (d), (e) and (f) of the box are the implementation contract. The authors post the full text free at incompleteideas.net; the URL above is the publisher page.

  2. Lecture 16: Model-Based RL Part 2, Dyna slidesBerkeley CS 185/285 Deep Reinforcement Learning (Spring 2026) - Model-Based RL

    Part 2 (Policy learning with models: the Dyna box slide and the general Dyna-style recipe slide)

  3. Lecture 11: Model-Based RL, Dyna slideStanford CS224R Spring 2026 - Model-Based RL

    Slides 11 to 12: the 4-step MBPO loop labeled as the algorithm called Dyna

2

Focus on

  • Direct RL, model learning and planning run the same update. Step (d) learns from real experience, step (f) replays the identical Q-learning update on imagined experience.
  • Planning samples a random previously observed state and a random action previously taken there, then queries the stored model. Unseen pairs are never sampled because the model has no entry for them.
  • With the agent is plain one-step Q-learning. The book reports about 25 episodes to near-optimal behavior for , 5 for , and 3 for : rank order on the book's maze, not a learner target.
Common mistakes · 3
  • Counting imagined updates as environment samples. Report real steps and imagined updates as two numbers; the sample-efficiency claim divides by the first.
  • Filling unseen model entries with zeros or defaults. The box samples only previously observed pairs; invented entries silently teach invented dynamics.
  • Keeping the overwrite model of step (e) in a stochastic or changing world. One stored outcome per pair then teaches noise as fact; Exercise 8.5 asks exactly for this failure.
3

Try it yourself

Closed-book, before checking anything

From a blank file, implement steps (a) to (f) of the Tabular Dyna-Q box on a small deterministic chain with . Hand-compute one direct update and one planning update for the same transition, and show your code produces both numbers exactly.
4

Quiz yourself

Answer first, then mark it. Missed ones go to Review.

0 got · 0 missed

  1. 1.What does Dyna-Q with reduce to, and why?Answer

    One-step tabular Q-learning. Steps (e) and (f) are omitted, leaving acting plus the direct update in step (d).

  2. 2.State the planning-sampling rule of step (f) precisely.Answer

    Draw a random previously observed state and a random action previously taken in it, look up the stored reward and next state, and apply the Q-learning update.

  3. 3.Why did larger reach near-optimal behavior in fewer episodes on the Dyna maze?Answer

    Each real step funds extra Q-learning updates on simulated experience, so values propagate to the start far earlier. The cost moves to compute, not samples.

  4. 4.What changes in Dyna-Q+ when the world changes, in one sentence?Answer

    Planning updates add a bonus that grows with time since the pair was last tried for real, so the agent retests stale transitions.

5

Practice

You're done when

Your box implementation matches both hand updates, and you can quote any Dyna result with real steps and imagined updates stated separately.

Only when you can do this without notes.

Leads to

Notes

Resources · 3 for this unit, 5 more in the section
  • Berkeley CS 185/285 Deep Reinforcement Learning (Spring 2026) - Model-Based RLUC Berkeley · primary

    Slides are public at https://rail.eecs.berkeley.edu/deeprlcourse/static/slides/lec-N.pdf; current videos are not, and the public Fall 2023 playlist numbers lectures differently. Study Lectures 15 and 16 (model-based RL: learned dynamics, open-loop and closed-loop planning, random shooting and CEM, MPC, model-based policy learning). There is no model-based homework, so build the planner yourself on a small environment with known dynamics first.

  • Reinforcement Learning: An Introduction (2nd ed.) - Chapter 8Richard Sutton and Andrew Barto · required

    The authors post the full second edition free at incompleteideas.net; cite the printed page numbers. Study Sections 8.1 to 8.3 (models, Dyna-Q, when the model is wrong) and Sections 8.8 to 8.11 (decision-time planning, rollout algorithms and Monte Carlo Tree Search). Reproduce the Dyna-Q versus Dyna-Q+ ranking on the blocking or shortcut maze.

  • Stanford CS224R Spring 2026 - Model-Based RLStanford University · support

    Use Lecture 11 (model-based RL) and its MBPO reading as a second treatment of model error, uncertainty and short model rollouts.

Also in this section

  • When to Trust Your Model: Model-Based Policy OptimizationJanner et al. · required

    Study the model-error analysis and short model-rollout design. Reproduce a reduced real-plus-imagined-data comparison and retain the horizon where model bias reverses the gain.

  • Deep Reinforcement Learning in a Handful of Trials using Probabilistic Dynamics Models (PETS)Chua et al. (NeurIPS 2018) · support

    Read the split between aleatoric uncertainty (probabilistic networks) and epistemic uncertainty (ensembles) and the trajectory-sampling planner. Implement an ensemble on a small task and show where the members disagree.

  • Mastering Diverse Domains through World ModelsDeepMind · depth

    Read DreamerV3 only after the small explicit dynamics and planning path passes. Trace representation, latent dynamics, imagination and actor-critic state, but do not make a large benchmark reproduction part of the exit gate.

  • Hands-on Modern RL - Model-Based and World-Model SectionsWalking Labs · support

    Use Sections 9.3 and 9.4 as concept maps for model-based RL, search and world models. No runnable dynamics or planner script exists, so reproduce its error-recursion numbers by hand and verify algorithm claims against the original papers. Pin commit 9231bab of walkinglabs/hands-on-modern-rl; its code/chapterNN folders do not follow the site chapter numbers.

  • Reinforcement Learning Control Laboratory - Model-Based StretchRoadmap-Final · support

    Add a learned-dynamics stretch with a known-dynamics sanity case, prediction and planning tests, horizon sweeps, model-exploitation failure and matched model-free comparison.