Log inStart free
LESSON 20.01 · 5 STAGES · 3 CONTROLS · 3 CHECKSPRO · PREVIEW

Model-based RL and Dyna

Watch an agent learn a model of a maze and plan with simulated steps.


Pro lesson. Stage 1 is free to watch. Pro opens all 5 stages, 3 controls and 3 checks, in this lesson and every other.

Go Pro · $8.25/mo
EXPLAINER · 20.01 · DYNA MAZEEPISODE 2 · 199 REAL STEPS
01
Stage 1 of 5 · Real steps
Episode 2 takes 199 real steps. Model-free RL makes one Q update per real step.
Explain it simply

The agent starts at S and looks for the goal G. The teal cells show where it walked in episode 2, and a stronger shade means more visits. Each real step is one move in the true maze. A model-free agent learns only from these real steps.

The 9 by 6 maze with walls. Episode 2 took 199 real steps; shaded cells show the visits.

real steps, visitsmodel, planning stepsvalues, preferred movesopen cell
the maze after episode 2the Dyna loop012345678012345SGreal maze199 real stepsQ values17 of 46 valuedmodel173 of 184 movesactreal steplearn modelplanning stepsepisode 2: 199 real stepsthe maze after episode 2the Dyna loop012345678012345SGreal maze199 real stepsQ values17 of 46 valuedmodel173 of 184 movesactreal steplearn modelplanning stepsepisode 2: 199 real steps
Toy: the 9 × 6 Dyna maze of Sutton and Barto, one seeded run of 30 episodes
STAGE 1 / 5
MATH · STAGE 1HOVER A SYMBOL OR A SHAPE
Q(s,a)←Q(s,a)+α [r+γmax⁡a′Q(s′,a′)−Q(s,a)]\sy{q}{out}{Q(s,a)} \leftarrow \sy{q}{out}{Q(s,a)} + \alpha\,[\sy{r}{data}{r} + \gamma \max_{a'} \sy{q}{out}{Q(s',a')} - \sy{q}{out}{Q(s,a)}]
r=1, max⁡Q(s′)=0.000: Q←0.271+0.1 (1+0.95⋅0.000−0.271)=0.344r = 1,\ \max Q(s') = 0.000:\ Q \leftarrow 0.271 + 0.1\,(1 + 0.95 \cdot 0.000 - 0.271) = 0.344

Each real step moves Q toward the reward plus the best next value.

Common mix-ups

MYTHPlanning needs a simulator that someone wrote by hand.

The fix, and 1 more mix-up with the diagram to show them, come with Pro.

Predict, then reveal
3 CHECKS · PRO
Q01After episode 2, do 50 planning steps give more cells a preferred move than 5?

Make your guess, then test it in the diagram. All 3 checks come with Pro.

PRO LESSON · YOU WATCHED STAGE 1 OF 5
Unlock the full explainer
  • 4 more stages and 3 live controls
  • 2 mix-up cards and 3 predict-then-reveal checks
  • Watch it as a narrated video, in three voices
  • Every Pro lesson and capstone · 656 in total

$99 a year, or $15 a month. Cancel any time.