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.

Iterative-Gaussianization warm start

Notebooks 01 and 02 trained Gaussianization / coupling flows from random initialisation. That works, but spends the first hundreds of epochs pulling the flow from a near-identity map towards the data.

Iterative Gaussianization (RBIG — Laparra & Malo 2011) is a non-gradient, greedy procedure that warm-starts the flow by walking block-by-block through the architecture and fitting each block’s parameters directly:

  1. Rotation block — fit PCA on the current state YY; push the eigenvectors into the rotation layer.

  2. Marginal block — fit a per-dim mixture-of-Gaussians on the rotated data with scikit-learn’s GaussianMixture, and assign (π,μ,σ)(\pi, \mu, \sigma) directly into the MixtureGaussianCDF layer weights.

  3. Coupling block — fit a per-b-dim GMM on the current YY; zero the conditioner’s final Dense kernel and set its bias to the flattened GMM params. At initialisation the conditioner output is constant-in-xax_a, so the coupling layer acts like a diagonal marginal with the fitted mixture. Gradient training then lets the conditioner learn to modulate on xax_a.

Between blocks the current YY is propagated forward through the newly-parameterised bijector, so the next block sees data that has already been partially Gaussianized. A classical result (Laparra & Malo 2011, Chen & Gopinath 2000) is that this drives YY towards N(0,I)\mathcal{N}(0, I) at a geometric rate — even with no gradient descent at all, the flow is already a decent density estimator after a handful of blocks.

The point of this notebook: a flow initialised this way starts at a much lower NLL than random init and reaches its training optimum in a fraction of the epochs.

/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. Dataset

Two moons, standardised. Same data as notebooks 01/02 so the comparison is apples-to-apples.

2. Diagonal flow — random vs IG init

Build two identical diagonal flows, warm-start one of them from IG (fit_rbig), and train both with the same optimiser and schedule.

Before any training: what did IG init already buy us?

RBIG on its own produces a density estimate. Below we compare the mean log-likelihood (per sample) of the IG-initialised flow against the random-init flow, both before a single gradient step.

mean log-likelihood before training:
  random init : -14.324 nats/sample
  IG init     : -1.733 nats/sample  (improvement: +12.590)

Pushforward at IG-init time

With no gradient training whatsoever, the pushforward of the IG-initialised flow should already be approximately N(0,I)\mathcal{N}(0, I). Jointplots make this immediately visible — the IG scatter should look isotropic and the marginals should line up with the black N(0,1)\mathcal{N}(0, 1) curves, while the random-init pushforward won’t.

/home/azureuser/localfiles/geo_repos/geo_ml/gauss_flows-fit/.venv/lib/python3.13/site-packages/seaborn/axisgrid.py:1766: UserWarning: The figure layout has changed to tight
  f.tight_layout()
<Figure size 825x825 with 3 Axes>
/home/azureuser/localfiles/geo_repos/geo_ml/gauss_flows-fit/.venv/lib/python3.13/site-packages/seaborn/axisgrid.py:1766: UserWarning: The figure layout has changed to tight
  f.tight_layout()
<Figure size 825x825 with 3 Axes>
IG-init pushforward (pre-training)
  mean:    [+0.000, -0.000]   target = [0, 0]
  cov[0,0]:1.001    cov[1,1]:1.004    target = 1, 1
  cov[0,1]:-0.008                          target = 0

Samples at init (no training)

The pushforward picture above checks z=f(x)z = f(x) for the given training points. The more direct “is the flow already usable?” question is: sample z∼N(0,I)z \sim \mathcal{N}(0, I), push through the inverse x=f−1(z)x = f^{-1}(z), and see whether the output looks like the training distribution. For IG init the answer should be “yes, roughly two-moons-shaped already”; for random init the answer is “no — the flow is essentially an arbitrary rotation of the base distribution”.

/home/azureuser/localfiles/geo_repos/geo_ml/gauss_flows-fit/.venv/lib/python3.13/site-packages/seaborn/axisgrid.py:1766: UserWarning: The figure layout has changed to tight
  f.tight_layout()
<Figure size 825x825 with 3 Axes>
/home/azureuser/localfiles/geo_repos/geo_ml/gauss_flows-fit/.venv/lib/python3.13/site-packages/seaborn/axisgrid.py:1766: UserWarning: The figure layout has changed to tight
  f.tight_layout()
<Figure size 825x825 with 3 Axes>

Training comparison

Both flows, same optimiser, same 150 epochs. The IG curve starts at (and finishes near) the random curve’s final value — the zoomed panel on the right makes the small end-of-training gap legible.

