# Introduction to State Space Models (SSM)

Community Article Published June 11, 2024
Une version en français est disponible sur mon blog.

Changelog
2023-12-14: article release.
2024-04-08: typos corrections (my English isn't perfect 😅).
2024-06-11: added links to the second article of my SSM blog posts serie.

## Foreword

I'd like to extend my warmest thanks to Boris ALBAR, Pierre BEDU and Nicolas PREVOT for agreeing to set up a working group on the subject of SSMs and thus accompanying me in my discovery of this type of model. A special thanks to the former for taking the time to proofread this blog post.

## Introduction

The States Spaces Models are traditionally used in control theory to model a dynamic system via state variables.
In the context of deep learning, when we speak of SSMs, we are referring to a subset of existing representations, namely linear invariant (or stationary) systems.
These models showed impressive performance as early as October 2021 with the paper Efficiently Modeling Long Sequences with Structured State Spaces by Albert GU et al., to the point of positioning themselves as an alternative to transformers.
In this article, we will define the basics of a deep learning SSM based on S4. Like the paper Attention is all you need by Ashish VASWANI et al. (2017) for transformers, the S4 is the foundation of a new type of neural network architecture that needs to be known, but it is not a model that is used as such in practice (other SSMs with better performance or easier to implement now being available). Released a week earlier than S4, LSSL, by the same authors, is also an important source of information on the subject. We'll take a look at the various developments arising from S4 in a future blog post (now available here). Before that, let's delve into the basics of SSM.

## Definition of an SSM in deep learning

Let's use the image below to define an SSM:

Figure 1: View of a continuous, time-invariant SSM (Source: https://en.wikipedia.org/wiki/State-space_representation)

It can be seen that an SSM is based on three variables that depend on time $tt$ :

• $x\left(t\right)\in {\mathbb{C}}^{n}x\left(t\right) \in \mathbb \left\{C\right\}^\left\{n\right\}$ represents the $nn$ state variables,
• $u\left(t\right)\in {\mathbb{C}}^{m}u\left(t\right) \in \mathbb \left\{C\right\}^\left\{m\right\}$ represents the $mm$ state inputs,
• $y\left(t\right)\in {\mathbb{C}}^{p}y\left(t\right) \in \mathbb \left\{C\right\}^\left\{p\right\}$ represents the $pp$ outputs,

We can also see that it's made up of four learnable matrices: $\mathbf{A},\mathbf{B},\mathbf{C}\mathbf A, \mathbf B, \mathbf C$ and $\mathbf{D}\mathbf D$.

• $\mathbf{A}\in {\mathbb{C}}^{m×n}\mathbf A \in \mathbb \left\{C\right\}^\left\{m \times n\right\}$ is the state matrix (controlling the latent state $xx$),
• $\mathbf{B}\in {\mathbb{C}}^{n×m}\mathbf B \in \mathbb \left\{C\right\}^\left\{n \times m\right\}$ is the control matrix,
• $\mathbf{C}\in {\mathbb{C}}^{p×n}\mathbf C \in \mathbb \left\{C\right\}^\left\{p \times n\right\}$ is the output matrix,
• $\mathbf{D}\in {\mathbb{C}}^{p×m}\mathbf D \in \mathbb \left\{C\right\}^\left\{p \times m\right\}$ is the command matrix,

The above picture can be reduced to the following system of equations:

\begin{array}{cc}{x}^{\mathrm{\prime }}\left(t\right)& =\mathbf{A}x\left(t\right)+\mathbf{B}u\left(t\right)\\ y\left(t\right)& =\mathbf{C}x\left(t\right)+\mathbf{D}u\left(t\right)\end{array}\begin\left\{aligned\right\} x\text{'}\left(t\right) &= \mathbf\left\{A\right\}x\left(t\right) + \mathbf\left\{B\right\}u\left(t\right) \\ y\left(t\right) &= \mathbf\left\{C\right\}x\left(t\right) + \mathbf\left\{D\right\}u\left(t\right) \end\left\{aligned\right\}

Note: here we use the notation ${x}^{\mathrm{\prime }}x\text{'}$ to designate the derivative of $xx$. It's not out of the question to encounter the notation $\stackrel{˙}{x}ẋ$ in the literature instead.

Similarly, since it is implicit that the variables depend on time, the preceding equation is generally written in the following form for the sake of simplicity:

\begin{array}{cc}{x}^{\mathrm{\prime }}& =\mathbf{A}x+\mathbf{B}u\\ y& =\mathbf{C}x+\mathbf{D}u\end{array}\begin\left\{aligned\right\} x\text{'} &= \mathbf\left\{A\right\}x + \mathbf\left\{B\right\}u \\ y &= \mathbf\left\{C\right\}x + \mathbf\left\{D\right\}u \end\left\{aligned\right\}

This system can be made even lighter, because in deep learning SSMs, $\mathbf{D}u=0\mathbf\left\{D\right\}u = 0$ is seen as an easily computable skip connection.

\begin{array}{cc}{x}^{\mathrm{\prime }}& =\mathbf{A}x+\mathbf{B}u\\ y& =\mathbf{C}x\end{array}\begin\left\{aligned\right\} x\text{'} &= \mathbf\left\{A\right\}x + \mathbf\left\{B\right\}u \\ y &= \mathbf\left\{C\right\}x \end\left\{aligned\right\}

This system is continuous. It must therefore first be discretized before it can be supplied to a computer.

## Discretization

Discretization is one of, if not the most important point in SSM. All the efficiency of this architecture lies in this step, since it enables us to pass from the continuous view of the SSM to its two other views: the recursive view and the convolutive view.

Figure 2: Image from blog post « Structured State Spaces: Combining Continuous-Time, Recurrent, and Convolutional Models » by Albert GU et al. (2022)

We'll see in later article that there are several possible discretizations. This is one of the main differences between the various existing SSM architectures.
For this first article, let's apply the "original" discretization proposed in S4 to illustrate the two additional views of an SSM.

## Recursive view of an SSM

To discretize the continuous case, let's use the trapezoid method where the principle is to assimilate the region under the representative curve of a function $ff$ defined on a segment $\left[{t}_{n},{t}_{n+1}\right]\left[t_n , t_\left\{n+1\right\}\right]$ to a trapezoid and calculate its area $TT$ : $T=\left({t}_{n+1}-{t}_{n}\right)\frac{f\left({t}_{n}\right)+f\left({t}_{n+1}\right)}{2}T=\left(t_\left\{n+1\right\} - t_n\right)\left\{\frac \left\{f\left(t_n\right)+f\left(t_\left\{n+1\right\}\right)\right\}\left\{2\right\}\right\}$.

We then have: ${x}_{n+1}-{x}_{n}=\frac{1}{2}\mathrm{\Delta }\left(f\left({t}_{n}\right)+f\left({t}_{n+1}\right)\right)x_\left\{n+1\right\} - x_n = \frac\left\{1\right\}\left\{2\right\}\Delta\left(f\left(t_n\right) + f\left(t_\left\{n+1\right\}\right)\right)$ with $\mathrm{\Delta }={t}_{n+1}-{t}_{n}\Delta = t_\left\{n+1\right\} - t_n$.
If ${x}_{n}^{\mathrm{\prime }}=\mathbf{A}{x}_{n}+\mathbf{B}{u}_{n}x\text{'}_n = \mathbf\left\{A\right\}x_n + \mathbf\left\{B\right\} u_n$ (first line of the SSM equation), corresponds to $ff$, so:

\begin{array}{cc}{x}_{n+1}& ={x}_{n}+\frac{\mathrm{\Delta }}{2}\left(\mathbf{A}{x}_{n}+\mathbf{B}{u}_{n}+\mathbf{A}{x}_{n+1}+\mathbf{B}{u}_{n+1}\right)\\ ⟺{x}_{n+1}-\frac{\mathrm{\Delta }}{2}\mathbf{A}{x}_{n+1}& ={x}_{n}+\frac{\mathrm{\Delta }}{2}\mathbf{A}{x}_{n}+\frac{\mathrm{\Delta }}{2}\mathbf{B}\left({u}_{n+1}+{u}_{n}\right)\\ \left(\ast \right)⟺\left(\mathbf{I}-\frac{\mathrm{\Delta }}{2}\mathbf{A}\right){x}_{n+1}& =\left(\mathbf{I}+\frac{\mathrm{\Delta }}{2}\mathbf{A}\right){x}_{n}+\mathrm{\Delta }\mathbf{B}{u}_{n+1}\\ ⟺{x}_{n+1}& =\left(\mathbf{I}-\frac{\mathrm{\Delta }}{2}\mathbf{A}{\right)}^{-1}\left(\mathbf{I}+\frac{\mathrm{\Delta }}{2}\mathbf{A}\right){x}_{n}+\left(\mathbf{I}-\frac{\mathrm{\Delta }}{2}\mathbf{A}{\right)}^{-1}\mathrm{\Delta }\mathbf{B}{u}_{n+1}\end{array}\begin\left\{aligned\right\} x_\left\{n+1\right\} & = x_n + \frac\left\{\Delta\right\}\left\{2\right\} \left(\mathbf\left\{A\right\}x_n + \mathbf\left\{B\right\} u_n + \mathbf\left\{A\right\}x_\left\{n+1\right\} + \mathbf\left\{B\right\} u_\left\{n+1\right\}\right) \\ \Longleftrightarrow x_\left\{n+1\right\} - \frac\left\{\Delta\right\}\left\{2\right\}\mathbf\left\{A\right\}x_\left\{n+1\right\} & = x_n + \frac\left\{\Delta\right\}\left\{2\right\}\mathbf\left\{A\right\}x_\left\{n\right\} + \frac\left\{\Delta\right\}\left\{2\right\}\mathbf\left\{B\right\}\left(u_\left\{n+1\right\} + u_n\right) \\ \left(*\right) \Longleftrightarrow \left(\mathbf\left\{I\right\} - \frac\left\{\Delta\right\}\left\{2\right\} \mathbf\left\{A\right\}\right) x_\left\{n+1\right\} & = \left(\mathbf\left\{I\right\} + \frac\left\{\Delta\right\}\left\{2\right\} \mathbf\left\{A\right\}\right) x_\left\{n\right\} + \Delta \mathbf\left\{B\right\} u_\left\{n+1\right\}\\ \Longleftrightarrow x_\left\{n+1\right\} & = \left(\mathbf\left\{I\right\} - \frac\left\{\Delta\right\}\left\{2\right\} \mathbf\left\{A\right\}\right)^\left\{-1\right\} \left(\mathbf\left\{I\right\} + \frac\left\{\Delta\right\}\left\{2\right\} \mathbf\left\{A\right\}\right) x_n + \left(\mathbf\left\{I\right\} - \frac\left\{\Delta\right\}\left\{2\right\} \mathbf\left\{A\right\}\right)^\left\{-1\right\} \Delta \mathbf\left\{B\right\} u_\left\{n+1\right\} \end\left\{aligned\right\}

(*) ${u}_{n+1}{u}_{n}u_\left\{n+1\right\} \overset\left\{\Delta\right\}\left\{\simeq\right\} u_n$ (the control vector is assumed to be constant over a small $\mathrm{\Delta }\Delta$).

We've just obtained our discretized SSM!
To make this completely explicit, let's pose :

\begin{array}{cc}\stackrel{ˉ}{\mathbf{A}}& =\left(\mathbf{I}-\frac{\mathrm{\Delta }}{2}\mathbf{A}{\right)}^{-1}\left(\mathbf{I}+\frac{\mathrm{\Delta }}{2}\mathbf{A}\right)\\ \stackrel{ˉ}{\mathbf{B}}& =\left(\mathbf{I}-\frac{\mathrm{\Delta }}{2}\mathbf{A}{\right)}^{-1}\mathrm{\Delta }\mathbf{B}\\ \stackrel{ˉ}{\mathbf{C}}& =\mathbf{C}\end{array}\begin\left\{aligned\right\} \mathbf\left\{\bar\left\{A\right\}\right\} &= \left(\mathbf \left\{I\right\} - \frac\left\{\Delta\right\}\left\{2\right\} \mathbf\left\{A\right\}\right)^\left\{-1\right\}\left(\mathbf \left\{I\right\} + \frac\left\{\Delta\right\}\left\{2\right\} \mathbf\left\{A\right\}\right) \\ \mathbf \left\{\bar\left\{B\right\}\right\} &= \left(\mathbf\left\{I\right\} - \frac\left\{\Delta\right\}\left\{2\right\} \mathbf \left\{A\right\}\right)^\left\{-1\right\} \Delta \mathbf\left\{B\right\} \\ \mathbf \left\{\bar\left\{C\right\}\right\} &= \mathbf\left\{C\right\}\\ \end\left\{aligned\right\}

We then have

\begin{array}{cc}{x}_{k}& =\stackrel{ˉ}{\mathbf{A}}{x}_{k-1}+\stackrel{ˉ}{\mathbf{B}}{u}_{k}\\ {y}_{k}& =\stackrel{ˉ}{\mathbf{C}}{x}_{k}\end{array}\begin\left\{aligned\right\} x_k &= \mathbf\left\{\bar\left\{A\right\}\right\}x_\left\{k-1\right\} + \mathbf\left\{\bar\left\{B\right\}\right\}u_k \\ y_k &= \mathbf\left\{\bar\left\{C\right\}\right\}x_k \end\left\{aligned\right\}

The notation of matrices with a bar was introduced in S4 to designate matrices in the discrete case and has since become a convention in the field of SSM applied to deep learning.

## Convolutive view of an SSM

This recurrence can be written as a convolution. To do this, simply iterate the equations of the system

\begin{array}{cc}{x}_{k}& =\stackrel{ˉ}{\mathbf{A}}{x}_{k-1}+\stackrel{ˉ}{\mathbf{B}}{u}_{k}\\ {y}_{k}& =\stackrel{ˉ}{\mathbf{C}}{x}_{k}\end{array}\begin\left\{aligned\right\} x_k &= \mathbf\left\{\bar\left\{A\right\}\right\}x_\left\{k-1\right\} + \mathbf\left\{\bar\left\{B\right\}\right\}u_k \\ y_k &= \mathbf\left\{\bar\left\{C\right\}\right\}x_k \end\left\{aligned\right\}

Step 0: ${x}_{0}=\stackrel{ˉ}{\mathbf{B}}{u}_{0}x_0 = \mathbf\left\{\bar\left\{B\right\}\right\} u_0$
Step 1: ${x}_{1}=\stackrel{ˉ}{\mathbf{A}}{x}_{0}+\stackrel{ˉ}{\mathbf{B}}{u}_{1}=\stackrel{ˉ}{\mathbf{A}}\stackrel{ˉ}{\mathbf{B}}{u}_{0}+\stackrel{ˉ}{\mathbf{B}}{u}_{1}x_1 = \mathbf\left\{\bar\left\{A\right\}\right\}x_\left\{0\right\} + \mathbf\left\{\bar\left\{B\right\}\right\}u_1 = \mathbf\left\{\bar\left\{A\right\}\right\} \mathbf\left\{\bar\left\{B\right\}\right\} u_0 + \mathbf\left\{\bar\left\{B\right\}\right\}u_1$
Step 2: ${x}_{2}=\stackrel{ˉ}{\mathbf{A}}{x}_{1}+\stackrel{ˉ}{\mathbf{B}}{u}_{2}=\stackrel{ˉ}{\mathbf{A}}\left(\stackrel{ˉ}{\mathbf{A}}\stackrel{ˉ}{\mathbf{B}}{u}_{0}+\stackrel{ˉ}{\mathbf{B}}{u}_{1}\right)+\stackrel{ˉ}{\mathbf{B}}{u}_{2}={\stackrel{ˉ}{\mathbf{A}}}^{2}\stackrel{ˉ}{\mathbf{B}}{u}_{0}+\stackrel{ˉ}{\mathbf{A}}\stackrel{ˉ}{\mathbf{B}}{u}_{1}+\stackrel{ˉ}{\mathbf{B}}{u}_{2}x_2 = \mathbf\left\{\bar\left\{A\right\}\right\}x_\left\{1\right\} + \mathbf\left\{\bar\left\{B\right\}\right\}u_2 = \mathbf\left\{\bar\left\{A\right\}\right\} \left(\mathbf\left\{\bar\left\{A\right\}\right\} \mathbf\left\{\bar\left\{B\right\}\right\} u_0 + \mathbf\left\{\bar\left\{B\right\}\right\}u_1\right) + \mathbf\left\{\bar\left\{B\right\}\right\}u_2 = \mathbf\left\{\bar\left\{A\right\}\right\}^\left\{2\right\} \mathbf\left\{\bar\left\{B\right\}\right\} u_0 + \mathbf\left\{\bar\left\{A\right\}\right\} \mathbf\left\{\bar\left\{B\right\}\right\} u_1 + \mathbf\left\{\bar\left\{B\right\}\right\}u_2$
We have ${x}_{k}x_k$ which can be written as a function $ff$ parametrized by $\left({u}_{0},{u}_{1},\mathrm{.}\mathrm{.}\mathrm{.}{u}_{k}\right)\left(u_0, u_1, ... u_k\right)$.

Let's move on to the second line of the system, where we can now inject the ${x}_{k}x_k$ values calculated just now:
Step 0: ${y}_{0}=\stackrel{ˉ}{\mathbf{C}}{x}_{0}=\stackrel{ˉ}{\mathbf{C}}\stackrel{ˉ}{\mathbf{B}}{u}_{0}y_0 = \mathbf\left\{\bar\left\{C\right\}\right\} x_0 = \mathbf\left\{\bar\left\{C\right\}\right\} \mathbf\left\{\bar\left\{B\right\}\right\} u_0$
Step 1: ${y}_{1}=\stackrel{ˉ}{\mathbf{C}}{x}_{1}=\stackrel{ˉ}{\mathbf{C}}\left(\stackrel{ˉ}{\mathbf{A}}\stackrel{ˉ}{\mathbf{B}}{u}_{0}+\stackrel{ˉ}{\mathbf{B}}{u}_{1}\right)=\stackrel{ˉ}{\mathbf{C}}\stackrel{ˉ}{\mathbf{A}}\stackrel{ˉ}{\mathbf{B}}{u}_{0}+\stackrel{ˉ}{\mathbf{C}}\stackrel{ˉ}{\mathbf{B}}{u}_{1}y_1 = \mathbf\left\{\bar\left\{C\right\}\right\} x_1 = \mathbf\left\{\bar\left\{C\right\}\right\} \left( \mathbf\left\{\bar\left\{A\right\}\right\} \mathbf\left\{\bar\left\{B\right\}\right\} u_0 + \mathbf\left\{\bar\left\{B\right\}\right\}u_1\right) = \mathbf\left\{\bar\left\{C\right\}\right\} \mathbf\left\{\bar\left\{A\right\}\right\} \mathbf\left\{\bar\left\{B\right\}\right\} u_0 + \mathbf\left\{\bar\left\{C\right\}\right\} \mathbf\left\{\bar\left\{B\right\}\right\}u_1$
Step 2: ${y}_{2}=\stackrel{ˉ}{\mathbf{C}}{x}_{2}=\stackrel{ˉ}{\mathbf{C}}\left({\stackrel{ˉ}{\mathbf{A}}}^{2}\stackrel{ˉ}{\mathbf{B}}{u}_{0}+\stackrel{ˉ}{\mathbf{A}}\stackrel{ˉ}{\mathbf{B}}{u}_{1}+\stackrel{ˉ}{\mathbf{B}}{u}_{2}\right)=\stackrel{ˉ}{\mathbf{C}}{\stackrel{ˉ}{\mathbf{A}}}^{2}\stackrel{ˉ}{\mathbf{B}}{u}_{0}+\stackrel{ˉ}{\mathbf{C}}\stackrel{ˉ}{\mathbf{A}}\stackrel{ˉ}{\mathbf{B}}{u}_{1}+\stackrel{ˉ}{\mathbf{C}}\stackrel{ˉ}{\mathbf{B}}{u}_{2}y_2 = \mathbf\left\{\bar\left\{C\right\}\right\} x_2 = \mathbf\left\{\bar\left\{C\right\}\right\}\left(\mathbf\left\{\bar\left\{A\right\}\right\}^\left\{2\right\} \mathbf\left\{\bar\left\{B\right\}\right\} u_0 + \mathbf\left\{\bar\left\{A\right\}\right\} \mathbf\left\{\bar\left\{B\right\}\right\} u_1 + \mathbf\left\{\bar\left\{B\right\}\right\}u_2 \right) = \mathbf\left\{\bar\left\{C\right\}\right\}\mathbf\left\{\bar\left\{A\right\}\right\}^\left\{2\right\} \mathbf\left\{\bar\left\{B\right\}\right\} u_0 + \mathbf\left\{\bar\left\{C\right\}\right\}\mathbf\left\{\bar\left\{A\right\}\right\} \mathbf\left\{\bar\left\{B\right\}\right\} u_1 + \mathbf\left\{\bar\left\{C\right\}\right\}\mathbf\left\{\bar\left\{B\right\}\right\}u_2$ We can observe the convolution kernel ${\stackrel{ˉ}{\mathbf{K}}}_{k}=\left(\stackrel{ˉ}{\mathbf{C}}\stackrel{ˉ}{\mathbf{B}},\stackrel{ˉ}{\mathbf{C}}\stackrel{ˉ}{\mathbf{A}}\stackrel{ˉ}{\mathbf{B}},\mathrm{.}\mathrm{.}\mathrm{.},\stackrel{ˉ}{\mathbf{C}}{\stackrel{ˉ}{\mathbf{A}}}^{k}\stackrel{ˉ}{\mathbf{B}}\right)\mathbf\left\{\bar\left\{K\right\}\right\} _k = \left(\mathbf\left\{\bar\left\{C\right\}\right\} \mathbf\left\{\bar\left\{B\right\}\right\}, \mathbf\left\{\bar\left\{C\right\}\right\} \mathbf\left\{\bar\left\{A\right\}\right\} \mathbf\left\{\bar\left\{B\right\}\right\}, ..., \mathbf\left\{\bar\left\{C\right\}\right\} \mathbf\left\{\bar\left\{A\right\}\right\}^\left\{k\right\} \mathbf\left\{\bar\left\{B\right\}\right\}\right)$ applicable to ${u}_{k}u_k$, hence $K\ast uK \ast u$.

As with matrices, we apply a bar to the $\stackrel{ˉ}{\mathbf{K}}\mathbf\left\{\bar\left\{K\right\}\right\}$ to specify that it is the convolution kernel obtained after discretization. It is generally referred to as the SSM convolution kernel in the literature, and its size is equivalent to the entire input sequence.
This convolution kernel is calculated by Fast Fourier Transform (FFT) and will be explained in future articles (do you like the Flash Attention of transformers? You'll love Flash FFT Convolution, which we'll look at in the third blog post).

## Advantages and limitations of each of the three views

Figure 3: Image from the paper Combining Recurrent, Convolutional, and Continuous-time Models with Linear State-Space Layers by Albert GU et al, released a week before S4

The different views of SSM each have their advantages and disadvantages - let's take a closer look.

✓ 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.

So, depending on the stage of the process (training or inference) or the type of data at our disposal, it is possible to switch from one view to another in order to fall back on a favorable framework for getting the most out of the model.
We prefer the convolutional training view for fast training via parallelization, the recursive view for efficient inference, and the continuous view for handling continuous data.

## Learning matrices

In the convolution kernel developed above, $\stackrel{ˉ}{\mathbf{C}}\mathbf\left\{\bar\left\{C\right\}\right\}$ and $\stackrel{ˉ}{\mathbf{B}}\mathbf\left\{\bar\left\{B\right\}\right\}$, are learnable scalars.
Concerning $\stackrel{ˉ}{\mathbf{A}}\mathbf\left\{\bar\left\{A\right\}\right\}$, we've seen that in our convolution kernel, it's expressed as a power of $kk$ at time $kk$. This can be very time-consuming to calculate, so we're looking for a fixed $\stackrel{ˉ}{\mathbf{A}}\mathbf\left\{\bar\left\{A\right\}\right\}$. For this, the best option is to have it diagonal:

$\mathbf{A}=\left[\begin{array}{cccc}{\lambda }_{1}& 0& \cdots & 0\\ 0& {\lambda }_{2}& \cdots & 0\\ & & \ddots & \\ 0& 0& \cdots & {\lambda }_{n}\end{array}\right]⇒{\mathbf{A}}^{\mathbf{k}}=\left[\begin{array}{cccc}{\lambda }_{1}^{k}& 0& \cdots & 0\\ 0& {\lambda }_{2}^{k}& \cdots & 0\\ & & \ddots & \\ 0& 0& \cdots & {\lambda }_{n}^{k}\end{array}\right]\mathbf\left\{A\right\} = \begin\left\{bmatrix\right\} \lambda_\left\{1\right\} & 0 & \cdots & 0 \\ 0 & \lambda_\left\{2\right\} & \cdots & 0 \\ \vdots & \vdots & \ddots & \vdots \\ 0 & 0 & \cdots & \lambda_\left\{n\right\} \end\left\{bmatrix\right\} \Rightarrow \mathbf\left\{A^k\right\} = \begin\left\{bmatrix\right\} \lambda_\left\{1\right\}^k & 0 & \cdots & 0 \\ 0 & \lambda_\left\{2\right\}^k & \cdots & 0 \\ \vdots & \vdots & \ddots & \vdots \\ 0 & 0 & \cdots & \lambda_\left\{n\right\}^k \end\left\{bmatrix\right\}$

By the spectral theorem of linear algebra, this is exactly the class of normal matrices.
In addition to the choice of discretization mentioned above, the way in which $\stackrel{ˉ}{\mathbf{A}}\mathbf\left\{\bar\left\{A\right\}\right\}$ is defined and initiated is one of the points that differentiates the various SSM architectures developed in the literature, which we'll develop in the next blog post. Indeed, empirically, it appears that an SSM initialized with a random $\mathbf{A}\mathbf\left\{A\right\}$ matrix leads to poor results, whereas an initialization based on the HiPPO matrix (for High-Order Polynomial Projection Operator) gives very good results (from 60% to 98% on the MNIST sequential benchmark).

The HiPPO matrix was introduced by the S4 authors in a previous paper (2020). It is included in the LSSL paper (2021), also by the S4 authors, as well as in the S4 appendix. Its formula is as follows:

$\mathbf{A}=\left[\begin{array}{c}1\\ -1& 2\\ 1& -3& 3\\ -1& 3& -5& 4\\ 1& -3& 5& -7& 5\\ -1& 3& -5& 7& -9& 6\\ 1& -3& 5& -7& 9& -11& 7\\ -1& 3& -5& 7& -9& 11& -13& 8\\ & & & & & & & & \ddots \end{array}\right]\phantom{\rule{0ex}{0ex}}⇒{\mathbf{A}}_{nk}=\left\{\begin{array}{cc}\left(-1{\right)}^{n-k}\left(2k+1\right)& n>k\\ k+1& n=k\\ 0& n k \\ k+1 & n=k \\ 0 & n

This matrix is not normal, but it can be decomposed as a normal matrix plus a matrix of lower rank (summarized in the paper as NPLR for Normal Plus Low Rank). The authors prove in their paper that this type of matrix can be computed efficiently via three techniques (see Algorithm 1 in the paper): truncated generating series, Cauchy kernels and Woodbury identity.

Details of the demonstration showing that an NPLR matrix can be computed efficiently as a diagonal matrix can be found in the appendix (see part B and C) of the paper.
The authors of S4 subsequently made modifications to the HiPPO matrix (on how to initiate it) in their paper How to Train Your HiPPO (2022). The model resulting from this paper is generally referred to as "S4 V2" or "S4 updated" in the literature as opposed to the "original S4" or "S4 V1".
In the next article, we'll see that other authors (notably Ankit GUPTA) have proposed using a diagonal matrix instead of an NPRL matrix, an approach that is now preferred as it is simpler to implement.

## Experimental results

Let's end this blog post by analyzing a selection of the S4's results on various tasks and benchmarks to get a feel for the potential of SSMs.

Figure 4: Image from the paper On the Parameterization and Initialization of Diagonal State Space Models by Albert GU et al. (2022), also known as S4D, published after S4 but which reproduces in a more structured form the results of S4 for this benchmark (the results of S4D having been removed from the image so as not to spoil the next article ;)

Several things can be observed in this table.
Firstly, for a more or less equivalent number of parameters, the S4 performs much better (at least +13%) than the other models, here of the ConvNet type.
Secondly, to achieve equivalent performance, a ConvNet requires 85 times more parameters.
Thirdly, a ConvNet trained on 16K Hz gives very poor results when then applied to 8K Hz data. In contrast, the S4 retains 95% of its performance on this resampling. This can be explained by the continuous view of the SSM, where it was sufficient to halve the $\mathrm{\Delta }\Delta$ value at the time of the test phase.

Let's continue with a time series task (introduced in a revision of S4).

Figure 5: Image from the S4 appendix

The authors of the paper take up the methodology of the Informer model by ZHOU et al. (2020) and show that their model outperforms this transformer on 40 of the 50 configurations. The results in the table are shown in a univariate framework, but the same is observable for a multivariate framework (table 14 in the appendix).

Let's continue with a vision task and the benchmark sCIFAR-10 by KRIZHESKY (2009).

Figure 6: Image from the S4 appendix

S4 establishes SoTA on sCIFAR-10 with just 100,000 parameters (the authors don't specify the number for the other methods).

Let's conclude with a textual task and the benchmark Long Range Arena (LRA) by TAY et al. (2020).

Figure 7: Image from the S4 appendix

The LRA consisted of 6 tasks, including Path-X with a length of 16K tokens, for which the S4 was the first model to succeed, demonstrating its performance on very long-sequence tasks.
It would be more than 2 years before AMOS et al. showed in their paper Never Train from Scratch: Fair Comparison of Long-Sequence Models Requires Data-Driven Priors (2023) that transformers (not hybridized with an SSM) could also solve this task. However, unlike SSMs, they are unable to pass the 65K token PathX-256.

Note, however, a negative point concerning the text for S4: it obtains a higher perplexity compared to that of a transformer (standard, with more optimized versions having an even lower perplexity) on WikiText-103 by MERITY et al. (2016).

Figure 8: Image from the S4 appendix

This is probably due to the non-continuous nature of text (it has not been sampled from an underlying physical process such as speech or time series). We'll see in the article devoted to developments in SSM in 2023 that this point has been the subject of a great deal of work, and that SSM has now succeeded in bridging this gap.

## Conclusion

SSMs are models with three views. A continuous view, and when discretized, a recurrent as well as a convolutive view.
The challenge with this type of architecture is to know when to favor one view over another, depending on the stage of the process (training or inference) and the type of data being processed.
This type of model is highly versatile, since it can be applied to text, vision, audio and time-series tasks (or even graphs).
One of its strengths is its ability to handle very long sequences, generally with a lower number of parameters than other models (ConvNet or transformers), while still being very fast.
As we'll see in later article, the main differences between the various existing SSM architectures lie in the way the basic SSM equation is discretized, or in the definition of the $\mathbf{A}\mathbf A$ matrix.

## To dig deeper

For S4, please consult the following resources: