Skip to content

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

\[ H(X) \;=\; -\,\mathbb{E}_{x\sim p_X}\big[\log p_X(x)\big] \;\approx\; -\frac{1}{N}\sum_{i=1}^{N}\log p_X(x_i),\qquad x_i \sim p_X, \]

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

entropy(dist: AbstractDistribution, n_samples: int = 10000, *, key: PRNGKeyArray) -> Array

Differential entropy of a flow (flow-based Monte-Carlo estimator).

Draws samples from the trained dist and averages its exact log-density:

H(X) = −E[log p(X)] ≈ −(1/N) Σᵢ log p(xᵢ),   xᵢ ∼ dist.

The estimate converges as O(1/√N) in n_samples.

Parameters:

Name Type Description Default
dist AbstractDistribution

A trained flowjax distribution exposing sample and log_prob.

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
def entropy(
    dist: AbstractDistribution, n_samples: int = 10000, *, key: PRNGKeyArray
) -> Array:
    """Differential entropy of a flow (flow-based Monte-Carlo estimator).

    Draws samples from the trained ``dist`` and averages its exact log-density:
    ```python
    H(X) = −E[log p(X)] ≈ −(1/N) Σᵢ log p(xᵢ),   xᵢ ∼ dist.
    ```

    The estimate converges as O(1/√N) in ``n_samples``.

    Args:
        dist: A trained flowjax distribution exposing ``sample`` and
            ``log_prob``.
        n_samples: Number of Monte-Carlo samples. Defaults to 10000.
        key: JAX PRNG key used to draw the samples.

    Returns:
        Scalar differential-entropy estimate (in nats).

    Examples:
        Requires a fitted flow, so the call is slow and non-deterministic:
        ```python
        import jax.random as jr
        from gauss_flows_models.info_theory import entropy

        h = entropy(trained_flow, n_samples=10000, key=jr.key(0))
        ```
    """
    samples = dist.sample(key, (n_samples,))
    log_probs = dist.log_prob(samples)
    return -jnp.mean(log_probs)

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:

TC(X) = Σᵢ H(Xᵢ) − H(X).

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
def 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:
    ```python
    TC(X) = Σᵢ H(Xᵢ) − H(X).
    ```

    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).

    Args:
        dist: A trained flowjax distribution with a 1-D event shape.
        n_samples: Number of Monte-Carlo samples. Defaults to 10000.
        key: JAX PRNG key used to draw the samples.

    Returns:
        Scalar total-correlation estimate (in nats).

    Examples:
        Requires a fitted flow, so the call is slow and non-deterministic:
        ```python
        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))
        ```
    """
    import jax.random as jr

    key1, _key2 = jr.split(key)
    samples = dist.sample(key1, (n_samples,))
    log_probs = dist.log_prob(samples)
    joint_entropy = -jnp.mean(log_probs)

    from flowjax.distributions import Normal

    n_dims = samples.shape[-1]
    marginal_entropies = jnp.zeros(())
    for i in range(n_dims):
        xi = samples[:, i]
        # Fit a simple Gaussian to the marginal
        mean_i = jnp.mean(xi)
        std_i = jnp.std(xi)
        marginal_dist = Normal(mean_i, std_i)
        log_p_marginal = marginal_dist.log_prob(xi[:, None])
        marginal_entropies = marginal_entropies + (-jnp.mean(log_p_marginal))

    return marginal_entropies - joint_entropy

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:

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

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
def 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:
    ```python
    I(X; Y) = H(X) + H(Y) − H(X, Y).
    ```

    Each entropy is estimated via `entropy` from independent sample
    batches, so the result converges as O(1/√N).

    Args:
        dist_xy: Trained joint distribution of (X, Y).
        dist_x: Trained marginal distribution of X.
        dist_y: Trained marginal distribution of Y.
        n_samples: Number of Monte-Carlo samples per entropy term.
            Defaults to 10000.
        key: JAX PRNG key; split three ways for the three entropy estimates.

    Returns:
        Scalar mutual-information estimate (in nats).

    Examples:
        Requires fitted flows, so the call is slow and non-deterministic:
        ```python
        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))
        ```
    """
    import jax.random as jr

    key1, key2, key3 = jr.split(key, 3)
    h_xy = entropy(dist_xy, n_samples=n_samples, key=key1)
    h_x = entropy(dist_x, n_samples=n_samples, key=key2)
    h_y = entropy(dist_y, n_samples=n_samples, key=key3)
    return h_x + h_y - h_xy

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:

