25.6 Mutual Information

The previous sections compared two distributions over the same variable, such as a data distribution and a model. Many questions in deep learning concern a pair of variables instead: an image and its caption, two crops of the same photograph, or a sentence and its translation. How much does one variable tell us about the other?

The standard measure of dependence, the correlation coefficient, detects only linear relationships. Consider X∼N(0,1)X\sim\mathcal N(0,1) and let Y=X2+0.3 ϵY=X^2+0.3\,\epsilon, where ϵ∼N(0,1)\epsilon\sim\mathcal N(0,1) is independent noise. Because X3X^3 is symmetric around zero, Cov(X,Y)=E[X3]=0\textrm{Cov}(X,Y)=\mathbb{E}[X^3]=0, so the correlation between XX and YY is zero. Yet XX nearly determines YY: once we know XX, YY varies only by noise of standard deviation 0.30.3, whereas on its own YY spreads roughly from 00 to 99. The quantity we define in this section captures this dependence readily—in fact, it credits this pair with more shared information than a bivariate Gaussian with correlation 0.90.9.

What we want is a measure that equals zero if and only if two variables are independent, grows as their dependence strengthens, and remains unchanged when either variable is re-expressed in different coordinates. We already have the exact tool needed to build it: the KL divergence DKL(P∥Q)D_{\textrm{KL}}(P\|Q) from Section 25.1, which by Gibbs' inequality is always nonnegative and vanishes only when P=QP=Q. Taking PP to be the true joint distribution of the pair and QQ to be the product distribution the pair would follow if its components were independent gives the mutual information I(X;Y)I(X;Y).

Defining mutual information is straightforward; its real value lies in what follows from it. We establish three fundamental results. First, processing a variable cannot increase its mutual information with anything else, so no layer of a neural network carries more information about the input than the layer below it. Second, a classifier cannot reach a given error rate unless its input carries a minimum amount of information about the label. Third, the test loss of any probabilistic model directly certifies a lower bound on that information. We then turn to Shannon's two foundational questions (how much information a noisy channel can carry and how little a lossy compressor must keep) and a third question that grows out of compression: what should a learned representation keep? Throughout this section we assume the underlying distributions are known; estimating mutual information from samples alone is a harder problem that we take up in Section 25.7.

As before, we work in nats, where 11 bit =ln⁡2≈0.693=\ln 2\approx0.693 nats. All logarithms are natural; we write log⁡\log in general formulas and ln⁡\ln when evaluating numerical values. We denote the binary entropy by Hb(p)=−plog⁡p−(1−p)log⁡(1−p)H_b(p)=-p\log p-(1-p)\log(1-p).

25.6.1 Measures of Dependence#

To keep every definition concrete, we evaluate each one first on a single 2×22 \times 2 probability table, which will return as a running example throughout the section.

25.6.1.1 Joint and Conditional Entropy#

Let XX be a fair bit, and let YY be a copy of XX that is flipped with probability δ=0.1\delta=0.1. We can read XX as a bit sent over a noisy line and YY as the bit received, or read YY as a binary label and XX as a noisy feature that agrees with it 90%90\% of the time. Because the table is symmetric, nothing below depends on which interpretation we choose. With rows indexing x∈{0,1}x\in\{0,1\} and columns indexing y∈{0,1}y\in\{0,1\}, the joint distribution is

pX,Y=(0.450.050.050.45),p_{X,Y}=\begin{pmatrix}0.45&0.05\\0.05&0.45\end{pmatrix},

and summing rows and columns gives the marginals pX=pY=(12,12)p_X=p_Y=(\tfrac12,\tfrac12). We call this pair the flipped bit. Throughout, subscripts name the variables of a distribution, and we drop them when the arguments already make the distribution clear, as in the conditional p(y∣x)p(y\mid x).

Beyond the individual entropies H(X)H(X) and H(Y)H(Y), a pair of random variables has two natural entropies, both introduced in Section 25.1.1.3. The joint entropy is the entropy of the pair viewed as a single random variable—here one with four outcomes:

H(X,Y)=−E(x,y)∼PX,Y[log⁡pX,Y(x,y)].(25.6.1)H(X, Y) = -\mathbb{E}_{(x, y) \sim P_{X,Y}} [\log p_{X, Y}(x, y)]. \tag{25.6.1}

For our table, H(X,Y)=−2(0.45ln⁡0.45)−2(0.05ln⁡0.05)=1.018H(X,Y)=-2(0.45\ln0.45)-2(0.05\ln0.05)=1.018 nats. That is larger than the 0.6930.693 nats of a single fair bit, but smaller than the 1.3861.386 nats of two independent fair bits.

The conditional entropy measures the surprise remaining in YY once XX is known. It is the average entropy of the conditional rows p(y∣x)=pX,Y(x,y)/pX(x)p(y\mid x)=p_{X,Y}(x,y)/p_X(x):

H(Y∣X)=−E(x,y)∼PX,Y[log⁡p(y∣x)]=∑xpX(x) H(Y∣X=x).(25.6.2)H(Y \mid X) = - \mathbb{E}_{(x, y) \sim P_{X,Y}} [\log p(y \mid x)] = \sum_x p_X(x)\, H(Y \mid X = x). \tag{25.6.2}

For the flipped bit, the two rows are (0.9,0.1)(0.9,0.1) and (0.1,0.9)(0.1,0.9), each with entropy Hb(0.1)=0.325H_b(0.1)=0.325 nats, so H(Y∣X)=0.325H(Y\mid X)=0.325 nats. Even after observing XX, YY still retains 0.3250.325 of its original 0.6930.693 nats of surprise.

Notice that the three numbers satisfy 1.018=0.693+0.3251.018=0.693+0.325. This is the chain rule H(X,Y)=H(X)+H(Y∣X)H(X,Y)=H(X)+H(Y\mid X) from Section 25.1.1.3: the surprise in the pair equals the surprise in XX plus the additional surprise in YY once XX is known.

25.6.1.2 Mutual Information#

Conditional entropy captures the part of the surprise in YY that XX cannot explain. What we want now is the part the two variables share. If XX and YY were independent, their joint distribution would be the product of their marginals, PX⊗PYP_X \otimes P_Y, placing pX(x) pY(y)p_X(x)\,p_Y(y) in every cell. The mutual information is the KL divergence from the actual joint distribution to that independent product:

I(X;Y)=DKL(PX,Y ∥ PX⊗PY)=E(x,y)∼PX,Y[log⁡pX,Y(x,y)pX(x) pY(y)].(25.6.3)I(X; Y) = D_{\textrm{KL}}\big(P_{X,Y} \,\|\, P_X \otimes P_Y\big) = \mathbb{E}_{(x, y) \sim P_{X,Y}} \left[ \log\frac{p_{X, Y}(x, y)}{p_X(x)\, p_Y(y)} \right]. \tag{25.6.3}

For the flipped bit, the product of the marginals puts 0.250.25 in every cell. The ratio of the joint probability to the independent product is therefore 0.45/0.25=1.80.45/0.25=1.8 on the diagonal, where XX and YY agree, and 0.05/0.25=0.20.05/0.25=0.2 off the diagonal, where they disagree. Averaging the log-ratios under the joint distribution gives

I(X;Y)=0.9ln⁡1.8+0.1ln⁡0.2=0.529−0.161=0.368 nats.I(X;Y)=0.9\ln1.8+0.1\ln0.2=0.529-0.161=0.368\textrm{ nats}.

Agreements occur 1.81.8 times as often as independence predicts, and disagreements one fifth as often; mutual information is simply the expected logarithm of this factor. Because a KL divergence also measures the extra code length incurred by using the wrong model (Section 25.2), I(X;Y)I(X;Y) is the number of nats per pair wasted by a code that treats XX and YY as independent. We encounter this exact penalty in Section 17.9, when a network predicts two masked tokens independently.

We can also read (25.6.3) one row of the table at a time. Dividing numerator and denominator by pX(x)p_X(x) turns the ratio into p(y∣x)/pY(y)p(y\mid x)/p_Y(y), rewriting the expectation over pairs as an average over xx of the KL divergence between the conditional and marginal distributions of YY:

I(X;Y)=Ex∼PX[DKL(p(y∣x) ∥ pY(y))].(25.6.4)I(X;Y)=\mathbb{E}_{x\sim P_X}\Big[D_{\textrm{KL}}\big(p(y\mid x)\,\|\,p_Y(y)\big)\Big]. \tag{25.6.4}

In this form, mutual information measures how far, on average, observing xx shifts the distribution of YY away from its marginal. For the flipped bit, each conditional row, (0.9,0.1)(0.9,0.1) or (0.1,0.9)(0.1,0.9), lies 0.9ln⁡1.8+0.1ln⁡0.2=0.3680.9\ln1.8+0.1\ln0.2=0.368 nats from the marginal (0.5,0.5)(0.5,0.5). This asymmetric perspective is especially natural when the two variables play different roles, such as an input and the output of a noisy encoder, and we will return to it in Section 25.6.4.

Proposition (properties of mutual information). For any pair (X,Y)(X,Y), I(X;Y)=I(Y;X)≥0I(X;Y)=I(Y;X)\ge0, with equality if and only if XX and YY are independent. When the entropies involved are finite,

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

Proof. Swapping XX and YY leaves the ratio in (25.6.3) unchanged, which proves symmetry. Nonnegativity and the equality condition follow immediately from Gibbs' inequality applied to PX,YP_{X,Y} and PX⊗PYP_X \otimes P_Y: the KL divergence is nonnegative and vanishes if and only if pX,Y(x,y)=pX(x) pY(y)p_{X,Y}(x,y) = p_X(x)\,p_Y(y) everywhere, which is the definition of independence. To obtain the entropy identities, split the logarithm of the ratio into three terms and take expectations:

I(X;Y)=E[log⁡pX,Y(x,y)]−E[log⁡pX(x)]−E[log⁡pY(y)]=−H(X,Y)+H(X)+H(Y).I(X; Y) = \mathbb{E}\left[\log p_{X,Y}(x,y)\right] - \mathbb{E}\left[\log p_X(x)\right] - \mathbb{E}\left[\log p_Y(y)\right] = -H(X,Y) + H(X) + H(Y).

Substituting the chain rule in its two orders, H(X,Y)=H(Y)+H(X∣Y)=H(X)+H(Y∣X)H(X,Y) = H(Y) + H(X \mid Y)=H(X)+H(Y\mid X), yields the remaining two forms. ■\blacksquare

Thus XX says exactly as much about YY as YY says about XX. The final identity interprets mutual information as a reduction in uncertainty: observing XX lowers the surprise in YY from H(Y)H(Y) to H(Y∣X)H(Y\mid X)—for the flipped bit, from 0.6930.693 down to 0.3250.325 nats. Nonnegativity also implies the subadditivity bound H(X,Y)≤H(X)+H(Y)H(X,Y)\le H(X)+H(Y), with equality only at independence: a pair never carries more surprise than its components taken separately. Figure 25.6.1 illustrates these relationships visually; each identity in the proposition is simply a different way of reading off the area of the overlap.

Figure 25.6.1:

Mutual information I(X;Y)I(X;Y) as the overlap of the entropies H(X)H(X) and H(Y)H(Y): the crescents are the conditional entropies H(X∣Y)H(X\mid Y) and H(Y∣X)H(Y\mid X), the union is the joint entropy H(X,Y)H(X,Y), and the three equivalent expressions for I(X;Y)I(X;Y) follow by reading off the areas.

The function mutual_information below implements the divergence form for any discrete joint table, and we will reuse it throughout the section. The cell also checks the identity I(X;Y)=H(Y)−H(Y∣X)I(X;Y) = H(Y) - H(Y\mid X) by averaging the row entropies.

p_xy = np.array([[0.45, 0.05],    # rows x, columns y: a fair bit X and
                 [0.05, 0.45]])   # its copy Y, flipped with probability 0.1

def entropy(p):
    """Entropy of a p.m.f. of any shape, in nats (0 log 0 = 0)."""
    p = p[p > 0]
    return float(-(p * np.log(p)).sum())

