Search

Search papers and lessons

Mutual Information

Level 3 · 12 min read

Mutual information measures how many bits one variable tells you about another: the drop in uncertainty about one once you know the other.

On this page

  • Colour = topic mix
  • Probability
  • Discrete math
  • Information theory
  • Sign in to see your progress

TL;DR

Mutual information between two random variables XX and YY is the number of bits that knowing YY removes from your uncertainty about XX. It is zero exactly when XX and YY are independent, and it grows as they become more tightly linked. Unlike correlation, it picks up any kind of dependence, not only straight-line dependence.

It is symmetric: the bits YY tells you about XX equal the bits XX tells you about YY.

Where you'll see it: in choosing which features to feed a classifier, in measuring how much a noisy channel can carry, and in the information bottleneck view of what a neural network keeps from its input.

Intuition

Uncertainty that a clue removes

Suppose you want to guess tomorrow's weather, and you know nothing else. Your uncertainty is the entropy of the forecast distribution. Now someone tells you today's weather. If the two days are linked, your uncertainty about tomorrow drops. If they are unrelated, it does not drop at all.

Mutual information is exactly that drop. Call the uncertainty before the clue H(Y)H(Y) and the uncertainty left after the clue H(Y∣X)H(Y \mid X). The difference is how much the clue was worth.

Why not just use correlation

Correlation measures how well a straight line fits the relationship between two variables. A relationship can be perfectly deterministic and still have zero correlation. If XX is equally likely to be −1-1, 00 or 11, and Y=X2Y = X^2, then knowing XX tells you YY exactly, yet the correlation is zero because YY goes up and down rather than in a line. Mutual information is positive there, as it should be. The worked examples return to this case.

The math

Definition

Let XX and YY be discrete random variables with joint distribution p(x,y)p(x, y) and marginals p(x)=∑yp(x,y)p(x) = \sum_y p(x, y) and p(y)=∑xp(x,y)p(y) = \sum_x p(x, y). Their mutual information is

I(X;Y)=∑x,yp(x,y) log⁡2p(x,y)p(x) p(y).I(X;Y) = \sum_{x,y} p(x,y)\,\log_2 \frac{p(x,y)}{p(x)\,p(y)}.

The sum runs over every pair of outcomes. Each term compares the actual chance of the pair (x,y)(x, y) with the chance it would have if XX and YY were independent. Where the two match, the log is zero and the term contributes nothing. The quantity is measured in bits when the base-2 logarithm is used.

Equivalent forms

Using log⁡p(x,y)p(x)p(y)=log⁡p(x,y)p(x)−log⁡p(y)\log \frac{p(x,y)}{p(x)p(y)} = \log \frac{p(x,y)}{p(x)} - \log p(y) and the definition of Entropy, the same quantity can be written three ways:

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

Here H(X∣Y)H(X \mid Y) is the conditional entropy: the average uncertainty left in XX once YY is known. The second and third forms show the drop in uncertainty described in the intuition. The first form is often the easiest to compute, because it needs only three entropies.

The formula is also the KL divergence between the joint distribution and the product of its marginals:

I(X;Y)=DKL(p(x,y) ∥ p(x) p(y)).I(X;Y) = D_{\mathrm{KL}}\big(p(x,y) \,\|\, p(x)\,p(y)\big).

This says mutual information measures how far the pair is from independence.

Key properties

Non-negativity. I(X;Y)≥0I(X;Y) \ge 0, with equality exactly when XX and YY are independent. Knowing YY never makes you more uncertain about XX on average.

Symmetry. I(X;Y)=I(Y;X)I(X;Y) = I(Y;X). The clue works in both directions.

Bounds. I(X;Y)≤min⁡(H(X),H(Y))I(X;Y) \le \min\big(H(X), H(Y)\big). You cannot learn more about XX than the total uncertainty in XX.

Continuous variables. For continuous variables with joint density p(x,y)p(x,y), replace the sum with an integral:

I(X;Y)=∬p(x,y) log⁡p(x,y)p(x) p(y) dx dy.I(X;Y) = \iint p(x,y)\,\log \frac{p(x,y)}{p(x)\,p(y)}\,dx\,dy.

