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

MatrixExponential is the simplest non-trivial time-indexed neural flow:

y=exp⁡(W t) x+h(t) b,log⁡ ∣det⁡∂y/∂x∣=t⋅tr(W).y = \exp(W\, t)\, x + h(t)\, b, \qquad \log\,|\det \partial y/\partial x| = t \cdot \mathrm{tr}(W).

Compared with FFJORD this is closed-form — no ODE solver, no Hutchinson trace — but linear in xx, so a single layer can only realise an affine map. Stacking layers (with non-linear time gates between them) gives a tractable, ODE-free alternative for the same family of problems FFJORD handles.

Highlights of this notebook:

  • The map is the identity at t=0t = 0 because exp⁡(0)=I\exp(0) = I and the default time gate satisfies h(0)=0h(0) = 0.

  • The log-det is exact and analytic — verified against slogdet(jacrev).

  • Stacking realises a richer family while keeping all three properties above.

/home/azureuser/localfiles/geo_repos/geo_ml/gauss_flows-fit/.venv/lib/python3.13/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html
  from .autonotebook import tqdm as notebook_tqdm

1. A single layer pushing a unit circle

Take the unit circle in R2\mathbb{R}^2, push it through exp⁡(Wt)⋅ ⋅ +h(t) b\exp(W t)\cdot\, \cdot\, + h(t)\, b for t∈[0,1]t \in [0, 1], and watch it morph from the identity at t=0t=0 into a rotated/scaled/translated ellipse at t=1t=1.

findfont: Failed to find font weight semibold for DejaVu Sans, now using 700.
findfont: Failed to find font weight semibold for DejaVu Sans, now using 700.
<Figure size 1980x440 with 5 Axes>

2. Closed-form log-det vs slogdet(jacrev)

The log-determinant has the analytic form t⋅tr(W)t \cdot \mathrm{tr}(W), regardless of the time gate hh (the bias term shifts but doesn’t scale). We verify this matches autodiff on a non-trivial layer with a learned time gate.

<Figure size 715x495 with 1 Axes>
max |closed - autodiff| over 21 query times: 2.09e-07

3. Fit an anisotropic Gaussian target

Important caveat. A chain of MatrixExponential layers is still affine in xx at any fixed query time tt (the composition of affine maps is affine). It is genuinely a more flexible parameterisation than a single linear layer — each block has its own WW, bb, and time gate — but it can only realise the family of affine push-forwards of the base Gaussian. Use this when your target is well-modelled by a Gaussian with arbitrary covariance and mean.

To model multi-modal or otherwise non-Gaussian densities, pair MatrixExponential with a non-linear layer (AffineCoupling, DeepSigmoidCoupling, RQSplineCoupling, …) — the matrix exponential then acts as a learned, exactly-invertible “rotation + scale” between non-linear blocks.

The target here is a strongly tilted, anisotropic 2D Gaussian. That is exactly the family MatrixExponential was designed for, so we expect a tight fit. We freeze the time query at t=1t=1 throughout training so the flow behaves as a deterministic composition.

<Figure size 660x440 with 1 Axes>

Density and samples

The fitted chain produces a closed-form log-density on a grid in milliseconds (no ODE), and we sample by pushing base draws forward.

<Figure size 1320x550 with 3 Axes>

4. The whole neural flow: distributions indexed by tt

Because the bijection is parameterised by tt, training at t=1t=1 also gives us — for free — a smooth one-parameter family of push-forwards

pt(⋅)=(exp⁡(WLt)∘⋯∘exp⁡(W1t))# N(0,I),p_t(\cdot) = (\exp(W_L t) \circ \cdots \circ \exp(W_1 t))_{\#}\, \mathcal{N}(0, I),

interpolating between the base Gaussian at t=0t=0 and the fitted target at t=1t=1. This is the “neural flow” perspective and the reason MatrixExponential uses the packed-time conditioning contract: a single trained model encodes the entire trajectory of distributions, and you can query any intermediate tt without re-training.

<Figure size 2200x550 with 5 Axes>

At t=0t=0 the chain is the identity, so p0p_0 is the base Normal. As tt moves from 0 to 1 the cloud smoothly tilts and stretches into the trained anisotropic target. The matrix exponential gives this interpolation exactly, with no ODE solve.

5. When to reach for which?

propertyMatrixExponential chainFFJORD
exact log-detyes (t⋅tr(W)t\cdot\mathrm{tr}(W) per layer)no (Hutchinson during training)
closed-form forward / inverseyes (matrix exponential + linear solve)no (ODE solve)
per-layer expressivityaffine in xxuniversal in fθ(t,x)f_\theta(t,x)
training costdense matrix opsmany ODE steps × Hutchinson probes
scaling to high dim⁡\dimdominated by O(dim⁡3)O(\dim^3) matrix expdominated by ODE steps

Use MatrixExponential chains when you want a fast, deterministic flow that respects an explicit time index (e.g. a time-indexed continuous-in-spirit model on tabular data, or as a cheap warm-start). Reach for FFJORD when the data really wants a non-affine vector field per layer and you can afford the ODE.