Recurrent State-Space Models › Hidden State: What Deterministic and Stochastic Each Buy You

Michael BrenndoerferJune 25, 20268 min read
World Models HandbookAll chapters
Part 5 of 12World-Model Architectures
Chapter 25Recurrent State-Space Models › Hidden State: What Deterministic and Stochastic Each Buy You
Reading section 2 of 10 · Hidden State: What Deterministic and Stochastic Each Buy You · 8 minSection 2 of 10 · 8 min

Book contents

Section 2 of 10 · 8 min read

Recurrent State-Space Models › Hidden State: What Deterministic and Stochastic Each Buy YouOne section · Sections in this chapter2 / 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 builds the two ingredients separately before combining them. PlaNet's experiments motivate the combination, but neither ingredient is a universal requirement for a capable world model. We need to distinguish how a state is computed from what distribution its outputs can represent.

The problem a hidden state solves

Recall from Bayesian Filtering and Belief States that an observation-action history contains the information available for inferring hidden state. Storing that raw history costs more as an episode grows. Some observations are redundant, while repeated noisy measurements can still help reduce uncertainty. A belief bt=p(st∣o≤t,a<t)b_t = p(s_t \mid o_{\le t}, a_{<t}) is the distribution of hidden environment state sts_t given observations through tt and earlier actions. It is a sufficient summary for the usual known-model POMDP prediction and decision problem, but a general belief distribution need not have an exact finite-dimensional representation. Classical filters exploit tractable special families. A learned world model instead fits a compact representation intended to retain the information its prediction tasks need.

There are two computational choices to separate:

  • A deterministic hidden vector is a fixed function of its inputs and parameters. It can store point estimates, probabilities, variances, or other learned features.
  • A stochastic latent is a random variable. Its distribution represents modeled alternatives; one sample is only one realization, not the distribution itself.

A Kalman filter is a useful counterexample to the idea that deterministic memory means certainty: its mean and covariance are updated deterministically, yet jointly describe an uncertain state. Likewise, a neural vector can encode the weights, means, and scales of a mixture distribution. The RSSM chooses a different implementation: recurrent memory plus sampled latent states. That choice can help retain information and generate alternative trajectories, but it does not by itself guarantee good inference or calibrated uncertainty.

Deterministic hidden state

A simple learned filter is a recurrent neural network that ingests observations and actions and maintains a fixed-size vector:

ht=fθ(ht−1,at−1,ot)h_t = f_\theta(h_{t-1}, a_{t-1}, o_t)

where:

  • hth_t: the learned hidden state at time tt, a fixed-size vector that summarizes the observation and action history
  • fθf_\theta: the learned recurrence, for instance a GRU or LSTM cell, with parameters θ\theta
  • at−1a_{t-1}: the action taken at the previous step
  • oto_t: the observation arriving at the current step

A related recurrent-memory pattern appears in Ha and Schmidhuber's World Models (2018). Its LSTM consumes VAE codes and actions and outputs a mixture distribution, not a point prediction. In our simpler recurrence, hth_t is a learned predictive summary, not a guaranteed sufficient statistic. A fixed-width representation puts pressure on the network to retain task-relevant information; it may also forget information that later turns out to matter. The prediction objective determines what is rewarded, and held-out tests tell us whether that training signal was enough.

Deterministic state has real strengths:

  • Repeatable updates. With fixed inputs, initialization, parameters, and deterministic numerical execution, the same recurrence returns the same state. This removes latent-sampling variance from that update, not representation or floating-point error.
  • Direct differentiation. Ordinary backpropagation follows the recurrence without a fresh sampling operation on each edge. Gradients can still vanish or explode.
  • Simple inference. The point-output baseline below needs one recurrent pass and no variational posterior.

The limitation appears when we attach a single point output and train it with mean squared error. If the next observation has two plausible modes, that output cannot report both. Conditional squared risk decomposes into the irreducible conditional variance plus the squared distance from the conditional mean, so the MSE-optimal point forecast is the mean. For a balanced symmetric bimodal distribution, that mean lies between the modes. A forecast of a ball on the left or right of a pillar can therefore average into a low-probability location in the middle. The cause is the point-output objective, not deterministic recurrent memory: a distributional head can report both alternatives.