KL(P ‖ Q) = E_P[log p(X) − log q(X)]
          ≈ (1/N) Σᵢ [log p(xᵢ) − log q(xᵢ)],   xᵢ ∼ dist_p.

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
def 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:
    ```python
    KL(P ‖ Q) = E_P[log p(X) − log q(X)]
              ≈ (1/N) Σᵢ [log p(xᵢ) − log q(xᵢ)],   xᵢ ∼ dist_p.
    ```

    Converges as O(1/√N) in ``n_samples``.

    Args:
        dist_p: Trained distribution P; samples are drawn from this.
        dist_q: Trained distribution Q; log-probs are evaluated under this.
        n_samples: Number of Monte-Carlo samples. Defaults to 10000.
        key: JAX PRNG key used to draw the samples from P.

    Returns:
        Scalar KL-divergence estimate (in nats).

    Examples:
        Requires fitted flows, so the call is slow and non-deterministic:
        ```python
        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))
        ```
    """
    samples = dist_p.sample(key, (n_samples,))
    log_p = dist_p.log_prob(samples)
    log_q = dist_q.log_prob(samples)
    return jnp.mean(log_p - log_q)

negentropy

negentropy(dist: AbstractDistribution, n_samples: int = 10000, *, key: PRNGKeyArray) -> Array

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:

J(X) = H(X_gauss) − H(X),

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
def negentropy(
    dist: AbstractDistribution, n_samples: int = 10000, *, key: PRNGKeyArray
) -> Array:
    """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:
    ```python
    J(X) = H(X_gauss) − H(X),
    ```

    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).

    Args:
        dist: A trained flowjax distribution.
        n_samples: Number of Monte-Carlo samples. Defaults to 10000.
        key: JAX PRNG key used to draw the samples and estimate both entropies.

    Returns:
        Scalar negentropy estimate (in nats).

    Examples:
        Requires a fitted flow, so the call is slow and non-deterministic:
        ```python
        import jax.random as jr
        from gauss_flows_models.info_theory import negentropy

        j = negentropy(trained_flow, n_samples=10000, key=jr.key(0))
        ```
    """
    import jax.random as jr
    from flowjax.distributions import Normal

    key1, key2 = jr.split(key)
    samples = dist.sample(key1, (n_samples,))

    # Estimate entropy of the distribution
    h = entropy(dist, n_samples=n_samples, key=key2)

    # Entropy of a Gaussian with the same mean and variance
    mean = jnp.mean(samples, axis=0)
    std = jnp.std(samples, axis=0)
    gauss = Normal(mean, std)
    h_gauss = entropy(gauss, n_samples=n_samples, key=key2)

    return h_gauss - h

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

gaussian_entropy(covariance: ArrayLike | AbstractLinearOperator) -> Array

Differential entropy of a Gaussian (analytical Gaussian closed form).

Deterministic, sample-free closed form in the covariance, computed by gaussx.gaussian_entropy:

H(X) = ½ log |2π e Σ| = ½ (d log(2π e) + log|Σ|).

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 d, either a dense array of shape (d, d) (wrapped as a PSD-tagged lineax.MatrixLinearOperator) or a lineax operator.

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
def gaussian_entropy(covariance: ArrayLike | lx.AbstractLinearOperator) -> Array:
    """Differential entropy of a Gaussian (analytical Gaussian closed form).

    Deterministic, sample-free closed form in the covariance, computed by
    `gaussx.gaussian_entropy`:
    ```python
    H(X) = ½ log |2π e Σ| = ½ (d log(2π e) + log|Σ|).
    ```

    The log-determinant dispatches on the structure of Σ, so a diagonal,
    low-rank-plus-diagonal, Kronecker or banded covariance is never densified.

    Args:
        covariance: Covariance Σ of size ``d``, either a dense array of shape
            ``(d, d)`` (wrapped as a PSD-tagged `lineax.MatrixLinearOperator`)
            or a lineax operator.

    Returns:
        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
    """
    return gx.gaussian_entropy(_as_covariance_operator(covariance))

gaussian_total_correlation

gaussian_total_correlation(covariance: ArrayLike | AbstractLinearOperator) -> Array

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:

TC(X) = Σᵢ H(𝒩(0, Σᵢᵢ)) − H(𝒩(0, Σ)) = ½ [ Σᵢ log Σᵢᵢ − log|Σ| ].

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 d, either a dense array of shape (d, d) or a lineax operator.

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
def gaussian_total_correlation(
    covariance: ArrayLike | lx.AbstractLinearOperator,
) -> Array:
    """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:
    ```python
    TC(X) = Σᵢ H(𝒩(0, Σᵢᵢ)) − H(𝒩(0, Σ)) = ½ [ Σᵢ log Σᵢᵢ − log|Σ| ].
    ```

    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).

    Args:
        covariance: Covariance Σ of size ``d``, either a dense array of shape
            ``(d, d)`` or a lineax operator.

    Returns:
        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
    """
    operator = _as_covariance_operator(covariance)
    # Σᵢᵢ, the marginal variances, as a diagonal covariance
    marginals = lx.DiagonalLinearOperator(gx.diag(operator))
    # sum_i H(N(0, Sigma_ii)) - H(N(0, Sigma))
    return gx.gaussian_entropy(marginals) - gx.gaussian_entropy(operator)

gaussian_mutual_information

gaussian_mutual_information(covariance: ArrayLike | AbstractLinearOperator, dim_x: int) -> Array

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:

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

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 [X, Y] of size d, either a dense array of shape (d, d) or a lineax operator.

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
def gaussian_mutual_information(
    covariance: ArrayLike | lx.AbstractLinearOperator, dim_x: int
) -> Array:
    """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:
    ```python
    I(X; Y) = H(X) + H(Y) − H(X, Y),
    ```

    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.

    Args:
        covariance: Joint covariance of ``[X, Y]`` of size ``d``, either a
            dense array of shape ``(d, d)`` or a lineax operator.
        dim_x: Number of leading dimensions belonging to X.

    Returns:
        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
    """
    operator = _as_covariance_operator(covariance)
    size = operator.in_size()
    cov_xx = _diagonal_block(operator, 0, dim_x)
    cov_yy = _diagonal_block(operator, dim_x, size)
    # H(X) + H(Y) - H(X, Y)
    return (
        gx.gaussian_entropy(cov_xx)
        + gx.gaussian_entropy(cov_yy)
        - gx.gaussian_entropy(operator)
    )

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:

KL(N_p ‖ N_q) = ½ [ tr(Σ_q⁻¹ Σ_p)
                    + (μ_q − μ_p)ᵀ Σ_q⁻¹ (μ_q − μ_p) − d
                    + log(|Σ_q| / |Σ_p|) ].

It is zero exactly when the two Gaussians coincide.

Parameters:

Name Type Description Default
mean_p ArrayLike

Mean of P, shape (d,).

required
cov_p ArrayLike | AbstractLinearOperator

Covariance of P, a dense array of shape (d, d) or a lineax operator.

required
mean_q ArrayLike

Mean of Q, shape (d,).

required
cov_q ArrayLike | AbstractLinearOperator

Covariance of Q, a dense array of shape (d, d) or a lineax operator.

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
def gaussian_kl_divergence(
    mean_p: ArrayLike,
    cov_p: ArrayLike | lx.AbstractLinearOperator,
    mean_q: ArrayLike,
    cov_q: ArrayLike | lx.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:
    ```python
    KL(N_p ‖ N_q) = ½ [ tr(Σ_q⁻¹ Σ_p)
                        + (μ_q − μ_p)ᵀ Σ_q⁻¹ (μ_q − μ_p) − d
                        + log(|Σ_q| / |Σ_p|) ].
    ```

    It is zero exactly when the two Gaussians coincide.

    Args:
        mean_p: Mean of P, shape ``(d,)``.
        cov_p: Covariance of P, a dense array of shape ``(d, d)`` or a lineax
            operator.
        mean_q: Mean of Q, shape ``(d,)``.
        cov_q: Covariance of Q, a dense array of shape ``(d, d)`` or a lineax
            operator.

    Returns:
        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
    """
    return gx.gaussian_kl(
        jnp.asarray(mean_p),
        _as_covariance_operator(cov_p),
        jnp.asarray(mean_q),
        _as_covariance_operator(cov_q),
    )

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:

