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.

Diagonal against coupling flows

Per-coordinate marginal maps between rotations against maps conditioned on the other coordinates, compared at matched parameter counts

04 · Diagonal against coupling flows

Open In Colab

The flows of Part 4 are diagonal: each layer fk(x)=Qkgk(x)f_k(\vect{x}) = \mat{Q}_k g_k(\vect{x}) (3) maps every coordinate with a one-dimensional map of its own, so the Jacobian of its marginal step is diagonal,

Jgk(x)=diag(T1′(x1),…,TDx′(xDx))\mat{J}_{g_k}(\vect{x}) = \mathrm{diag}(T_1'(x_1), \ldots, T_{D_x}'(x_{D_x}))

and the coordinates meet only through the rotations Qk\mat{Q}_k. A coupling layer (notebook 00) maps its active half with parameters computed from its passive half, so its Jacobian (3) has a block below the diagonal, and the coordinates meet inside every layer. That conditioner is a neural network, so a coupling layer also has far more parameters. Is the coupling flow more expressive, or does it just have more parameters? We compare the two at matched parameter counts, on a distribution built to need dependence between the coordinates: a two-armed spiral.

Python implementation: CPython
Python version       : 3.13.12
IPython version      : 9.12.0

jax               : 0.12.1
numpy             : 2.4.3
optax             : 0.2.8
flowjax           : 19.1.0
pipekit_train     : 0.3.4
gauss_flows_models: 0.3.1

Compiler    : Clang 21.1.4 
OS          : Linux
Release     : 6.8.0-1044-azure
Machine     : x86_64
Processor   : x86_64
CPU cores   : 16
Architecture: 64bit

The spiral has two arms: a point at arc parameter t∼U(0.5,3.5)t \sim \mathcal{U}(0.5, 3.5) sits at ±(tcos⁡2.5t,tsin⁡2.5t)\pm (t \cos 2.5 t, t \sin 2.5 t), with the sign chosen at random and normal noise of standard deviation 0.08 added. Where one coordinate is, the other is confined to a few narrow bands, a dependence no per-coordinate map can express. We standardise N=4000N = 4000 points and split them into Nt=3000N_t = 3000 training rows and Nv=1000N_v = 1000 held-out rows, in float64.

1. What coupling_gaussianization_flow builds

Part 4 took gaussianization_flow apart. Its coupling counterpart, coupling_gaussianization_flow, stacks KK layers of a rational-quadratic-spline coupling Durkan et al., 2019, whose conditioner is an MLP of width nn_width and depth nn_depth, followed by a flip of the coordinates for Dx=2D_x = 2 (notebook 03). We build it with the defaults and count parameters per layer.

bijection: Invert(Scan(...))
one layer: ['RQSplineCoupling', 'Flip']
base distribution: Normal

