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')37.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\sim\mathcal N(0,1)\) and let \(Y=X^2+0.3\,\epsilon\), where \(\epsilon\sim\mathcal N(0,1)\) is independent noise. Because \(X^3\) is symmetric around zero, \(\textrm{Cov}(X,Y)=\mathbb{E}[X^3]=0\), so the correlation between \(X\) and \(Y\) is zero. Yet \(X\) nearly determines \(Y\): once we know \(X\), \(Y\) varies only by noise of standard deviation \(0.3\), whereas on its own \(Y\) spreads roughly from \(0\) to \(9\). 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.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 \(D_{\textrm{KL}}(P\|Q)\) from Section 37.1, which by Gibbs’ inequality is always nonnegative and vanishes only when \(P=Q\). Taking \(P\) to be the true joint distribution of the pair and \(Q\) to be the product distribution the pair would follow if its components were independent gives the mutual information \(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 37.7.
As before, we work in nats, where \(1\) bit \(=\ln 2\approx0.693\) nats. All logarithms are natural; we write \(\log\) in general formulas and \(\ln\) when evaluating numerical values. We denote the binary entropy by \(H_b(p)=-p\log p-(1-p)\log(1-p)\).
37.6.1 Measures of Dependence
To keep every definition concrete, we evaluate each one first on a single \(2 \times 2\) probability table, which will return as a running example throughout the section.
37.6.1.1 Joint and Conditional Entropy
Let \(X\) be a fair bit, and let \(Y\) be a copy of \(X\) that is flipped with probability \(\delta=0.1\). We can read \(X\) as a bit sent over a noisy line and \(Y\) as the bit received, or read \(Y\) as a binary label and \(X\) as a noisy feature that agrees with it \(90\%\) of the time. Because the table is symmetric, nothing below depends on which interpretation we choose. With rows indexing \(x\in\{0,1\}\) and columns indexing \(y\in\{0,1\}\), the joint distribution is
\[ p_{X,Y}=\begin{pmatrix}0.45&0.05\\0.05&0.45\end{pmatrix}, \]
and summing rows and columns gives the marginals \(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\mid x)\).
Beyond the individual entropies \(H(X)\) and \(H(Y)\), a pair of random variables has two natural entropies, both introduced in Section 37.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) = -\mathbb{E}_{(x, y) \sim P_{X,Y}} [\log p_{X, Y}(x, y)]. \tag{37.6.1}\]
For our table, \(H(X,Y)=-2(0.45\ln0.45)-2(0.05\ln0.05)=1.018\) nats. That is larger than the \(0.693\) nats of a single fair bit, but smaller than the \(1.386\) nats of two independent fair bits.
The conditional entropy measures the surprise remaining in \(Y\) once \(X\) is known. It is the average entropy of the conditional rows \(p(y\mid x)=p_{X,Y}(x,y)/p_X(x)\):
\[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{37.6.2}\]
For the flipped bit, the two rows are \((0.9,0.1)\) and \((0.1,0.9)\), each with entropy \(H_b(0.1)=0.325\) nats, so \(H(Y\mid X)=0.325\) nats. Even after observing \(X\), \(Y\) still retains \(0.325\) of its original \(0.693\) nats of surprise.
Notice that the three numbers satisfy \(1.018=0.693+0.325\). This is the chain rule \(H(X,Y)=H(X)+H(Y\mid X)\) from Section 37.1.1.3: the surprise in the pair equals the surprise in \(X\) plus the additional surprise in \(Y\) once \(X\) is known.
37.6.1.2 Mutual Information
Conditional entropy captures the part of the surprise in \(Y\) that \(X\) cannot explain. What we want now is the part the two variables share. If \(X\) and \(Y\) were independent, their joint distribution would be the product of their marginals, \(P_X \otimes P_Y\), placing \(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) = 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{37.6.3}\]
For the flipped bit, the product of the marginals puts \(0.25\) in every cell. The ratio of the joint probability to the independent product is therefore \(0.45/0.25=1.8\) on the diagonal, where \(X\) and \(Y\) agree, and \(0.05/0.25=0.2\) off the diagonal, where they disagree. Averaging the log-ratios under the joint distribution gives
\[ I(X;Y)=0.9\ln1.8+0.1\ln0.2=0.529-0.161=0.368\textrm{ nats}. \]
Agreements occur \(1.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 37.2), \(I(X;Y)\) is the number of nats per pair wasted by a code that treats \(X\) and \(Y\) as independent. We encounter this exact penalty in Section 17.9, when a network predicts two masked tokens independently.
We can also read Equation 37.6.3 one row of the table at a time. Dividing numerator and denominator by \(p_X(x)\) turns the ratio into \(p(y\mid x)/p_Y(y)\), rewriting the expectation over pairs as an average over \(x\) of the KL divergence between the conditional and marginal distributions of \(Y\):
\[I(X;Y)=\mathbb{E}_{x\sim P_X}\Big[D_{\textrm{KL}}\big(p(y\mid x)\,\|\,p_Y(y)\big)\Big]. \tag{37.6.4}\]
In this form, mutual information measures how far, on average, observing \(x\) shifts the distribution of \(Y\) away from its marginal. For the flipped bit, each conditional row, \((0.9,0.1)\) or \((0.1,0.9)\), lies \(0.9\ln1.8+0.1\ln0.2=0.368\) nats from the marginal \((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 37.6.4.
Proposition (properties of mutual information). For any pair \((X,Y)\), \(I(X;Y)=I(Y;X)\ge0\), with equality if and only if \(X\) and \(Y\) are independent. When the entropies involved are finite,
\[ I(X;Y)=H(X)+H(Y)-H(X,Y)=H(X)-H(X\mid Y)=H(Y)-H(Y\mid X). \]
Proof. Swapping \(X\) and \(Y\) leaves the ratio in Equation 37.6.3 unchanged, which proves symmetry. Nonnegativity and the equality condition follow immediately from Gibbs’ inequality applied to \(P_{X,Y}\) and \(P_X \otimes P_Y\): the KL divergence is nonnegative and vanishes if and only if \(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) = \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 \mid Y)=H(X)+H(Y\mid X)\), yields the remaining two forms. \(\blacksquare\)
Thus \(X\) says exactly as much about \(Y\) as \(Y\) says about \(X\). The final identity interprets mutual information as a reduction in uncertainty: observing \(X\) lowers the surprise in \(Y\) from \(H(Y)\) to \(H(Y\mid X)\)—for the flipped bit, from \(0.693\) down to \(0.325\) nats. Nonnegativity also implies the subadditivity bound \(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 37.6.1 illustrates these relationships visually; each identity in the proposition is simply a different way of reading off the area of the overlap.
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\mid X)\) by averaging the row entropies.
I(X;Y) = 0.3681 nats (KL form) = 0.3681 (H(Y) - H(Y|X)) = 0.531 bits
Both expressions return \(0.3681\) nats, or \(0.531\) bits: a copy that flips one time in ten still conveys just over half a bit about the original.
37.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 \(h\) of Section 37.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\mid X)\) whenever these quantities are finite, where \(h(Y\mid X)\) denotes the differential entropy of the conditional density \(p(y\mid x)\), averaged over \(x\).
Proposition (Gaussian mutual information). If \((X, Y)\) is bivariate Gaussian with variances \(\sigma_X^2,\sigma_Y^2>0\) and correlation coefficient \(\rho\), \(\rho^2<1\), then
\[I(X; Y) = -\tfrac{1}{2} \log\left(1 - \rho^2\right). \tag{37.6.5}\]
Proof. We use \(I(X;Y)=h(Y)-h(Y\mid X)\). A Gaussian variable with variance \(\sigma^2\) has differential entropy \(\tfrac12\log(2\pi e\sigma^2)\) (Section 37.1.4.3), so \(h(Y)=\tfrac12\log(2\pi e\sigma_Y^2)\). Conditioned on \(X=x\), \(Y\) remains Gaussian with variance \(\sigma_Y^2(1-\rho^2)\), regardless of \(x\). This is the variance of the residual left after subtracting the best linear prediction of \(Y\) from \(X\), and for a bivariate Gaussian that residual is independent of \(X\) (Section 36.3.3.3). Hence \(h(Y\mid X)=\tfrac12\log\big(2\pi e\sigma_Y^2(1-\rho^2)\big)\), and subtracting gives \(-\tfrac12\log(1-\rho^2)\). \(\blacksquare\)
The result depends solely on \(1-\rho^2\), the fraction of \(Y\)’s variance left unexplained by \(X\). Notice that the units of \(Y\) have cancelled out—our first glimpse of the coordinate invariance proved in Section 37.6.1.5.
When \(\rho = 0\), the variables are independent and \(I(X;Y) = 0\). As \(\rho \to \pm 1\), the joint density collapses onto a straight line and \(I(X;Y) \to \infty\). Between those extremes, \(\rho = 0.5\) yields \(0.144\) nats, \(\rho = 0.9\) yields \(0.830\) nats, and \(\rho = 0.99\) yields \(1.959\) nats. The bivariate Gaussian with standard normal marginals and \(\rho=0.9\) will reappear throughout this section; we refer to it as the Gaussian pair at \(\rho=0.9\).
As the limit \(\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=X\) for a continuous random variable \(X\), knowing \(X\) pins down \(Y\) to infinitely many decimal places, and the same holds whenever \(Y\) is a deterministic function of \(X\) that takes no single value with positive probability. By contrast, infinite mutual information is impossible when \(Y\) is discrete with finite entropy: then \(I(X;Y)=H(Y)-H(Y\mid X)\le H(Y)\) regardless of \(X\), where \(H(Y\mid X)\) averages the entropy of \(p(\cdot\mid x)\) over \(x\). For a standard normal \(X\), for instance, the sign of \(X\) carries exactly \(\ln 2\) nats. This same ceiling caps the Jensen–Shannon divergence of Section 16.1 at \(\ln 2\): as shown there, it equals the mutual information between a sample and the binary label identifying its source.
37.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 Equation 37.6.3 answers this directly. It is the pointwise mutual information,
\[\textrm{pmi}(x, y) = \log\frac{p_{X, Y}(x, y)}{p_X(x)\, p_Y(y)}, \tag{37.6.6}\]
which compares how often the specific pair \((x, y)\) occurs with how often it would occur if \(X\) and \(Y\) 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) = \mathbb{E}_{(x,y) \sim P_{X,Y}}[\textrm{pmi}(x,y)]\) is their average attraction. For the flipped bit, the pmi is \(\ln1.8=+0.588\) on the two agreeing cells and \(\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:
| count | york | learning | day |
|---|---|---|---|
| new | 38 | 3 | 9 |
| machine | 1 | 46 | 3 |
| the | 11 | 21 | 168 |
Raw counts are misleading here. “The day” is by far the most frequent pair (\(168\) occurrences versus \(38\) 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.52\) nats and “machine learning” scores \(1.37\), whereas the frequent pair “the day” reaches only \(0.34\). Meanwhile, “the york” is negative at \(-1.11\) nats, occurring roughly three times less often than independence would predict. The mutual information of the table, \(0.41\) nats, summarizes how strongly the first word constrains the second on average. This same marginal correction reappears in learned word embeddings (Section 19.1): by training a skip-gram model to distinguish observed pairs of neighboring words from \(K\) random pairs, we implicitly factorize the matrix of shifted pointwise mutual informations, \(\textrm{pmi}(x,y)-\log K\) (Levy and Goldberg 2014), as Exercise 7 of Section 37.7 derives.
37.6.1.5 Mutual Information and Correlation
The correlation coefficient \(\rho(X,Y)=\textrm{Cov}(X,Y)/(\sigma_X\sigma_Y)\) of Section 36.2 detects only linear dependence: having \(\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 \sim \mathcal{N}(0, 1)\) and \(Y = X^2 + 0.3\,\epsilon\) with independent \(\epsilon \sim \mathcal{N}(0,1)\), a pair whose correlation is \(\rho=0\). Writing \(I(X;Y)=h(Y)-h(Y\mid X)\) lets us evaluate the mutual information using one-dimensional integrals. Conditioned on \(X=x\), the only randomness left in \(Y\) is the additive noise, and shifting a distribution by the known constant \(x^2\) leaves differential entropy unchanged, so \(h(Y\mid X)=h(0.3\,\epsilon)=\tfrac12\ln(2\pi e\cdot0.09)=0.215\) nats. Before computing \(h(Y)\) numerically, we can bound it analytically: \(Y\) has variance \(\textrm{Var}(X^2)+0.09=2.09\), and among all densities with a given variance the Gaussian maximizes differential entropy (Section 37.1.4.3), giving \(h(Y)\le\tfrac12\ln(2\pi e\cdot2.09)=1.79\) nats and thus \(I(X;Y)\le1.79-0.215=1.57\) nats. Because the marginal density of \(Y\) is a continuous mixture over \(x\), \(p_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)\).
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.141\) nats. This sits well below our Gaussian upper bound of \(1.57\) nats because the density of \(Y\)—concentrated near zero with a long right tail—is far from Gaussian. At the same time, it exceeds the \(0.830\) nats of the Gaussian pair at \(\rho=0.9\), even though its linear correlation is zero. Figure 37.6.2 compares all three cases side by side.
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 \(X\) and of \(Y\). Then \(I(\phi(X);\psi(Y))=I(X;Y)\).
Proof. For discrete variables, invertible maps simply relabel the outcomes: the joint distribution of \((\phi(X), \psi(Y))\) assigns the same probabilities as that of \((X, Y)\) to the relabeled outcomes, leaving the sum in Equation 37.6.3 unchanged. For continuous variables, we prove the smooth case here to show the mechanism; Section 37.6.2.2 removes the smoothness assumption. Suppose \(\phi\) and \(\psi\) are continuously differentiable with continuously differentiable inverses, and change variables via \((x, y) \mapsto (\phi(x), \psi(y))\). The joint density of the transformed pair at \((\phi(x),\psi(y))\) is \(p_{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\phi(x)|^{-1}\) and \(|\det D\psi(y)|^{-1}\). Those Jacobian factors cancel in the density ratio, so the integrand of Equation 37.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\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 \(h\) depends on units. Correlation is preserved only by affine transformations (up to sign). Applying the invertible map \(x\mapsto x^3\) to the first coordinate of the Gaussian pair at \(\rho=0.9\), for example, leaves mutual information fixed at \(0.830\) nats, while the correlation drops from \(0.9\) to \(3\rho/\sqrt{15}=0.697\) (since \(\mathbb{E}[X^3Y]=3\rho\) and \(\textrm{Var}(X^3)=15\) for standard normal \(X\)). Mutual information asks whether two variables carry information about each other in any coordinates, not whether they happen to lie along a straight line.
37.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.
37.6.2.1 Conditional Mutual Information and the Chain Rule
Let us extend the flipped bit by one step. Suppose \(Z\) is produced by flipping \(Y\) once more, independently, with probability \(0.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 37.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\cdot0.8+0.9\cdot0.2=0.26\). The pair \((X,Z)\) is therefore a flipped bit with \(\delta=0.26\), giving \(I(X;Z)=\ln2-H_b(0.26)=0.120\) nats. The second noisy line has wiped out two thirds of the \(0.368\) nats that \(Y\) carried.
With three variables, a new question arises: how much information do \(X\) and \(Y\) share once \(Z\) is already known? Just as entropy has a conditional version, so does mutual information:
\[I(X; Y \mid Z) = H(X \mid Z) - H(X \mid Y, Z), \tag{37.6.7}\]
where \(H(X\mid Y,Z)\) is the conditional entropy of \(X\) given the pair \((Y,Z)\). Writing each conditional entropy as an expectation and combining the logarithms yields the divergence form \(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 \(z\). Because it is an expectation of KL divergences, \(I(X; Y \mid Z)\) is always nonnegative, and it equals zero if and only if \(X\) and \(Y\) are conditionally independent given \(Z\).
This definition lets us split the information that the pair \((Y,Z)\) carries about \(X\) into two pieces. Subtracting and adding \(H(X\mid Z)\) inside \(I(X;Y,Z)=H(X)-H(X\mid Y,Z)\) gives
\[ 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)\) tells us about \(X\) equals what \(Z\) tells us plus what \(Y\) adds once \(Z\) is known. We can equally well condition on \(Y\) first. For our two flips in series, the two orderings decompose the same total in two ways. Because \(Z\) is generated from \(Y\) and independent noise, once \(Y\) is known \(Z\) adds nothing further about \(X\): \(I(X;Z\mid Y)=0\), so putting \(Y\) first gives \(I(X;Y,Z)=I(X;Y)+0=0.368\) nats. Putting \(Z\) first splits the same \(0.368\) nats as \(I(X;Z)+I(X;Y\mid Z)=0.120+I(X;Y\mid Z)\), leaving \(I(X;Y\mid Z)=0.248\) nats. Here conditioning on \(Z\) reduced what \(Y\) reveals about \(X\), because \(Z\) already holds part of that information. As we will see in the next subsection, however, conditioning can also increase mutual information.
37.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, Z\) form a Markov chain, written \(X \to Y \to Z\), when \(Z\) depends on \((X, Y)\) solely through \(Y\), meaning \(p(z \mid x, y) = p(z \mid y)\). This captures the exact structure of sequential processing: \(Y\) is produced from \(X\) (a measurement, feature map, or hidden layer), and \(Z\) is then computed from \(Y\) alone, possibly with fresh randomness. Equivalently, \(X\) and \(Z\) are conditionally independent given \(Y\), so \(I(X; Z \mid Y) = 0\).
Proposition (data-processing inequality). If \(X \to Y \to Z\) is a Markov chain and the entropies involved are finite, then
\[ I(X; Z) \leq I(X; Y), \]
with equality if and only if \(I(X; Y \mid Z) = 0\), that is, if and only if \(X \to Z \to Y\) is also a Markov chain (Cover and Thomas 1999).
Proof. Expand \(I(X; Y, Z)\) by the chain rule in both orders:
\[ 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 \mid Z) \leq I(X; Y)\), since conditional mutual information is nonnegative. Equality holds if and only if \(I(X; Y \mid Z) = 0\). \(\blacksquare\)
No processing of \(Y\), whether deterministic or randomized, can increase the information it carries about \(X\). For our two flips in series, the inequality simply reads \(0.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 \(X\) and \(Y\) are independent fair bits and \(Z = X \oplus Y\) is their exclusive or. Marginally \(X\) and \(Y\) share zero information, yet once \(Z\) is revealed, \(Y\) determines \(X\) 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 \mid Y) = 0\) confirms the Markov property numerically, and both chain-rule decompositions of \(I(X; Y, Z)\) yield \(0.3681\) nats. For the exclusive or, conditioning on \(Z\) boosts the mutual information between \(X\) and \(Y\) from \(0\) to the full \(\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\to Z\to Y\) is also a Markov chain, meaning \(Z\) retains everything \(Y\) tells us about \(X\). An invertible transformation \(Z=g(Y)\) certainly achieves this, since \(Y\) can be recovered from \(Z\). Yet a map can also discard part of \(Y\) without losing information about \(X\), as long as whatever it discards is unrelated to \(X\). 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)\) with this property (so that \(p(x \mid y)\) depends on \(y\) only through \(T(y)\), and therefore \(I(X;T(Y))=I(X;Y)\)) is called a sufficient statistic. The sufficient statistics of an exponential family (Section 36.4) are precisely summaries of this kind, with \(Y\) playing the role of the data and \(X\) the parameter \(\theta\) (equipped with a prior so that \(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 37.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 37.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 \to Z_1 \to Z_2 \to \cdots\), so \(I(X; Z_\ell)\) cannot increase with depth \(\ell\). From here to the end of this part, let \(Y\) 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 \to X \to Z_1 \to Z_2 \to \cdots\) is also a Markov chain, and \(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 \(Y\) is a fair bit, and the input \(X \in \mathbb{R}^2\) is uniform on the circle of radius \(1\) when \(Y=0\) and on the circle of radius \(2\) when \(Y=1\). The input determines the label exactly, so \(I(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/3\). Now apply a single nonlinear feature \(Z=\|X\|^2\), which takes only the values \(1\) and \(4\). A simple threshold between them classifies every point perfectly, even though \(I(Y;Z)=\ln2\) is no larger than \(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 \to Z_1 \to Z_2 \to \cdots\). For a deterministic layer, \(H(Z_\ell\mid X)=0\). If the representation is discrete or quantized, \(I(X;Z_\ell)\) simply reduces to the entropy \(H(Z_\ell)\); if it is continuous, \(I(X;Z_\ell)\) is typically infinite (Section 37.6.1.3). As a measure of how much a layer retains about its input, \(I(X;Z_\ell)\) is therefore meaningful only when the layer injects noise or produces a discrete output.
37.6.2.3 Fano’s Inequality
Accurate prediction demands mutual information. A classifier that achieves \(5\%\) error across \(1{,}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 \(Y\) take values in a set of \(k\) elements, let \(\hat Y=g(X)\) be any estimate of \(Y\) computed from \(X\) and taking values in the same set, and let \(P_e=P(\hat Y\ne Y)\) be its error probability. Then
\[H_b(P_e) + P_e \log(k - 1) \geq H(Y \mid X) = H(Y) - I(X; Y). \tag{37.6.8}\]
The left-hand side has a clean coding interpretation as the cost of repairing the estimate \(\hat Y\): it takes \(H_b(P_e)\) nats to specify whether \(\hat Y\) is wrong, and whenever it is wrong (with probability \(P_e\)), at most \(\log(k-1)\) nats to specify which of the remaining \(k-1\) labels is correct. Anyone who has both the estimate and the repair knows \(Y\) exactly, so the repair cannot cost less than the uncertainty about \(Y\) left by \(\hat Y\)—which, by data processing, is at least the uncertainty left by \(X\).
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 = \mathbf{1}\{\hat Y \neq Y\}\) be the error indicator. We expand \(H(W, Y \mid \hat Y)\), the remaining uncertainty about both the error and the true label given the estimate, in two ways. First, \(W\) is completely determined by \((Y,\hat Y)\) and therefore adds no entropy, so \(H(W, Y \mid \hat Y) = H(Y \mid \hat Y)\). Second, the chain rule gives \(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\mid\hat Y)=I(W;\hat Y)\ge0\). Therefore \(H(W \mid \hat Y) \leq H(W) = H_b(P_e)\).
- When \(W=0\), the label equals \(\hat Y\) and has zero uncertainty. When \(W=1\) (which happens with probability \(P_e\)), the label must be one of the \(k-1\) values other than \(\hat Y\), so its entropy is at most \(\log(k-1)\). Averaging over \(W\) gives \(H(Y \mid W, \hat Y) \leq P_e \log(k-1)\).
Combining both bounds yields \(H(Y\mid\hat Y)\le H_b(P_e)+P_e\log(k-1)\). Finally, because \(\hat Y\) is computed solely from \(X\), the triple \(Y \to X \to \hat Y\) forms a Markov chain, and the data-processing inequality gives \(I(Y; \hat Y) \leq I(Y; X)\), or equivalently \(H(Y \mid \hat Y) \geq H(Y \mid X)\). \(\blacksquare\)
Notice that the count of \(k-1\) remaining labels in the second step relies on \(\hat Y\) taking values inside the same label set. If the classifier is allowed to answer “abstain”, then \(\log k\) must replace \(\log(k-1)\), and the stated inequality breaks down: for a fair bit \(Y\) independent of \(X\) and a classifier that always abstains, \(P_e=1\) and the left-hand side becomes \(H_b(1)+\ln1=0\), which lies below \(H(Y\mid X)=\ln2\).
In the simplest case, Fano’s bound is exact. For the flipped bit with the estimate \(\hat Y=X\), we have \(P_e=0.1\) and \(k=2\), so the left-hand side equals \(H_b(0.1)+0.1\ln1=0.325\), matching \(H(Y\mid X)\) exactly.
No classifier, regardless of architecture or training procedure, can beat Fano’s bound. For \(1{,}000\) balanced classes, \(H(Y)=\ln1000=6.91\) nats; rearranging Equation 37.6.8 for \(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\%\) error requires at least \(6.36\) of the \(6.91\) nats of label entropy (\(92\%\) of the total), and even a classifier that is wrong half the time needs \(2.76\) nats, or two fifths of the total.
37.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\mid x)\) be any model of the label given the input, with cross-entropy loss \(L=\mathbb{E}[-\log q(Y\mid X)]\) under \(P_{X,Y}\). Then
\[I(X;Y)\;\ge\;H(Y)-L, \tag{37.6.9}\]
and for \(k\) balanced classes, \(I(X;Y)\ge\log k-L\).
Proof. By definition, \(I(X;Y)=H(Y)-H(Y\mid X)\). For each \(x\), the cross-entropy of \(q(\cdot\mid x)\) under \(p(\cdot\mid x)\) exceeds the true conditional entropy of \(p(\cdot\mid x)\) by \(D_{\textrm{KL}}(p(\cdot\mid x)\,\|\,q(\cdot\mid x))\ge0\) (Section 37.1). Averaging over \(x\) yields \(H(Y\mid X)\le L\), and subtracting from \(H(Y)\) completes the proof. \(\blacksquare\)
Because held-out test loss estimates \(L\), the test loss of any classifier or language model directly certifies a lower bound on the information its input carries. For example, a \(10\)-class classifier on balanced labels with a test loss of \(0.3\) nats certifies that its input carries at least \(\ln10-0.3=2.0\) of the label’s \(2.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 37.7.3 develops it into a broader family of mutual information estimators.
The certificate is tight if and only if \(q(y\mid x)\) matches the true conditional distribution \(p(y\mid x)\). On the flipped bit, a model that predicts \(\hat Y=X\) with confidence \(c\) has expected loss \(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.9\)) certifies the full \(0.368\) nats. An overconfident model (\(c=0.99\)) pays a steep penalty whenever it errs and certifies only \(0.22\) nats, while an underconfident one (\(c=0.6\)) certifies \(0.14\) nats. Yet all four models make identical hard predictions and err \(10\%\) of the time, so Fano’s inequality, which sees only the error rate, certifies the full \(0.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\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)\). 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.
37.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.
37.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\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 \(X\) and output \(Y\). Although the channel noise is fixed, the sender is free to choose the input distribution \(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). \tag{37.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 \(C\), whereas reliable communication is impossible at any rate above \(C\) (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\mid X)\). Every row of \(p(y\mid x)\) is \((1-\delta,\delta)\) up to ordering, so \(H(Y\mid X)=H_b(\delta)\) regardless of the input distribution. Meanwhile, \(H(Y)\le\ln2\), with equality if and only if \(Y\) is uniform. Because \(P(Y=1)=\delta+P(X=1)(1-2\delta)\), whenever \(\delta\ne\tfrac12\) the output is uniform if and only if the input is uniform. Hence
\[C=\ln 2-H_b(\delta)\quad\textrm{nats per use}, \tag{37.6.11}\]
achieved by the uniform input. At \(\delta=0.1\), this recovers the \(0.368\) nats of our flipped bit (whose input was already uniform); for the two lines in series (\(\delta=0.26\)), capacity drops to \(0.120\) nats. At \(\delta=\tfrac12\), the output is independent of the input and capacity vanishes. At \(\delta=1\), capacity returns to the full \(\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 \(\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 \(1\) only \(10\%\) of the time has only \(H_b(0.1)=0.325\) nats to offer and gets \(0.146\) of them through—two fifths of what the uniform input achieves. The left panel of Figure 37.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-\alpha)\ln2\) nats through it.
37.6.3.2 Rate–Distortion
Lossless compression requires \(H(X)\) nats per symbol (Section 37.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,\hat x)\ge0\) scoring how well \(\hat x\) reconstructs \(x\), and allow an average distortion of at most \(D\). How few nats per sample are required? The rate–distortion function answers this as the minimum mutual information an encoder \(p(\hat x\mid x)\) must retain to stay within the distortion budget:
\[ R(D)=\inf_{p(\hat x\mid x):\;\mathbb{E}[d(X,\hat X)]\le D} I(X;\hat X). \tag{37.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)\) can achieve average distortion \(D\), whereas no code below \(R(D)\) can (Shannon 1959).
In practice, it is usually easier to replace the hard distortion constraint with a penalty, minimizing \(I(X;\hat X)+\lambda\,\mathbb{E}[d(X,\hat X)]\) over all encoders for a multiplier \(\lambda>0\). Every encoder corresponds to a point in the distortion–rate plane lying on or above the curve \(R(D)\), and the penalized objective is constant along straight lines of slope \(-\lambda\). Because \(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 37.6.4 is formulated in exactly this Lagrangian form.
Proposition (Gaussian rate–distortion). For a source \(X\sim\mathcal N(0,\sigma_X^2)\) under squared error \(d(x,\hat x)=(x-\hat x)^2\),
\[ R(D)=\frac12\log\frac{\sigma_X^2}{D} \quad (0<D<\sigma_X^2), \qquad R(D)=0\quad(D\ge\sigma_X^2). \tag{37.6.13}\]
Inverting this formula for distortion gives \(D=\sigma_X^2 e^{-2R}\): every additional bit of rate (\(\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 37.1.4.3: among all densities with variance \(s^2\), the Gaussian maximizes differential entropy at \(\tfrac12\log(2\pi e s^2)\), which increases with \(s^2\). Take any encoder satisfying \(\mathbb{E}[(X-\hat X)^2]\le D\). Then
\[ \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 \(\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-\hat X\) has variance at most \(\mathbb{E}[(X-\hat X)^2]\le D\). When \(D\ge\sigma_X^2\), a constant encoder that transmits nothing and always outputs the mean \(0\) already meets the budget, so \(R(D)=0\).
It remains to construct an encoder that achieves this bound for \(D<\sigma_X^2\). Set \(\sigma_X^2=1\) and add independent Gaussian noise: \(Z=X+\sigma\epsilon\) with \(\epsilon\sim\mathcal N(0,1)\) and \(\sigma>0\). Then \(\textrm{Cov}(X,Z)=1\) and \(\textrm{Var}(Z)=1+\sigma^2\), giving squared correlation \(\rho_{XZ}^2=1/(1+\sigma^2)\). Applying Equation 37.6.5 gives the mutual information retained by this encoder:
\[I(X;X+\sigma\epsilon)=\tfrac12\log\left(1+\sigma^{-2}\right). \tag{37.6.14}\]
Now reconstruct \(X\) using the conditional mean \(\hat X=\mathbb{E}[X\mid Z]=Z/(1+\sigma^2)\), the optimal linear regression of \(X\) on \(Z\) with slope \(\textrm{Cov}(X,Z)/\textrm{Var}(Z)\). Its mean squared error is the conditional variance \(D=1-1/(1+\sigma^2)=\sigma^2/(1+\sigma^2)\), which sweeps across the entire interval \((0,1)\) as \(\sigma\) varies. Because \(\hat X\) is an invertible rescaling of \(Z\), we have \(I(X;\hat X)=\tfrac12\log(1+\sigma^{-2})=\tfrac12\log(1/D)\). For a general variance \(\sigma_X^2\), simply rescale \(X\) and \(\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 \(\sigma^{-2}\), and Equation 37.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 \(s\) carries at most \(\tfrac12\log(1+s)\) nats about its clean value. The code below simulates this encoder on one million samples at \(\sigma^2=1/9\), \(1\), and \(3\) (corresponding to \(D=0.1\), \(0.5\), and \(0.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
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.499, 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
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.498, I(X;Z) = R(D) = 0.347 nats
sigma^2 = 3.000: D = 0.750, MSE 0.749, I(X;Z) = R(D) = 0.144 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.501, I(X;Z) = R(D) = 0.347 nats
sigma^2 = 3.000: D = 0.750, MSE 0.752, I(X;Z) = R(D) = 0.144 nats
The empirical squared errors match \(D\) to within a few thousandths: a distortion of \(D=0.1\) costs \(1.15\) nats per sample, \(D=0.5\) costs \(0.35\) nats (half a bit), and \(D=0.75\) costs \(0.14\) nats.
Keep in mind that this noisy encoder achieves \(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 \(X\): it spends \(\ln2=0.693\) nats and reconstructs \(\pm\sqrt{2/\pi}\) (the mean of \(|X|\)), incurring squared error \(1-2/\pi=0.363\), whereas the rate–distortion curve asks only \(0.506\) nats for that distortion.
The right panel of Figure 37.6.4 shows the full curve. As \(D\to0\), the required rate climbs without bound—reflecting the infinite information in an exact copy of a continuous variable—and drops to \(0\) once \(D\) reaches \(\sigma_X^2\). That steep climb near \(D=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.
37.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.
37.6.4.1 The Bottleneck Objective
Let \(Z\) be a representation of an input \(X\) generated by a stochastic encoder \(p(z\mid x)\), and let \(Y\) be the target label. When \(Z\) is continuous, the encoder must be stochastic, because a deterministic map would typically yield \(I(X;Z)=\infty\) (Section 37.6.1.3). The information bottleneck (Tishby et al. 1999) seeks a representation \(Z\) that retains as little of \(X\) as possible while preserving as much about \(Y\) as possible:
\[\min_{p(z \mid x)}\; I(X; Z) - \beta\, I(Y; Z). \tag{37.6.15}\]
Here \(I(X;Z)\) is the rate—how much information the representation keeps about the input—while \(I(Y;Z)\), weighted by \(\beta>0\), is the information it keeps about the label. Because the encoder sees only \(X\), the variables form a Markov chain \(Y\to X\to Z\), and the data-processing inequality constrains \(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 \(\beta\le1\), keeping nothing is optimal: by the inequality above, \(I(X;Z)-\beta I(Y;Z)\ge(1-\beta)\,I(X;Z)\ge0\), and a constant encoder that ignores \(X\) completely achieves \(I(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 \(Y\). In that limit, \(I(Y;Z)\) approaches its ceiling \(I(X;Y)\), and the representation approaches a minimal sufficient statistic: the coarsest summary of \(X\) that still predicts \(Y\) as well as \(X\) 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\to X\to Z\) is a Markov chain, then
\[ 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{37.6.16}\]
Proof. Expand \(I(Y;X,Z)\) via the chain rule in both orders: \(I(Y;Z)+I(Y;X\mid Z)=I(Y;X)+I(Y;Z\mid X)\). The Markov property gives \(I(Y;Z\mid X)=0\). Writing the remaining conditional mutual information in KL form yields \(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\mid x,z)\) to \(p(y\mid x)\). \(\blacksquare\)
Substituting Equation 37.6.16 into the objective turns Equation 37.6.15 into \(I(X;Z)+\beta\,\mathbb{E}[d(X,Z)]-\beta I(X;Y)\), with distortion \(d(x,z)=D_{\textrm{KL}}(p(y\mid x)\,\|\,p(y\mid z))\). Since the final term \(\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 \(z\) is a faithful representation of \(x\) whenever it predicts \(Y\) just as accurately as \(x\) does. Unlike ordinary rate–distortion, however, this distortion depends on the encoder itself through \(p(y\mid z)\), making optimization considerably harder.
37.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)\) to be our Gaussian pair at \(\rho = 0.9\), for which \(I(X; Y) = 0.830\) nats, and use the additive-noise encoder from Section 37.6.3.2:
\[ Z = X + \sigma\, \epsilon, \qquad \epsilon \sim \mathcal{N}(0, 1), \]
parameterized solely by the noise scale \(\sigma\). The rate \(I(X;Z)\) is already given by Equation 37.6.14. For the label, \(\textrm{Cov}(Y,Z)=\textrm{Cov}(Y,X)=\rho\) and \(\textrm{Var}(Z)=1+\sigma^2\), so \(\rho_{YZ}^2=\rho^2/(1+\sigma^2)\). Applying Equation 37.6.5 gives both mutual informations:
\[ 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{37.6.17}\]
As \(\sigma\) decreases from \(\infty\) to \(0\), the representation moves smoothly from knowing nothing about \(X\) to knowing \(X\) exactly, and its label information rises from \(0\) to the data-processing ceiling of \(0.830\) nats.
To visualize this trade-off directly, write \(u=I(X;Z)\) for the rate (reserving \(R\) for the rate–distortion function \(R(D)\)). Inverting Equation 37.6.17 gives \(\sigma^{-2}=e^{2u}-1\), hence \(1/(1+\sigma^2)=1-e^{-2u}\), expressing label information directly as a function of rate:
\[ 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 \(\rho^2\) at \(u=0\) toward \(0\), so the curve is strictly concave. Leaving the origin with slope \(\rho^2=0.81\), the first nat of input information buys at most \(0.81\) nats of label information, and each subsequent nat yields diminishing returns as \(I(Y;Z)\) approaches \(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 \(\rho^2<1\), the Lagrangian \(u-\beta\,I(Y;Z)\) is convex in \(u\), with derivative \(1-\beta\rho^2\) at \(u=0\). For \(\beta\le1/\rho^2\) its minimum is \(u=0\), the constant encoder. For \(\beta>1/\rho^2\) the minimizer and its label information are
\[ 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{37.6.18}\]
Proof. Because \(I(Y;Z)\) is concave in \(u\), the Lagrangian \(u-\beta I(Y;Z)\) is convex, with derivative \(1-\beta\rho^2/(\rho^2+(1-\rho^2)e^{2u})\). At \(u=0\), this derivative equals \(1-\beta\rho^2\). Whenever \(\beta\rho^2\le1\), the derivative is nonnegative at \(u=0\) and strictly increasing, so the minimum over \(u\ge0\) occurs at \(u=0\). Otherwise, setting the derivative to zero gives \(\rho^2+(1-\rho^2)e^{2u}=\beta\rho^2\), or \(e^{2u}=\rho^2(\beta-1)/(1-\rho^2)\). Substituting \(\rho^2e^{-2u}=(1-\rho^2)/(\beta-1)\) into \(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 \(\beta\le1\). For the Gaussian pair at \(\rho=0.9\), collapse actually extends all the way to \(\beta\le1/\rho^2=1.235\). Below that threshold, every nat of rate adds \(1\) to the objective while reducing it by at most \(\beta\rho^2\le1\), because the frontier’s slope never exceeds its initial value \(\rho^2\). Above the threshold, increasing \(\beta\) slides the operating point up the frontier toward the ceiling: \(\beta=2\) gives \(u^*=\tfrac12\ln(0.81/0.19)=0.725\) nats of rate and \(0.484\) nats of label information, while \(\beta=16\) reaches \(2.079\) and \(0.798\) nats. Figure 37.6.5 plots this frontier and its operating points in the information plane, with rate \(I(X;Z)\) on the horizontal axis and label information \(I(Y;Z)\) on the vertical axis.
A phase transition this sharp is worth checking numerically: the proposition predicts that the optimal encoder keeps nothing at \(\beta=1.2\) yet retains information at \(\beta=1.25\). Below, we minimize the Lagrangian directly over a grid of \(4{,}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 \(\beta=1.2\) the constant encoder is optimal, whereas by \(\beta=1.25\) the encoder already retains \(0.032\) nats. Notice that this exact same encoder with noise scale \(\sigma\) also achieves the rate–distortion curve \(R(D)\) for squared error at \(D=\sigma^2/(1+\sigma^2)\). Rate–distortion judges the encoder by how well it reconstructs \(X\), whereas the information bottleneck judges it by how well it predicts \(Y\).
37.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)\) paired with an encoder \(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\mid z)\) (a classifier predicting the label from the representation) with cross-entropy loss \(L_Z=\mathbb{E}[-\log q(Y\mid Z)]\). Applying the loss certificate Equation 37.6.9 to the pair \((Z,Y)\) immediately gives \(I(Y;Z)\ge H(Y)-L_Z\).
Because we want to minimize the rate \(I(X;Z)\), we need an upper bound on it instead. Write the rate in the conditional form Equation 37.6.4, \(I(X;Z)=\mathbb{E}_x\big[D_{\textrm{KL}}(p(z\mid x)\,\|\,p(z))\big]\). While the encoder \(p(z\mid x)\) is known, the aggregated marginal \(p(z)\) is not, since it averages \(p(z\mid x)\) over the unknown data distribution. Replace \(p(z)\) by any fixed prior density \(r(z)\) of our choice, such as a standard normal. Using the identity \(\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 \(x\) and \(z\) gives
\[\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{37.6.19}\]
Any mismatch between our chosen prior \(r\) and the true marginal \(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 Equation 37.6.19 plus \(\beta L_Z\) upper-bounds the bottleneck objective Equation 37.6.15 up to the constant \(\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 Equation 37.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\mid x)\), a fixed prior \(r(z)\), and a decoder that reconstructs \(x\) from \(z\) 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: Equation 37.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 37.7, we ask how much about mutual information can be estimated from samples alone.
37.6.5 Summary
Mutual information is the KL divergence between a joint distribution and the product of its marginals, \(I(X;Y)=D_{\textrm{KL}}(P_{X,Y}\,\|\,P_X\otimes P_Y)\); it vanishes if and only if \(X\) and \(Y\) are independent and is invariant under invertible reparameterizations of either variable. Unlike linear correlation, it detects nonlinear dependence—assigning \(1.14\) nats to \(X\) and \(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 \(L\) of any probabilistic model certifies \(I(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)-\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/\rho^2\), and in its variational form its rate penalty becomes the familiar KL regularizer of a variational autoencoder.
37.6.6 Exercises
[code] Rare pairs and PMI. Pointwise mutual information Equation 37.6.6 corrects co-occurrence counts for the frequencies of the two words (Section 37.6.1.4).
- Show that \(\textrm{pmi}(x, y) \leq \min\{-\log p_X(x), -\log p_Y(y)\}\). When is each of the two bounds attained?
- Extend
countsby a fourth first word sri and a fourth second word lanka that occur only in the bigram “sri lanka”, with count \(2\). Recompute the pmi of “new york”, “machine learning”, “the day”, and “sri lanka”, and repeat with count \(1\). Zero counts give \(\textrm{pmi} = -\infty\) and make(p * pmi).sum()returnnan, so restrict sums to the nonzero cells, asmutual_informationdoes. - Compare the contributions \(p_{X,Y}(x, y)\,\textrm{pmi}(x, y)\) of “new york” and “sri lanka” to \(I(X;Y)\). Then add \(1\) to every count and recompute both pmi values. Which of these scores would you use to rank collocations, and why?
Information versus usable information. A label \(Y\) is a fair bit. Given \(Y = 0\) the input \(X \in \mathbb{R}^2\) is uniform on the circle of radius \(1\), and given \(Y = 1\) it is uniform on the circle of radius \(2\). A representation computes \(Z = \|X\|^2\).
Show that \(I(Y;Z) = I(Y;X) = \ln 2\), although \(x \mapsto \|x\|^2\) is not invertible. Which condition for equality in the data-processing inequality of Section 37.6.2.2 holds?
Show that no linear classifier \(\hat y = \mathbf{1}(\mathbf{w}^\top \mathbf{x} + b > 0)\) classifies every input correctly, whereas a threshold on \(Z\) does.
The layers of a network form a Markov chain \(X \to Z_1 \to Z_2 \to \cdots\). Show that the error of the best classifier of any kind that reads \(Z_\ell\) cannot fall as \(\ell\) grows. The accuracy of a linear classifier fit to \(Z_\ell\) often rises with \(\ell\) all the same. Why is there no contradiction?
Xu et al. (2020) measure the information that a family \(\mathcal{V}\) of predictors \(q(y \mid x)\) can extract. Let \(H_{\mathcal{V}}(Y \mid X) = \inf_{q \in \mathcal{V}} \mathbb{E}[-\log q(Y \mid X)]\), and let \(H_{\mathcal{V}}(Y)\) be the same infimum over the predictors in \(\mathcal{V}\) that ignore their input. The usable information is
\[I_{\mathcal{V}}(X \to Y) = H_{\mathcal{V}}(Y) - H_{\mathcal{V}}(Y \mid X).\]
Let \(\mathcal{V}\) be logistic regression on the given input. Show that \(I_{\mathcal{V}}(X \to Y) = 0\) and \(I_{\mathcal{V}}(Z \to Y) = \ln 2\). For \(X\), use that the expected logistic loss is convex in \((\mathbf{w}, b)\) and unchanged when \(\mathbf{w}\) is rotated. Which inequality of Section 37.6.2.2 does \(I_{\mathcal{V}}\) violate?
Synergy and the Venn diagram. Let \(X\) and \(Y\) be independent fair bits and \(Z = X \oplus Y\) their exclusive or, for which the section computed \(I(X;Y) = 0\) and \(I(X;Y \mid Z) = \ln 2\).
- Which of the Markov chains \(X \to Z \to Y\), \(X \to Y \to Z\), and \(Y \to X \to Z\) hold? What does the data-processing inequality therefore say about this triple?
- In a three-variable version of Figure 37.6.1, the area common to all three disks would be the interaction information \(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)\), and conclude that \(I(X;Y;Z)\) is symmetric in its three arguments.
- Evaluate \(I(X;Y;Z)\) for the triple of (a) and for three copies \(X = 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.
[code] Data processing from \(f\)-divergences. For any channel \(\kappa\) that maps an input to a random output, and any two distributions \(P\) and \(Q\) of the input, the output distributions satisfy \(D_f(P\kappa\,\|\,Q\kappa)\le D_f(P\,\|\,Q)\) for every \(f\)-divergence (Section 37.3.3.3). The KL divergence and \(\chi^2(P\|Q)=\sum_x p(x)^2/q(x)-1\) are two of them.
- Let \(X\to Y\to Z\) be a Markov chain. Take \(P=P_{X,Y}\), \(Q=P_X\otimes P_Y\), and the channel \(\kappa\) that maps \((x,y)\) to \((x,z)\) with \(z\sim p(z\mid y)\). Show that \(P\kappa=P_{X,Z}\) and \(Q\kappa=P_X\otimes P_Z\), and conclude that \(I(X;Z)\le I(X;Y)\).
- Which part of the section’s data-processing proposition does this route not deliver?
- For the two flips in series, with probabilities \(0.1\) and \(0.2\), compute the KL divergence and the \(\chi^2\) divergence of each joint table from the product of its marginals, before and after the second flip.
- Show that for a fair input through the flip channel with probability \(\delta\), \(\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\delta')^2\), here by \(0.36\). Is the ratio \(I(X;Z)/I(X;Y)\) from
- the same factor?
Fano and a converse. ● Fano’s inequality Equation 37.6.8 bounds from below the error of any estimate \(\hat Y = g(X)\) of a label \(Y\) with \(k\) values.
- Let \(\hat Y(x) = \arg\max_y p(y \mid x)\) be the most probable label. Show that its error satisfies \(P_e \leq 1 - e^{-H(Y \mid X)}\). Bound \(\max_y p(y \mid x)\) from below by \(\sum_y p(y \mid x)^2=\mathbb{E}[p(Y\mid X)\mid X=x]\), then apply Jensen’s inequality once, to \(\mathbb{E}[p(Y\mid X)]=\mathbb{E}\big[e^{\log p(Y\mid X)}\big]\).
- An observation \(X\) carries \(I(X;Y) = 9\) nats about a balanced \(10{,}000\)-class label \(Y\). Use Equation 37.6.8 and (a) to bracket the error of the best classifier. The inequality Equation 37.6.8 has no closed-form solution for \(P_e\), so solve it numerically. What does the width of this interval say about predicting a downstream error rate from a mutual information?
The loss certificate and Fano. A classifier of \(k=10\) balanced classes has test error \(P_e=0.08\) and test loss \(L=0.30\) nats.
- How many nats of \(I(X;Y)\) does Fano’s inequality Equation 37.6.8 certify, and how many does the loss certificate Equation 37.6.9?
- For any estimate \(\hat Y=g(X)\) with error probability \(P_e\), let the model \(q(y\mid x)\) put probability \(1-P_e\) on \(y=g(x)\) and spread \(P_e\) evenly over the other \(k-1\) labels. Show that its cross-entropy loss is \(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 37.6.2.4 is it?
- 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)\) with a binary label and a model with error rate \(P_e\) that certifies more than Fano’s inequality does.
Binary channels. ● Work in nats with the binary entropy \(H_b\).
- A Z-channel passes a \(0\) unchanged and turns a \(1\) into a \(0\) with probability \(\tfrac12\). Compute \(I(X;Y)=H(Y)-H(Y\mid X)\) as a function of \(a=P(X=1)\), and show that it is largest at \(a=\tfrac25\), where it equals \(\ln\tfrac54\) nats. Why does the best input send the unreliable symbol less than half the time, and why not never?
- A feature takes the values \(\pm 1\) and passes through dropout with rate \(\alpha\), which replaces it by \(0\) with probability \(\alpha\) and rescales it otherwise. Show that this binary erasure channel has capacity \((1 - \alpha)\ln2\) nats.
- Find the flip probability \(\delta\) at which the binary symmetric channel has the same capacity as dropout with \(\alpha = 0.5\). Why does a flipped bit cost more capacity than an erased one?
The Gaussian channel. Let \(Y=X+N\) with noise \(N\sim\mathcal N(0,\sigma_N^2)\) independent of \(X\), and let the input obey the power constraint \(\mathbb{E}[X^2]\le P\).
- Show that \(I(X;Y)=h(Y)-h(N)\) for any input with a density.
- Among densities with variance \(s^2\), the Gaussian has the largest differential entropy, \(\tfrac12\log(2\pi e s^2)\). Use this to show \(h(Y)\le\tfrac12\log\big(2\pi e(P+\sigma_N^2)\big)\), and conclude that the capacity is \(C=\tfrac12\log(1+P/\sigma_N^2)\), attained by a Gaussian input.
- Evaluate \(C\) at signal-to-noise ratios \(P/\sigma_N^2=1,10,100\), in nats and in bits. Show that at high signal-to-noise ratio each doubling of \(P\) adds about \(\tfrac12\ln2\) nats, half a bit.
- A diffusion model replaces a coordinate \(X\) of the data, scaled so that \(\mathbb{E}[X^2]=1\), by \(\sqrt{a}\,X+\sqrt{1-a}\,\epsilon\) with \(0<a<1\) and independent \(\epsilon\sim\mathcal N(0,1)\). Show that the noised coordinate carries at most \(\tfrac12\log\frac{1}{1-a}\) nats about \(X\), whatever the distribution of \(X\), and evaluate the bound at \(a=0.5\) and \(a=0.01\). For which data is it attained?
The rate bound of a variational autoencoder. Let \(X\sim\mathcal N(0,1)\), let the encoder be \(Z=X+\sigma\epsilon\) as in Section 37.6.4.2, so that \(p(z\mid x)=\mathcal N(z;x,\sigma^2)\), and let the prior be \(r=\mathcal N(0,1)\). Use \(D_{\textrm{KL}}\big(\mathcal N(\mu,s^2)\,\|\,\mathcal N(0,1)\big)=\tfrac12(\mu^2+s^2-1-\log s^2)\).
- Compute the three terms of Equation 37.6.19 and check the identity. By how many nats does the KL penalty overstate the rate at \(\sigma=1\)?
- Rescale the code to \(Z'=Z/\sqrt{1+\sigma^2}\). Show that \(I(X;Z')=I(X;Z)\) and that the bound is now an equality.
- The rate does not depend on the units of the code, and the bound does. Which prior \(r\) makes the bound an equality for a given encoder? What does minimizing the KL penalty therefore do to the code, besides lowering its rate?