Recurrent State-Space Models › The Recurrent State-Space Model
World Models HandbookAll chapters Recurrent State-Space Models › The Recurrent State-Space ModelOne section · Sections in this chapter3 / 10 ↓
Reading tools Definitions & inline links
Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.
Article links
Make inline references clickable
This section assembles the architecture, name by name, and explains the wiring that makes the posterior and prior cooperate. Read it slowly: every design choice here has a reason, and the reasons compound.
The five components
An RSSM for a partially observable environment with observations and actions consists of:
-
Deterministic recurrence (the memory path). A GRU (or LSTM) updates from the previous deterministic state, the previous sampled latent, and the previous action:
-
Prior (transition model). Before seeing anything at time , the model guesses the stochastic state:
-
Posterior (inference model). During training and filtering, an encoder sees the current observation and re-places where the evidence says it should be:
-
Observation model (decoder). Reconstructs or predicts the observation from the joint state:
-
Optional heads. In the Dreamer line, a reward head and a discount or continuation head for episode boundaries (the original Dreamer already modeled early termination). We will use them in Part VII: Planning and Agency; here we focus on the observation model.
where:
- : the GRU or LSTM update, a neural network with parameters applied identically at every step
- , : the prior's mean vector and per-dimension variances, produced from by a small network head
- , : the posterior's mean vector and per-dimension variances, produced from the pair by the encoder with parameters
- : a covariance matrix carrying the given variance vector on its diagonal and zeros elsewhere, so the Gaussian treats the coordinates as independent conditional on its inputs
- : the reward at time
Notice the timing convention, because it trips everyone up at least once. The GRU input at time is , not . So is the model's prediction of the situation at time before the observation arrives. The observation never touches directly; it enters the model only through the posterior, which shapes , which enters the recurrence at the next step. All per-step information about the current observation must therefore flow through the stochastic latent. This is deliberate, and it is what makes the KL term meaningful, as you will see below. If the observation could leak into by some side channel, the prior itself could use the observation it is supposed to predict, and the KL would no longer measure a real prediction gap. By forcing all observation information through the sampled bottleneck , the architecture guarantees that the only way the model can use the present is by encoding it in exactly the place the prior is trying to predict.
The prior is the transition model: what the model expects before it looks. It exists at all times, including during imagination. The posterior is the inference model: an approximate latent distribution after incorporating the evidence. It exists only when an observation is available, such as during training and filtering. The two have the same functional form but different inputs and different jobs.
Separate the modeled structure from assumptions about its adequacy:
- The generative model is Markov in its joint internal state. Whether the learned representation retains enough history for the environment's prediction tasks must be tested, not assumed from its fixed width.
- This example uses stationary dynamics and shared parameters across time. Other settings may require time or regime information in the state or inputs.
- History and actions must contain enough information for the task. Relevant unobservable quantities require a belief over alternatives, not a promise of exact recovery; task-irrelevant hidden variables need not be recovered.
- Recorded actions are available during training and evaluation. The model is not asked to infer which actions occurred.
The figure below shows the wiring unrolled over three steps. Read the middle column: the prior flows down from into ; the posterior flows up from into ; the decoder emits a predicted observation from ; and the GRU carries into . The third column is drawn faded deliberately: it is imagination, where the posterior arrows do not exist and the prior must carry the sequence on its own.

Why keep both paths
The division of labor between and is the design insight that makes the architecture work, so it deserves a careful statement.
The deterministic path provides a direct recurrent route for information and gradients. With differentiable gates, backpropagation through a GRU is an ordinary chain-rule calculation conditional on its inputs. This can help preserve information that would be difficult to carry through repeated stochastic transitions. It does not guarantee small gradient variance or stable optimization: the inputs still include sampled latents, and the recurrent Jacobians can attenuate or amplify gradients. PlaNet's ablation is evidence about its tested architecture and tasks, rather than a proof that stochastic-only models cannot learn.
The stochastic path supplies sampled latent variation. In the graph defined here, enters the joint state through the posterior distribution for , then influences later memory through the recurrence. The KL compares distributions, not two sampled values: even identical distributions can generate different samples, and an observation can change posterior variance without changing its mean. Uncertainty can also reside in distribution parameters carried by memory, in the observation model, and in uncertainty about fitted parameters. No single latent draw contains all of those uncertainties.
The Kalman analogy concerns the order of computation: predict a state distribution, then update it using an observation. A Kalman filter represents uncertainty with both a mean and a covariance, and its innovation is an observation residual, not a KL divergence. Under the linear-Gaussian assumptions its update is exact; an RSSM uses learned nonlinear dynamics and approximate inference. Comparing filtering with imagination can help locate a failure, but does not isolate one guilty component: the encoder, transition, decoder, and available information all influence the observed errors.
DreamerV2 (Hafner et al., 2021) uses 32 categorical variables with 32 classes each, sampled with straight-through gradients; DreamerV3 retains categorical stochastic latents. Categoricals provide discrete alternatives in latent coordinates. A diagonal Gaussian is unimodal conditional on its context in those coordinates, but a nonlinear decoder can still turn Gaussian latents into multimodal or correlated observations. The high-level prior/posterior/recurrence graph remains recognizable across the variants, while the distribution parameterization, KL calculation, and gradient estimator change. Straight-through differentiation is a biased surrogate; its practical usefulness does not imply that score-function estimators inevitably have exploding variance.