Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Matrix-exponential neural flow

The linear special case of a continuous flow: dx/dt = Wx has the closed-form solution exp(Wt)x and the closed-form log-det t·tr(W) — no ODE solver, no Hutchinson, but only affine, so it Gaussianizes a Gaussian exactly and needs nonlinear partners for the rest

02 — Matrix-exponential neural flow

Notebooks 00 and 01 paid two prices for a free-form continuous flow: an ODE solve in both directions, and a stochastic estimate of the log-det trace. Both prices vanish the moment the vector field is linear. Take

dxtdt=Wxt    ⟹    xt=exp⁡(Wt) x0,\frac{\mathrm{d}x_t}{\mathrm{d}t} = W x_t \;\;\Longrightarrow\;\; x_t = \exp(W t)\,x_0,

the matrix exponential. The instantaneous change-of-variables trace is now constant in xx — tr⁡(∂x(Wx))=tr⁡(W)\operatorname{tr}(\partial_x (Wx)) = \operatorname{tr}(W) — so the log-det integral collapses to a closed form:

log⁡∣det⁡∂xT/∂x0∣=∫0Ttr⁡(W) dt=T tr⁡(W).\log\big|\det \partial x_T/\partial x_0\big| = \int_0^T \operatorname{tr}(W)\,\mathrm{d}t = T\,\operatorname{tr}(W).

gauss_flows.MatrixExponential adds a time-gated bias, y=exp⁡(Wt) x+h(t) by = \exp(W t)\,x + h(t)\,b, and is a neural flow Biloš et al. (2021), Kidger (2021): the closed-form solution of an ODE rather than something a solver integrates. It is the continuous-time face of Part 2’s linear mixers — a trainable, exactly-invertible rotation-plus-scale with a free, analytic log-det. The catch is the flip side of the gift: a linear map is affine, so on its own it can only Gaussianize a Gaussian.

What you will see

1. A single layer morphing a ring

Push the unit circle through exp⁡(Wt) ⋅+h(t) b\exp(W t)\,\cdot + h(t)\,b for t∈[0,1]t\in[0,1]. At t=0t=0 the map is the identity (exp⁡(0)=I\exp(0)=I, h(0)=0h(0)=0), and as tt grows it becomes a rotated, scaled, shifted ellipse — a continuum of affine maps indexed by tt.

<Figure size 1600x360 with 5 Axes>

2. The log-det is exactly t tr⁡(W)t\,\operatorname{tr}(W)

This is the whole appeal: no trace integral to estimate, no solver — the log-det is the analytic t tr⁡(W)t\,\operatorname{tr}(W), independent of the bias gate hh (a shift never scales volume). We check it against an autodiff slogdet of the Jacobian on a 4-D layer with a learned time gate, across a range of query times.

max |closed-form - autodiff| over 21 times: 4.72e-16
<Figure size 620x420 with 1 Axes>

Agreement to machine precision. The log-det never touches the Jacobian — it reads tr⁡(W)\operatorname{tr}(W) straight off the weight matrix.

3. Gaussianizing an anisotropic Gaussian — exactly

A linear flow is exactly the right tool when the data is Gaussian: whitening a correlated, tilted Gaussian to N(0,I)\mathcal{N}(0,I) is a linear map, and MatrixExponential represents it with a closed-form log-det. We fit a short chain (each block its own WW, bb, gate) to a tilted anisotropic Gaussian, querying the time at t=1t=1 so the chain acts as a fixed composition.

anisotropic-Gaussian fit: stopped at 250 epochs, val NLL = 3.0454
<Figure size 1150x500 with 2 Axes>

Now the Gaussianization direction: push the data through the inverse map and check the pushforward is standard normal.

Gaussianized moments (target 0, 1, 0, 0):
  z_1: mean=+0.021  std=1.083  skew=+0.031  exc-kurt=-0.122
  z_2: mean=-0.156  std=0.890  skew=-0.026  exc-kurt=-0.182
<Figure size 1500x460 with 3 Axes>

Clean: the latent fills the N(0,I)\mathcal{N}(0,I) rings, the QQ plots sit on the diagonal, the skew is ~0 and there are no residual modes — the map that whitens a Gaussian is the affine family this flow spans, so the fit lands at the optimum (the log-det being exact helps the optimiser get there). Contrast the next section, where the target is not Gaussian.

4. The affine ceiling — two moons

Stacking matrix exponentials does not escape affine: a composition of linear maps is linear. So the moment the data is genuinely non-Gaussian, a MatrixExponential chain hits a wall. We fit the same chain to standardised two moons and look at the Gaussianized latent — it keeps the bimodal crescent structure that no affine map can remove.

two-moons latent excess-kurtosis: z_1=-0.408, z_2=-1.273  (non-zero => not Gaussianized)
<Figure size 1150x500 with 2 Axes>

The density is a single tilted blob and the latent is still two crescents: an affine map cannot separate the modes. This is exactly why MatrixExponential earns its keep as a mixing block between nonlinear layers — the continuous-time analogue of a learned rotation in Part 2 — rather than as a stand-alone Gaussianizer. Slot a coupling or mixture-CDF layer (Parts 4-5) between two matrix-exponential blocks, or reach for FFJORD, and the modes come apart.

5. The tt-indexed family, for free

Because the bijection carries an explicit time, training at t=1t=1 hands us the whole one-parameter family pt=(exp⁡(WLt)∘⋯∘exp⁡(W1t))# N(0,I)p_t = (\exp(W_L t)\circ\cdots\circ\exp(W_1 t))_\#\, \mathcal{N}(0,I) — a smooth, exact interpolation from the base Gaussian at t=0t=0 to the fitted target at t=1t=1, queryable at any tt with no retraining and no solver.

<Figure size 1600x360 with 5 Axes>

At t=0t=0 the cloud is the base Gaussian; as t→1t\to1 it tilts and stretches into the target — the matrix exponential delivers this interpolation in closed form.

Recap

matrix-exponential flowFFJORD (00–01)
flow mapexp⁡(Wt)\exp(Wt) (closed form)numerical ODE solve
log-detexact t tr⁡(W)t\,\operatorname{tr}(W)trace integral, Hutchinson-estimated
per layeraffine in xxuniversal fθ(t,x)f_\theta(t,x)
Gaussianizesa Gaussian, exactlynon-Gaussian data too
costdense matrix-exp, O(d3)O(d^3)many ODE steps × probes

The matrix-exponential flow is the linear corner of the continuous-time family: everything is closed-form and exact, the log-det is a one-liner, and it whitens a Gaussian perfectly — but it is affine, so it Gaussianizes only what a linear map can. Treat it as Part 2’s mixer made continuous, to be composed with the nonlinear blocks of Parts 4-5.

Next up. 03 — Latent ODE on spirals closes Part 6 by moving the dynamics into a latent space: encode, run an ODE on the latent state, decode — Gaussianization on the latent z(0)z(0) — which is also the bridge to irregular time-series in Part 11.

References
  1. Biloš, M., Sommer, J., Rangapuram, S. S., Januschowski, T., & Günnemann, S. (2021). Neural Flows: Efficient Alternative to Neural ODEs. Advances in Neural Information Processing Systems (NeurIPS).
  2. Kidger, P. (2021). On Neural Differential Equations [Phdthesis]. University of Oxford.