Project 5 — Dyna-Q on a Maze 🐭¶
Home | Notes | Exercises | Quiz Hub | All Projects
Concepts: 8.1 models & planning, 8.2 Dyna-Q
What this shows¶
Planning = replaying a learned model through the same Q-learning update. By doing n simulated updates per real step, the agent propagates the goal's value backward between real moves, dramatically cutting the real experience needed.
Run it¶
Prints steps-to-goal per episode forn_plan ∈ {0, 5, 50} (0 = plain Q-learning). Saves dyna_steps.png if matplotlib is present.
What to look for¶
- n=0 (no planning): early episodes take hundreds of steps.
- n=5: noticeably faster.
- n=50: near-optimal within a handful of episodes — memory + compute converted into sample efficiency.
Experiments to try¶
- Flip on Dyna-Q+ (
plus=Trueindyna_q) and change the maze mid-run (move a wall to open a shortcut). The √τ exploration bonus drives the agent to rediscover the changed region; plain Dyna-Q may never notice. - Compare wall-clock vs. episodes — planning costs compute per real step; is it "free"? (No — but it's usually worth it when real steps are expensive.)
- Swap uniform planning for prioritized sweeping (queue updates by TD-error magnitude, sweep predecessors) and count updates to convergence.