Foundations to Frontier
Tests
E. Deep Learning › E17 State-Space and Recurrent-Revival Models

Linear state-space layers

A linear state-space model (SSM) maps an input sequence to an output through a hidden state that evolves linearly: x' = Ax + Bu, y = Cx. The idea comes from control theory and signal processing. Discretised with a step Δ, it becomes a linear recurrence x_k = Āx_(k−1) + B̄u_k. Unrolled, that recurrence is a convolution with the kernel K_k = CĀ^kB̄. The same layer can therefore run as a fast parallel convolution during training and as a constant-memory recurrence during generation. This is the foundation of S4, S5, Mamba and their relatives. This page covers continuous and discrete SSMs, the recurrence–convolution duality, discretisation methods and memory. In the exercises you implement discretisation and check the duality, then simulate a 16-mode SSM's step response at four step sizes. Forward Euler blew up once Δ > 2/16 (|Ā| up to 15). The bilinear method stayed stable but drifted (error 3.3 at Δ = 1). Zero-order hold was exact at every step size.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

A memory that evolves smoothly

A state-space layer keeps a small memory (the state) that changes over time according to simple linear rules: part of the old memory fades, and part of each new input is added. Engineers have used such models for decades in control and filtering. In deep learning they are attractive because the same layer can be computed two ways: step by step like an RNN, or all at once like a convolution. To run on a computer, the continuous rules must be turned into discrete steps, and how you do that matters. The demo discretises one mode with three methods.

State-space lab
Mode λ = −4, discrete multiplier -0.200 (stable). Red: simulation; green: exact. Euler needs Δ < 2/|λ| = 0.5; zero-order hold is exact for piecewise-constant inputs.
Why engineers care

State-space models are the native language of control and estimation (Kalman filters, autopilots). Deep SSM layers bring that structure to sequence learning over long sensor and telemetry streams.

📝 Quick check (Level 0)
0/3 answered
  1. 1. A state-space layer's state evolves…
  2. 2. It can be computed as…
  3. 3. Turning continuous rules into steps is called…

Level 1: Beginner

★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.

By hand

  • Continuous model: x’(t) = Ax(t) + Bu(t), y(t) = Cx(t).
  • Discretisation with step Δ, mode by mode for a diagonal A = diag(λ):
    • forward Euler: ā = 1 + Δλ, b̄ = Δb;
    • bilinear (Tustin): ā = (1 + Δλ/2)/(1 − Δλ/2);
    • zero-order hold (ZOH): ā = e^(Δλ), b̄ = (e^(Δλ) − 1)b/λ, exact when the input is constant over each step.
  • Stability:
    • Euler needs |1 + Δλ| < 1, so Δ < 2/|λ| (0.125 for λ = −16);
    • bilinear and ZOH are stable for any Δ > 0 when λ < 0;
    • bilinear maps fast modes near −1, giving −0.78 for λ = −16, Δ = 1, so they oscillate.
  • Recurrence: x_k = Āx_(k−1) + B̄u_k, y_k = Cx_k. Convolution: y = K ∗ u with K_k = CĀ^kB̄.
  • Memory: a mode with ZOH multiplier e^(λΔ) decays below 1% after ln(0.01)/(λΔ) steps (47 for λ = −1, Δ = 0.1).
📝 Quick check (Level 1)
0/3 answered
  1. 1. Largest stable Euler step for λ = −16:
  2. 2. ZOH multiplier for λ = −1, Δ = 1:
  3. 3. The convolution kernel is…

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.

SSM layers in code

Exercise 1.

  • ZOH multipliers matched e^(Δλ), and Euler at Δ = 1 gave the expected values.
  • Convolving with the kernel reproduced the recurrence exactly.

Practice.

  • Deep SSM layers apply many independent SSMs (one per channel), with learnable A, B, C and Δ, then mix channels with a linear layer and nonlinearity.
  • Train with the convolutional form (computed by FFT in O(L log L)) and generate with the recurrent form (O(1) memory per step).
  • Parameterise A so it stays stable (negative real parts), for example λ = −exp(θ).
