Information Theory¶
A Gaussianization flow is also an information-theoretic estimator. Because the flow gives a tractable density, differential entropy follows from the Monte-Carlo identity
and total correlation, mutual information, KL, and negentropy reduce to combinations of entropies. This module offers three families that share the measures but differ in how the density is obtained.
Flow-based (Monte-Carlo) estimators¶
Estimate a measure from a trained flow by sampling and scoring. Each takes the flow, a sample
count n_samples, and a key; the estimate's variance shrinks as \(O(1/\sqrt{N})\).
entropy
¶
Differential entropy of a flow (flow-based Monte-Carlo estimator).
Draws samples from the trained dist and averages its exact log-density:
The estimate converges as O(1/√N) in n_samples.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dist
|
AbstractDistribution
|
A trained flowjax distribution exposing |
required |
n_samples
|
int
|
Number of Monte-Carlo samples. Defaults to 10000. |
10000
|
key
|
PRNGKeyArray
|
JAX PRNG key used to draw the samples. |
required |
Returns:
| Type | Description |
|---|---|
Array
|
Scalar differential-entropy estimate (in nats). |
Examples:
Requires a fitted flow, so the call is slow and non-deterministic:
import jax.random as jr
from gauss_flows_models.info_theory import entropy
h = entropy(trained_flow, n_samples=10000, key=jr.key(0))
Source code in packages/gauss-flows-models/src/gauss_flows_models/_src/info_theory.py
total_correlation
¶
total_correlation(dist: AbstractDistribution, n_samples: int = 10000, *, key: PRNGKeyArray) -> Array
Total correlation of a flow (flow-based Monte-Carlo estimator).
Total correlation (multi-information) is the gap between the sum of marginal entropies and the joint entropy:
Samples are drawn from the trained dist; the joint entropy is the
Monte-Carlo average −(1/N) Σ log p(xᵢ), while each marginal entropy uses a
Gaussian fitted to the corresponding sample column. Converges as O(1/√N).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dist
|
AbstractDistribution
|
A trained flowjax distribution with a 1-D event shape. |
required |
n_samples
|
int
|
Number of Monte-Carlo samples. Defaults to 10000. |
10000
|
key
|
PRNGKeyArray
|
JAX PRNG key used to draw the samples. |
required |
Returns:
| Type | Description |
|---|---|
Array
|
Scalar total-correlation estimate (in nats). |
Examples:
Requires a fitted flow, so the call is slow and non-deterministic:
import jax.random as jr
from gauss_flows_models.info_theory import total_correlation
tc = total_correlation(trained_flow, n_samples=10000, key=jr.key(0))
Source code in packages/gauss-flows-models/src/gauss_flows_models/_src/info_theory.py
mutual_information
¶
mutual_information(dist_xy: AbstractDistribution, dist_x: AbstractDistribution, dist_y: AbstractDistribution, n_samples: int = 10000, *, key: PRNGKeyArray) -> Array
Mutual information I(X; Y) of flows (flow-based Monte-Carlo estimator).
Combines three Monte-Carlo entropy estimates of the supplied trained flows:
Each entropy is estimated via entropy from independent sample
batches, so the result converges as O(1/√N).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dist_xy
|
AbstractDistribution
|
Trained joint distribution of (X, Y). |
required |
dist_x
|
AbstractDistribution
|
Trained marginal distribution of X. |
required |
dist_y
|
AbstractDistribution
|
Trained marginal distribution of Y. |
required |
n_samples
|
int
|
Number of Monte-Carlo samples per entropy term. Defaults to 10000. |
10000
|
key
|
PRNGKeyArray
|
JAX PRNG key; split three ways for the three entropy estimates. |
required |
Returns:
| Type | Description |
|---|---|
Array
|
Scalar mutual-information estimate (in nats). |
Examples:
Requires fitted flows, so the call is slow and non-deterministic:
import jax.random as jr
from gauss_flows_models.info_theory import mutual_information
mi = mutual_information(flow_xy, flow_x, flow_y, key=jr.key(0))
Source code in packages/gauss-flows-models/src/gauss_flows_models/_src/info_theory.py
kl_divergence
¶
kl_divergence(dist_p: AbstractDistribution, dist_q: AbstractDistribution, n_samples: int = 10000, *, key: PRNGKeyArray) -> Array
KL divergence KL(P ‖ Q) of flows (flow-based Monte-Carlo estimator).
Samples are drawn from dist_p and both flows' exact log-densities are
averaged:
Converges as O(1/√N) in n_samples.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dist_p
|
AbstractDistribution
|
Trained distribution P; samples are drawn from this. |
required |
dist_q
|
AbstractDistribution
|
Trained distribution Q; log-probs are evaluated under this. |
required |
n_samples
|
int
|
Number of Monte-Carlo samples. Defaults to 10000. |
10000
|
key
|
PRNGKeyArray
|
JAX PRNG key used to draw the samples from P. |
required |
Returns:
| Type | Description |
|---|---|
Array
|
Scalar KL-divergence estimate (in nats). |
Examples:
Requires fitted flows, so the call is slow and non-deterministic:
import jax.random as jr
from gauss_flows_models.info_theory import kl_divergence
kl = kl_divergence(flow_p, flow_q, n_samples=10000, key=jr.key(0))
Source code in packages/gauss-flows-models/src/gauss_flows_models/_src/info_theory.py
negentropy
¶
Negentropy of a flow (flow-based Monte-Carlo estimator).
Negentropy is the entropy gap to the Gaussian of matched moments — a non-negative measure of non-Gaussianity:
where X_gauss is the Normal sharing the per-dimension mean and standard
deviation of the samples drawn from dist. Both entropies are estimated
via entropy, so the result converges as O(1/√N).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dist
|
AbstractDistribution
|
A trained flowjax distribution. |
required |
n_samples
|
int
|
Number of Monte-Carlo samples. Defaults to 10000. |
10000
|
key
|
PRNGKeyArray
|
JAX PRNG key used to draw the samples and estimate both entropies. |
required |
Returns:
| Type | Description |
|---|---|
Array
|
Scalar negentropy estimate (in nats). |
Examples:
Requires a fitted flow, so the call is slow and non-deterministic:
import jax.random as jr
from gauss_flows_models.info_theory import negentropy
j = negentropy(trained_flow, n_samples=10000, key=jr.key(0))
Source code in packages/gauss-flows-models/src/gauss_flows_models/_src/info_theory.py
Analytical Gaussian closed forms¶
Exact values for (multivariate) Gaussians — useful as ground truth in tests and as a baseline. For a covariance \(\Sigma\) the differential entropy is \(H = \tfrac12\log\!\big((2\pi e)^D\,|\Sigma|\big)\), and total correlation / mutual information follow from the log-determinant gap between the joint and its marginals.
The four Gaussian forms are computed with gaussx: gaussian_entropy and gaussian_kl_divergence call gaussx.gaussian_entropy and gaussx.gaussian_kl, and gaussian_total_correlation and gaussian_mutual_information are differences of gaussx.gaussian_entropy values. Every covariance argument accepts either a dense array of shape \((D, D)\), which is wrapped as a positive-semidefinite lineax.MatrixLinearOperator, or a lineax operator, so a diagonal, low-rank-plus-diagonal, Kronecker or banded covariance keeps its structure through the log-determinant and the solves. The marginal variances of total correlation are read with gaussx.diag. The diagonal blocks of mutual information keep the structure of a diagonal, tagged or low-rank-plus-diagonal covariance, and any other operator is densified to cut the blocks out.
gaussian_entropy
¶
Differential entropy of a Gaussian (analytical Gaussian closed form).
Deterministic, sample-free closed form in the covariance, computed by
gaussx.gaussian_entropy:
The log-determinant dispatches on the structure of Σ, so a diagonal, low-rank-plus-diagonal, Kronecker or banded covariance is never densified.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
covariance
|
ArrayLike | AbstractLinearOperator
|
Covariance Σ of size |
required |
Returns:
| Type | Description |
|---|---|
Array
|
Scalar differential entropy (in nats). |
Examples:
>>> import jax.numpy as jnp
>>> from gauss_flows_models.info_theory import gaussian_entropy
>>> round(float(gaussian_entropy(jnp.eye(3))), 4)
4.2568
Source code in packages/gauss-flows-models/src/gauss_flows_models/_src/info_theory.py
gaussian_total_correlation
¶
Total correlation of a Gaussian (analytical Gaussian closed form).
Deterministic, sample-free closed form comparing the diagonal variances to
the full covariance, as a difference of gaussx.gaussian_entropy values:
The variances Σᵢᵢ come from gaussx.diag, which reads them off a
diagonal, low-rank-plus-diagonal, Kronecker or block-diagonal operator
without forming it, and materialises an operator that has no structural
rule. It is zero exactly when Σ is diagonal (independent components).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
covariance
|
ArrayLike | AbstractLinearOperator
|
Covariance Σ of size |
required |
Returns:
| Type | Description |
|---|---|
Array
|
Scalar total correlation (in nats). |
Examples:
>>> import jax.numpy as jnp
>>> from gauss_flows_models.info_theory import gaussian_total_correlation
>>> cov = jnp.array([[1.0, 0.5], [0.5, 1.0]])
>>> round(float(gaussian_total_correlation(cov)), 4)
0.1438
>>> float(gaussian_total_correlation(jnp.eye(2))) # diagonal → 0
0.0
Source code in packages/gauss-flows-models/src/gauss_flows_models/_src/info_theory.py
gaussian_mutual_information
¶
Mutual information of Gaussian blocks (analytical Gaussian closed form).
Deterministic, sample-free closed form. The joint covariance is partitioned
into the leading dim_x dimensions (X) and the remainder (Y), then:
each entropy evaluated by gaussx.gaussian_entropy.
The diagonal blocks Σ_xx and Σ_yy keep the structure of Σ when Σ is
diagonal, tagged, or a low-rank update A₀ + U D Vᵀ (the block is then
A₀[s, s] + U[s] D V[s]ᵀ, again low-rank plus the base's structure).
Any other operator is densified with as_matrix to cut the blocks out.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
covariance
|
ArrayLike | AbstractLinearOperator
|
Joint covariance of |
required |
dim_x
|
int
|
Number of leading dimensions belonging to X. |
required |
Returns:
| Type | Description |
|---|---|
Array
|
Scalar mutual information (in nats). |
Examples:
>>> import jax.numpy as jnp
>>> from gauss_flows_models.info_theory import gaussian_mutual_information
>>> cov = jnp.array([[1.0, 0.5], [0.5, 1.0]])
>>> round(float(gaussian_mutual_information(cov, dim_x=1)), 4)
0.1438
Source code in packages/gauss-flows-models/src/gauss_flows_models/_src/info_theory.py
gaussian_kl_divergence
¶
gaussian_kl_divergence(mean_p: ArrayLike, cov_p: ArrayLike | AbstractLinearOperator, mean_q: ArrayLike, cov_q: ArrayLike | AbstractLinearOperator) -> Array
KL divergence of two Gaussians (analytical Gaussian closed form).
Deterministic, sample-free closed form, computed by gaussx.gaussian_kl,
which dispatches the solves and log-determinants on the structure of the
covariances:
It is zero exactly when the two Gaussians coincide.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mean_p
|
ArrayLike
|
Mean of P, shape |
required |
cov_p
|
ArrayLike | AbstractLinearOperator
|
Covariance of P, a dense array of shape |
required |
mean_q
|
ArrayLike
|
Mean of Q, shape |
required |
cov_q
|
ArrayLike | AbstractLinearOperator
|
Covariance of Q, a dense array of shape |
required |
Returns:
| Type | Description |
|---|---|
Array
|
Scalar KL divergence (in nats). |
Examples:
>>> import jax.numpy as jnp
>>> from gauss_flows_models.info_theory import gaussian_kl_divergence
>>> mu, eye = jnp.zeros(2), jnp.eye(2)
>>> float(gaussian_kl_divergence(mu, eye, mu, eye)) # identical → 0
0.0
Source code in packages/gauss-flows-models/src/gauss_flows_models/_src/info_theory.py
RBIG-way reductions¶
The original RBIG estimators read a measure off the total-correlation reduction achieved by
each Gaussianization layer, accumulated across the stack rather than scored from the final
density. information_reduction is the per-pair building block; the others sum it along a
fitted flow.
information_reduction
¶
information_reduction(x_before: ArrayLike, x_after: ArrayLike, *, n_bins: int | None = None) -> Array
Total correlation removed between two representations (RBIG-way reduction).
The building block of the RBIG-way estimators: the drop in total
correlation when moving from x_before to x_after:
with TC(X) = Σᵢ H(Xᵢ) − H(X), marginal entropies estimated from
histograms and the joint entropy from the Gaussian (maximum-entropy)
approximation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x_before
|
ArrayLike
|
Data before the transformation, shape |
required |
x_after
|
ArrayLike
|
Data after the transformation, shape |
required |
n_bins
|
int | None
|
Histogram bins per marginal. Defaults to |
None
|
Returns:
| Type | Description |
|---|---|
Array
|
Scalar total-correlation reduction (in nats). |
Examples:
Plain sampled data, no flow required:
from gauss_flows_models.info_theory import information_reduction
delta_tc = information_reduction(x_before, x_after)
Source code in packages/gauss-flows-models/src/gauss_flows_models/_src/info_theory.py
total_correlation_reduction
¶
total_correlation_reduction(flow: AbstractDistribution, x: ArrayLike, *, n_bins: int | None = None) -> Array
Total correlation of x via a Gaussianization flow (RBIG-way).
The flow Gaussianizes the data, z = f(x), via flow.bijection.inverse.
The total correlation removed is the drop from the data to the
(approximately independent) latent representation:
which mirrors RBIG's total_correlation_reduction. No Jacobian is needed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
flow
|
AbstractDistribution
|
A fitted flowjax |
required |
x
|
ArrayLike
|
Data of shape |
required |
n_bins
|
int | None
|
Histogram bins per marginal. Defaults to |
None
|
Returns:
| Type | Description |
|---|---|
Array
|
Scalar total-correlation estimate in nats. |
Source code in packages/gauss-flows-models/src/gauss_flows_models/_src/info_theory.py
entropy_reduction
¶
Differential entropy of x via a Gaussianization flow (RBIG-way).
Uses the decomposition H(X) = sum_i H(X_i) - TC(X) with the marginal
entropies estimated from histograms and TC(X) obtained from
total_correlation_reduction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
flow
|
AbstractDistribution
|
A fitted flowjax |
required |
x
|
ArrayLike
|
Data of shape |
required |
n_bins
|
int | None
|
Histogram bins per marginal. Defaults to |
None
|
Returns:
| Type | Description |
|---|---|
Array
|
Scalar differential-entropy estimate in nats. |
Source code in packages/gauss-flows-models/src/gauss_flows_models/_src/info_theory.py
kl_divergence_reduction
¶
kl_divergence_reduction(flow_ref: AbstractDistribution, x_query: ArrayLike, *, n_bins: int | None = None) -> Array
KL divergence KL(P || Q) via a reference Gaussianization (RBIG-way).
The reference flow flow_ref Gaussianizes Q (the distribution it was
fitted to). Applying that same map to samples x_query drawn from P
gives z = f_Q(x); if P == Q then z is standard normal. The
divergence is recovered as the per-marginal KL to a standard normal plus the
residual total correlation:
This mirrors RBIG's estimate_kld and requires no Jacobian.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
flow_ref
|
AbstractDistribution
|
A flow fitted to the reference distribution |
required |
x_query
|
ArrayLike
|
Samples from |
required |
n_bins
|
int | None
|
Histogram bins per marginal. Defaults to |
None
|
Returns:
| Type | Description |
|---|---|
Array
|
Scalar KL-divergence estimate in nats. |