A deterministic world has a terminal goal G and two states A and B, each with one action, "right". Right from B gives reward 1 and ends at G. Right from A gives reward 0 and moves to B. Start with Q=0 everywhere, α=0.5, γ=0.9. The agent experiences (B,right,1,G) and then (A,right,0,B), each with one Q-learning update, and stores them in a model. Then Dyna-Q does two planning updates, replaying (B,right) first and (A,right) second. What are Q(A,right) and Q(B,right) after each stage, and what did planning achieve?

Reinforcement learning, Model-based RL
Level L2 Elementary. Length Medium. Nature Mat Mathematical.

What's being asked

Whether you understand that Dyna-Q reuses stored experience as simulated experience, so value information travels further per real step.

Key idea

Dyna-Q performs the real Q-learning update and then n extra updates of the same form on transitions (s,a,r,s′) sampled from a learned model. Each planning update costs no real interaction.

Steps

  1. Real step 1 on (B,right,1,G), with terminal value 0: Q(B)=0+0.5(1+0−0)=0.5. Store the transition in the model.
  2. Real step 2 on (A,right,0,B): Q(A)=0+0.5(0+0.9×Q(B)−0)=0.5×0.45=0.225. Store it too.
  3. Planning update 1, replaying (B,right,1,G): Q(B)=0.5+0.5(1−0.5)=0.75.
  4. Planning update 2, replaying (A,right,0,B): the target is 0.9×0.75=0.675, so Q(A)=0.225+0.5(0.675−0.225)=0.45.
  5. Summarise: without planning the values are Q(B)=0.5 and Q(A)=0.225. After planning they are 0.75 and 0.45. The true values are Q(B)=1 and Q(A)=0.9.
  6. State the point: the same two real transitions produced much more learning, and the order of replay matters. Replaying B first lets the improved Q(B) flow back to A.

Common mistakes

How long your answer should be

6 steps of arithmetic; about 4 minutes.

Last checked on 4 December 2026.

Read this

Previous in Reinforcement learning: After t=10 total pulls, a three-armed bandit with rewards in [0,1] has pull counts n=(5,3,2) and sample means μ^=(0.6,0.5,0.4). Which arm does UCB1 pull next, using the index μ^i+2ln⁡t/ni? What would a greedy agent do?
Next in Reinforcement learning: One episode with γ=0.5 visits states A, B, A, C in that order and then ends. The rewards received after leaving each state are 2,0,4,−1 respectively. What are the returns from each time step and the first-visit and every-visit Monte Carlo estimates of V(A), V(B) and V(C) from this single episode?