def mutual_information(p_xy):
    """I(X;Y) of a discrete joint p.m.f. (rows x, columns y), in nats."""
    p_x = p_xy.sum(axis=1, keepdims=True)
    p_y = p_xy.sum(axis=0, keepdims=True)
    m = p_xy > 0                                  # 0 log 0 = 0
    return float((p_xy[m] * np.log(p_xy[m] / (p_x * p_y)[m])).sum())

p_x, p_y = p_xy.sum(axis=1), p_xy.sum(axis=0)     # marginals from the joint
H_rows = sum(p_x[i] * entropy(p_xy[i] / p_x[i]) for i in range(2))   # H(Y|X)
I = mutual_information(p_xy)
print(f'I(X;Y) = {I:.4f} nats (KL form) = {entropy(p_y) - H_rows:.4f} '
      f'(H(Y) - H(Y|X)) = {I / np.log(2):.3f} bits')
I(X;Y) = 0.3681 nats (KL form) = 0.3681 (H(Y) - H(Y|X)) = 0.531 bits

Both expressions return 0.36810.3681 nats, or 0.5310.531 bits: a copy that flips one time in ten still conveys just over half a bit about the original.

25.6.1.3 The Gaussian Pair#

So far we have worked with discrete tables, whereas most variables in deep learning (activations, gradients, and embeddings) are continuous. One continuous case can be computed completely by hand: the bivariate Gaussian. It will serve as our second running example and form the foundation for both the rate–distortion curve and the information bottleneck later in this section. For continuous densities, discrete entropies are replaced by the differential entropies hh of Section 25.1.4.1, which can be negative and depend on the units of measurement. The KL definition of mutual information suffers from neither drawback. Because the chain-rule algebra never relied on discreteness, I(X;Y)=h(X)+h(Y)−h(X,Y)=h(Y)−h(Y∣X)I(X;Y)=h(X)+h(Y)-h(X,Y)=h(Y)-h(Y\mid X) whenever these quantities are finite, where h(Y∣X)h(Y\mid X) denotes the differential entropy of the conditional density p(y∣x)p(y\mid x), averaged over xx.

Proposition (Gaussian mutual information). If (X,Y)(X, Y) is bivariate Gaussian with variances σX2,σY2>0\sigma_X^2,\sigma_Y^2>0 and correlation coefficient ρ\rho, ρ2<1\rho^2\lt 1, then

I(X;Y)=−12log⁡(1−ρ2).(25.6.5)I(X; Y) = -\tfrac{1}{2} \log\left(1 - \rho^2\right). \tag{25.6.5}

Proof. We use I(X;Y)=h(Y)−h(Y∣X)I(X;Y)=h(Y)-h(Y\mid X). A Gaussian variable with variance σ2\sigma^2 has differential entropy 12log⁡(2πeσ2)\tfrac12\log(2\pi e\sigma^2) (Section 25.1.4.3), so h(Y)=12log⁡(2πeσY2)h(Y)=\tfrac12\log(2\pi e\sigma_Y^2). Conditioned on X=xX=x, YY remains Gaussian with variance σY2(1−ρ2)\sigma_Y^2(1-\rho^2), regardless of xx. This is the variance of the residual left after subtracting the best linear prediction of YY from XX, and for a bivariate Gaussian that residual is independent of XX (Section 24.3.3.3). Hence h(Y∣X)=12log⁡(2πeσY2(1−ρ2))h(Y\mid X)=\tfrac12\log\big(2\pi e\sigma_Y^2(1-\rho^2)\big), and subtracting gives −12log⁡(1−ρ2)-\tfrac12\log(1-\rho^2). ■\blacksquare

The result depends solely on 1−ρ21-\rho^2, the fraction of YY's variance left unexplained by XX. Notice that the units of YY have cancelled out—our first glimpse of the coordinate invariance proved in Section 25.6.1.5.

When ρ=0\rho = 0, the variables are independent and I(X;Y)=0I(X;Y) = 0. As ρ→±1\rho \to \pm 1, the joint density collapses onto a straight line and I(X;Y)→∞I(X;Y) \to \infty. Between those extremes, ρ=0.5\rho = 0.5 yields 0.1440.144 nats, ρ=0.9\rho = 0.9 yields 0.8300.830 nats, and ρ=0.99\rho = 0.99 yields 1.9591.959 nats. The bivariate Gaussian with standard normal marginals and ρ=0.9\rho=0.9 will reappear throughout this section; we refer to it as the Gaussian pair at ρ=0.9\rho=0.9.

As the limit ρ→±1\rho \to \pm 1 shows, mutual information can indeed be infinite. This phenomenon will come up twice later—for deterministic layers of a neural network and for the encoder of the information bottleneck. If Y=XY=X for a continuous random variable XX, knowing XX pins down YY to infinitely many decimal places, and the same holds whenever YY is a deterministic function of XX that takes no single value with positive probability. By contrast, infinite mutual information is impossible when YY is discrete with finite entropy: then I(X;Y)=H(Y)−H(Y∣X)≤H(Y)I(X;Y)=H(Y)-H(Y\mid X)\le H(Y) regardless of XX, where H(Y∣X)H(Y\mid X) averages the entropy of p(⋅∣x)p(\cdot\mid x) over xx. For a standard normal XX, for instance, the sign of XX carries exactly ln⁡2\ln 2 nats. This same ceiling caps the Jensen–Shannon divergence of Section 16.1 at ln⁡2\ln 2: as shown there, it equals the mutual information between a sample and the binary label identifying its source.

25.6.1.4 Pointwise Mutual Information#

Mutual information averages over all pairs of outcomes, which hides which specific pairs drive the dependence. Often a single pair is what we care about: does seeing the word new make the next word york much more likely than chance? The summand inside (25.6.3) answers this directly. It is the pointwise mutual information,

pmi(x,y)=log⁡pX,Y(x,y)pX(x) pY(y),(25.6.6)\textrm{pmi}(x, y) = \log\frac{p_{X, Y}(x, y)}{p_X(x)\, p_Y(y)}, \tag{25.6.6}

which compares how often the specific pair (x,y)(x, y) occurs with how often it would occur if XX and YY were independent. A positive pmi indicates that the two outcomes attract (they co-occur more often than chance predicts), a negative pmi indicates that they repel, and I(X;Y)=E(x,y)∼PX,Y[pmi(x,y)]I(X;Y) = \mathbb{E}_{(x,y) \sim P_{X,Y}}[\textrm{pmi}(x,y)] is their average attraction. For the flipped bit, the pmi is ln⁡1.8=+0.588\ln1.8=+0.588 on the two agreeing cells and ln⁡0.2=−1.609\ln0.2=-1.609 on the two disagreeing cells—the exact logarithms we averaged earlier.

Pointwise mutual information is a classic tool in natural language processing (Church and Hanks, 1990), where it separates collocations, word pairs that naturally belong together, from words that co-occur simply because both are common. Suppose we count consecutive word pairs (bigrams) in a small corpus and tally how often each of new, machine, and the is followed by york, learning, or day:

countyorklearningday
new3839
machine1463
the1121168

Raw counts are misleading here. "The day" is by far the most frequent pair (168168 occurrences versus 3838 for "new york") simply because the and day are both high-frequency words. The code below divides each joint frequency by the product of its two marginal word frequencies, prints the resulting pmi for four pairs, and reports the mutual information of the full table.

counts = np.array([[38., 3., 9.],      # new york / new learning / new day
                   [1., 46., 3.],      # machine ...
                   [11., 21., 168.]])  # the ...
first, second = ['new', 'machine', 'the'], ['york', 'learning', 'day']

p = counts / counts.sum()
pmi = np.log(p / (p.sum(axis=1, keepdims=True) * p.sum(axis=0, keepdims=True)))
for (i, j) in [(0, 0), (1, 1), (2, 2), (2, 0)]:
    print(f'pmi({first[i]}, {second[j]}) = {pmi[i, j]:6.3f} nats '
          f'(count {counts[i, j]:.0f})')
print(f'I(first; second) = {float((p * pmi).sum()):.4f} nats')
pmi(new, york) =  1.517 nats (count 38)
pmi(machine, learning) =  1.372 nats (count 46)
pmi(the, day) =  0.336 nats (count 168)
pmi(the, york) = -1.109 nats (count 11)
I(first; second) = 0.4146 nats

Once we correct for the marginals, the true collocations rise to the top: "new york" scores 1.521.52 nats and "machine learning" scores 1.371.37, whereas the frequent pair "the day" reaches only 0.340.34. Meanwhile, "the york" is negative at −1.11-1.11 nats, occurring roughly three times less often than independence would predict. The mutual information of the table, 0.410.41 nats, summarizes how strongly the first word constrains the second on average. This same marginal correction reappears in learned word embeddings (Section 18.1): by training a skip-gram model to distinguish observed pairs of neighboring words from KK random pairs, we implicitly factorize the matrix of shifted pointwise mutual informations, pmi(x,y)−log⁡K\textrm{pmi}(x,y)-\log K (Levy and Goldberg, 2014), as Exercise 7 of Section 25.7 derives.

25.6.1.5 Mutual Information and Correlation#

The correlation coefficient ρ(X,Y)=Cov(X,Y)/(σXσY)\rho(X,Y)=\textrm{Cov}(X,Y)/(\sigma_X\sigma_Y) of Section 24.2 detects only linear dependence: having ρ(X,Y)=0\rho(X,Y)=0 does not imply independence. Mutual information, by contrast, vanishes if and only if the variables are independent. Returning to our opening example makes this difference concrete.

Let X∼N(0,1)X \sim \mathcal{N}(0, 1) and Y=X2+0.3 ϵY = X^2 + 0.3\,\epsilon with independent ϵ∼N(0,1)\epsilon \sim \mathcal{N}(0,1), a pair whose correlation is ρ=0\rho=0. Writing I(X;Y)=h(Y)−h(Y∣X)I(X;Y)=h(Y)-h(Y\mid X) lets us evaluate the mutual information using one-dimensional integrals. Conditioned on X=xX=x, the only randomness left in YY is the additive noise, and shifting a distribution by the known constant x2x^2 leaves differential entropy unchanged, so h(Y∣X)=h(0.3 ϵ)=12ln⁡(2πe⋅0.09)=0.215h(Y\mid X)=h(0.3\,\epsilon)=\tfrac12\ln(2\pi e\cdot0.09)=0.215 nats. Before computing h(Y)h(Y) numerically, we can bound it analytically: YY has variance Var(X2)+0.09=2.09\textrm{Var}(X^2)+0.09=2.09, and among all densities with a given variance the Gaussian maximizes differential entropy (Section 25.1.4.3), giving h(Y)≤12ln⁡(2πe⋅2.09)=1.79h(Y)\le\tfrac12\ln(2\pi e\cdot2.09)=1.79 nats and thus I(X;Y)≤1.79−0.215=1.57I(X;Y)\le1.79-0.215=1.57 nats. Because the marginal density of YY is a continuous mixture over xx, pY(y)=∫N(x;0,1) N(y;x2,0.09) dxp_Y(y)=\int\mathcal N(x;0,1)\,\mathcal N(y;x^2,0.09)\,dx, with no closed form, we integrate it numerically to obtain h(Y)h(Y).

normal = lambda t, var: np.exp(-t**2 / (2 * var)) / np.sqrt(2 * np.pi * var)
xs = np.linspace(-6, 6, 6001)              # quadrature grid for X
ys = np.linspace(-2.5, 30, 6501)           # grid for Y = X^2 + 0.3 eps
dx, dy = xs[1] - xs[0], ys[1] - ys[0]
p_Y = np.concatenate([                     # p_Y(y) = int N(x;0,1) N(y;x^2,0.09) dx
    (normal(xs, 1) * normal(c[:, None] - xs**2, 0.09)).sum(axis=1) * dx
    for c in np.array_split(ys, 13)])      # 13 chunks keep memory small
h_Y = float(-(p_Y[p_Y > 0] * np.log(p_Y[p_Y > 0])).sum() * dy)
h_noise = 0.5 * np.log(2 * np.pi * np.e * 0.09)   # h(Y|X) = h(0.3 eps)
print(f'h(Y) = {h_Y:.3f}, h(Y|X) = {h_noise:.3f}, '
      f'I(X;Y) = h(Y) - h(Y|X) = {h_Y - h_noise:.3f} nats')
