TExcelTAD
Home › Information Theory › Properties of Entropy

Properties of Entropy

Entropy behaves in a few very predictable ways. These properties are used constantly in proofs and in sanity checks of code: if your computed entropy breaks one of them, there is a bug.

Bounds

For a random variable with NN possible values,

0≤H(X)≤log⁡2N0 \le H(X) \le \log_2 N
  • H(X)=0H(X) = 0 exactly when one outcome has probability 1.
  • H(X)=log⁡2NH(X) = \log_2 N exactly when XX is uniform.

The upper bound follows from Gibbs' inequality (Jensen's and Gibbs' Inequalities): log⁡2N−H(X)=DKL(P∥U)≥0\log_2 N - H(X) = D_{\text{KL}}(P \parallel U) \ge 0, where UU is uniform.

python · try it yourself
import numpy as np

def H(p):
    p = np.asarray(p, float); p = p[p > 0]
    return float(-np.sum(p * np.log2(p))) + 0.0

rng = np.random.default_rng(0)
N = 8
worst = max(H(rng.dirichlet(np.ones(N) * a)) for a in [0.1, 1, 10] for _ in range(2000))
print("largest entropy over 6000 random distributions:", round(worst, 4), " bound log2 N =", np.log2(N))
print("uniform:", H(np.ones(N) / N))
largest entropy over 6000 random distributions: 2.9972  bound log2 N = 3.0
uniform: 3.0

Invariance under relabelling

Entropy depends only on the probabilities, not on the values. Renaming outcomes, or sorting the probabilities, leaves HH unchanged. A die with faces 1 to 6 and a die with faces red, green, ... have the same entropy.

Grouping (the chain rule for a decision)

Splitting a choice into stages adds entropies, weighted by how often each stage is reached. For three outcomes with probabilities (p1,p2,p3)(p_1, p_2, p_3), first decide "outcome 1 or not", then, if not, decide between 2 and 3:

H(p1,p2,p3)=H2(p1)+(1−p1) H ⁣(p21−p1,p31−p1)H(p_1, p_2, p_3) = H_2(p_1) + (1 - p_1)\,H\!\left(\frac{p_2}{1 - p_1}, \frac{p_3}{1 - p_1}\right)

Shannon took this grouping property, together with continuity and the requirement that uniform entropy grows with NN, as the axioms that pin down HH uniquely.

python · try it yourself
import numpy as np

def H(p):
    p = np.asarray(p, float); p = p[p > 0]
    return float(-np.sum(p * np.log2(p))) + 0.0

p1, p2, p3 = 0.5, 0.3, 0.2
lhs = H([p1, p2, p3])
rhs = H([p1, 1 - p1]) + (1 - p1) * H([p2 / (1 - p1), p3 / (1 - p1)])
print(round(lhs, 6), round(rhs, 6))
1.485475 1.485475

Concavity

Entropy is a concave function of the distribution: mixing two distributions never lowers the entropy below the average of their entropies,

H(λP+(1−λ)Q)≥λH(P)+(1−λ)H(Q)H(\lambda P + (1 - \lambda)Q) \ge \lambda H(P) + (1 - \lambda)H(Q)

Mixing adds uncertainty about which distribution produced the sample. Concavity is why maximum-entropy problems have unique solutions (The Maximum-Entropy Principle).

python · try it yourself
import numpy as np

def H(p):
    p = np.asarray(p, float); p = p[p > 0]
    return float(-np.sum(p * np.log2(p))) + 0.0

rng = np.random.default_rng(1)
ok = True
for _ in range(5000):
    P, Q = rng.dirichlet(np.ones(5)), rng.dirichlet(np.ones(5)); lam = rng.uniform()
    ok &= H(lam * P + (1 - lam) * Q) >= lam * H(P) + (1 - lam) * H(Q) - 1e-12
print("concavity held in 5000 random tests:", bool(ok))
concavity held in 5000 random tests: True

Functions of a random variable

Applying a function can only lose information: H(f(X))≤H(X)H(f(X)) \le H(X), with equality when ff is one-to-one on the support. Rounding a die roll to "low/high" drops from 2.585 to 1 bit.

python · try it yourself
import numpy as np

def H(p):
    p = np.asarray(p, float); p = p[p > 0]
    return float(-np.sum(p * np.log2(p))) + 0.0

die = np.ones(6) / 6
parity = np.array([die[0::2].sum(), die[1::2].sum()])          # odd, even
mod3 = np.array([die[k::3].sum() for k in range(3)])
print("H(X) =", round(H(die), 4), " H(X mod 2) =", round(H(parity), 4), " H(X mod 3) =", round(H(mod3), 4))
H(X) = 2.585  H(X mod 2) = 1.0  H(X mod 3) = 1.585

In software

  • Unit tests for an entropy function: check H≥0H \ge 0, H≤log⁡2NH \le \log_2 N, H(uniform)=log⁡2NH(\text{uniform}) = \log_2 N, and invariance under np.random.permutation.
  • Concavity is the reason a mixture of training sets has higher label entropy than either one, a common effect in dataset merging.

Exercises

Exercise 1: Maximum entropy

What is the largest possible entropy of a random byte (256 values)?

Answer

8 bits.

Solution

log⁡2256=8\log_2 256 = 8, reached by uniformly random bytes. This is why encrypted data looks incompressible.

Exercise 2: Grouping

Use the grouping rule to compute H(12,14,14)H(\frac{1}{2}, \frac{1}{4}, \frac{1}{4}).

Answer

1.5 bits.

Solution

H2(12)+12H(12,12)=1+12=1.5H_2(\frac{1}{2}) + \frac{1}{2}H(\frac{1}{2}, \frac{1}{2}) = 1 + \frac{1}{2} = 1.5.

Exercise 3: Sum of two dice (code)

Compute H(X)H(X) for one die, and H(S)H(S) for the sum SS of two dice. Compare H(S)H(S) with H(X1,X2)=2H(X)H(X_1, X_2) = 2H(X).

Answer

H(X)=2.585H(X) = 2.585, H(S)=3.274H(S) = 3.274, which is less than 5.1705.170.

Solution
python · try it yourself
import numpy as np

def H(p):
    p = np.asarray(p, float); p = p[p > 0]
    return float(-np.sum(p * np.log2(p))) + 0.0

die = np.ones(6) / 6
S = np.convolve(die, die)
print(round(H(die), 3), round(H(S), 3), round(2 * H(die), 3))
2.585 3.274 5.17

The sum is a function of the pair (X1,X2)(X_1, X_2) that is not one-to-one, so it carries less information.

Test yourself

Which distribution on 4 outcomes has the largest entropy?

  1. (0.25, 0.25, 0.25, 0.25)
  2. (0.4, 0.3, 0.2, 0.1)
  3. (0.7, 0.1, 0.1, 0.1)
  4. (1, 0, 0, 0)

Entropy as a function of the distribution is…

  1. concave
  2. convex
  3. linear
  4. neither

For any function f, H(f(X))H(f(X)) is…

  1. at most H(X)H(X)
  2. at least H(X)H(X)
  3. always equal to H(X)H(X)
  4. always 0