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.

Information-Theory Measures with Gaussianization Flows

!!! note “Requirements” Beyond gauss_flows, this notebook uses the rbig package and pandas: pip install rbig pandas.

This notebook reproduces the RBIG information-theory notebook for gauss_flows. We estimate four information-theoretic quantities of a correlated multivariate Gaussian:

  • Entropy H(X)H(X)

  • Total correlation TC(X)\mathrm{TC}(X)

  • Mutual information I(X;Y)I(X; Y)

  • KL divergence KL(P ∥ Q)\mathrm{KL}(P \,\|\, Q)

Every quantity here ultimately reduces to a differential entropy — the expected surprise −Ep[log⁡p(x)]-\mathbb{E}_p[\log p(x)] of some distribution. The only thing that changes between methods is how we get a density to take that expectation against. We compute each quantity three ways:

MethodDensity object usedNeeds a Jacobian?
Analyticalthe known Gaussian covariance (ground truth)—
Change-of-variablesthe exact flow density log⁡p(x)=log⁡pZ(f(x))+log⁡∣det⁡Jf(x)∣\log p(x) = \log p_Z(f(x)) + \log\lvert\det J_f(x)\rvertyes
RBIG-wayper-layer total-correlation reduction (no density evaluated)no

As icing on the cake we run three models:

  • RBIG — AnnealedRBIG from the rbig package.

  • GF-Diagonal — a gauss_flows diagonal Gaussianization flow (fit_rbig).

  • GF-Coupling — a gauss_flows mixture-CDF coupling flow (fit_rbig_coupling).

Both gauss_flows models are RBIG warm-started (see the RBIG warm-start notebook) and then briefly fine-tuned, so they converge quickly to an accurate density.

0. The measures and their equations

All four quantities are functionals of a density. For a continuous random vector X∈RdX \in \mathbb{R}^d with density pp:

Differential entropy — the average log-density:

H(X)=−Ep ⁣[log⁡p(X)].H(X) = -\mathbb{E}_{p}\!\left[\log p(X)\right].

For a Gaussian X∼N(μ,Σ)X \sim \mathcal{N}(\mu, \Sigma) this has a closed form that depends only on the covariance:

H(X)=12log⁡ ⁣((2πe)d ∣Σ∣).H(X) = \tfrac{1}{2}\log\!\big((2\pi e)^{d}\,\lvert\Sigma\rvert\big).

Total correlation (multi-information) — the KL divergence between the joint and the product of its marginals, i.e. all the statistical dependence among the coordinates:

TC(X)=∑i=1dH(Xi)−H(X)=DKL ⁣(p(x)  ∥  ∏ip(xi))≥0.\mathrm{TC}(X) = \sum_{i=1}^{d} H(X_i) - H(X) = D_{\mathrm{KL}}\!\Big(p(x)\;\Big\|\;\textstyle\prod_i p(x_i)\Big) \ge 0.

For a Gaussian it collapses to a determinant ratio (equivalently, minus the log-determinant of the correlation matrix RR):

TC(X)=12(∑ilog⁡Σii−log⁡∣Σ∣)=−12log⁡∣R∣.\mathrm{TC}(X) = \tfrac{1}{2}\Big(\textstyle\sum_i \log \Sigma_{ii} - \log\lvert\Sigma\rvert\Big) = -\tfrac{1}{2}\log\lvert R\rvert.

Mutual information between two blocks X,YX, Y — the special case of total correlation between two groups of variables:

I(X;Y)=H(X)+H(Y)−H(X,Y).I(X; Y) = H(X) + H(Y) - H(X, Y).

KL divergence between two densities — the expected log-ratio:

DKL(p ∥ q)=Ep ⁣[log⁡p(x)q(x)]≥0,D_{\mathrm{KL}}(p \,\|\, q) = \mathbb{E}_{p}\!\left[\log \tfrac{p(x)}{q(x)}\right] \ge 0,

with the Gaussian closed form (used below for the mean-shifted case)

DKL(N(μp,Σp) ∥ N(μq,Σq))=12[tr⁡(Σq−1Σp)+(μq−μp)⊤Σq−1(μq−μp)−d+log⁡∣Σq∣∣Σp∣].D_{\mathrm{KL}}\big(\mathcal{N}(\mu_p,\Sigma_p)\,\|\,\mathcal{N}(\mu_q,\Sigma_q)\big) = \tfrac12\Big[\operatorname{tr}(\Sigma_q^{-1}\Sigma_p) + (\mu_q-\mu_p)^{\top}\Sigma_q^{-1}(\mu_q-\mu_p) - d + \log\tfrac{\lvert\Sigma_q\rvert}{\lvert\Sigma_p\rvert}\Big].