For a pair of Gaussians with correlation ρ\rho, the result is I=−12ln⁡(1−ρ2)I = -\tfrac{1}{2}\ln(1 - \rho^2) in nats. This is zero when ρ=0\rho = 0 and grows without bound as ∣ρ∣→1|\rho| \to 1. That is a standard result, and it shows how mutual information relates to the correlation most people already know.

For a fair bit sent through a channel that flips it with probability ff, the mutual information is 1−Hb(f)1 - H_b(f), where HbH_b is the binary entropy from Entropy. The plot shows how the information falls as the channel gets noisier.

0.20.40.60.800.20.40.60.81flip probability fbits
  • I(X;Y) in bits
A fair bit through a channel that flips it with probability f. The information is 1 bit when f is 0 and 0 bits at f = 1/2, where the output is pure noise. The marked point is the example below, f = 0.2.

Worked examples

Example
A noisy binary channel, by hand

Let XX be a fair bit and let YY be the same bit after a channel that flips it with probability 0.20.2. The joint distribution is

p(0,0)=0.4,p(0,1)=0.1,p(1,0)=0.1,p(1,1)=0.4.p(0,0) = 0.4,\quad p(0,1) = 0.1,\quad p(1,0) = 0.1,\quad p(1,1) = 0.4.
  1. Marginals: p(X=0)=p(X=1)=0.5p(X=0) = p(X=1) = 0.5, and the same for YY.
  2. Entropies: H(X)=1H(X) = 1 bit and H(Y)=1H(Y) = 1 bit, because each marginal is fair.
  3. Joint entropy: H(X,Y)=−(0.8log⁡20.4+0.2log⁡20.1)H(X,Y) = -\big(0.8\log_2 0.4 + 0.2\log_2 0.1\big). Using log⁡20.4≈−1.3219\log_2 0.4 \approx -1.3219 and log⁡20.1≈−3.3219\log_2 0.1 \approx -3.3219, this is 1.0575+0.6644=1.72191.0575 + 0.6644 = 1.7219 bits.
  4. Mutual information: I=1+1−1.7219=0.2781I = 1 + 1 - 1.7219 = 0.2781 bits.
  5. Check with the definition: the two diagonal terms each give 0.4log⁡21.6=0.27120.4\log_2 1.6 = 0.2712, and the two off-diagonal terms each give 0.1log⁡20.4=−0.13220.1\log_2 0.4 = -0.1322. The total is 0.5425−0.2644=0.27810.5425 - 0.2644 = 0.2781 bits.

Interpretation: a single received bit tells you about a quarter of a bit about the bit that was sent, out of the one full bit it could carry. The rest is lost to the flips.

Example
Rain today and rain tomorrow

Let XX be 1 if it rains today and YY be 1 if it rains tomorrow. Suppose the joint probabilities are

p(1,1)=0.3,p(1,0)=0.1,p(0,1)=0.2,p(0,0)=0.4.p(1,1) = 0.3,\quad p(1,0) = 0.1,\quad p(0,1) = 0.2,\quad p(0,0) = 0.4.
  1. Marginals: p(X=1)=0.4p(X=1) = 0.4 and p(Y=1)=0.5p(Y=1) = 0.5.
  2. Entropies: H(X)=−(0.4log⁡20.4+0.6log⁡20.6)=0.9710H(X) = -(0.4\log_2 0.4 + 0.6\log_2 0.6) = 0.9710 bits, and H(Y)=1H(Y) = 1 bit.
  3. Joint entropy: H(X,Y)=−(0.3log⁡20.3+0.1log⁡20.1+0.2log⁡20.2+0.4log⁡20.4)=1.8464H(X,Y) = -(0.3\log_2 0.3 + 0.1\log_2 0.1 + 0.2\log_2 0.2 + 0.4\log_2 0.4) = 1.8464 bits.
  4. Mutual information: I=0.9710+1−1.8464=0.1245I = 0.9710 + 1 - 1.8464 = 0.1245 bits.
  5. Check with the definition: the four terms are 0.17550.1755, −0.1-0.1, −0.1170-0.1170 and 0.16600.1660. Their sum is 0.12450.1245 bits.