Δ_TC = TC(x_before) − TC(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 (n, d).

required
x_after ArrayLike

Data after the transformation, shape (n, d).

required
n_bins int | None

Histogram bins per marginal. Defaults to round(√n).

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
def 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``:
    ```python
    Δ_TC = TC(x_before) − TC(x_after),
    ```

    with ``TC(X) = Σᵢ H(Xᵢ) − H(X)``, marginal entropies estimated from
    histograms and the joint entropy from the Gaussian (maximum-entropy)
    approximation.

    Args:
        x_before: Data before the transformation, shape ``(n, d)``.
        x_after: Data after the transformation, shape ``(n, d)``.
        n_bins: Histogram bins per marginal. Defaults to ``round(√n)``.

    Returns:
        Scalar total-correlation reduction (in nats).

    Examples:
        Plain sampled data, no flow required:
        ```python
        from gauss_flows_models.info_theory import information_reduction

        delta_tc = information_reduction(x_before, x_after)
        ```
    """
    xb = jnp.asarray(x_before)
    xa = jnp.asarray(x_after)
    bins = _n_bins(xb.shape[0], n_bins)
    return _total_correlation_estimate(xb, bins) - _total_correlation_estimate(xa, bins)

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:

TC(X) ~= TC(x) - TC(z)

which mirrors RBIG's total_correlation_reduction. No Jacobian is needed.

Parameters:

Name Type Description Default
flow AbstractDistribution

A fitted flowjax Transformed distribution whose bijection maps the latent base to the data space.

required
x ArrayLike

Data of shape (n, d).

required
n_bins int | None

Histogram bins per marginal. Defaults to round(sqrt(n)).

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
def 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:
    ```python
    TC(X) ~= TC(x) - TC(z)
    ```

    which mirrors RBIG's ``total_correlation_reduction``. No Jacobian is needed.

    Args:
        flow: A fitted flowjax ``Transformed`` distribution whose bijection
            maps the latent base to the data space.
        x: Data of shape ``(n, d)``.
        n_bins: Histogram bins per marginal. Defaults to ``round(sqrt(n))``.

    Returns:
        Scalar total-correlation estimate in nats.
    """
    xx = jnp.asarray(x)
    z = jax.vmap(flow.bijection.inverse)(xx)
    return information_reduction(xx, z, n_bins=n_bins)

entropy_reduction

entropy_reduction(flow: AbstractDistribution, x: ArrayLike, *, n_bins: int | None = None) -> Array

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 Transformed distribution.

required
x ArrayLike

Data of shape (n, d).

required
n_bins int | None

Histogram bins per marginal. Defaults to round(sqrt(n)).

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
def entropy_reduction(
    flow: AbstractDistribution, x: ArrayLike, *, n_bins: int | None = None
) -> Array:
    """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`.

    Args:
        flow: A fitted flowjax ``Transformed`` distribution.
        x: Data of shape ``(n, d)``.
        n_bins: Histogram bins per marginal. Defaults to ``round(sqrt(n))``.

    Returns:
        Scalar differential-entropy estimate in nats.
    """
    xx = jnp.asarray(x)
    bins = _n_bins(xx.shape[0], n_bins)
    marginal = _marginal_entropy_sum(xx, bins)
    tc = total_correlation_reduction(flow, xx, n_bins=bins)
    return marginal - tc

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:

KL(P || Q) ~= sum_d KL(z_d || N(0, 1)) + TC(z)

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 Q.

required
x_query ArrayLike

Samples from P of shape (n, d).

required
n_bins int | None

Histogram bins per marginal. Defaults to round(sqrt(n)).

None

Returns:

Type Description
Array

Scalar KL-divergence estimate in nats.

Source code in packages/gauss-flows-models/src/gauss_flows_models/_src/info_theory.py
def 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:
    ```python
    KL(P || Q) ~= sum_d KL(z_d || N(0, 1)) + TC(z)
    ```

    This mirrors RBIG's ``estimate_kld`` and requires no Jacobian.

    Args:
        flow_ref: A flow fitted to the reference distribution ``Q``.
        x_query: Samples from ``P`` of shape ``(n, d)``.
        n_bins: Histogram bins per marginal. Defaults to ``round(sqrt(n))``.

    Returns:
        Scalar KL-divergence estimate in nats.
    """
    xq = jnp.asarray(x_query)
    z = jax.vmap(flow_ref.bijection.inverse)(xq)
    bins = _n_bins(z.shape[0], n_bins)
    marginal_kl = jnp.sum(
        jnp.stack([_kl_hist_to_normal(z[:, i], bins) for i in range(z.shape[-1])])
    )
    residual_tc = _total_correlation_estimate(z, bins)
    return marginal_kl + residual_tc