> For the complete documentation index, see [llms.txt](https://world-models-from-scratch.gitbook.io/wmfs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://world-models-from-scratch.gitbook.io/wmfs/chapters/chapter_01/01-what-is-a-world-model.md).

# 1.1 What Is a World Model?

A world is the bounded environment in which a system operates. For example: in a self-driving car, the world includes the road, nearby vehicles, pedestrians, traffic signals, and the car itself. For a computer-use agent, the world might be a browser, its interface, and the applications it can control. A robot, game-playing agent, or software agent each operates in a different world.

The boundary of the world depends on the system and its task.

| System             | World                      | Observation                 | Action                    | Predicted future              |
| ------------------ | -------------------------- | --------------------------- | ------------------------- | ----------------------------- |
| Self-driving car   | Road environment           | Cameras and vehicle sensors | Steer or brake            | Future traffic scene          |
| Robot              | Robot and workspace        | Cameras and joint state     | Move, push, or grasp      | Future robot and object state |
| Game-playing agent | Game environment           | Board state or pixels       | Game move                 | Future game state             |
| Video model        | Recorded scene             | Recent frames               | Optional control          | Future frames                 |
| Computer-use agent | Interface and applications | Screen or interface state   | Click, type, or tool call | Updated interface state       |

A world model learns how that environment changes. It uses what has already been observed, and, when relevant, an action to predict what could happen next. For example: What happens if the car brakes? If the robot moves its arm? If the computer-use agent clicks a button?

A prediction of the next observation is one predicted **transition**. A sequence of predicted future observations is a predicted trajectory. In this book, that predicted trajectory is called a **rollout**.

The way an environment changes from one time step to the next is called its **dynamics**. This includes the effect of actions on that change. A world model learns an approximation of those dynamics. Given a history of observations and, when applicable, a sequence of actions, it predicts a distribution over future trajectories, or rollouts:

$$
p\_\theta(o\_{t+1:t+H} \mid o\_{\leq t}, a\_{t:t+H-1})
$$

Here, `H` is the prediction horizon. The predicted trajectory contains the observations from step `t + 1` through step `t + H`.

![](https://565757139-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F64ikEJQaVP2LxutrTAH9%2Fuploads%2Fgit-blob-f50abdd9a44d40f26e4ead151fc74bad0e291bba%2Ffig_1_1_transition.png?alt=media)

*Figure 1.1: Encode an observation, advance the learned state under an action, then decode a prediction.*

## From One Transition to a Rollout

There are two common ways to produce a rollout. Some models generate the full trajectory in one operation. Other models predict one transition at a time and carry the predicted state into the next step.

The following pseudocode shows the second approach:

```python
def rollout(model, observation, actions):
    state = model.encode(observation)
    future = []

    for action in actions:
        state = model.step(state, action)
        future.append(model.decode(state))

    return future
```

## Generalization and Multiple Futures

Training data contains a finite set of observed transitions. A world model learns patterns from those transitions. It uses those patterns to estimate what may happen in states that were not recorded exactly in the training data.

A future is not always unique. The same observation and action may lead to different outcomes. A deterministic model predicts one trajectory. A probabilistic model represents a distribution over trajectories. Each sampled rollout is one trajectory from that distribution.

The playground shows one predicted transition at a time. Apply each prediction as the next observation to build a rollout. You can also compare one predicted future with several possible futures.

[Open the transition and rollout playground in a new tab](https://nahidalam.github.io/world_model_from_scratch/interactive/chapter_01/transition_playground.html).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://world-models-from-scratch.gitbook.io/wmfs/chapters/chapter_01/01-what-is-a-world-model.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