h(Y) = 1.356, h(Y|X) = 0.215, I(X;Y) = h(Y) - h(Y|X) = 1.141 nats

The pair shares 1.1411.141 nats. This sits well below our Gaussian upper bound of 1.571.57 nats because the density of YY—concentrated near zero with a long right tail—is far from Gaussian. At the same time, it exceeds the 0.8300.830 nats of the Gaussian pair at ρ=0.9\rho=0.9, even though its linear correlation is zero. Figure 25.6.2 compares all three cases side by side.

Figure 25.6.2:

Three pairs compared by correlation and by mutual information. (a) A Gaussian pair with correlation 0.90.9. (b) Y=X2+0.3ϵY=X^2+0.3\epsilon, whose correlation vanishes by symmetry even though XX nearly determines YY; note the different vertical scale in (b). (c) An independent pair. Correlation cannot distinguish (b) from (c), whereas mutual information ranks (b) above (a).

Correlation and mutual information differ in a second fundamental way: their behavior under changes of coordinates. Measuring temperature in Fahrenheit instead of Celsius, or recording a price on a logarithmic scale, changes nothing about how informative that variable is about anything else, so a principled measure of dependence should remain invariant.

Proposition (reparameterization invariance). Let ϕ\phi and ψ\psi be invertible maps of the values of XX and of YY. Then I(ϕ(X);ψ(Y))=I(X;Y)I(\phi(X);\psi(Y))=I(X;Y).

Proof. For discrete variables, invertible maps simply relabel the outcomes: the joint distribution of (ϕ(X),ψ(Y))(\phi(X), \psi(Y)) assigns the same probabilities as that of (X,Y)(X, Y) to the relabeled outcomes, leaving the sum in (25.6.3) unchanged. For continuous variables, we prove the smooth case here to show the mechanism; Section 25.6.2.2 removes the smoothness assumption. Suppose ϕ\phi and ψ\psi are continuously differentiable with continuously differentiable inverses, and change variables via (x,y)↦(ϕ(x),ψ(y))(x, y) \mapsto (\phi(x), \psi(y)). The joint density of the transformed pair at (ϕ(x),ψ(y))(\phi(x),\psi(y)) is pX,Y(x,y) ∣det⁡Dϕ(x)∣−1∣det⁡Dψ(y)∣−1p_{X,Y}(x,y)\,|\det D\phi(x)|^{-1}|\det D\psi(y)|^{-1}, while the two marginal densities pick up the factors ∣det⁡Dϕ(x)∣−1|\det D\phi(x)|^{-1} and ∣det⁡Dψ(y)∣−1|\det D\psi(y)|^{-1}. Those Jacobian factors cancel in the density ratio, so the integrand of (25.6.3) takes the same value at corresponding points, and its expectation is unchanged. A set of exceptional points of probability zero, such as the origin for x↦x3x\mapsto x^3, does not affect the integral. ■\blacksquare

Differential entropy lacks this invariance because its Jacobian factor has nothing to cancel against, which is why hh depends on units. Correlation is preserved only by affine transformations (up to sign). Applying the invertible map x↦x3x\mapsto x^3 to the first coordinate of the Gaussian pair at ρ=0.9\rho=0.9, for example, leaves mutual information fixed at 0.8300.830 nats, while the correlation drops from 0.90.9 to 3ρ/15=0.6973\rho/\sqrt{15}=0.697 (since E[X3Y]=3ρ\mathbb{E}[X^3Y]=3\rho and Var(X3)=15\textrm{Var}(X^3)=15 for standard normal XX). Mutual information asks whether two variables carry information about each other in any coordinates, not whether they happen to lie along a straight line.

25.6.2 Processing and Prediction#

We now establish the three results promised in the introduction. The first two are fundamental limits: processing data cannot create information, and accurate prediction requires a minimum amount of it. Both follow from a single identity, the chain rule for mutual information. The third result turns the cross-entropy loss of any probabilistic model into a direct lower bound on the information carried by its input.

25.6.2.1 Conditional Mutual Information and the Chain Rule#

Let us extend the flipped bit by one step. Suppose ZZ is produced by flipping YY once more, independently, with probability 0.20.2—a fair bit sent over two noisy lines in series, or a label followed by a noisy feature and a noisy copy of that feature (Figure 25.6.3). Two flips in series act as a single flip: the bit arrives inverted if and only if exactly one of the two lines flips it, which happens with probability 0.1⋅0.8+0.9⋅0.2=0.260.1\cdot0.8+0.9\cdot0.2=0.26. The pair (X,Z)(X,Z) is therefore a flipped bit with δ=0.26\delta=0.26, giving I(X;Z)=ln⁡2−Hb(0.26)=0.120I(X;Z)=\ln2-H_b(0.26)=0.120 nats. The second noisy line has wiped out two thirds of the 0.3680.368 nats that YY carried.

Figure 25.6.3:

Two flips in series: a fair bit XX is flipped with probability 0.10.1 to give YY, and YY is flipped with probability 0.20.2 to give ZZ; the two flips compose to a single flip with probability 0.260.26. The second flip removes two thirds of the information, and I(X;Z∣Y)=0I(X;Z\mid Y)=0 expresses that ZZ knows nothing about XX that YY does not already know.

With three variables, a new question arises: how much information do XX and YY share once ZZ is already known? Just as entropy has a conditional version, so does mutual information:

I(X;Y∣Z)=H(X∣Z)−H(X∣Y,Z),(25.6.7)I(X; Y \mid Z) = H(X \mid Z) - H(X \mid Y, Z), \tag{25.6.7}

where H(X∣Y,Z)H(X\mid Y,Z) is the conditional entropy of XX given the pair (Y,Z)(Y,Z). Writing each conditional entropy as an expectation and combining the logarithms yields the divergence form I(X;Y∣Z)=Ez[DKL(PX,Y∣z ∥ PX∣z⊗PY∣z)]I(X; Y \mid Z) = \mathbb{E}_{z}\big[D_{\textrm{KL}}(P_{X,Y \mid z}\,\|\, P_{X \mid z} \otimes P_{Y \mid z})\big], which is simply the ordinary mutual information averaged over the conditional distributions for each value of zz. Because it is an expectation of KL divergences, I(X;Y∣Z)I(X; Y \mid Z) is always nonnegative, and it equals zero if and only if XX and YY are conditionally independent given ZZ.

This definition lets us split the information that the pair (Y,Z)(Y,Z) carries about XX into two pieces. Subtracting and adding H(X∣Z)H(X\mid Z) inside I(X;Y,Z)=H(X)−H(X∣Y,Z)I(X;Y,Z)=H(X)-H(X\mid Y,Z) gives

I(X;Y,Z)=H(X)−H(X∣Z)⏟I(X; Z)+H(X∣Z)−H(X∣Y,Z)⏟I(X; Y∣Z).I(X; Y, Z) = \underbrace{H(X) - H(X \mid Z)}_{I(X;\, Z)} + \underbrace{H(X \mid Z) - H(X \mid Y, Z)}_{I(X;\, Y \mid Z)}.

This identity is the chain rule for mutual information, and it holds in full generality when each term is written in KL form. In words, what (Y,Z)(Y,Z) tells us about XX equals what ZZ tells us plus what YY adds once ZZ is known. We can equally well condition on YY first. For our two flips in series, the two orderings decompose the same total in two ways. Because ZZ is generated from YY and independent noise, once YY is known ZZ adds nothing further about XX: I(X;Z∣Y)=0I(X;Z\mid Y)=0, so putting YY first gives I(X;Y,Z)=I(X;Y)+0=0.368I(X;Y,Z)=I(X;Y)+0=0.368 nats. Putting ZZ first splits the same 0.3680.368 nats as I(X;Z)+I(X;Y∣Z)=0.120+I(X;Y∣Z)I(X;Z)+I(X;Y\mid Z)=0.120+I(X;Y\mid Z), leaving I(X;Y∣Z)=0.248I(X;Y\mid Z)=0.248 nats. Here conditioning on ZZ reduced what YY reveals about XX, because ZZ already holds part of that information. As we will see in the next subsection, however, conditioning can also increase mutual information.

25.6.2.2 The Data-Processing Inequality#

In a neural network, each hidden layer is computed from the layer below it, which in turn is computed from the input. Can such processing ever create information about the input that the earlier layer did not already contain? For the two noisy lines the answer was no, and the reason has nothing to do with bits in particular.

Three random variables X,Y,ZX, Y, Z form a Markov chain, written X→Y→ZX \to Y \to Z, when ZZ depends on (X,Y)(X, Y) solely through YY, meaning p(z∣x,y)=p(z∣y)p(z \mid x, y) = p(z \mid y). This captures the exact structure of sequential processing: YY is produced from XX (a measurement, feature map, or hidden layer), and ZZ is then computed from YY alone, possibly with fresh randomness. Equivalently, XX and ZZ are conditionally independent given YY, so I(X;Z∣Y)=0I(X; Z \mid Y) = 0.

Proposition (data-processing inequality). If X→Y→ZX \to Y \to Z is a Markov chain and the entropies involved are finite, then

I(X;Z)≤I(X;Y),I(X; Z) \leq I(X; Y),

with equality if and only if I(X;Y∣Z)=0I(X; Y \mid Z) = 0, that is, if and only if X→Z→YX \to Z \to Y is also a Markov chain (Cover and Thomas, 1999).

Proof. Expand I(X;Y,Z)I(X; Y, Z) by the chain rule in both orders:

I(X;Z)+I(X;Y∣Z)=I(X;Y,Z)=I(X;Y)+I(X;Z∣Y).I(X; Z) + I(X; Y \mid Z) = I(X; Y, Z) = I(X; Y) + I(X; Z \mid Y).

By the Markov property the last term vanishes, leaving I(X;Z)=I(X;Y)−I(X;Y∣Z)≤I(X;Y)I(X; Z) = I(X; Y) - I(X; Y \mid Z) \leq I(X; Y), since conditional mutual information is nonnegative. Equality holds if and only if I(X;Y∣Z)=0I(X; Y \mid Z) = 0. ■\blacksquare

No processing of YY, whether deterministic or randomized, can increase the information it carries about XX. For our two flips in series, the inequality simply reads 0.120≤0.3680.120 \le 0.368.

Notice that this inequality relies strictly on the Markov chain structure, not on conditioning in general: outside a Markov chain, conditioning can create dependence where none existed. Suppose XX and YY are independent fair bits and Z=X⊕YZ = X \oplus Y is their exclusive or. Marginally XX and YY share zero information, yet once ZZ is revealed, YY determines XX completely. The code below computes the mutual informations for both the two flips in series and this XOR triple.

def cond_mi(p_abc):
    """I(A;B|C) of a joint p.m.f. indexed [a, b, c], in nats."""
    p_ac, p_bc, p_c = p_abc.sum(1), p_abc.sum(0), p_abc.sum((0, 1))
    m = p_abc > 0                                  # 0 log 0 = 0
    ratio = ((p_abc * p_c[None, None, :])[m]
             / (p_ac[:, None, :] * p_bc[None, :, :])[m])
    return float((p_abc[m] * np.log(ratio)).sum())

flip = lambda d: np.array([[1 - d, d], [d, 1 - d]])   # p(output | input)
p_xyz = 0.5 * flip(0.1)[:, :, None] * flip(0.2)[None, :, :]   # X -> Y -> Z
I_xy, I_xz = mutual_information(p_xyz.sum(2)), mutual_information(p_xyz.sum(1))
I_xz_y, I_xy_z = cond_mi(p_xyz.transpose(0, 2, 1)), cond_mi(p_xyz)
print(f'I(X;Y) = {I_xy:.4f}, I(X;Z) = {I_xz:.4f}, '
      f'I(X;Z|Y) = {I_xz_y:.4f}, I(X;Y|Z) = {I_xy_z:.4f}')
print(f'I(X;Y,Z) by the chain rule: {I_xz + I_xy_z:.4f} = {I_xy + I_xz_y:.4f}')
p_xor = np.zeros((2, 2, 2))
for a, b in np.ndindex(2, 2):
    p_xor[a, b, a ^ b] = 0.25          # independent fair bits, Z = X xor Y