Interpretation: today's weather removes about 0.12 of the 1 bit of uncertainty about tomorrow. That is a real but modest link, and it is the kind of number a forecaster would compare against the entropy of tomorrow to judge how useful yesterday's data is.

Tradeoffs and failure modes

Mutual information is the right measure when you care about any dependence, not only linear dependence. It has pitfalls, though.

SituationWhat goes wrongBetter choice
Continuous data with few samplesEstimates depend heavily on how the data is binned, and bias is largek-nearest-neighbour estimators or a variational lower bound
You want to compare two distributions as a distanceMutual information is a special case of a divergence, not a general distance between arbitrary distributionsKullback–Leibler Divergence or another divergence
Picking features that predict a labelEach feature is scored alone, so two copies of the same feature look equally goodConditional mutual information, or redundancy-penalised selection
You want the direction of cause and effectMutual information is symmetric and says nothing about directionA causal model with interventions
You need a linear summary of dependenceMutual information does not give a sign, unlike correlationCorrelation, when the relationship is roughly linear

History

Claude Shannon introduced entropy and the closely related quantity of channel rate in his 1948 paper "A Mathematical Theory of Communication". He used these to ask how much information a noisy telephone or radio channel can carry reliably. The idea that the rate of a channel is a difference of entropies, the bits received minus the bits lost to noise, is the root of what is now called mutual information.

The name "mutual information" came into common use later, in the early 1960s, through the work of Robert Fano. The quantity moved beyond communications engineering in the following decades. It became a standard tool in statistics, in neuroscience for asking how much a spike train says about a stimulus, and in machine learning for choosing features and training representations.

Its link to the KL divergence was made explicit in the same period, which is why the two are usually taught together.

Check yourself

QuestionWhat does I(X;Y)=0I(X;Y) = 0 tell you about XX and YY?Show answer

It tells you that XX and YY are independent. Knowing YY leaves your uncertainty about XX exactly where it was, and the joint distribution factors into the product of its marginals. Mutual information cannot be negative, so zero is its smallest possible value.

QuestionTwo fair bits XX and YY always agree, so P(X=Y)=1P(X = Y) = 1. What is I(X;Y)I(X;Y) in bits?Show answer

Each bit has entropy 11 bit. Because they always agree, the pair has joint entropy 11 bit, since knowing one fixes the other. Then I=H(X)+H(Y)−H(X,Y)=1+1−1=1I = H(X) + H(Y) - H(X,Y) = 1 + 1 - 1 = 1 bit. Knowing one bit removes all of the uncertainty about the other.

QuestionLet XX be equally likely to be −1-1, 00 or 11, and let Y=X2Y = X^2. Why is the correlation between XX and YY zero, yet the mutual information positive?Show answer

Correlation only measures linear dependence. Here YY is large for X=±1X = \pm 1 and small for X=0X = 0, so the average linear trend cancels out and the correlation is zero. Yet YY is determined by XX, so H(Y∣X)=0H(Y \mid X) = 0. Then I(X;Y)=H(Y)I(X;Y) = H(Y). Since Y=0Y = 0 with probability 1/31/3 and Y=1Y = 1 with probability 2/32/3, H(Y)≈0.918H(Y) \approx 0.918 bits. Mutual information sees the full dependence, not only the line.

QuestionA sensor reading YY is taken to determine the state XX. Before the reading, H(X)=2H(X) = 2 bits. After the reading, the conditional entropy is H(X∣Y)=0.5H(X \mid Y) = 0.5 bits. How much does the reading tell you?Show answer

The reading tells you I(X;Y)=H(X)−H(X∣Y)=2−0.5=1.5I(X;Y) = H(X) - H(X \mid Y) = 2 - 0.5 = 1.5 bits. The sensor removes three quarters of the uncertainty about the state. The result depends only on the two entropies, so it can be read straight off the form I=H(X)−H(X∣Y)I = H(X) - H(X \mid Y).

Sources