Skip to content
AI360XpertBeta

Joint and Conditional Entropy

Pairs carry joint surprise; knowing one variable discounts the other. The chain rule splits the pair into staged, additive predictions.

Two fair coins carry 2 bits jointly as 1 plus 1, while correlation shrinks the pair to 1.722 bits with the second coin costing only 0.722
Two fair coins carry 2 bits jointly as 1 plus 1, while correlation shrinks the pair to 1.722 bits with the second coin costing only 0.722

Why Does This Exist?

Features arrive in bundles: pixels, tokens, sensor channels. Pricing the bundle by adding up single-variable surprises overcounts whenever variables share information, and it never undercounts. A compressor that budgets 1 bit per fair coin needs 2 bits for two independent coins but only 1.722 bits for the correlated pair below. Feature selection, sequential prediction, and compression all need two numbers: the price of the pair and the discount for knowing one side.

This page defines both numbers and the rule that links them. It extends entropy from one variable to two and sets up mutual information as the overlap they share.

The one idea you need first

Entropy averages −log⁡p-\log p. A fair coin gives −(0.5log⁡20.5+0.5log⁡20.5)=1- (0.5 \log_2 0.5 + 0.5 \log_2 0.5) = 1 bit. Joint entropy runs the same average over pairs. Conditional entropy subtracts what XX already told you about YY.

Think of It Like This

Two weather reporters

Two reporters cover neighboring towns. Reading both reports fresh takes two minutes. Reading the second after the first takes less, because shared weather is old news.

Independent towns give no discount. Identical towns make the second report free. The mapping is exact: the pair is the joint, the leftover read is the conditional, and the saved time is the overlap.

Where it stops: reporters editorialize and add noise. Conditional entropy assumes the true joint distribution, not two biased retellings.

How It Actually Works

For discrete XX and YY with joint chances p(x,y)p(x, y), define the pair price:

H(X,Y)=−∑x,yp(x,y)log⁡2p(x,y)H(X, Y) = - \sum_{x, y} p(x, y) \log_2 p(x, y)

In plain words: average the surprise over pairs instead of singles. Define the remainder after knowing XX:

H(Y∣X)=H(X,Y)−H(X)H(Y \mid X) = H(X, Y) - H(X)

In plain words: start from the pair price and subtract what XX alone already cost. Averaging H(Y∣X=x)H(Y \mid X = x) over xx gives the same number. The chain rule links them:

H(X,Y)=H(X)+H(Y∣X)H(X, Y) = H(X) + H(Y \mid X)

In plain words: predict XX first, then predict YY with XX known. The total never depends on order, so H(X)+H(Y∣X)=H(Y)+H(X∣Y)H(X) + H(Y \mid X) = H(Y) + H(X \mid Y). For nn variables the chain telescopes to ∑iH(Xi∣X<i)\sum_i H(X_i \mid X_{<i}).

Two facts organize practice. Conditioning never increases entropy, so H(Y∣X)≤H(Y)H(Y \mid X) \leq H(Y) with equality exactly for independence. The discount has a name: I(X;Y)=H(Y)−H(Y∣X)=H(X)+H(Y)−H(X,Y)I(X; Y) = H(Y) - H(Y \mid X) = H(X) + H(Y) - H(X, Y). Estimation from counts needs smoothing, because plug-in estimates miss unseen pairs and run low.

Worked example

Two independent fair coins give four pairs at 1/41/4 each:

H(X,Y)=−4×(0.25log⁡20.25)=−4×(0.25×−2)=2 bitsH(X, Y) = -4 \times (0.25 \log_2 0.25) = -4 \times (0.25 \times -2) = 2 \text{ bits}

Here H(X)=1H(X) = 1 and H(Y∣X)=1H(Y \mid X) = 1, so the chain reads 1+1=21 + 1 = 2.

Now correlate them: P(00)=0.4P(00) = 0.4, P(11)=0.4P(11) = 0.4, P(01)=0.1P(01) = 0.1, P(10)=0.1P(10) = 0.1. Margins stay fair at 1 bit each. With log⁡20.4≈−1.322\log_2 0.4 \approx -1.322 and log⁡20.1≈−3.322\log_2 0.1 \approx -3.322:

H(X,Y)=−2×(0.4×−1.322)−2×(0.1×−3.322)=1.057+0.664=1.722 bitsH(X, Y) = -2 \times (0.4 \times -1.322) - 2 \times (0.1 \times -3.322) = 1.057 + 0.664 = 1.722 \text{ bits}

Then H(Y∣X)=1.722−1=0.722H(Y \mid X) = 1.722 - 1 = 0.722 bits and I(X;Y)=1−0.722=0.278I(X; Y) = 1 - 0.722 = 0.278 bits. Correlation donated 0.278 bits of discount, which is exactly the overlap in the diagram.

Code

The snippet recomputes the correlated pair from its four chances, so the hand arithmetic above can be checked in one run.

import numpy as np

def joint_entropy(probs: np.ndarray) -> float:    return float(-(probs * np.log2(probs)).sum())  # average surprise over pairs

p = np.array([0.4, 0.1, 0.1, 0.4])  # 00, 01, 10, 11h_joint = joint_entropy(p)print(round(h_joint, 3))  # -> 1.722print(round(h_joint - 1.0, 3))  # -> 0.722 conditional

Joint 1.722 minus the 1-bit margin leaves 0.722 conditional. Same margins as independence, but dependence moved the total.

Watch Out For

Summing marginal entropies for correlated features

Adding per-feature entropies double-counts shared bits. Above, the sum is 2.0 while the joint is 1.722, so a capacity budget built on the sum overbuys by 0.278 bits per pair.

Price bundles jointly or subtract the overlap. When features correlate strongly, treat the marginal sum as fiction.

Trusting plug-in entropy on small samples

Few samples hide rare pairs, so the plug-in estimate runs low. With 100 samples spread over 64 pairs, the downward bias is roughly 0.3 nats, about 0.45 bits, before any correction.

Smooth the counts, use a bias-corrected estimator, or collect more data. When many pairs are unseen, read the estimate as a floor rather than a value.

The Quick Version

  • Joint entropy prices pairs by averaging surprise over joint outcomes.
  • Conditional entropy prices the remainder after knowing one variable.
  • The chain rule splits pairs additively: H(X,Y)=H(X)+H(Y∣X)H(X, Y) = H(X) + H(Y \mid X).
  • Two independent fair coins total 2 bits; the correlated pair totals 1.722 bits with 0.278 bits of overlap.
  • Conditioning never increases entropy, with equality exactly under independence.
  • Never sum marginal entropies for correlated bundles, and never trust tiny-sample plug-in estimates at face value.