print(f'XOR: I(X;Y) = {mutual_information(p_xor.sum(2)):.4f}, '
      f'I(X;Y|Z) = {cond_mi(p_xor):.4f} nats')
I(X;Y) = 0.3681, I(X;Z) = 0.1201, I(X;Z|Y) = 0.0000, I(X;Y|Z) = 0.2480
I(X;Y,Z) by the chain rule: 0.3681 = 0.3681
XOR: I(X;Y) = 0.0000, I(X;Y|Z) = 0.6931 nats

For the two flips, I(X;Z∣Y)=0I(X; Z \mid Y) = 0 confirms the Markov property numerically, and both chain-rule decompositions of I(X;Y,Z)I(X; Y, Z) yield 0.36810.3681 nats. For the exclusive or, conditioning on ZZ boosts the mutual information between XX and YY from 00 to the full ln⁡2=0.693\ln2=0.693 nats of a bit.

When does processing lose no information at all? By the proposition, equality holds if and only if X→Z→YX\to Z\to Y is also a Markov chain, meaning ZZ retains everything YY tells us about XX. An invertible transformation Z=g(Y)Z=g(Y) certainly achieves this, since YY can be recovered from ZZ. Yet a map can also discard part of YY without losing information about XX, as long as whatever it discards is unrelated to XX. For example, the total number of heads in a sequence of coin flips preserves everything the sequence says about the coin's bias, because the order of the flips carries no information about that bias. Any summary T(Y)T(Y) with this property (so that p(x∣y)p(x \mid y) depends on yy only through T(y)T(y), and therefore I(X;T(Y))=I(X;Y)I(X;T(Y))=I(X;Y)) is called a sufficient statistic. The sufficient statistics of an exponential family (Section 24.4) are precisely summaries of this kind, with YY playing the role of the data and XX the parameter θ\theta (equipped with a prior so that I(θ;Y)I(\theta;Y) is well defined).

The data-processing inequality itself requires neither finite entropies nor densities. Because mutual information is a KL divergence, and no map of the data, random or deterministic, can increase a KL divergence (Section 25.3.3.3 proves this for countable sets, and it holds in full generality), Exercise 4 turns that fact into a general proof of the inequality. Applying the inequality once to an invertible map and once to its inverse also yields the reparameterization invariance of Section 25.6.1.5 without needing smoothness.

When applied to deep networks, the data-processing inequality is easy to misread. The layers of a network form a Markov chain X→Z1→Z2→⋯X \to Z_1 \to Z_2 \to \cdots, so I(X;Zℓ)I(X; Z_\ell) cannot increase with depth ℓ\ell. From here to the end of this part, let YY denote a prediction label rather than the middle variable of a chain. Whatever a network knows about the label must pass through the input, so Y→X→Z1→Z2→⋯Y \to X \to Z_1 \to Z_2 \to \cdots is also a Markov chain, and I(Y;Zℓ)I(Y; Z_\ell) cannot increase with ℓ\ell either. No architecture can conjure up label information that was absent from the input, and no later layer can recover information that an earlier layer threw away.

This does not mean depth is unhelpful. Hidden layers do not add information about the label; rather, they reorganize existing information so that a simple final layer can read it out. Suppose the label YY is a fair bit, and the input X∈R2X \in \mathbb{R}^2 is uniform on the circle of radius 11 when Y=0Y=0 and on the circle of radius 22 when Y=1Y=1. The input determines the label exactly, so I(Y;X)=ln⁡2I(Y;X)=\ln2, yet no straight line separates two concentric circles. The best linear classifier places its decision boundary tangent to the inner circle: it classifies the entire inner circle correctly, along with the one third of the outer circle that lies beyond the line, achieving an accuracy of 2/32/3. Now apply a single nonlinear feature Z=∥X∥2Z=\|X\|^2, which takes only the values 11 and 44. A simple threshold between them classifies every point perfectly, even though I(Y;Z)=ln⁡2I(Y;Z)=\ln2 is no larger than I(Y;X)I(Y;X). The transformation added no information, yet made all of it linearly readable. Exercise 2 formalizes a notion of usable information that counts only what a restricted family of classifiers can extract.

One final caution applies to the input chain X→Z1→Z2→⋯X \to Z_1 \to Z_2 \to \cdots. For a deterministic layer, H(Zℓ∣X)=0H(Z_\ell\mid X)=0. If the representation is discrete or quantized, I(X;Zℓ)I(X;Z_\ell) simply reduces to the entropy H(Zℓ)H(Z_\ell); if it is continuous, I(X;Zℓ)I(X;Z_\ell) is typically infinite (Section 25.6.1.3). As a measure of how much a layer retains about its input, I(X;Zℓ)I(X;Z_\ell) is therefore meaningful only when the layer injects noise or produces a discrete output.

25.6.2.3 Fano's Inequality#

Accurate prediction demands mutual information. A classifier that achieves 5%5\% error across 1,0001{,}000 classes must receive an input carrying most of the label's entropy, and Fano's inequality tells us exactly how much.

