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.

Density destructors

Naming the object: an invertible map that destroys structure, built by alternating a marginal Gaussianization with a rotation

04 · Density destructors

Open In Colab

The earlier notebooks assembled the parts: an invertible map carries a density ((4)), maps compose with additive log-determinants ((4)), and a standard Gaussian is the natural target. Now we name the object those parts describe, a density destructor, and build one.

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

jax               : 0.12.1
numpy             : 2.4.3
matplotlib        : 3.11.2
rbig              : 0.1.16
gauss_flows_models: 0.3.0

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

Throughout, the data are N=2000N = 2000 points of two moons in Dx=2D_x = 2 coordinates, standardised per coordinate so that the target is N(0,I)\mathcal{N}(\vect{0}, \mat{I}).

1. What is a density destructor?

The map destroys the density: everything that made pxp_x structured (skew, heavy tails, several modes, dependence between coordinates) is removed, and isotropic Gaussian noise is left. “Normalizing flow” in machine learning, “Gaussianization” in signal processing and “density destructor” Inouye & Ravikumar, 2018 are three names for this one map, and each earlier notebook is one of the things it gives us:

Once we have a destructor ffwe getfrom
the log-density (4), with (5) for a deep ffan exact densitynotebooks 00 and 01
ff run backward on Gaussian noise, (4)a generatornotebook 02
independent coordinates with Gaussian marginalscoordinates in which information measures are easynotebook 03

The whole curriculum is about building good destructors.

2. The classic recipe: a nonlinearity and a rotation

How do we build ff for a tangled distribution like two moons? Gaussianization Chen & Gopinath, 2000, in the form of rotation-based iterative Gaussianization Laparra et al., 2011, alternates two moves that each fix what the other cannot.

Marginal Gaussianization. Each coordinate xdx_d, for d=1,…,Dxd = 1, \ldots, D_x, goes through its own CDF and then the inverse standard-normal CDF,

g(x)d=Φ−1(Fd(xd))g(\vect{x})_d = \Phi^{-1}(F_d(x_d))

where Fd:R→[0,1]F_d: \mathbb{R} \to [0, 1] is the CDF of coordinate dd and Φ\Phi the standard-normal CDF. Every axis becomes standard normal, but an elementwise map cannot touch the dependence between axes.

Rotation. An orthogonal matrix Q∈RDx×Dx\mat{Q} \in \mathbb{R}^{D_x \times D_x}, with Q⊤Q=I\mat{Q}^\top \mat{Q} = \mat{I}, mixes the axes. It is free, log⁡∣det⁡Q∣=0\log \vert \det \mat{Q} \vert = 0, and it turns the dependence left by gg into new non-Gaussian structure along each axis, which the next marginal step can remove.

One layer of the destructor is a marginal step followed by a rotation,

fk(x)=Qkgk(x)f_k(\vect{x}) = \mat{Q}_k g_k(\vect{x})

and the destructor is the composition (1) of KK such layers. We take one layer with rbig and look at the data after each move (Figure 1).

per-axis std after the marginal step: [0.9997 0.9997]
correlation after the marginal step:  -0.375
<Figure size 1500x500 with 3 Axes>

Figure 1:One layer on two moons. Left: the standardised data. Middle: after the marginal Gaussianization each axis is standard normal but the crescents remain. Right: after a random rotation the leftover structure is spread across both axes.

After the marginal step each axis has unit standard deviation, yet the crescents are still there and the two axes are still correlated: an elementwise map cannot remove dependence. The rotation moves that structure onto new axes, where it again looks non-Gaussian coordinate by coordinate, so the next marginal step has something to work on. One RBIGLayer in rbig is exactly this pair.

3. Iterate: the picture behind Gaussianization

Stacking many layers grinds the distribution down towards N(0,I)\mathcal{N}(\vect{0}, \mat{I}). rbig.AnnealedRBIG is this iterated destructor; we fit K=30K = 30 layers and look at the data after 0, 3, 12 and all 30 of them (Figure 2).

Pushing the data through all of the layers gives the latent, and we check its first two moments and the likelihood rbig assigns to the data.

