TL;DR
Mutual information between two random variables and is the number of bits that knowing removes from your uncertainty about . It is zero exactly when and 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 tells you about equal the bits tells you about .
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 and the uncertainty left after the clue . 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 is equally likely to be , or , and , then knowing tells you exactly, yet the correlation is zero because 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 and be discrete random variables with joint distribution and marginals and . Their mutual information is
The sum runs over every pair of outcomes. Each term compares the actual chance of the pair with the chance it would have if and 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 and the definition of Entropy, the same quantity can be written three ways:
Here is the conditional entropy: the average uncertainty left in once 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:
This says mutual information measures how far the pair is from independence.
Key properties
Non-negativity. , with equality exactly when and are independent. Knowing never makes you more uncertain about on average.
Symmetry. . The clue works in both directions.
Bounds. . You cannot learn more about than the total uncertainty in .
Continuous variables. For continuous variables with joint density , replace the sum with an integral:
For a pair of Gaussians with correlation , the result is in nats. This is zero when and grows without bound as . 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 , the mutual information is , where is the binary entropy from Entropy. The plot shows how the information falls as the channel gets noisier.
- I(X;Y) in bits
Worked examples
Let be a fair bit and let be the same bit after a channel that flips it with probability . The joint distribution is
- Marginals: , and the same for .
- Entropies: bit and bit, because each marginal is fair.
- Joint entropy: . Using and , this is bits.
- Mutual information: bits.
- Check with the definition: the two diagonal terms each give , and the two off-diagonal terms each give . The total is 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.
Let be 1 if it rains today and be 1 if it rains tomorrow. Suppose the joint probabilities are
- Marginals: and .
- Entropies: bits, and bit.
- Joint entropy: bits.
- Mutual information: bits.
- Check with the definition: the four terms are , , and . Their sum is 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.
| Situation | What goes wrong | Better choice |
|---|---|---|
| Continuous data with few samples | Estimates depend heavily on how the data is binned, and bias is large | k-nearest-neighbour estimators or a variational lower bound |
| You want to compare two distributions as a distance | Mutual information is a special case of a divergence, not a general distance between arbitrary distributions | Kullback–Leibler Divergence or another divergence |
| Picking features that predict a label | Each feature is scored alone, so two copies of the same feature look equally good | Conditional mutual information, or redundancy-penalised selection |
| You want the direction of cause and effect | Mutual information is symmetric and says nothing about direction | A causal model with interventions |
| You need a linear summary of dependence | Mutual information does not give a sign, unlike correlation | Correlation, 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 tell you about and ?Show answer
It tells you that and are independent. Knowing leaves your uncertainty about 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 and always agree, so . What is in bits?Show answer
Each bit has entropy bit. Because they always agree, the pair has joint entropy bit, since knowing one fixes the other. Then bit. Knowing one bit removes all of the uncertainty about the other.
QuestionLet be equally likely to be , or , and let . Why is the correlation between and zero, yet the mutual information positive?Show answer
Correlation only measures linear dependence. Here is large for and small for , so the average linear trend cancels out and the correlation is zero. Yet is determined by , so . Then . Since with probability and with probability , bits. Mutual information sees the full dependence, not only the line.
QuestionA sensor reading is taken to determine the state . Before the reading, bits. After the reading, the conditional entropy is bits. How much does the reading tell you?Show answer
The reading tells you 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 .