The change-of-variables (density) route

A normalizing flow is an invertible map z=f(x)z = f(x) that pushes the data to a simple base pZ=N(0,I)p_Z = \mathcal{N}(0, I). The change-of-variables formula gives the data density exactly:

pX(x)=pZ ⁣(f(x)) ∣det⁡Jf(x)∣,log⁡pX(x)=log⁡pZ ⁣(f(x))+log⁡∣det⁡Jf(x)∣.p_X(x) = p_Z\!\big(f(x)\big)\,\big\lvert\det J_f(x)\big\rvert, \qquad \log p_X(x) = \log p_Z\!\big(f(x)\big) + \log\big\lvert\det J_f(x)\big\rvert.

Once we can evaluate log⁡pX\log p_X, entropy is a one-line Monte-Carlo estimate, H(X)≈−1N∑nlog⁡pX(xn)H(X) \approx -\tfrac{1}{N}\sum_n \log p_X(x_n), and MI / KL follow from their definitions above. Both RBIG’s AnnealedRBIG.score_samples and the gauss_flows flow.log_prob implement exactly this formula — the Jacobian is accumulated layer by layer.

The RBIG-way (iterative reduction) route

A Gaussianization flow is a stack of layers, each a marginal Gaussianization followed by a rotation. After layer kk the data is x(k)x^{(k)}, and each layer removes some dependence. Define the information reduction of a layer as the drop in total correlation it produces:

ΔTCk=TC(x(k−1))−TC(x(k)).\Delta\mathrm{TC}_k = \mathrm{TC}\big(x^{(k-1)}\big) - \mathrm{TC}\big(x^{(k)}\big).

Because the final latent z=x(K)z = x^{(K)} is (approximately) independent standard-normal with TC(z)≈0\mathrm{TC}(z)\approx 0, the reductions telescope to the total correlation of the data — without ever evaluating a density or a Jacobian:

TC(X)=∑k=1KΔTCk=TC(x(0))−TC(z).\mathrm{TC}(X) = \sum_{k=1}^{K} \Delta\mathrm{TC}_k = \mathrm{TC}\big(x^{(0)}\big) - \mathrm{TC}(z).

Entropy then follows from the marginal decomposition, and KL from a per-marginal divergence to a standard normal plus the residual dependence:

H(X)=∑iH(Xi)−TC(X),KL(P ∥ Q)≈∑dKL ⁣(zd ∥ N(0,1))+TC(z),H(X) = \sum_i H(X_i) - \mathrm{TC}(X), \qquad \mathrm{KL}(P\,\|\,Q) \approx \sum_d \mathrm{KL}\!\big(z_d \,\|\, \mathcal{N}(0,1)\big) + \mathrm{TC}(z),

where z=fQ(x)z = f_Q(x) applies the reference (QQ) Gaussianization to the query (PP) samples.

Iterative vs. trained: two ways to build the same flow

The two gauss_flows models are fit in fundamentally different ways, and it is worth being explicit about the contrast — it is the reason the RBIG warm-start matters.

Iterative (RBIG)Trained (gradient ML)
How it is fitgreedily, one layer at a time, with closed-form / EM sub-fits (PCA rotation + per-dim mixture or histogram). No gradients.jointly, by gradient descent on all parameters at once.
Objectiveeach layer locally maximizes the Gaussianity of the current marginals (maximizes ΔTCk\Delta\mathrm{TC}_k).globally minimizes the negative log-likelihood −EX[log⁡pX(x)]-\mathbb{E}_X[\log p_X(x)], i.e. min⁡θDKL(pdata ∣ pθ)\min_\theta D_{\mathrm{KL}}(p_{\text{data}} \,|\, p_\theta).
Natural estimatorper-layer reduction ∑kΔTCk\sum_k \Delta\mathrm{TC}_k (the RBIG-way).the exact density log⁡pX\log p_X (change-of-variables).
Cost & behaviourfast, deterministic, hard to overfit; but needs many layers and each layer is only locally optimal.fewer, more expressive layers; can couple dimensions a rotation cannot; but needs a good initialization and an optimizer.

Crucially the two agree in the limit: both drive the latent toward independence, so both recover the same TC(X)\mathrm{TC}(X). They differ in how they get there — the iterative method takes many cheap, locally-greedy steps, while the trained method takes a few expensive, globally-coordinated ones. The best of both worlds is to warm-start the trainable flow from the iterative RBIG solution and then fine-tune: the flow already sits near a good optimum, so a handful of gradient epochs sharpen the density rather than having to discover the Gaussianization from scratch. That is exactly the recipe used for both gauss_flows models below.

