Dyna architecture

Also known as: Dyna-Q

On this page 7

The Dyna architecture is a reinforcement learning framework, introduced by Richard Sutton around 1990, that integrates learning, planning and acting in one agent. The agent updates its value function or policy from real experience, learns a model of the environment from the same experience, and then performs extra updates on simulated experience generated by that model.

Its best-known instance, Dyna-Q, combines one-step Q-learning with a simple table model and a fixed number of planning updates per real step. Dyna showed that model-free and model-based reinforcement learning are not opposites: the same update rule can learn from both, and planning becomes simply learning from imagined transitions.

How the Dyna architecture combines learning and planning

The Dyna architecture runs a loop with two sources of experience. Real interaction with the environment drives both direct reinforcement learning and model learning, while the learned model feeds an inner loop of indirect learning, which Sutton called planning.

In each cycle the agent acts, observes a reward and next state, updates its value estimates, stores the transition in its model, and then replays n simulated transitions drawn from the model. The table below names the four processes and what each contributes.

ProcessInputOutput
ActingCurrent policy and stateReal transition in the environment
Direct learningReal transitionUpdated value function or policy
Model learningReal transitionUpdated transition and reward model
PlanningSimulated transitions from the modelFurther value or policy updates
The four processes of a Dyna agent

Because direct learning and planning use the same update rule, the value function becomes a shared memory. Every real step improves the model, and every planning step propagates value information further through the state space without additional interaction.

The Dyna-Q algorithm step by step

Dyna-Q is the tabular version of the Dyna architecture for deterministic environments, and it is the form taught in most courses. It keeps a Q-table and a model table that maps each visited state-action pair to the last observed reward and next state.

  1. Observe the current state and choose an action with an epsilon-greedy policy.
  2. Execute the action and observe the reward and next state.
  3. Apply a Q-learning update to the real transition.
  4. Store the reward and next state in the model for that state-action pair.
  5. Repeat n planning steps: sample a previously visited pair, query the model, and apply the same Q-learning update.

The parameter n controls the planning budget. Setting n to zero reduces Dyna-Q to ordinary Q-learning, while larger values trade extra computation for fewer real interactions. The table summarizes the main parameters.

ParameterTypical rangeEffect
Planning steps n0 to several hundredMore planning, faster value propagation
Step size alpha0.1 to 0.5 in tabular tasksSpeed versus stability of updates
Discount factor gamma0.9 to 0.99Weight of future rewards
Exploration epsilon0.05 to 0.2Share of random actions
Exploration bonus kappaSmall positive value in Dyna-Q+Encourages revisiting old states
Key parameters of Dyna-Q

Variants and modern descendants

The original Dyna-Q samples state-action pairs uniformly, which wastes planning effort on states whose values do not change. Later variants focus planning where it matters or handle environments that change over time.

MethodKey ideaMain benefit
Dyna-QUniform replay from a table modelSimple and sample efficient
Dyna-Q+Bonus for long-untried actionsAdapts when the environment changes
Prioritized sweepingPlan backward from large value changesMuch less wasted computation
Linear DynaLinear models over featuresWorks beyond small tables
Deep model-based RLNeural world models generate rolloutsScales to images and continuous control
Dyna variants and related methods

Modern algorithms such as model-based policy optimization and the Dreamer family follow the Dyna principle with neural networks: they learn a world model and train a policy on short imagined rollouts. Dyna also resembles experience replay, since replaying stored transitions is equivalent to planning with a nonparametric model that can only reproduce past experience.

Dyna compared with model-free and pure planning methods

Dyna occupies a middle ground between model-free learning and full planning. Unlike Q-learning or SARSA, it reuses experience through a model; unlike value iteration or Monte Carlo tree search, it does not require a complete model in advance and plans incrementally in the background.

ApproachNeeds a modelSample efficiencyComputation per step
Q-learningNoLowVery low
Dyna-QLearned onlineHighModerate, grows with n
Value iterationComplete model givenNot applicableHigh, full sweeps
Monte Carlo tree searchSimulator or learned modelHighHigh at decision time
How Dyna differs from neighboring approaches

The deciding factor is the relative cost of real experience and computation. When interaction is slow or expensive, as in robotics or user-facing systems, Dyna-style planning is attractive; when a fast simulator exists, model-free learning at scale may be simpler.

Limitations and common mistakes

The main limitation of the Dyna architecture is model error. Planning with an inaccurate model can spread wrong values quickly, and the agent may exploit flaws in the model rather than solving the real task.

  • Stale models in changing environments mislead planning until Dyna-Q+ style bonuses force re-exploration.
  • Deterministic models in stochastic tasks overfit to the last observed outcome; sample or average outcomes instead.
  • Long imagined rollouts with neural models compound errors, so modern methods keep rollouts short.
  • Uniform sampling wastes planning on irrelevant states; prioritized sweeping fixes this in tabular settings.
  • Excessive n can cost more computation than the saved interactions justify.

Practitioners should therefore monitor model accuracy, tune n against wall-clock cost, and treat planning gains as conditional on model quality rather than guaranteed.

Understanding it simply

Think of a person learning a new city. They walk real streets and remember what they saw. Later, at home, they replay those walks in their head. They work out shortcuts without leaving the house.

The Dyna architecture does the same thing. The agent learns from real steps and from imagined steps. The imagined steps come from its own map of the world. More mental practice means fewer real trips, as long as the mental map is accurate.

Applied in practice

A standard teaching case is a grid maze with 47 open cells, a start square and a goal that gives a reward of 1. An agent using plain Q-learning needs many episodes to learn the path, because each episode only moves value information one step back from the goal.

When the same agent uses Dyna-Q with 50 planning steps per real step, each real move triggers dozens of simulated updates across previously visited cells. In the classic textbook version of this experiment, the planning agent finds a near-optimal path within roughly three episodes, while the non-planning agent needs around twenty-five. A robotics team applies the same logic when physical trials are slow: it logs each real trial, fits a dynamics model, and runs short simulated rollouts between trials, which reduces the number of costly hardware runs needed to reach a working controller.