Proposition (Fano's inequality). Let YY take values in a set of kk elements, let Y^=g(X)\hat Y=g(X) be any estimate of YY computed from XX and taking values in the same set, and let Pe=P(Y^≠Y)P_e=P(\hat Y\ne Y) be its error probability. Then

Hb(Pe)+Pelog⁡(k−1)≥H(Y∣X)=H(Y)−I(X;Y).(25.6.8)H_b(P_e) + P_e \log(k - 1) \geq H(Y \mid X) = H(Y) - I(X; Y). \tag{25.6.8}

The left-hand side has a clean coding interpretation as the cost of repairing the estimate Y^\hat Y: it takes Hb(Pe)H_b(P_e) nats to specify whether Y^\hat Y is wrong, and whenever it is wrong (with probability PeP_e), at most log⁡(k−1)\log(k-1) nats to specify which of the remaining k−1k-1 labels is correct. Anyone who has both the estimate and the repair knows YY exactly, so the repair cannot cost less than the uncertainty about YY left by Y^\hat Y—which, by data processing, is at least the uncertainty left by XX.

The proof turns this intuition into an exact bound using a single device: an indicator variable for whether an error occurred. The rest is just the chain rule.

Proof. Let W=1{Y^≠Y}W = \mathbf{1}\{\hat Y \neq Y\} be the error indicator. We expand H(W,Y∣Y^)H(W, Y \mid \hat Y), the remaining uncertainty about both the error and the true label given the estimate, in two ways. First, WW is completely determined by (Y,Y^)(Y,\hat Y) and therefore adds no entropy, so H(W,Y∣Y^)=H(Y∣Y^)H(W, Y \mid \hat Y) = H(Y \mid \hat Y). Second, the chain rule gives H(W,Y∣Y^)=H(W∣Y^)+H(Y∣W,Y^)H(W, Y \mid \hat Y) = H(W \mid \hat Y) + H(Y \mid W, \hat Y), and we bound each term separately:

  • Conditioning cannot increase entropy, since H(W)−H(W∣Y^)=I(W;Y^)≥0H(W)-H(W\mid\hat Y)=I(W;\hat Y)\ge0. Therefore H(W∣Y^)≤H(W)=Hb(Pe)H(W \mid \hat Y) \leq H(W) = H_b(P_e).
  • When W=0W=0, the label equals Y^\hat Y and has zero uncertainty. When W=1W=1 (which happens with probability PeP_e), the label must be one of the k−1k-1 values other than Y^\hat Y, so its entropy is at most log⁡(k−1)\log(k-1). Averaging over WW gives H(Y∣W,Y^)≤Pelog⁡(k−1)H(Y \mid W, \hat Y) \leq P_e \log(k-1).

Combining both bounds yields H(Y∣Y^)≤Hb(Pe)+Pelog⁡(k−1)H(Y\mid\hat Y)\le H_b(P_e)+P_e\log(k-1). Finally, because Y^\hat Y is computed solely from XX, the triple Y→X→Y^Y \to X \to \hat Y forms a Markov chain, and the data-processing inequality gives I(Y;Y^)≤I(Y;X)I(Y; \hat Y) \leq I(Y; X), or equivalently H(Y∣Y^)≥H(Y∣X)H(Y \mid \hat Y) \geq H(Y \mid X). ■\blacksquare

Notice that the count of k−1k-1 remaining labels in the second step relies on Y^\hat Y taking values inside the same label set. If the classifier is allowed to answer "abstain", then log⁡k\log k must replace log⁡(k−1)\log(k-1), and the stated inequality breaks down: for a fair bit YY independent of XX and a classifier that always abstains, Pe=1P_e=1 and the left-hand side becomes Hb(1)+ln⁡1=0H_b(1)+\ln1=0, which lies below H(Y∣X)=ln⁡2H(Y\mid X)=\ln2.

In the simplest case, Fano's bound is exact. For the flipped bit with the estimate Y^=X\hat Y=X, we have Pe=0.1P_e=0.1 and k=2k=2, so the left-hand side equals Hb(0.1)+0.1ln⁡1=0.325H_b(0.1)+0.1\ln1=0.325, matching H(Y∣X)H(Y\mid X) exactly.

No classifier, regardless of architecture or training procedure, can beat Fano's bound. For 1,0001{,}000 balanced classes, H(Y)=ln⁡1000=6.91H(Y)=\ln1000=6.91 nats; rearranging (25.6.8) for I(X;Y)I(X;Y) shows the minimum mutual information required to achieve each target error rate.

H_b = lambda p: -p * np.log(p) - (1 - p) * np.log(1 - p)   # binary entropy
k = 1000
for p_e in (0.01, 0.05, 0.2, 0.5):
    need = np.log(k) - H_b(p_e) - p_e * np.log(k - 1)
    print(f'P_e = {p_e:4.2f}: I(X;Y) >= {need:.3f} of log k = {np.log(k):.3f} nats')
P_e = 0.01: I(X;Y) >= 6.783 of log k = 6.908 nats
P_e = 0.05: I(X;Y) >= 6.364 of log k = 6.908 nats
P_e = 0.20: I(X;Y) >= 5.026 of log k = 6.908 nats
P_e = 0.50: I(X;Y) >= 2.761 of log k = 6.908 nats

Reaching 5%5\% error requires at least 6.366.36 of the 6.916.91 nats of label entropy (92%92\% of the total), and even a classifier that is wrong half the time needs 2.762.76 nats, or two fifths of the total.

25.6.2.4 The Loss Certificate#

Fano's inequality turns a classification error rate into a lower bound on mutual information. A language model, however, is not evaluated by hard error rate; like almost every model trained by maximum likelihood, it reports a cross-entropy loss instead. That loss yields a lower bound on mutual information as well, and the proof takes only three lines.

Proposition (a loss certifies information). Let q(y∣x)q(y\mid x) be any model of the label given the input, with cross-entropy loss L=E[−log⁡q(Y∣X)]L=\mathbb{E}[-\log q(Y\mid X)] under PX,YP_{X,Y}. Then

I(X;Y)  ≥  H(Y)−L,(25.6.9)I(X;Y)\;\ge\;H(Y)-L, \tag{25.6.9}

and for kk balanced classes, I(X;Y)≥log⁡k−LI(X;Y)\ge\log k-L.

Proof. By definition, I(X;Y)=H(Y)−H(Y∣X)I(X;Y)=H(Y)-H(Y\mid X). For each xx, the cross-entropy of q(⋅∣x)q(\cdot\mid x) under p(⋅∣x)p(\cdot\mid x) exceeds the true conditional entropy of p(⋅∣x)p(\cdot\mid x) by DKL(p(⋅∣x) ∥ q(⋅∣x))≥0D_{\textrm{KL}}(p(\cdot\mid x)\,\|\,q(\cdot\mid x))\ge0 (Section 25.1). Averaging over xx yields H(Y∣X)≤LH(Y\mid X)\le L, and subtracting from H(Y)H(Y) completes the proof. ■\blacksquare

Because held-out test loss estimates LL, the test loss of any classifier or language model directly certifies a lower bound on the information its input carries. For example, a 1010-class classifier on balanced labels with a test loss of 0.30.3 nats certifies that its input carries at least ln⁡10−0.3=2.0\ln10-0.3=2.0 of the label's 2.302.30 nats. The bound holds even if the model is poorly calibrated or badly trained; a weaker model simply certifies a smaller lower bound. This is the variational bound of Barber and Agakov (2003) with a classifier acting as the decoder, and Section 25.7.3 develops it into a broader family of mutual information estimators.

The certificate is tight if and only if q(y∣x)q(y\mid x) matches the true conditional distribution p(y∣x)p(y\mid x). On the flipped bit, a model that predicts Y^=X\hat Y=X with confidence cc has expected loss L=−0.9log⁡c−0.1log⁡(1−c)L=-0.9\log c-0.1\log(1-c), which we evaluate below across four confidence levels.

for c in (0.6, 0.8, 0.9, 0.99):
    L = -(0.9 * np.log(c) + 0.1 * np.log(1 - c))   # cross-entropy of q
    print(f'confidence {c:4.2f}: loss {L:.4f}, '
          f'certifies I(X;Y) >= {np.log(2) - L:.4f} nats')
confidence 0.60: loss 0.5514, certifies I(X;Y) >= 0.1418 nats
confidence 0.80: loss 0.3618, certifies I(X;Y) >= 0.3314 nats
confidence 0.90: loss 0.3251, certifies I(X;Y) >= 0.3681 nats
confidence 0.99: loss 0.4696, certifies I(X;Y) >= 0.2236 nats

Only the calibrated model (c=0.9c=0.9) certifies the full 0.3680.368 nats. An overconfident model (c=0.99c=0.99) pays a steep penalty whenever it errs and certifies only 0.220.22 nats, while an underconfident one (c=0.6c=0.6) certifies 0.140.14 nats. Yet all four models make identical hard predictions and err 10%10\% of the time, so Fano's inequality, which sees only the error rate, certifies the full 0.3680.368 nats for every one of them. Cross-entropy loss sees the predicted probabilities as well, and penalizes miscalibration. Both results upper-bound the same conditional entropy H(Y∣X)H(Y\mid X) (Fano via an error rate and the certificate via a loss), turning each upper bound into a lower bound on I(X;Y)I(X;Y). In fact, the two are even more closely connected than they appear: Exercise 6 shows that Fano's bound is itself the loss certificate of one specific model, and that a well-calibrated classifier that knows when it is uncertain can certify strictly more.

25.6.3 Communication and Compression#

Shannon posed two foundational engineering questions whose answers turn out to be a maximum and a minimum of mutual information: how much information a noisy channel can reliably carry, and how little information a lossy compressor must keep. Readers focused on representation learning may skim channel capacity on a first pass, whereas rate–distortion theory is essential because the final part of this section builds directly on it.

25.6.3.1 Channel Capacity#

How much information can survive a communication line that flips each bit independently with probability δ\delta? A memoryless channel is specified by a conditional distribution p(y∣x)p(y\mid x) applied independently to each input symbol, with each transmitted symbol counting as one use of the channel. Our flipped bit is exactly such a channel, with input XX and output YY. Although the channel noise is fixed, the sender is free to choose the input distribution p(x)p(x). The capacity of the channel is the maximum mutual information achievable over all choices of input distribution, measured in nats per use:

C=max⁡p(x)I(X;Y).(25.6.10)C=\max_{p(x)} I(X;Y). \tag{25.6.10}

A sender who transmits mostly zeros underuses the channel, since such an input carries little entropy to begin with. Shannon's channel coding theorem gives this quantity its operational meaning. Defining the rate of a code as the number of nats of message it delivers per channel use, Shannon showed that by encoding long blocks of symbols one can transmit reliably—with error probability as small as desired—at any rate below CC, whereas reliable communication is impossible at any rate above CC (Shannon, 1948; Cover and Thomas, 1999). We state this theorem without proof.

For the bit-flipping channel, known as the binary symmetric channel, computing the capacity takes a single line. Write I(X;Y)=H(Y)−H(Y∣X)I(X;Y)=H(Y)-H(Y\mid X). Every row of p(y∣x)p(y\mid x) is (1−δ,δ)(1-\delta,\delta) up to ordering, so H(Y∣X)=Hb(δ)H(Y\mid X)=H_b(\delta) regardless of the input distribution. Meanwhile, H(Y)≤ln⁡2H(Y)\le\ln2, with equality if and only if YY is uniform. Because P(Y=1)=δ+P(X=1)(1−2δ)P(Y=1)=\delta+P(X=1)(1-2\delta), whenever δ≠12\delta\ne\tfrac12 the output is uniform if and only if the input is uniform. Hence

C=ln⁡2−Hb(δ)nats per use,(25.6.11)C=\ln 2-H_b(\delta)\quad\textrm{nats per use}, \tag{25.6.11}

achieved by the uniform input. At δ=0.1\delta=0.1, this recovers the 0.3680.368 nats of our flipped bit (whose input was already uniform); for the two lines in series (δ=0.26\delta=0.26), capacity drops to 0.1200.120 nats. At δ=12\delta=\tfrac12, the output is independent of the input and capacity vanishes. At δ=1\delta=1, capacity returns to the full ln⁡2\ln2 nats, since a receiver who knows every bit is inverted can simply flip it back: noise destroys information only to the extent that the receiver cannot predict it. The code below first sweeps the input distribution for the δ=0.1\delta=0.1 channel, and then sweeps the flip probability δ\delta under a uniform input.

inputs = (0.1, 0.3, 0.5, 0.7, 0.9)
I_in = [mutual_information(np.array([[1 - a], [a]]) * flip(0.1)) for a in inputs]
print('P(X=1):', '  '.join(f'{a:6.2f}' for a in inputs))
print('I(X;Y):', '  '.join(f'{v:6.4f}' for v in I_in))
deltas = (0.0, 0.1, 0.26, 0.5, 1.0)
C = [np.log(2) - entropy(np.array([d, 1 - d])) for d in deltas]
print('delta: ', '  '.join(f'{d:6.2f}' for d in deltas))
print('C:     ', '  '.join(f'{c:6.4f}' for c in C))
P(X=1):   0.10    0.30    0.50    0.70    0.90
I(X;Y): 0.1463  0.3160  0.3681  0.3160  0.1463
delta:    0.00    0.10    0.26    0.50    1.00
C:      0.6931  0.3681  0.1201  0.0000  0.6931

An input that sends a 11 only 10%10\% of the time has only Hb(0.1)=0.325H_b(0.1)=0.325 nats to offer and gets 0.1460.146 of them through—two fifths of what the uniform input achieves. The left panel of Figure 25.6.4 plots the capacity as a function of δ\delta. Neural networks contain channels of their own: dropout erases a feature with probability α\alpha and passes it through otherwise, and Exercise 7 shows that a binary feature can push at most (1−α)ln⁡2(1-\alpha)\ln2 nats through it.

Figure 25.6.4:

Shannon's two operational curves, in nats. Left: the capacity C=ln⁡2−Hb(δ)C=\ln2-H_b(\delta) of the binary symmetric channel, with the flipped bit (δ=0.1\delta=0.1) and the two flips in series (δ=0.26\delta=0.26) marked; a channel that flips with probability 1/21/2 carries nothing, while one that always flips carries the full ln⁡2\ln2. Right: the Gaussian rate–distortion function for a source of variance σX2=1\sigma_X^2=1; the rate diverges as D→0D\to0 and reaches zero once DD meets the source variance.

25.6.3.2 Rate–Distortion#

Lossless compression requires H(X)H(X) nats per symbol (Section 25.2), which means an exact lossless code for a continuous source would require infinitely many nats. In practice, an approximate reconstruction is usually all we need: an image codec may perturb pixels slightly, and a learned representation may deliberately discard irrelevant detail. Suppose we choose a nonnegative distortion measure d(x,x^)≥0d(x,\hat x)\ge0 scoring how well x^\hat x reconstructs xx, and allow an average distortion of at most DD. How few nats per sample are required? The rate–distortion function answers this as the minimum mutual information an encoder p(x^∣x)p(\hat x\mid x) must retain to stay within the distortion budget:

R(D)=inf⁡p(x^∣x):  E[d(X,X^)]≤DI(X;X^).(25.6.12)R(D)=\inf_{p(\hat x\mid x):\;\mathbb{E}[d(X,\hat X)]\le D} I(X;\hat X). \tag{25.6.12}

A tighter distortion budget demands more information. Shannon's rate–distortion theorem mirrors the channel coding theorem, with the rate now measuring the nats a code spends per source sample: block codes operating at any rate above R(D)R(D) can achieve average distortion DD, whereas no code below R(D)R(D) can (Shannon, 1959).

In practice, it is usually easier to replace the hard distortion constraint with a penalty, minimizing I(X;X^)+λ E[d(X,X^)]I(X;\hat X)+\lambda\,\mathbb{E}[d(X,\hat X)] over all encoders for a multiplier λ>0\lambda>0. Every encoder corresponds to a point in the distortion–rate plane lying on or above the curve R(D)R(D), and the penalized objective is constant along straight lines of slope −λ-\lambda. Because R(D)R(D) is convex, the minimum occurs where a line of slope −λ-\lambda touches the curve from below: larger λ\lambda selects lower distortion at a higher rate. The information bottleneck of Section 25.6.4 is formulated in exactly this Lagrangian form.

Proposition (Gaussian rate–distortion). For a source X∼N(0,σX2)X\sim\mathcal N(0,\sigma_X^2) under squared error d(x,x^)=(x−x^)2d(x,\hat x)=(x-\hat x)^2,

R(D)=12log⁡σX2D(0<D<σX2),R(D)=0(D≥σX2).(25.6.13)R(D)=\frac12\log\frac{\sigma_X^2}{D} \quad (0\lt D\lt \sigma_X^2), \qquad R(D)=0\quad(D\ge\sigma_X^2). \tag{25.6.13}

Inverting this formula for distortion gives D=σX2e−2RD=\sigma_X^2 e^{-2R}: every additional bit of rate (ln⁡2\ln2 nats) cuts the squared error by a factor of four.

Proof. The lower bound is the main step, and it rests on a single fact from Section 25.1.4.3: among all densities with variance s2s^2, the Gaussian maximizes differential entropy at 12log⁡(2πes2)\tfrac12\log(2\pi e s^2), which increases with s2s^2. Take any encoder satisfying E[(X−X^)2]≤D\mathbb{E}[(X-\hat X)^2]\le D. Then

I(X;X^)=h(X)−h(X∣X^)=h(X)−h(X−X^∣X^)≥h(X)−h(X−X^)≥12log⁡(2πeσX2)−12log⁡(2πeD)=12log⁡σX2D.\begin{aligned} I(X;\hat X)&=h(X)-h(X\mid\hat X)=h(X)-h(X-\hat X\mid\hat X)\\ &\ge h(X)-h(X-\hat X)\\ &\ge \tfrac12\log(2\pi e\sigma_X^2)-\tfrac12\log(2\pi eD)=\tfrac12\log\frac{\sigma_X^2}{D}. \end{aligned}

The second equality holds because subtracting the known value X^\hat X merely shifts the conditional density without changing its entropy. The first inequality uses the fact that conditioning cannot increase entropy, and the second applies the Gaussian maximum-entropy bound, since the reconstruction error X−X^X-\hat X has variance at most E[(X−X^)2]≤D\mathbb{E}[(X-\hat X)^2]\le D. When D≥σX2D\ge\sigma_X^2, a constant encoder that transmits nothing and always outputs the mean 00 already meets the budget, so R(D)=0R(D)=0.

It remains to construct an encoder that achieves this bound for D<σX2D\lt \sigma_X^2. Set σX2=1\sigma_X^2=1 and add independent Gaussian noise: Z=X+σϵZ=X+\sigma\epsilon with ϵ∼N(0,1)\epsilon\sim\mathcal N(0,1) and σ>0\sigma>0. Then Cov(X,Z)=1\textrm{Cov}(X,Z)=1 and Var(Z)=1+σ2\textrm{Var}(Z)=1+\sigma^2, giving squared correlation ρXZ2=1/(1+σ2)\rho_{XZ}^2=1/(1+\sigma^2). Applying (25.6.5) gives the mutual information retained by this encoder:

I(X;X+σϵ)=12log⁡(1+σ−2).(25.6.14)I(X;X+\sigma\epsilon)=\tfrac12\log\left(1+\sigma^{-2}\right). \tag{25.6.14}

Now reconstruct XX using the conditional mean X^=E[X∣Z]=Z/(1+σ2)\hat X=\mathbb{E}[X\mid Z]=Z/(1+\sigma^2), the optimal linear regression of XX on ZZ with slope Cov(X,Z)/Var(Z)\textrm{Cov}(X,Z)/\textrm{Var}(Z). Its mean squared error is the conditional variance D=1−1/(1+σ2)=σ2/(1+σ2)D=1-1/(1+\sigma^2)=\sigma^2/(1+\sigma^2), which sweeps across the entire interval (0,1)(0,1) as σ\sigma varies. Because X^\hat X is an invertible rescaling of ZZ, we have I(X;X^)=12log⁡(1+σ−2)=12log⁡(1/D)I(X;\hat X)=\tfrac12\log(1+\sigma^{-2})=\tfrac12\log(1/D). For a general variance σX2\sigma_X^2, simply rescale XX and X^\hat X. ■\blacksquare

The encoder used in this proof—a signal corrupted by independent Gaussian noise—is known as a Gaussian channel with signal-to-noise ratio σ−2\sigma^{-2}, and (25.6.14) is its capacity (Exercise 8). The forward noising process of a diffusion model (Chapter 17) is precisely such a channel: regardless of the data distribution, a coordinate noised to signal-to-noise ratio ss carries at most 12log⁡(1+s)\tfrac12\log(1+s) nats about its clean value. The code below simulates this encoder on one million samples at σ2=1/9\sigma^2=1/9, 11, and 33 (corresponding to D=0.1D=0.1, 0.50.5, and 0.750.75) and verifies its squared error.

rng = np.random.default_rng()
x = rng.standard_normal(1_000_000)
for s2 in (1 / 9, 1.0, 3.0):                              # sigma^2
    z = x + np.sqrt(s2) * rng.standard_normal(x.size)     # encoder
    x_hat = z / (1 + s2)                                  # E[X | Z]
    D = s2 / (1 + s2)
    mse = np.mean((x - x_hat)**2)
    print(f'sigma^2 = {s2:5.3f}: D = {D:.3f}, MSE {mse:.3f}, '
          f'I(X;Z) = R(D) = {0.5 * np.log(1 + 1 / s2):.3f} nats')
sigma^2 = 0.111: D = 0.100, MSE 0.100, I(X;Z) = R(D) = 1.151 nats
sigma^2 = 1.000: D = 0.500, MSE 0.500, I(X;Z) = R(D) = 0.347 nats
sigma^2 = 3.000: D = 0.750, MSE 0.750, I(X;Z) = R(D) = 0.144 nats

The empirical squared errors match DD to within a few thousandths: a distortion of D=0.1D=0.1 costs 1.151.15 nats per sample, D=0.5D=0.5 costs 0.350.35 nats (half a bit), and D=0.75D=0.75 costs 0.140.14 nats.

Keep in mind that this noisy encoder achieves R(D)R(D) as a mutual information, not yet as an actual file size. A practical code must map samples to discrete bit strings, and it approaches the rate–distortion curve only by coding long blocks of samples jointly. Any scalar code that quantizes one sample at a time stays strictly above the curve. The simplest example keeps only the sign of XX: it spends ln⁡2=0.693\ln2=0.693 nats and reconstructs ±2/π\pm\sqrt{2/\pi} (the mean of ∣X∣|X|), incurring squared error 1−2/π=0.3631-2/\pi=0.363, whereas the rate–distortion curve asks only 0.5060.506 nats for that distortion.

The right panel of Figure 25.6.4 shows the full curve. As D→0D\to0, the required rate climbs without bound—reflecting the infinite information in an exact copy of a continuous variable—and drops to 00 once DD reaches σX2\sigma_X^2. That steep climb near D=0D=0 explains why modern image generators compress images before modeling them: the finest, nearly imperceptible pixel details consume the vast majority of the bits, so Section 17.7 delegates them to an autoencoder.

25.6.4 The Information Bottleneck#

A good representation should keep what predicts the label and discard the rest. At first glance, discarding anything might seem counterproductive, since the data-processing inequality tells us that throwing away information can never improve the Bayes-optimal predictor. In practice, however, irrelevant details carry a real cost. A photograph of a dog also encodes the lighting, the lawn, and where in the frame the dog happens to stand. Storing all of those nuances costs extra nats, and a classifier trained on finitely many images can easily mistake them for genuine cues to the label. The information bottleneck formalizes this trade-off using two mutual informations: it is a rate–distortion problem in which the label itself defines the distortion.

25.6.4.1 The Bottleneck Objective#

Let ZZ be a representation of an input XX generated by a stochastic encoder p(z∣x)p(z\mid x), and let YY be the target label. When ZZ is continuous, the encoder must be stochastic, because a deterministic map would typically yield I(X;Z)=∞I(X;Z)=\infty (Section 25.6.1.3). The information bottleneck (Tishby et al., 1999) seeks a representation ZZ that retains as little of XX as possible while preserving as much about YY as possible:

min⁡p(z∣x)  I(X;Z)−β I(Y;Z).(25.6.15)\min_{p(z \mid x)}\; I(X; Z) - \beta\, I(Y; Z). \tag{25.6.15}

Here I(X;Z)I(X;Z) is the rate—how much information the representation keeps about the input—while I(Y;Z)I(Y;Z), weighted by β>0\beta>0, is the information it keeps about the label. Because the encoder sees only XX, the variables form a Markov chain Y→X→ZY\to X\to Z, and the data-processing inequality constrains I(Y;Z)≤min⁡{I(X;Y), I(X;Z)}I(Y; Z) \leq \min\{I(X; Y),\, I(X; Z)\}. A representation can never know more about the label than the input does, nor can it predict well without keeping input information.

The multiplier β\beta governs the trade-off, and its two extremes are easy to understand. Whenever β≤1\beta\le1, keeping nothing is optimal: by the inequality above, I(X;Z)−βI(Y;Z)≥(1−β) I(X;Z)≥0I(X;Z)-\beta I(Y;Z)\ge(1-\beta)\,I(X;Z)\ge0, and a constant encoder that ignores XX completely achieves I(X;Z)=I(Y;Z)=0I(X;Z)=I(Y;Z)=0. When the constant encoder is optimal, we say the bottleneck collapses. Conversely, as β\beta grows large, the label term dominates and the encoder preserves whatever helps predict YY. In that limit, I(Y;Z)I(Y;Z) approaches its ceiling I(X;Y)I(X;Y), and the representation approaches a minimal sufficient statistic: the coarsest summary of XX that still predicts YY as well as XX itself. Of course, when the encoder is restricted to a parametric family—as every neural network is—it may stop short of that ceiling.

Proposition (the bottleneck as a rate–distortion problem). If Y→X→ZY\to X\to Z is a Markov chain, then

I(Y;Z)=I(X;Y)−E(x,z)∼PX,Z[DKL(p(y∣x) ∥ p(y∣z))].(25.6.16)I(Y;Z)=I(X;Y)-\mathbb{E}_{(x,z)\sim P_{X,Z}}\Big[D_{\textrm{KL}}\big(p(y\mid x)\,\|\,p(y\mid z)\big)\Big]. \tag{25.6.16}

Proof. Expand I(Y;X,Z)I(Y;X,Z) via the chain rule in both orders: I(Y;Z)+I(Y;X∣Z)=I(Y;X)+I(Y;Z∣X)I(Y;Z)+I(Y;X\mid Z)=I(Y;X)+I(Y;Z\mid X). The Markov property gives I(Y;Z∣X)=0I(Y;Z\mid X)=0. Writing the remaining conditional mutual information in KL form yields I(Y;X∣Z)=E(x,z)[DKL(p(y∣x,z) ∥ p(y∣z))]I(Y;X\mid Z)=\mathbb{E}_{(x,z)}\big[D_{\textrm{KL}}(p(y\mid x,z)\,\|\,p(y\mid z))\big], and the Markov property simplifies p(y∣x,z)p(y\mid x,z) to p(y∣x)p(y\mid x). ■\blacksquare

Substituting (25.6.16) into the objective turns (25.6.15) into I(X;Z)+β E[d(X,Z)]−βI(X;Y)I(X;Z)+\beta\,\mathbb{E}[d(X,Z)]-\beta I(X;Y), with distortion d(x,z)=DKL(p(y∣x) ∥ p(y∣z))d(x,z)=D_{\textrm{KL}}(p(y\mid x)\,\|\,p(y\mid z)). Since the final term βI(X;Y)\beta I(X;Y) does not depend on the encoder, the information bottleneck is precisely the Lagrangian form of a rate–distortion problem. Instead of asking a designer to hand-craft a distortion metric, the label supplies it automatically: a code zz is a faithful representation of xx whenever it predicts YY just as accurately as xx does. Unlike ordinary rate–distortion, however, this distortion depends on the encoder itself through p(y∣z)p(y\mid z), making optimization considerably harder.

25.6.4.2 The Gaussian Information Bottleneck#

In one special setting, every quantity in the information bottleneck can be solved in closed form (Chechik et al., 2005). Take (X,Y)(X, Y) to be our Gaussian pair at ρ=0.9\rho = 0.9, for which I(X;Y)=0.830I(X; Y) = 0.830 nats, and use the additive-noise encoder from Section 25.6.3.2:

Z=X+σ ϵ,ϵ∼N(0,1),Z = X + \sigma\, \epsilon, \qquad \epsilon \sim \mathcal{N}(0, 1),

parameterized solely by the noise scale σ\sigma. The rate I(X;Z)I(X;Z) is already given by (25.6.14). For the label, Cov(Y,Z)=Cov(Y,X)=ρ\textrm{Cov}(Y,Z)=\textrm{Cov}(Y,X)=\rho and Var(Z)=1+σ2\textrm{Var}(Z)=1+\sigma^2, so ρYZ2=ρ2/(1+σ2)\rho_{YZ}^2=\rho^2/(1+\sigma^2). Applying (25.6.5) gives both mutual informations:

I(X;Z)=12log⁡(1+σ−2),I(Y;Z)=−12log⁡(1−ρ21+σ2).(25.6.17)I(X; Z) = \tfrac{1}{2}\log\left(1 + \sigma^{-2}\right), \qquad I(Y; Z) = -\tfrac{1}{2}\log\left(1 - \frac{\rho^2}{1 + \sigma^2}\right). \tag{25.6.17}

As σ\sigma decreases from ∞\infty to 00, the representation moves smoothly from knowing nothing about XX to knowing XX exactly, and its label information rises from 00 to the data-processing ceiling of 0.8300.830 nats.

To visualize this trade-off directly, write u=I(X;Z)u=I(X;Z) for the rate (reserving RR for the rate–distortion function R(D)R(D)). Inverting (25.6.17) gives σ−2=e2u−1\sigma^{-2}=e^{2u}-1, hence 1/(1+σ2)=1−e−2u1/(1+\sigma^2)=1-e^{-2u}, expressing label information directly as a function of rate:

I(Y;Z)=−12log⁡(1−ρ2(1−e−2u)),d I(Y;Z)du=ρ2ρ2+(1−ρ2) e2u.I(Y;Z)=-\tfrac12\log\big(1-\rho^2(1-e^{-2u})\big),\qquad \frac{d\,I(Y;Z)}{du}=\frac{\rho^2}{\rho^2+(1-\rho^2)\,e^{2u}}.

The derivative decreases monotonically from ρ2\rho^2 at u=0u=0 toward 00, so the curve is strictly concave. Leaving the origin with slope ρ2=0.81\rho^2=0.81, the first nat of input information buys at most 0.810.81 nats of label information, and each subsequent nat yields diminishing returns as I(Y;Z)I(Y;Z) approaches I(X;Y)I(X;Y). Chechik et al. (2005) proved that for a Gaussian pair no encoder, linear or nonlinear, can surpass this curve, making it the exact optimal frontier; we use that result without proof. For any chosen β\beta, the minimizer of the Lagrangian selects a single operating point along this frontier.

Proposition (operating point and collapse). In the Gaussian bottleneck with ρ2<1\rho^2\lt 1, the Lagrangian u−β I(Y;Z)u-\beta\,I(Y;Z) is convex in uu, with derivative 1−βρ21-\beta\rho^2 at u=0u=0. For β≤1/ρ2\beta\le1/\rho^2 its minimum is u=0u=0, the constant encoder. For β>1/ρ2\beta>1/\rho^2 the minimizer and its label information are

u∗=12log⁡ρ2(β−1)1−ρ2,I(Y;Z)∗=12log⁡β−1β(1−ρ2).(25.6.18)u^*=\frac12\log\frac{\rho^2(\beta-1)}{1-\rho^2},\qquad I(Y;Z)^*=\frac12\log\frac{\beta-1}{\beta(1-\rho^2)}. \tag{25.6.18}

Proof. Because I(Y;Z)I(Y;Z) is concave in uu, the Lagrangian u−βI(Y;Z)u-\beta I(Y;Z) is convex, with derivative 1−βρ2/(ρ2+(1−ρ2)e2u)1-\beta\rho^2/(\rho^2+(1-\rho^2)e^{2u}). At u=0u=0, this derivative equals 1−βρ21-\beta\rho^2. Whenever βρ2≤1\beta\rho^2\le1, the derivative is nonnegative at u=0u=0 and strictly increasing, so the minimum over u≥0u\ge0 occurs at u=0u=0. Otherwise, setting the derivative to zero gives ρ2+(1−ρ2)e2u=βρ2\rho^2+(1-\rho^2)e^{2u}=\beta\rho^2, or e2u=ρ2(β−1)/(1−ρ2)e^{2u}=\rho^2(\beta-1)/(1-\rho^2). Substituting ρ2e−2u=(1−ρ2)/(β−1)\rho^2e^{-2u}=(1-\rho^2)/(\beta-1) into I(Y;Z)=−12log⁡(1−ρ2+ρ2e−2u)I(Y;Z)=-\tfrac12\log(1-\rho^2+\rho^2e^{-2u}) yields the second expression. ■\blacksquare

Earlier, the general data-processing argument guaranteed collapse for β≤1\beta\le1. For the Gaussian pair at ρ=0.9\rho=0.9, collapse actually extends all the way to β≤1/ρ2=1.235\beta\le1/\rho^2=1.235. Below that threshold, every nat of rate adds 11 to the objective while reducing it by at most βρ2≤1\beta\rho^2\le1, because the frontier's slope never exceeds its initial value ρ2\rho^2. Above the threshold, increasing β\beta slides the operating point up the frontier toward the ceiling: β=2\beta=2 gives u∗=12ln⁡(0.81/0.19)=0.725u^*=\tfrac12\ln(0.81/0.19)=0.725 nats of rate and 0.4840.484 nats of label information, while β=16\beta=16 reaches 2.0792.079 and 0.7980.798 nats. Figure 25.6.5 plots this frontier and its operating points in the information plane, with rate I(X;Z)I(X;Z) on the horizontal axis and label information I(Y;Z)I(Y;Z) on the vertical axis.

Figure 25.6.5:

The information plane of the Gaussian bottleneck with ρ=0.9\rho = 0.9. The concave frontier traces the largest attainable I(Y;Z)I(Y;Z) at each rate I(X;Z)I(X;Z); the shaded region above it is infeasible, and the dashed ceiling is the data-processing limit I(X;Y)=−12log⁡(1−ρ2)≈0.830I(X;Y) = -\tfrac{1}{2}\log(1-\rho^2) \approx 0.830 nats. The frontier leaves the origin with slope ρ2\rho^2, and the multiplier selects the point where the slope equals 1/β1/\beta; for β≤1/ρ2≈1.23\beta\le1/\rho^2\approx1.23 that point collapses to the origin.

A phase transition this sharp is worth checking numerically: the proposition predicts that the optimal encoder keeps nothing at β=1.2\beta=1.2 yet retains information at β=1.25\beta=1.25. Below, we minimize the Lagrangian directly over a grid of 4,0014{,}001 noise scales without invoking the closed-form solution.

rho = 0.9
sigma = np.logspace(-2, 2, 4001)                  # encoder Z = X + sigma eps
I_xz = 0.5 * np.log(1 + sigma**-2)
I_yz = -0.5 * np.log(1 - rho**2 / (1 + sigma**2))
for beta in (1.2, 1.25, 1.5, 2, 4, 16):
    i = np.argmin(I_xz - beta * I_yz)             # Lagrangian on the grid
    u = (0.5 * np.log(rho**2 * (beta - 1) / (1 - rho**2))
         if beta * rho**2 > 1 else 0.0)           # closed-form optimum
    print(f'beta = {beta:5.2f}: I(X;Z) grid {I_xz[i]:.3f}, closed form {u:.3f};'
          f' I(Y;Z) = {I_yz[i]:.3f}')
beta =  1.20: I(X;Z) grid 0.000, closed form 0.000; I(Y;Z) = 0.000
beta =  1.25: I(X;Z) grid 0.032, closed form 0.032; I(Y;Z) = 0.026
beta =  1.50: I(X;Z) grid 0.379, closed form 0.378; I(Y;Z) = 0.281
beta =  2.00: I(X;Z) grid 0.725, closed form 0.725; I(Y;Z) = 0.484
beta =  4.00: I(X;Z) grid 1.275, closed form 1.274; I(Y;Z) = 0.687
beta = 16.00: I(X;Z) grid 2.078, closed form 2.079; I(Y;Z) = 0.798

The grid search and the closed-form solution agree to a thousandth of a nat, confirming the collapse threshold right where the proposition predicts: at β=1.2\beta=1.2 the constant encoder is optimal, whereas by β=1.25\beta=1.25 the encoder already retains 0.0320.032 nats. Notice that this exact same encoder with noise scale σ\sigma also achieves the rate–distortion curve R(D)R(D) for squared error at D=σ2/(1+σ2)D=\sigma^2/(1+\sigma^2). Rate–distortion judges the encoder by how well it reconstructs XX, whereas the information bottleneck judges it by how well it predicts YY.

25.6.4.3 The Variational Information Bottleneck#

For a Gaussian pair we could compute both mutual informations in the bottleneck objective analytically. On real data we can compute neither, because the true joint distribution is unknown: all we observe are samples (x,y)(x,y) paired with an encoder p(z∣x)p(z\mid x) that we choose. The variational information bottleneck (Alemi et al., 2017) makes the objective trainable by replacing each mutual information with a tractable bound that can be estimated from samples.

For the label term, we already have the needed bound. Introduce a decoder q(y∣z)q(y\mid z) (a classifier predicting the label from the representation) with cross-entropy loss LZ=E[−log⁡q(Y∣Z)]L_Z=\mathbb{E}[-\log q(Y\mid Z)]. Applying the loss certificate (25.6.9) to the pair (Z,Y)(Z,Y) immediately gives I(Y;Z)≥H(Y)−LZI(Y;Z)\ge H(Y)-L_Z.

Because we want to minimize the rate I(X;Z)I(X;Z), we need an upper bound on it instead. Write the rate in the conditional form (25.6.4), I(X;Z)=Ex[DKL(p(z∣x) ∥ p(z))]I(X;Z)=\mathbb{E}_x\big[D_{\textrm{KL}}(p(z\mid x)\,\|\,p(z))\big]. While the encoder p(z∣x)p(z\mid x) is known, the aggregated marginal p(z)p(z) is not, since it averages p(z∣x)p(z\mid x) over the unknown data distribution. Replace p(z)p(z) by any fixed prior density r(z)r(z) of our choice, such as a standard normal. Using the identity log⁡p(z∣x)r(z)=log⁡p(z∣x)p(z)+log⁡p(z)r(z)\log\frac{p(z\mid x)}{r(z)}=\log\frac{p(z\mid x)}{p(z)}+\log\frac{p(z)}{r(z)} and taking expectations over xx and zz gives

Ex[DKL(p(z∣x) ∥ r(z))]=I(X;Z)+DKL(p(z) ∥ r(z))  ≥  I(X;Z).(25.6.19)\mathbb{E}_x\Big[D_{\textrm{KL}}\big(p(z\mid x)\,\|\,r(z)\big)\Big]=I(X;Z)+D_{\textrm{KL}}\big(p(z)\,\|\,r(z)\big)\;\ge\;I(X;Z). \tag{25.6.19}

Any mismatch between our chosen prior rr and the true marginal p(z)p(z) can only inflate the rate bound; Exercise 9 calculates this gap explicitly for a Gaussian encoder. Combining both bounds shows that the KL term on the left-hand side of (25.6.19) plus βLZ\beta L_Z upper-bounds the bottleneck objective (25.6.15) up to the constant βH(Y)\beta H(Y). Because both terms are simple expectations over training examples, a neural network can minimize this bound directly with stochastic gradient descent.

Anyone who has trained a variational autoencoder will recognize the left-hand side of (25.6.19) immediately. A variational autoencoder (Section 17.7) is precisely this same construction with the input serving as its own label: an encoder p(z∣x)p(z\mid x), a fixed prior r(z)r(z), and a decoder that reconstructs xx from zz instead of predicting a separate class label. Its training loss is the reconstruction error plus a weighted KL penalty. Viewed through our lens, that KL penalty is an upper bound on the rate, capping how many nats the latent code can store about the input, while the reconstruction error plays the role of distortion. Only the placement of the trade-off weight differs: (25.6.15) multiplies the preserved information by β\beta, whereas a variational autoencoder places its weight on the KL rate term, so a large KL weight there corresponds to a small β\beta here.

The decoder's cross-entropy loss and the KL divergence to a prior are the only quantities in this section that can be evaluated from samples alone—giving a lower bound on one mutual information and an upper bound on another. Every other number we computed relied on knowing the joint distribution, which we never have for real images or text. In Section 25.7, we ask how much about mutual information can be estimated from samples alone.

25.6.5 Summary#

Mutual information is the KL divergence between a joint distribution and the product of its marginals, I(X;Y)=DKL(PX,Y ∥ PX⊗PY)I(X;Y)=D_{\textrm{KL}}(P_{X,Y}\,\|\,P_X\otimes P_Y); it vanishes if and only if XX and YY are independent and is invariant under invertible reparameterizations of either variable. Unlike linear correlation, it detects nonlinear dependence—assigning 1.141.14 nats to XX and Y=X2+0.3ϵY=X^2+0.3\epsilon even though their correlation is zero. By the data-processing inequality, sequential processing cannot create information, though neural network layers can rearrange existing information to make it easier for a classifier to read. Fano's inequality turns any target error rate into a minimum requirement on mutual information, and the cross-entropy loss LL of any probabilistic model certifies I(X;Y)≥H(Y)−LI(X;Y)\ge H(Y)-L. Shannon's channel capacity and rate–distortion function arise as the maximum of mutual information over inputs and its minimum over lossy encoders. Finally, the information bottleneck min⁡I(X;Z)−βI(Y;Z)\min I(X;Z)-\beta I(Y;Z) casts representation learning as a rate–distortion problem whose distortion is supplied by the label: for a Gaussian pair it collapses until β\beta exceeds 1/ρ21/\rho^2, and in its variational form its rate penalty becomes the familiar KL regularizer of a variational autoencoder.

25.6.6 Exercises#

  1. [code] Rare pairs and PMI. Pointwise mutual information (25.6.6) corrects co-occurrence counts for the frequencies of the two words (Section 25.6.1.4).

    1. Show that pmi(x,y)≤min⁡{−log⁡pX(x),−log⁡pY(y)}\textrm{pmi}(x, y) \leq \min\{-\log p_X(x), -\log p_Y(y)\}. When is each of the two bounds attained?
    2. Extend counts by a fourth first word sri and a fourth second word lanka that occur only in the bigram "sri lanka", with count 22. Recompute the pmi of "new york", "machine learning", "the day", and "sri lanka", and repeat with count 11. Zero counts give pmi=−∞\textrm{pmi} = -\infty and make (p * pmi).sum() return nan, so restrict sums to the nonzero cells, as mutual_information does.
    3. Compare the contributions pX,Y(x,y) pmi(x,y)p_{X,Y}(x, y)\,\textrm{pmi}(x, y) of "new york" and "sri lanka" to I(X;Y)I(X;Y). Then add 11 to every count and recompute both pmi values. Which of these scores would you use to rank collocations, and why?
  2. Information versus usable information. A label YY is a fair bit. Given Y=0Y = 0 the input X∈R2X \in \mathbb{R}^2 is uniform on the circle of radius 11, and given Y=1Y = 1 it is uniform on the circle of radius 22. A representation computes Z=∥X∥2Z = \|X\|^2.

    1. Show that I(Y;Z)=I(Y;X)=ln⁡2I(Y;Z) = I(Y;X) = \ln 2, although x↦∥x∥2x \mapsto \|x\|^2 is not invertible. Which condition for equality in the data-processing inequality of Section 25.6.2.2 holds?
    2. Show that no linear classifier y^=1(w⊤x+b>0)\hat y = \mathbf{1}(\mathbf{w}^\top \mathbf{x} + b > 0) classifies every input correctly, whereas a threshold on ZZ does.
    3. The layers of a network form a Markov chain X→Z1→Z2→⋯X \to Z_1 \to Z_2 \to \cdots. Show that the error of the best classifier of any kind that reads ZℓZ_\ell cannot fall as ℓ\ell grows. The accuracy of a linear classifier fit to ZℓZ_\ell often rises with ℓ\ell all the same. Why is there no contradiction?
    4. Xu et al. (2020) measure the information that a family V\mathcal{V} of predictors q(y∣x)q(y \mid x) can extract. Let HV(Y∣X)=inf⁡q∈VE[−log⁡q(Y∣X)]H_{\mathcal{V}}(Y \mid X) = \inf_{q \in \mathcal{V}} \mathbb{E}[-\log q(Y \mid X)], and let HV(Y)H_{\mathcal{V}}(Y) be the same infimum over the predictors in V\mathcal{V} that ignore their input. The usable information is
IV(X→Y)=HV(Y)−HV(Y∣X).I_{\mathcal{V}}(X \to Y) = H_{\mathcal{V}}(Y) - H_{\mathcal{V}}(Y \mid X).

Let V\mathcal{V} be logistic regression on the given input. Show that IV(X→Y)=0I_{\mathcal{V}}(X \to Y) = 0 and IV(Z→Y)=ln⁡2I_{\mathcal{V}}(Z \to Y) = \ln 2. For XX, use that the expected logistic loss is convex in (w,b)(\mathbf{w}, b) and unchanged when w\mathbf{w} is rotated. Which inequality of Section 25.6.2.2 does IVI_{\mathcal{V}} violate?

  1. Synergy and the Venn diagram. Let XX and YY be independent fair bits and Z=X⊕YZ = X \oplus Y their exclusive or, for which the section computed I(X;Y)=0I(X;Y) = 0 and I(X;Y∣Z)=ln⁡2I(X;Y \mid Z) = \ln 2.

    1. Which of the Markov chains X→Z→YX \to Z \to Y, X→Y→ZX \to Y \to Z, and Y→X→ZY \to X \to Z hold? What does the data-processing inequality therefore say about this triple?
    2. In a three-variable version of Figure 25.6.1, the area common to all three disks would be the interaction information I(X;Y;Z)=I(X;Y)−I(X;Y∣Z)I(X;Y;Z) = I(X;Y) - I(X;Y \mid Z). Prove that I(X;Y;Z)=H(X)+H(Y)+H(Z)−H(X,Y)−H(X,Z)−H(Y,Z)+H(X,Y,Z)I(X;Y;Z) = H(X) + H(Y) + H(Z) - H(X,Y) - H(X,Z) - H(Y,Z) + H(X,Y,Z), and conclude that I(X;Y;Z)I(X;Y;Z) is symmetric in its three arguments.
    3. Evaluate I(X;Y;Z)I(X;Y;Z) for the triple of (a) and for three copies X=Y=ZX = Y = Z of one fair bit. What do the two values imply for a three-disk diagram of entropies?

    Adapted from Thomas M. Cover and Joy A. Thomas, Elements of Information Theory, 2nd ed., Exercise 2.25, and David J. C. MacKay, Information Theory, Inference, and Learning Algorithms, Exercise 8.8.

  2. [code] Data processing from ff-divergences. For any channel κ\kappa that maps an input to a random output, and any two distributions PP and QQ of the input, the output distributions satisfy Df(Pκ ∥ Qκ)≤Df(P ∥ Q)D_f(P\kappa\,\|\,Q\kappa)\le D_f(P\,\|\,Q) for every ff-divergence (Section 25.3.3.3). The KL divergence and χ2(P∥Q)=∑xp(x)2/q(x)−1\chi^2(P\|Q)=\sum_x p(x)^2/q(x)-1 are two of them.

    1. Let X→Y→ZX\to Y\to Z be a Markov chain. Take P=PX,YP=P_{X,Y}, Q=PX⊗PYQ=P_X\otimes P_Y, and the channel κ\kappa that maps (x,y)(x,y) to (x,z)(x,z) with z∼p(z∣y)z\sim p(z\mid y). Show that Pκ=PX,ZP\kappa=P_{X,Z} and Qκ=PX⊗PZQ\kappa=P_X\otimes P_Z, and conclude that I(X;Z)≤I(X;Y)I(X;Z)\le I(X;Y).
    2. Which part of the section's data-processing proposition does this route not deliver?
    3. For the two flips in series, with probabilities 0.10.1 and 0.20.2, compute the KL divergence and the χ2\chi^2 divergence of each joint table from the product of its marginals, before and after the second flip.
    4. Show that for a fair input through the flip channel with probability δ\delta, χ2(PX,Y ∥ PX⊗PY)=(1−2δ)2\chi^2(P_{X,Y}\,\|\,P_X\otimes P_Y)=(1-2\delta)^2, and check your numbers from (c). Conclude that a further flip with probability δ′\delta' multiplies this divergence by (1−2δ′)2(1-2\delta')^2, here by 0.360.36. Is the ratio I(X;Z)/I(X;Y)I(X;Z)/I(X;Y) from (c) the same factor?
  3. Fano and a converse. ● Fano's inequality (25.6.8) bounds from below the error of any estimate Y^=g(X)\hat Y = g(X) of a label YY with kk values.

    1. Let Y^(x)=arg⁡max⁡yp(y∣x)\hat Y(x) = \arg\max_y p(y \mid x) be the most probable label. Show that its error satisfies Pe≤1−e−H(Y∣X)P_e \leq 1 - e^{-H(Y \mid X)}. Bound max⁡yp(y∣x)\max_y p(y \mid x) from below by ∑yp(y∣x)2=E[p(Y∣X)∣X=x]\sum_y p(y \mid x)^2=\mathbb{E}[p(Y\mid X)\mid X=x], then apply Jensen's inequality once, to E[p(Y∣X)]=E[elog⁡p(Y∣X)]\mathbb{E}[p(Y\mid X)]=\mathbb{E}\big[e^{\log p(Y\mid X)}\big].
    2. An observation XX carries I(X;Y)=9I(X;Y) = 9 nats about a balanced 10,00010{,}000-class label YY. Use (25.6.8) and (a) to bracket the error of the best classifier. The inequality (25.6.8) has no closed-form solution for PeP_e, so solve it numerically. What does the width of this interval say about predicting a downstream error rate from a mutual information?
  4. The loss certificate and Fano. A classifier of k=10k=10 balanced classes has test error Pe=0.08P_e=0.08 and test loss L=0.30L=0.30 nats.

    1. How many nats of I(X;Y)I(X;Y) does Fano's inequality (25.6.8) certify, and how many does the loss certificate (25.6.9)?
    2. For any estimate Y^=g(X)\hat Y=g(X) with error probability PeP_e, let the model q(y∣x)q(y\mid x) put probability 1−Pe1-P_e on y=g(x)y=g(x) and spread PeP_e evenly over the other k−1k-1 labels. Show that its cross-entropy loss is Hb(Pe)+Pelog⁡(k−1)H_b(P_e)+P_e\log(k-1), and conclude that Fano's inequality is the loss certificate of this model. Which of the four models evaluated in Section 25.6.2.4 is it?
    3. The classifier of (a) reports a smaller loss than the model that (b) builds from its decisions. What must its confidences do for that to happen? Give a pair (X,Y)(X,Y) with a binary label and a model with error rate PeP_e that certifies more than Fano's inequality does.
  5. Binary channels. ● Work in nats with the binary entropy HbH_b.

    1. A Z-channel passes a 00 unchanged and turns a 11 into a 00 with probability 12\tfrac12. Compute I(X;Y)=H(Y)−H(Y∣X)I(X;Y)=H(Y)-H(Y\mid X) as a function of a=P(X=1)a=P(X=1), and show that it is largest at a=25a=\tfrac25, where it equals ln⁡54\ln\tfrac54 nats. Why does the best input send the unreliable symbol less than half the time, and why not never?
    2. A feature takes the values ±1\pm 1 and passes through dropout with rate α\alpha, which replaces it by 00 with probability α\alpha and rescales it otherwise. Show that this binary erasure channel has capacity (1−α)ln⁡2(1 - \alpha)\ln2 nats.
    3. Find the flip probability δ\delta at which the binary symmetric channel has the same capacity as dropout with α=0.5\alpha = 0.5. Why does a flipped bit cost more capacity than an erased one?
  6. The Gaussian channel. Let Y=X+NY=X+N with noise N∼N(0,σN2)N\sim\mathcal N(0,\sigma_N^2) independent of XX, and let the input obey the power constraint E[X2]≤P\mathbb{E}[X^2]\le P.

    1. Show that I(X;Y)=h(Y)−h(N)I(X;Y)=h(Y)-h(N) for any input with a density.
    2. Among densities with variance s2s^2, the Gaussian has the largest differential entropy, 12log⁡(2πes2)\tfrac12\log(2\pi e s^2). Use this to show h(Y)≤12log⁡(2πe(P+σN2))h(Y)\le\tfrac12\log\big(2\pi e(P+\sigma_N^2)\big), and conclude that the capacity is C=12log⁡(1+P/σN2)C=\tfrac12\log(1+P/\sigma_N^2), attained by a Gaussian input.
    3. Evaluate CC at signal-to-noise ratios P/σN2=1,10,100P/\sigma_N^2=1,10,100, in nats and in bits. Show that at high signal-to-noise ratio each doubling of PP adds about 12ln⁡2\tfrac12\ln2 nats, half a bit.
    4. A diffusion model replaces a coordinate XX of the data, scaled so that E[X2]=1\mathbb{E}[X^2]=1, by a X+1−a ϵ\sqrt{a}\,X+\sqrt{1-a}\,\epsilon with 0<a<10\lt a\lt 1 and independent ϵ∼N(0,1)\epsilon\sim\mathcal N(0,1). Show that the noised coordinate carries at most 12log⁡11−a\tfrac12\log\frac{1}{1-a} nats about XX, whatever the distribution of XX, and evaluate the bound at a=0.5a=0.5 and a=0.01a=0.01. For which data is it attained?
  7. The rate bound of a variational autoencoder. Let X∼N(0,1)X\sim\mathcal N(0,1), let the encoder be Z=X+σϵZ=X+\sigma\epsilon as in Section 25.6.4.2, so that p(z∣x)=N(z;x,σ2)p(z\mid x)=\mathcal N(z;x,\sigma^2), and let the prior be r=N(0,1)r=\mathcal N(0,1). Use DKL(N(μ,s2) ∥ N(0,1))=12(μ2+s2−1−log⁡s2)D_{\textrm{KL}}\big(\mathcal N(\mu,s^2)\,\|\,\mathcal N(0,1)\big)=\tfrac12(\mu^2+s^2-1-\log s^2).

    1. Compute the three terms of (25.6.19) and check the identity. By how many nats does the KL penalty overstate the rate at σ=1\sigma=1?
    2. Rescale the code to Z′=Z/1+σ2Z'=Z/\sqrt{1+\sigma^2}. Show that I(X;Z′)=I(X;Z)I(X;Z')=I(X;Z) and that the bound is now an equality.
    3. The rate does not depend on the units of the code, and the bound does. Which prior rr makes the bound an equality for a given encoder? What does minimizing the KL penalty therefore do to the code, besides lowering its rate?

Discussions