dA = torch.exp(dt * A)                                   # ZOH, diagonal A (negative real part)
dB = (dA - 1) / A * B
K = (C * dB * dA ** torch.arange(L)[:, None]).sum(-1)    # convolution kernel, length L
y = torch.fft.irfft(torch.fft.rfft(u, 2 * L) * torch.fft.rfft(K, 2 * L))[..., :L]   # training: FFT conv
🐍 Exercise 1: discretisation and duality
Implement discretisation methods, the SSM convolution kernel and the recurrent form.
📝 Quick check (Level 2)
0/3 answered
  1. 1. During training SSMs use…
  2. 2. During generation SSMs use…
  3. 3. Stable parameterisation of λ:

Level 3: Advanced

★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.

Theory

Duality. Because the system is linear and time-invariant, its output is the input convolved with its impulse response. Unrolling the recurrence gives exactly the kernel K_k = CĀ^kB̄. Training can exploit parallel convolution, and inference can exploit the recurrence: the best of CNNs and RNNs.

Discretisation as numerical integration.

  • Euler is a first-order explicit scheme with a bounded stability region, so stiff systems (fast modes) force small steps.
  • Bilinear is A-stable (any step) and second-order accurate, but distorts fast dynamics.
  • ZOH integrates exactly under a piecewise-constant input, which is why it is the default in S4 and Mamba.

Memory and timescales.

  • Each mode remembers for about 1/|λ| units of time. A set of modes with spread-out rates covers many timescales, and learnable Δ rescales them.
  • Long-range memory needs some modes very close to the stability boundary (λΔ → 0), which plain RNNs struggle to maintain.
📝 Quick check (Level 3)
0/3 answered
  1. 1. The SSM output is the input convolved with…
  2. 2. Bilinear discretisation is…
  3. 3. Long memory needs modes with λΔ…

Level 4: Expert

★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.

How much does the discretisation method matter?

History.

  • R. E. Kalman (1960) introduced state-space methods for filtering and control.
  • A. Gu et al., “Combining recurrent, convolutional, and continuous-time models with linear state-space layers” (LSSL, NeurIPS 2021).
  • Followed by S4 (2022) and its descendants.

Exercise 2.

  • Model: a 16-mode diagonal SSM (decay rates 1 to 16) driven by a step input.
  • Simulation: forward Euler, bilinear and zero-order hold at Δ = 0.01, 0.1, 0.5 and 1, over 10 time units.
  • Measurements: the relative error against the exact continuous solution, and the spectral radius max |ā|. The recurrence and convolution forms are also compared.
Δ Euler error (max abs ā) bilinear error (max abs ā) ZOH error (max abs ā)
0.01 0.020 (0.99) 0.0005 (0.99) 0.0000 (0.99)
0.1 0.459 (0.90) 0.054 (0.905) 0.0000 (0.905)
0.5 diverged (7.0) 1.21 (0.60) 0.0000 (0.607)
1.0 diverged (15.0) 3.29 (0.78) 0.0000 (0.368)

Recurrent and convolutional outputs agreed exactly.

  • Euler blows up beyond Δ = 2/16: the fastest mode’s multiplier 1 − 16Δ leaves the unit circle (7 at Δ = 0.5), and the simulation diverges. Even at Δ = 0.1 its error is 46%.
  • Bilinear never blows up but drifts: fast modes are mapped to negative multipliers (−0.78 at Δ = 1) that oscillate, giving large errors at coarse steps.
  • ZOH is exact for this input at every step size, because the step input is constant within each step. This is why S4 and Mamba use ZOH.
🐍 Exercise 2 (research): how much does the discretisation method matter?
Simulate a 16-mode SSM's step response with Euler, bilinear and zero-order hold at several step sizes; check the recurrence–convolution duality.

State-space layers in AI, robotics and aerospace

  • Long telemetry streams: SSM layers process very long sensor sequences in linear time.
  • Control: a natural bridge between learned sequence models and classical state-space control and estimation.
  • Design lesson: discretisation is numerical integration. Choose a method whose stability and accuracy suit the fastest dynamics you model.

References

  1. A. Gu et al. (2021). “Combining recurrent, convolutional, and continuous-time models with linear state-space layers.” NeurIPS.
  2. R. E. Kalman (1960). “A new approach to linear filtering and prediction problems.” Journal of Basic Engineering 82.
  3. E. Hairer and G. Wanner (1996). Solving Ordinary Differential Equations II: Stiff and Differential-Algebraic Problems. Springer.