WARNING:matplotlib.font_manager:findfont: Failed to find font weight semibold for DejaVu Sans, now using 700.
WARNING:matplotlib.font_manager:findfont: Failed to find font weight semibold for DejaVu Sans, now using 700.
<Figure size 1870x715 with 2 Axes>
final loss:  random init = +1.388   IG init = +1.154

Density and samples after training

<Figure size 1870x825 with 4 Axes>
/home/azureuser/localfiles/geo_repos/geo_ml/gauss_flows-fit/.venv/lib/python3.13/site-packages/seaborn/axisgrid.py:1766: UserWarning: The figure layout has changed to tight
  f.tight_layout()
<Figure size 825x825 with 3 Axes>
/home/azureuser/localfiles/geo_repos/geo_ml/gauss_flows-fit/.venv/lib/python3.13/site-packages/seaborn/axisgrid.py:1766: UserWarning: The figure layout has changed to tight
  f.tight_layout()
<Figure size 825x825 with 3 Axes>

3. Coupling flow — random vs IG init

Same experiment with a coupling flow. IG init for coupling layers is weaker in isolation (the conditioner is not exercised at init — it emits a constant bias), but it still lets training skip the “the conditioner is effectively random, so the coupling transform is random” phase by handing it a sensible starting point where the conditioner behaves as a well-fit diagonal marginal.

mean log-likelihood before training (coupling flow):
  random init : -2.838 nats/sample
  IG init     : -1.821 nats/sample  (improvement: +1.017)

Coupling samples at init (no training)

Same sanity check for the coupling flow. IG-init coupling samples should already look moon-ish; random-init coupling samples are whatever a random MLP conditioner does to a N(0,I)\mathcal{N}(0, I) sample.

/home/azureuser/localfiles/geo_repos/geo_ml/gauss_flows-fit/.venv/lib/python3.13/site-packages/seaborn/axisgrid.py:1766: UserWarning: The figure layout has changed to tight
  f.tight_layout()
<Figure size 825x825 with 3 Axes>
/home/azureuser/localfiles/geo_repos/geo_ml/gauss_flows-fit/.venv/lib/python3.13/site-packages/seaborn/axisgrid.py:1766: UserWarning: The figure layout has changed to tight
  f.tight_layout()
<Figure size 825x825 with 3 Axes>

Training comparison for the coupling flow

<Figure size 1870x715 with 2 Axes>
final loss:  random init = +1.842   IG init = +1.106

Coupling density and samples after training

<Figure size 1870x825 with 4 Axes>
/home/azureuser/localfiles/geo_repos/geo_ml/gauss_flows-fit/.venv/lib/python3.13/site-packages/seaborn/axisgrid.py:1766: UserWarning: The figure layout has changed to tight
  f.tight_layout()
<Figure size 825x825 with 3 Axes>
/home/azureuser/localfiles/geo_repos/geo_ml/gauss_flows-fit/.venv/lib/python3.13/site-packages/seaborn/axisgrid.py:1766: UserWarning: The figure layout has changed to tight
  f.tight_layout()
<Figure size 825x825 with 3 Axes>

4. Verifying the zero-kernel contract

Immediately after fit_rbig_coupling every MixtureGaussianCDFCoupling’s final Dense has a zero kernel (so the conditioner emits its bias for any input — the coupling layer behaves as a diagonal marginal on its b-half). During gradient training those kernels become non-zero as the conditioner learns to modulate on xax_a. Below: build a fresh coupling flow, IG-init it, check the kernels before any training, then train briefly and check again. Notebook 04 proves the full-flow equivalence.

right after IG init (no train):   max|W| per coupling = ['0.0e+00', '0.0e+00', '0.0e+00', '0.0e+00', '0.0e+00', '0.0e+00', '0.0e+00', '0.0e+00']
all zero after IG init : True
after 20 epochs of training:      max|W| per coupling = ['0.085', '0.165', '0.104', '0.114', '0.170', '0.110', '0.104', '0.098']
(non-zero is expected — the conditioner has started to modulate on x_a)

Recap

  • RBIG (Laparra & Malo 2011) is a non-gradient greedy warm-start that fits each block’s parameters in sequence (PCA for rotation, sklearn GaussianMixture per dim for marginal/coupling) and propagates the data forward.

  • For the diagonal flow the init is exact: the layer’s (π,μ,σ)(\pi, \mu, \sigma) parameters are exactly the GMM fit, and the pre-training pushforward is already near N(0,I)\mathcal{N}(0, I).

  • For the coupling flow the conditioner’s inner Dense weights stay random, but the final Dense is forced to kernel=0, bias = fitted mixture params. So at init the coupling layer behaves like a diagonal marginal layer with the IG-fitted mixture; gradient training then lets the conditioner become genuinely conditional.

  • End result in both cases: lower starting NLL, faster convergence, and fewer chances for the optimiser to get stuck in a bad local minimum.