The structure matches gaussianization_flow’s: an Invert around a Scan over identical layers, so log_prob runs the layers forwards. Its base is FlowJax’s Normal, whose location and scale are trainable, so training moves the base away from N(0,I)\mathcal{N}(\vect{0}, \mat{I}), a bug in gauss_flows (gauss_flows#256). Unlike gaussianization_flow, this factory takes no base_dist, so below we put its bijection on a fixed StandardNormal base ourselves. Counting what is left to train:

per layer: diagonal 52, coupling 6108

A coupling layer with the default conditioner has over a hundred times the parameters of a diagonal layer, so comparing the two at the same number of layers says little. We compare them at matched parameter counts instead: we shrink the coupling conditioner to one hidden layer of width 16, and stack more diagonal layers. The ranges cannot match exactly, since a diagonal flow would need far more layers than it can usefully train to reach a coupling flow’s count, but they meet in the middle.

2. Likelihood against parameter count

We train diagonal flows with K=4,8,16K = 4, 8, 16 layers and coupling flows with K=2,4,8K = 2, 4, 8 layers, all on a fixed N(0,I)\mathcal{N}(\vect{0}, \mat{I}) base, with the training recipe of Part 4: pipekit-train runs Adam on the mean negative log-likelihood (1) with a one-cycle cosine learning rate peaking at 3×10−33 \times 10^{-3} and the gradient clipped to a global norm of 1, here for 2,000 steps on batches of 512 rows.

trainable numbers, diagonal: {4: 208, 8: 416, 16: 832}
trainable numbers, coupling: {2: 1016, 4: 2032, 8: 4064}

We train the six flows; the diagonal ones take longer, since a Scan over 16 layers is slower per step than one over 2.

diagonal K =  4:  208 parameters, NLL 2.637 on training rows, 2.634 held out
diagonal K =  8:  416 parameters, NLL 2.673 on training rows, 2.679 held out
diagonal K = 16:  832 parameters, NLL 2.716 on training rows, 2.716 held out
coupling K =  2: 1016 parameters, NLL 1.853 on training rows, 1.890 held out
coupling K =  4: 2032 parameters, NLL 1.659 on training rows, 1.700 held out
coupling K =  8: 4064 parameters, NLL 1.502 on training rows, 1.540 held out
<Figure size 800x460 with 1 Axes>

Figure 1:Held-out negative log-likelihood against the number of parameters, on a log scale, for diagonal flows of 4, 8 and 16 layers (blue circles) and coupling flows of 2, 4 and 8 layers with a small conditioner (green squares). Lower is better.

The two curves do not overlap. The diagonal flow sits between 2.63 and 2.72 nats held out over its whole range, and its deeper versions are slightly worse, not better: at this training budget, more layers of per-coordinate maps and rotations do not carve the spiral (a separate run with three times as many steps lowered both, but kept the 16-layer flow behind the 4-layer one). The smallest coupling flow, with 1,016 parameters against the deepest diagonal flow’s 832, is already 0.83 nats better held out, and the coupling flows keep improving as they grow, to 1.54 nats at 4,064 parameters. The advantage is not that coupling flows have more parameters: per parameter, a conditioner that lets one coordinate’s map depend on the other is far more efficient for this dependence.

3. The learned densities at similar parameter counts

The closest pair is the diagonal flow with 16 layers and the coupling flow with 2 layers. We evaluate both densities on a grid.

<Figure size 1650x500 with 3 Axes>

Figure 2:The held-out spiral (left) and the densities of the 16-layer diagonal flow (centre) and the 2-layer coupling flow (right), each with the held-out points in white. The diagonal flow spreads its mass over a blob around the spiral; the coupling flow puts it along the arms.

With a similar budget, the diagonal flow spreads its mass over a blob that covers the spiral and the gaps between its arms, with its peak at the centre, while the coupling flow puts its mass along the arms. The conditioner does the work: it lets the map of one coordinate depend on where the other is, which is what the spiral needs. When the dependence between coordinates is mild, the cheaper diagonal flow and its RBIG warm start (Part 4) can be enough.

Recap

PieceEquationIn code
a diagonal layer: per-coordinate maps, then a rotation(3), (1)gaussianization_flow
a coupling layer: maps conditioned on the other half(1), (3)coupling_gaussianization_flow, RQSplineCoupling and Flip
a fixed base for the coupling factory(5)Transformed(StandardNormal((2,)), flow.bijection), until gauss_flows#256 is fixed
a fair comparisonparameter counts from eqx.filter(flow.bijection, eqx.is_inexact_array)
training(1)pipekit-train’s TrainingLoop on negative_log_likelihood

Next. Coupling flows are more expressive, but they start from the identity and must learn everything by training. Notebook 05 starts one from a greedy RBIG fit instead, with fit_rbig_coupling.

References
  1. Durkan, C., Bekasov, A., Murray, I., & Papamakarios, G. (2019). Neural Spline Flows. Advances in Neural Information Processing Systems (NeurIPS).