# Why do we need a model of the environment in Dyna?

In chapter 8 of "Reinforcement Learning: An Introduction" by Sutton and Barto, it is stated that Dyna needs a model to simulate the environment.

But why do we need a model? Why can't we just use the real environment itself? Wouldn't it be more helpful to use real environment instead of fake one?

Unlike algorithms presented in other chapters of Sutton and Barto, Dyna is a planning algorithm. That means that it makes decisions online, in a real environment, that attempt to be as optimal as possible given some constraints such as current knowledge and time available to compute between time steps. This differs from learning-only online algorithms which typically take a small step towards optimality on each piece of new experience as it happens.

A planning algorithm can only do its job well if it is allowed to "look ahead" at the consequences of its behaviour whilst learning online. In fact, this is the definition of planning - to choose an action based on reasoning about consequences of that action.

For an algorithm to look ahead before taking an action, it needs a model of how the environment will respond to that action. That model does not need to be coded up directly - e.g. you don't necessarily need to write a physics engine to predict the real world (although a basic one might be a good prior or pre-training step). Instead it can be a learned model, and typically in e.g. Dyna-Q, that is what you use.

There is a strong relation between Dyna-Q, and regular Q-learning with experience replay. In the most basic forms, they are essentially the same algorithm with a different framing. However, you can take the planning ideas further e.g. focus improvements around the currently experienced state and paths to a goal state in Dyna-Q, perhaps making it closer to MCTS conceptually.

Wouldn't it be more helpful to use real env instead of fake one?

Most real environments do not let you take actions, see the consequences and then rewind in order to re-try. Essentially that is what planning algorithms are making up for - they try to predict consequences. This is important when mistakes made during training have real consequences, for example for a physical robot navigating an environment where there might be a possibility of a fall or collision that damaged something. Whilst online learning algorithms such as SARSA will also help with this in different ways (in SARSA by changing policy to allow for exploratory moves), typically Q-learning will be weaker than Dyna-Q when it comes to learning quickly from mistakes. With the usual caveat: Much still depends on the specific problem and choices of hyperparameters.

• You said, "That means that it makes decisions online, in a real environment, that attempt to be optimal". Question. Do other algorithms, such as Monte Carlo, SARSA, Q-learning, etc, make decisions online as well?? What is the meaning of 'decision' you are talking about? Action? if so, all of those algorithms make decision online(every time it faced with a new state), don't they? (based on Q-value & e-greedy etc) – user3595632 May 29 '18 at 8:42
• You said "A 'planning algorithm' can only do its job well if it is allowed to 'look ahead' at the consequences of its behaviour. For that it needs a 'model'". Question. You said 'look ahead', but according to the Dyna algorithm, it makes (or improve) a model only with the states and actions it already took before.. Why is it considered as 'look ahead'? – user3595632 May 29 '18 at 8:44
• You said, "There is a strong relation between "Dyna-Q" and 'regular Q-learning with experience replay'". Question. Now that after I saw your explanation, It seems like they are really look same.. I think that 'experience replay' completely corresponds to the model of Dyna-Q. What's the difference? – user3595632 May 29 '18 at 8:45
• You said, "This is important when mistakes made during training have real consequences, for example ~". Question. But in this real environment case, wouldn't the return of that (state, action) be getting updated to lower value everytime the robot experience that situation? Then as time goes, the robot would evade those action cuz it decide the action based on the Value? Also, even if I use a model, If I made a mistake in a real env, does it also affect the model to choose that action again? – user3595632 May 29 '18 at 8:52
• @FauChristian Your slide chapter is different with that of book (2nd edition)... We talked about Planning and Learning !! – user3595632 May 31 '18 at 14:15

Sutton's Dyna has been shown to be more effective for many problem spaces than learning systems that work without a model, yet it requires fewer processing cycles than certainty-equivalence methods. It is advanced in that it, in parallel, builds a model and adjusts behavioral policy based on both incoming information and the model. The goal was to integrate both identified capabilities of the human brain.

Why do we need Model in Dyna?

The capacity to model is an essential part of the Dyna architecture and may, over time, prove to be an essential component to achieve the greater effectiveness. Many think so, myself included. In other words, there may be no equivalently effective mechanism than building and maintaining a model for many problem sets.

Why can't we just utilize a real environment itself? Wouldn't it be more helpful to use real environment instead of fake one?

The real environment cannot be placed in memory for many reasons. Primarily, it would not fit. Furthermore, not much of it can be acquired. Only images of the environment can be acquired and placed in memory. The most important characteristic of images, whether they be stock prices, temperature readings, or streamed video, is that they are grossly sparse and undifferentiated representations of the environment on which we are attempting to operate.