Pages and contents
Pages
State Space Models
Adapted from https://huggingface.co/blog/lbourdois/get-on-the-ssm-train,
State Space Models (SSM)
State space models (SSMs) are a class of machine learning algorithms used to make predictions about dynamic systems by modeling how their internal state evolves over time through differential equations. Historically used in control systems engineering, SSMs are a remarkably flexible mathematical platform adaptable to most sequence modeling tasks.
In general, state space models are built from three essential vectors.
1. represents the state variables
2. represents the state inputs
3. represents the state outputs
They are also composed of four learnable matrices
1. is the state matrix. It determines how the state evolves over time and what it forgets.
2. is the control matrix. It determines how the new input influences the state.
3. is the output matrix. It determines how the state translates to the predicted output.
4. is the command matrix. It acts as a skip connection directly from input to output.
Which we can reduce to the following system of equations
x'(t) = Ax(t) + Bu(t) \\ y(t) = Cx(t) + Du(t)
In deep learning, because it is an βeasily computable skip connection.β
[image: G7icfkYoxIqHZcJGHM7UD.png]
Discretization
Discretization allows us to pass from the continuous mathematics to recurrent and convolutional representations.
[image: 289609011-12bbe1cf-3911-4bad-9a3b-3f427bc6bc82.png]
Trapezoid Method
The trapezoid method is one of many methods to discretize an SSM. The principle of the trapezoid method is to approximate the region under a curve defined on a segment with a trapezoid and calculate its area .
We then have: with . If (first line of the SSM equation), corresponds to , so:
x_{n+1} = x_n + \frac{\Delta}{2} (Ax_n + Bu_n + Ax_{n+1} + Bu_{n+1}) \\ x_{n+1} - \frac{\Delta}{2} Ax_{n+1} = x_n + \frac{\Delta}{2} Ax_n + \frac{\Delta}{2} B(u_{n+1} + u_n) \\ (I - \frac{\Delta}{2} A)x_{n+1} = (I + \frac{\Delta}{2} A)x_n + \Delta Bu_{n+1} \\ x_{n+1} = \left(I - \frac{\Delta}{2} A\right)^{-1}\left(I + \frac{\Delta}{2} A\right)x_n + \left(I - \frac{\Delta}{2} A\right)^{-1}\Delta Bu_{n+1}
This may be condensed into the following recursive formula
x_k= \bar{A}x_{k-1} + \bar{B}u_k \\ y_k = \bar{C}x_k
See the attached notes link for more in depth coverage of the convolutional view.
For the continuous view, the advantages and disadvantages are as follows:
β Automatically handles continuous data (audio signals, time series, for example). This represents a huge practical advantage when processing data with irregular or time-shifted sampling.
β Mathematically feasible analysis, e.g. by calculating exact trajectories or building memory systems (HiPPO).
β Extremely slow for both training and inference.
For the recursive view these are the well-known advantages and disadvantages of recursive neural networks, namely:
β Natural inductive bias for sequential data, and in principle unbounded context.
β Efficient inference (constant-time state updates).
β Slow learning (lack of parallelism).
β Gradient disappearance or explosion when training too-long sequences.
For the convolutional view, we're talking here about the well-known advantages and disadvantages of convolutional neural networks (we're here in the context of their one-dimensional version), namely:
β Local, interpretable features.
β Efficient (parallelizable) training.
β Slowness in online or autoregressive contexts (must recalculate entire input for each new data point).
β Fixed context size.
Examples
Mamba
Mamba SSM rivals the performance of transformers at sequence modeling, using an efficient GPU algorithm to model attention based token updates.
DreamerV3's RSSM
The DreamerV3 RSSM is a latent dynamics model used to learn a representation of the world from sequence data (inputs, actions, rewards, and continuation flags). It partitions its latent state into two parts to handle both memory and uncertainty: a deterministic state (usually a Recurrent Neural Network hidden state) and a stochastic state .
The model consists of several neural network components (parameterized by ):
β’ Sequence model: updates the deterministic memory using the previous state and action.
β’ Encoder: forms the "posterior" representation by compressing the current observation and the deterministic state into a stochastic representation.
β’ Dynamics predictor: forms the "prior" representation. It guesses what the stochastic state will be without seeing the current observation. This is critical for "imagining" future trajectories during reinforcement learning.
β’ Predictors (Reward, Continue, Decoder): These reconstruct the current environment signals (reward , episode continuation , and observation ) strictly from the joint latent state .
The entire system is optimized end-to-end using a combined loss function containing a prediction loss (how well it reconstructs outputs), a dynamics loss (forcing the prior to match the posterior), and a representation loss.
Mapping RSSM to Standard Linear SSM Equations
The standard discrete-time linear SSM equations you provided are:
1. State Equation:
2. Observation Equation:
DreamerV3's RSSM is essentially a deeply non-linear, probabilistic extension of this exact framework. Here is how the variables and concepts align:
1\. The Latent State
β’ Linear SSM: Uses a single, continuous vector .
β’ DreamerV3: Splits the state into . The state is represented jointly by a deterministic vector and a stochastic vector (which the text notes is sampled from a vector of softmax distributions).
2\. The Control Input
β’ Linear SSM: The control variable drives the system.
β’ DreamerV3: The action taken by the agent, , serves as the control input.
3\. The State Transition / Dynamics d
β’ Linear SSM: Transitions are handled by linear matrices and. It is entirely deterministic.
β’ DreamerV3: Replaces the linear matrices with non-linear neural networks (MLPs). The transition happens in two steps: a deterministic update and a stochastic transition (prior) .
β’ Why the difference? Environments are highly complex and unpredictable. The linear SSM struggles with multimodal uncertainty. Dreamer uses non-linear neural networks to capture complex dynamics and the stochastic sampling to prevent the model from failing when multiple future outcomes are possible.
4\. The Observation / Output Model
β’ Linear SSM: The output is projected linearly from the state using matrix .
β’ DreamerV3: The output consists of the observation , reward , and continuation . It replaces the linear matrix with deep neural networks. The decoder predicts (using CNNs for images), and auxiliary predictors handle and via MLPs.