The failure is easiest to see with numbers rather than words, so we make it concrete before moving on.

In[3]:
Code
import numpy as np

## Bimodal belief over the ball's next position: left of the pillar or right.
try:
    _trapz = np.trapezoid  # NumPy >= 2.0
except AttributeError:
    _trapz = np.trapz  # NumPy 1.x
mixture_x = np.linspace(-3.0, 3.0, 400)
mode_centers = np.array([-1.5, 1.5])
mode_std = 0.45
dens = 0.5 * (
    np.exp(-0.5 * ((mixture_x - mode_centers[0]) / mode_std) ** 2)
    + np.exp(-0.5 * ((mixture_x - mode_centers[1]) / mode_std) ** 2)
)
dens /= _trapz(dens, mixture_x)

## The MSE-optimal deterministic forecast is the conditional mean, which for
## this symmetric mixture sits exactly between the two modes.
cond_mean = _trapz(mixture_x * dens, mixture_x)
mean_gap_to_modes = float(np.min(np.abs(mode_centers - cond_mean)))
Out[4]:
Console
conditional mean = -0.000 (midway between modes)
distance from conditional mean to the nearest mode: 1.50
density at the conditional mean: 0.0034
peak density: 0.4434
Out[5]:
Visualization
Bimodal density curve with a marker at the low-density conditional mean.
Distribution of a bimodal belief over the ball's next position, with the MSE-optimal deterministic forecast marked at the conditional mean. The forecast lands in the low-probability valley between the two modes, a low-probability location between the plausible modes.

The plot illustrates mode averaging: the conditional mean lies in the low-density valley between the modes, not at the global minimum of the density. Enlarging a model while retaining an MSE point-output objective does not change the optimum into two alternatives. Changing the output distribution or the prediction objective addresses a different problem than adding hidden-state capacity.

A point output also leaves uncertainty unreported. Consider two grasps with the same predicted mean outcome but different failure risks. A planner receiving only those mean outcomes cannot distinguish them by uncertainty. Risk-sensitive decisions or information gathering may need a distribution, quantiles, or other uncertainty-sensitive information. These can come from deterministic memory with a probabilistic head, from ensembles, or from stochastic latent rollouts. A point forecast can still be useful for decisions; it simply does not answer every decision question.

Stochastic hidden state

One way to generate alternatives is to make part of the latent state stochastic. Instead of reporting only a point, the model predicts a distribution and samples from it. One trajectory may go left and another right if its learned distribution represents both outcomes. Sampling represents what the model believes, not a certificate that the belief is correct. Calibration must be checked against held-out outcomes.

Stochastic latent sequence models precede RSSMs: variational RNNs (Chung et al., 2015), stochastic RNNs (Fraccaro et al., 2016), deep variational Bayes filters (Karl et al., 2017), and structured inference networks (Krishnan et al., 2017) develop related latent-state and inference ideas. In these models, distinguish the approximate latent distribution from a sample drawn from it. For an RSSM, the joint distribution of (ht,zt)(h_t,z_t) matters: hth_t varies across previously sampled latent histories, even though each recurrent update is deterministic conditional on its inputs.

Stochastic recurrence can make retaining information and optimizing long sequences difficult. PlaNet reported that its combined recurrent and stochastic state performed substantially better than the particular single-path variants it tested. That result does not establish a universal law that each additional sample increases gradient variance. For example, in zt=zt−1+θ+ϵtz_t=z_{t-1}+\theta+\epsilon_t with a terminal linear loss zTz_T, the pathwise derivative is exactly TT for every noise draw. Actual gradient variance depends on the transition, objective, and estimator. The RSSM's deterministic path offers a route for recurrent information without requiring a fresh sample on every edge.

The learned state is not the environment's state

The hidden states hth_t and ztz_t are model-internal quantities. Nothing forces them to correspond one-to-one to the environment's true state variables, and in general they will not. What matters is the notion of sufficiency you met in Sufficient State and State Abstraction: the learned state must contain enough information to predict the observations, rewards, and dynamics the agent cares about. In the worked example below, the true state is (position, velocity), but the learned latent may encode position in some nonlinear combination with velocity, and that is fine as long as predictions are good.