1. Synthetic data

We build a 4-dimensional Gaussian split into two 2-D blocks XX and YY with cross-correlations ρ=0.8\rho = 0.8 and ρ=0.5\rho = 0.5, exactly as in the RBIG notebook. Because the data is Gaussian, every measure has a closed form, which gives us an exact yardstick for the two estimators. For the KL divergence we use a mean-shifted copy of XX.

/home/azureuser/.cache/uv/archive-v0/f1Q8rI7QUTdFMdRtBr6AD/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
X: (2000, 2), Y: (2000, 2), XY: (2000, 4)

2. Analytical ground truth

Closed-form Gaussian expressions via gauss_flows’s analytical helpers — these evaluate the equations from Section 0 directly on the known covariance, so they are exact (up to the sampling of the empirical covariance).

H(X)     = +2.8379
H(X,Y)   = +5.0211
TC(X)    = +0.0000
TC(X,Y)  = +0.6547
MI(X;Y)  = +0.6547
KL       = +0.1250

3. Fit the three models

3a. RBIG (rbig package)

AnnealedRBIG is the iterative model: it Gaussianizes greedily, one (rotation, marginal) block at a time, recording the total correlation remaining after each block. No gradients are involved.

3b. gauss_flows models — RBIG warm-start + short fine-tune

Each flow is first warm-started with the gradient-free RBIG procedure (Section “Iterative vs. trained”), which already places it near a good Gaussianization, and then fine-tuned with a few epochs of fit_flow, the pipekit-train loop of notebook 01 (gradient maximum-likelihood). Because the warm-start did the heavy lifting, only light training is needed for the density to become accurate.

GF-Diagonal   mean log-likelihood on XY: -5.0724 nats
GF-Coupling   mean log-likelihood on XY: -4.9694 nats

4. Change-of-variables estimates

Here every estimate uses an exact log-density, following H(X)≈−1N∑nlog⁡pX(xn)H(X) \approx -\tfrac1N\sum_n \log p_X(x_n) and the definitions of MI and KL. For the flows the density is flow.log_prob (Monte-Carlo over flow samples); for RBIG it is AnnealedRBIG.score_samples (the same change-of-variables formula, with the per-layer log-determinant Jacobian).

5. RBIG-way estimates

These accumulate the total correlation removed by the Gaussianization (TC(X)=∑kΔTCk\mathrm{TC}(X) = \sum_k \Delta\mathrm{TC}_k), with entropy and KL following the decompositions in Section 0. No Jacobian is evaluated. For the flows we use total_correlation_reduction / entropy_reduction / kl_divergence_reduction; for RBIG we use the estimate_* helpers. Mutual information is the total correlation of the jointly Gaussianized blocks, I(X;Y)=TC([ GX(X),GY(Y) ])I(X;Y) = \mathrm{TC}\big([\,G_X(X), G_Y(Y)\,]\big).

6. Comparison

Columns are the three models; rows group the measures by estimation method. Read the two change-of-vars / RBIG-way rows for each measure side by side: the iterative RBIG-way estimates (which only need per-layer reductions) track the analytical values about as well as the trained change-of-variables estimates (which need the full density), confirming that the two routes agree.

Loading...

7. Visual comparison

Absolute error of each estimator against the analytical ground truth. Lower is better; the two panels let us compare the change-of-variables (trained density) and RBIG-way (iterative reduction) routes directly.

<Figure size 1300x450 with 2 Axes>

Summary

All three models recover the analytical Gaussian quantities closely. The two estimation routes mirror the two ways the flows are built:

  • the change-of-variables route leans on each model’s exact log-density log⁡pX(x)=log⁡pZ(f(x))+log⁡∣det⁡Jf(x)∣\log p_X(x) = \log p_Z(f(x)) + \log\lvert\det J_f(x)\rvert — the natural estimator for a trained (maximum-likelihood) flow;

  • the RBIG-way route only needs the total correlation removed by Gaussianization, TC(X)=∑kΔTCk\mathrm{TC}(X) = \sum_k \Delta\mathrm{TC}_k — the natural estimator for an iterative flow, and it never forms a Jacobian.

The RBIG warm-start is what lets the gauss_flows diagonal and coupling flows reach accurate densities after only a short fine-tune: the iterative solution supplies a near-optimal initialization, and gradient training then sharpens it.