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.

Coupling and diagonal equivalence

A coupling flow whose conditioners return constants is a diagonal Gaussianization flow; we check it block by block, and find where it fails today

06 · Coupling and diagonal equivalence

Open In Colab

Notebook 05 started a coupling flow from fit_rbig_coupling and found that its conditioners return constants until training switches them on. A coupling whose conditioner returns a constant no longer couples anything: it is a marginal map on its active half. So a warm-started coupling flow should be the diagonal Gaussianization flow that fit_rbig builds, written with many more numbers. The example Zero-kernel coupling ≡ diagonal Gaussianization proves this lemma by lemma and shows training breaking it. Here we test the claim layer by layer, which shows where float32 rounding enters, and where the equivalence fails today.

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

jax               : 0.12.1
numpy             : 2.4.3
flowjax           : 19.1.0
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

1. Why a zero readout gives a marginal map

The last layer of a coupling’s conditioner is affine (1). When its weight Wout\mat{W}_{\mathrm{out}} is zero, the conditioner returns its bias bout\vect{b}_{\mathrm{out}} whatever the passive half, so the transformer’s parameters no longer depend on xA\vect{x}_A, and the coupling of (1) becomes

zA=xA,zB=Tbout(xB)\begin{aligned} \vect{z}_A &= \vect{x}_A, \\ \vect{z}_B &= T_{\vect{b}_{\mathrm{out}}}(\vect{x}_B) \end{aligned}

The block of the Jacobian below the diagonal (3) is zero, so the layer maps each active coordinate on its own. For MixtureGaussianCDFCoupling the transformer is the mixture Gaussianization z=Φ−1(F(x))z = \Phi^{-1}(F(x)) (3) of the mixture that bout\vect{b}_{\mathrm{out}} encodes. fit_rbig_coupling builds each layer as a PCA frame followed by two such couplings with a flip after each, so that each coordinate is active once; the pair is one diagonal layer gkg_k (2). It fits each bout\vect{b}_{\mathrm{out}} by the same per-coordinate EM, with the same seeds, as fit_rbig fits its marginals, so the two warm starts should be one map.

2. Four layers: one map