fitted layers:                  30
latent per-axis mean:           [-0.  0.]
latent per-axis std:            [0.9999 0.9994]
latent correlation:             -0.0005
mean log-likelihood (rbig):     -1.662
<Figure size 1600x450 with 4 Axes>

Figure 2:Two moons pushed through 0, 3, 12 and 30 layers of rbig.AnnealedRBIG. The crescents are worn away layer by layer until an isotropic Gaussian cloud is left.

After 30 layers the latent has zero mean, unit standard deviation on each axis and almost no correlation between the axes: the moons have been destroyed. That sequence is Gaussianization, an iterated nonlinearity and rotation grinding the structure away. How many layers are enough is a convergence question, which notebook 06 answers with Gaussianity diagnostics.

4. Run it backward to generate

A destructor is invertible, so its inverse is a generator: draw Gaussian noise and push it back through the inverted layers,

x=f−1(z) with z∼N(0,I)\vect{x} = f^{-1}(\vect{z}) \text{ with } \vect{z} \sim \mathcal{N}(\vect{0}, \mat{I})

rbig does this with sample, which inverts each marginal step and transposes each rotation (Figure 3).

<Figure size 1000x500 with 2 Axes>

Figure 3:Left: the two-moons data. Right: 2000 samples from the inverse of the rbig destructor applied to standard-normal noise.

The same map, read in reverse, turns Gaussian noise back into two moons. A good destructor is a density estimator in one direction and a generative model in the other: one object, both jobs.

5. The bridge: the same destructor in gauss_flows

fit_rbig builds the destructor as a FlowJax Transformed distribution. Each of its layers is a PCA rotation followed by a MixtureGaussianCDF marginal, fitted in closed form (an EM fit per coordinate, no gradients) to the state that reaches it, exactly the greedy construction of section 3. Its bijection runs from the base to the data, so the destructor ff is the bijection’s inverse. We fit 8 layers and look at the latent and at samples (Figure 4).

latent per-axis mean:           [0.0005 0.    ]
latent per-axis std:            [1.005  1.0035]
latent correlation:             -0.0015
mean log-likelihood (gauss_flows): -1.351
<Figure size 1000x500 with 2 Axes>

Figure 4:The gauss_flows destructor from fit_rbig with 8 layers. Left: the latent f(x) of the two-moons data, standardised but with structure left. Right: 2000 samples drawn from the flow, which join the tips of the moons.

With 8 layers the gauss_flows latent has zero mean, unit standard deviation and almost no correlation, the same first two moments as the 30-layer rbig latent. The scatter still shows structure, though, and the samples join the tips of the two moons. Matching the mean and covariance does not make a distribution Gaussian; notebook 06 gives tests that see the difference. Because the flow is a FlowJax distribution, it also gives the exact log-density (5) and samples, and it is the warm start that later parts refine by training on the likelihood. The two packages model the marginals differently (Gaussian mixtures here, empirical CDFs in rbig), so their mean log-likelihoods differ.

Recap

ConceptEquationIn code
density destructor(1)rbig.AnnealedRBIG, fit_rbig
marginal Gaussianization(2)rbig.MarginalGaussianize
one layer(3)marginal step, then rbig.RandomRotation
many layers(1)destructor.layers_
density of a deep destructor(5)flow.log_prob(x)
generate(4)destructor.sample, flow.sample

Next. Iterating Φ−1∘Fd\Phi^{-1} \circ F_d many times is numerically delicate: CDFs reach 0 and 1, Φ−1\Phi^{-1} blows up there, and log-determinants must not drift. The next notebook covers the clamping, jitter and float64 bookkeeping that keep a deep destructor stable.

References
  1. Inouye, D. I., & Ravikumar, P. (2018). Deep Density Destructors. International Conference on Machine Learning (ICML).
  2. Chen, S. S., & Gopinath, R. A. (2000). Gaussianization. Advances in Neural Information Processing Systems (NeurIPS).
  3. Laparra, V., Camps-Valls, G., & Malo, J. (2011). Iterative Gaussianization: From ICA to Random Rotations. IEEE Transactions on Neural Networks, 22(4), 537–549. 10.1109/TNN.2011.2106511
  4. Meng, C., Song, Y., Song, J., & Ermon, S. (2020). Gaussianization Flows. International Conference on Artificial Intelligence and Statistics (AISTATS).