State Space Models for Language › Discretization with a Zero-Order Hold

Michael BrenndoerferNovember 17, 20264 min read
Language AI HandbookAll chapters
Part 19 of 67Alternative Sequence and Generative Architectures
Chapter 133State Space Models for Language › Discretization with a Zero-Order Hold
Reading section 4 of 13 · Discretization with a Zero-Order Hold · 4 minSection 4 of 13 · 4 min

Section 4 of 13 · 4 min read

Reading settings

Definitions

Choose how many terms have tooltips.

Article links

Make inline references clickable

Notes & comments

A sequence gives one input uku_k per position. Choose a step size Δ>0\Delta>0 and hold u(t)=uku(t)=u_k over [kΔ,(k+1)Δ)[k\Delta,(k+1)\Delta). This is a zero-order hold (ZOH). Name the state at the start of the interval xk−1x_{k-1} and the state at its end xkx_k, so input u0u_0 updates initial state x−1x_{-1}. We read out by combining the endpoint state with the held input uku_k before the next input replaces it. Integrating the linear equation across the interval gives

x((k+1)Δ)=eΔAx(kΔ)+∫0Δe(Δ−τ)ABuk dτ.x((k+1)\Delta) = e^{\Delta A}x(k\Delta) + \int_0^\Delta e^{(\Delta-\tau)A}Bu_k\,d\tau .

The first term propagates the initial state. The integrand propagates the contribution made at each instant τ\tau for the remaining time Δ−τ\Delta-\tau. Reversing the integration variable and pulling the constant input outside the integral gives the recurrence below.

xk=Aˉxk−1+Bˉuk,Aˉ=eΔA,Bˉ=(∫0ΔeτA dτ)B.x_k = \bar A x_{k-1} + \bar B u_k,\qquad \bar A = e^{\Delta A},\qquad \bar B = \left(\int_0^\Delta e^{\tau A}\,d\tau\right)B.

With our endpoint convention, the output is yk=Cxk+Duky_k=Cx_k+Du_k. The step changes the transition and the write map. The readout CC and direct path DD already act on instantaneous values.

The Integral and Singular Matrices

For invertible AA, the integral equals A−1(eΔA−I)A^{-1}(e^{\Delta A}-I). The integral itself works for singular matrices too. To see why, integrate the matrix exponential's power series term by term.

∫0ΔeτA dτ=∑j≥0Δj+1(j+1)!Aj.\int_0^\Delta e^{\tau A}\,d\tau = \sum_{j\ge 0}\frac{\Delta^{j+1}}{(j+1)!}A^j .

The factorial in the denominator gives convergence for any finite square matrix. For A=0A=0, the only nonzero term is ΔI\Delta I, so each step adds ΔBuk\Delta Bu_k.

A Diagonal Example You Can Compute by Hand

Take N=1N = 1 and a single stable rate a<0a < 0. The continuous system is x′=ax+bux' = a x + b u. Then

aˉ=eΔa,bˉ=b⋅eΔa−1a.\bar{a} = e^{\Delta a}, \qquad \bar{b} = b \cdot \frac{e^{\Delta a} - 1}{a}.

Since a<0a < 0 and Δ>0\Delta > 0, the factor Δa\Delta a is negative, so aˉ∈(0,1)\bar{a} \in (0, 1). The discrete system is a geometric decay. Two sanity checks are worth doing.

First, as a→0a \to 0 the fraction (eΔa−1)/a(e^{\Delta a} - 1)/a tends to Δ\Delta, so bˉ→Δb\bar{b} \to \Delta b. With a zero rate, the state simply accumulates the input. Mamba's reference implementation also uses Δb\Delta b, as a first-order approximation to the write at finite rates.

Second, the continuous half-life is ln⁡2/∣a∣\ln 2 / |a| in units of time. The discrete half-life in units of steps is

h1/2=ln⁡2Δ ∣a∣.h_{1/2} = \frac{\ln 2}{\Delta\, |a|}.

For a single mode, Δ∣a∣\Delta |a| sets the half-life in step units. This scale can be fractional. The first whole update at which the magnitude is at or below half its starting value is ⌈h1/2⌉\lceil h_{1/2}\rceil.

When the rate stays fixed, increasing the step size makes one update cover more continuous time. The contribution decays more in each step. Later we will let the input determine the step size separately at each position.

PythonIn [3]
CollapseExpand
import numpy as np

rate_grid = -np.logspace(np.log10(0.01), np.log10(4.0), 240)  # a in [-4, -0.01]
step_grid = np.logspace(
    np.log10(0.01), np.log10(2.0), 240
)  # Delta in [0.01, 2]
persistence = np.exp(
    np.multiply.outer(step_grid, rate_grid)
)  # shape (step, rate)

halflife_steps = np.log(2.0) / np.multiply.outer(step_grid, -rate_grid)

We now have a grid of aˉ=eΔa\bar{a} = e^{\Delta a} over a range of continuous rates and step sizes. The map below makes the joint dependence visible.

VisualizationOut [4]
CollapseExpand
Heatmap of discrete persistence over continuous decay rate and step size.
The remaining fraction of an existing state after one held-input interval. The contours connect decay rates and step sizes that give the same half-life in steps.

A point near the upper left combines a large step with a strongly negative rate. Little of the previous state survives that step. As you move toward the lower right, the rate and the step produce a multiplier closer to one. The contour lines pick out combinations with the same half-life.

Comments

Add to the conversation

A question, a correction, or an example from your own work.

No comments yet. Be the first to share your thoughts!

Newsletter

Stay up to date

Get new articles, book updates, and notes on AI and technology.

Unsubscribe at any time. Privacy policy