The data are those of Part 4: two moons with noise of standard deviation 0.08, standardised, split into Nt=3000N_t = 3000 training rows and Nv=1000N_v = 1000 held-out rows. Both builders work in float32 (fit_rbig cannot run in float64 today, gauss_flows#247).

diagonal: 8 blocks, first layer ['FixedRotation', 'MixtureGaussianCDF'], 212 numbers
coupling: 20 blocks, first layer ['FixedRotation', 'MixtureGaussianCDFCoupling', 'Flip', 'MixtureGaussianCDFCoupling', 'Flip'], 46804 numbers

Both flows start each layer with a PCA frame. The diagonal flow holds 212 numbers: four 2×22 \times 2 frames, eight mixtures of 8 components with a weight, a mean and a scale each, and the base’s location and scale. The coupling flow holds 46,804, about 220 times more: each of its eight couplings has a conditioner MLP of width 64 and depth 2, and at the warm start only the readout’s bias of each conditioner has any effect on the map.

One function runs the blocks of a flow one at a time, in the density direction, and keeps the state at the end of each layer: every 2 blocks for the diagonal flow, every 5 for the coupling flow.

We compare the two flows on the training rows.

layer 1: median 1.9e-07, max 3.7e-05
layer 2: median 2.2e-05, max 4.7e-04
layer 3: median 6.6e-05, max 6.7e-04
layer 4: median 3.4e-05, max 3.6e-04
diagonal: NLL 2.02326 on training rows, 2.09955 held out
coupling: NLL 2.02327 on training rows, 2.09417 held out

With 4 layers the two flows are one map to float32 rounding. After the first layer their states agree to 1.9×10−71.9 \times 10^{-7} in the median and 3.7×10−53.7 \times 10^{-5} at worst, and the largest gap stays below 7×10−47 \times 10^{-4} through all four layers. The largest gaps are at points in the tails, where the coupling takes the probit of the mixture CDF itself while MixtureGaussianCDF works with its logarithm, and loses digits as the CDF approaches 1. The training NLLs agree to 10-5 nats. The held-out NLLs differ by 0.005 nats (2.09955 against 2.09417), and the whole difference comes from three held-out rows that the diagonal flow sends beyond -5 in a latent coordinate: the coupling flow cannot send them that far, for the reason section 3 finds.

3. Eight layers: where it breaks

We build both flows again with K=8K = 8 layers and compare them the same way.

layer 1: median 1.9e-07, max 3.7e-05
layer 2: median 2.2e-05, max 4.7e-04
layer 3: median 6.6e-05, max 6.7e-04
layer 4: median 3.4e-05, max 3.6e-04
layer 5: median 5.0e-05, max 5.0e-01
layer 6: median 4.2e-02, max 8.6e-01
layer 7: median 1.9e+00, max 7.5e+00
layer 8: median 1.9e+00, max 8.3e+00
<Figure size 750x440 with 1 Axes>

Figure 1:The distance between the states of the coupling flow and the diagonal flow after each layer, on the training rows: the median (solid) and the largest (dashed), for 4 layers (blue) and 8 layers (orange), on a log scale. The first four layers of the two pairs coincide.

Both builders are deterministic, so the first four layers of the 8-layer flows are those of the 4-layer flows, gaps included. In layer 5 the median gap is still 5×10−55 \times 10^{-5}, but one point jumps to 0.5. From layer 6 on the median grows, and after layer 7 the two flows send a typical point 1.9 apart. We look at the point that jumps in layer 5.

layer 5, training row 2071: in the PCA frame [1.6596 4.2851]
  diagonal marginal: [1.6513 5.2507]
  coupling pair:     [1.6512 4.7508]

In layer 5’s PCA frame this training row has 4.285 in its second coordinate, far in the tail of that layer’s mixture. The diagonal marginal sends it to 5.251. The coupling sends it to 4.7508, which is Φ−1(1−10−6)\Phi^{-1}(1 - 10^{-6}), the largest value it can return: it clips the mixture CDF to [10−6,1−10−6][10^{-6}, 1 - 10^{-6}] before the probit. Past that value the coupling is not invertible and its log-determinant is wrong, a bug in gauss_flows (gauss_flows#260). fit_rbig_coupling moves its states from layer to layer through the same clipped formula, so it fits layer 6 to states that differ from those of fit_rbig in this one row.

layer 1: frames differ by 0.0e+00
layer 2: frames differ by 1.1e-05
layer 3: frames differ by 2.4e-05
layer 4: frames differ by 2.4e-05
layer 5: frames differ by 3.9e-05
layer 6: frames differ by 2.5e-02
layer 7: frames differ by 1.4e+00
layer 8: frames differ by 1.6e+00
diagonal: NLL 1.926 on training rows, 2.430 held out
coupling: NLL 1.830 on training rows, 2.022 held out

One row out of 3,000 is enough. Layer 6’s PCA frame moves by 2.5×10−22.5 \times 10^{-2}, the EM fits after it land elsewhere, and by layer 7 the frames differ by 1.4: the two flows are now different maps, and different densities, with training NLLs of 1.830 for the coupling flow and 1.926 for the diagonal one, and held-out NLLs of 2.022 and 2.430. We read neither as the better model; once the coupling works in log space the two should agree at any depth, which the docs ticket gauss_flows#261 will check.

Recap

PieceEquationIn code
a zero readout makes a coupling a marginal map(1), (1)fit_rbig_coupling
a coupling pair with flips is one diagonal layer(2)[FixedRotation, MixtureGaussianCDFCoupling, Flip, MixtureGaussianCDFCoupling, Flip]
the two warm starts compared layer by layer(2)layer_states, layer_gaps
where the equivalence fails today(3)the coupling’s clipped CDF, gauss_flows#260

RBIG, the diagonal Gaussianization flow and the zero-readout coupling flow are three ways of writing one map; the coupling flow adds a conditioner that training can switch on, as notebook 05 showed.

Next. Notebook 07 stacks coupling layers deeper: what depth buys, how the gradient grows with it, and the residual maps that give up the coupling’s triangular Jacobian.