Jensen's and Gibbs' Inequalities
Almost every inequality in information theory, from "entropy is at most " to "mutual information is non-negative", comes from one source: Jensen's inequality for convex functions. Applied to the logarithm it gives Gibbs' inequality, .
Jensen's inequality
A function is convex if its graph lies below every chord (Convex Functions). Jensen's inequality says that for convex and any random variable ,
For concave , such as , the inequality flips: . Equality holds only when is constant (for strictly convex or concave ).
import numpy as np
rng = np.random.default_rng(0)
X = rng.exponential(2.0, size=1_000_000)
print("convex x^2: f(E[X]) =", round(float(X.mean()**2), 3), " E[f(X)] =", round(float(np.mean(X**2)), 3))
print("concave log2: f(E[X]) =", round(float(np.log2(X.mean())), 3), " E[f(X)] =", round(float(np.mean(np.log2(X))), 3))convex x^2: f(E[X]) = 3.998 E[f(X)] = 8.009
concave log2: f(E[X]) = 1.0 E[f(X)] = 0.165
The first line is the familiar fact that variance is non-negative.
Gibbs' inequality
For any two distributions and ,
with equality if and only if .
Proof. Let for drawn from . By Jensen's inequality for the concave :
import numpy as np
rng = np.random.default_rng(1)
smallest = np.inf
for _ in range(10_000):
P, Q = rng.dirichlet(np.ones(6)), rng.dirichlet(np.ones(6))
smallest = min(smallest, float(np.sum(P * np.log2(P / Q))))
print("smallest KL over 10000 random pairs:", round(smallest, 4), "(never negative)")smallest KL over 10000 random pairs: 0.0205 (never negative)
Consequences
| Inequality | From Gibbs with |
|---|---|
| uniform: | |
| because | |
| the cross-entropy decomposition | |
| Kraft-optimal code lengths are | Optimal Code Lengths |
The log-sum inequality
A useful corollary: for non-negative numbers ,
It proves that KL divergence is convex and that merging outcomes (coarse-graining) can only decrease the divergence.
import numpy as np
rng = np.random.default_rng(2)
ok = True
for _ in range(5000):
a, b = rng.uniform(0.01, 5, 4), rng.uniform(0.01, 5, 4)
ok &= np.sum(a * np.log(a / b)) >= a.sum() * np.log(a.sum() / b.sum()) - 1e-12
print("log-sum inequality held 5000 times:", bool(ok))log-sum inequality held 5000 times: True
Where this is used elsewhere
The same Jensen argument gives the evidence lower bound (ELBO) of variational inference and the convergence of the EM algorithm (The EM Algorithm), and it is used in The Lagrangian and Multipliers to show that the maximum-entropy distribution is unique.
In software
- Gibbs' inequality is a cheap test: a KL implementation that ever returns a clearly negative number has a bug (often unnormalized inputs or mixed log bases).
- Tiny negative values like
-1e-17are rounding; clip them to 0 before taking square roots or logs.
Exercises
Exercise 1: Jensen for the square
takes values 1 and 3 with probability each. Compute and .
Answer
4 and 5.
Solution
so ; . The gap 1 is the variance.
Exercise 2: Equality case
When is for a positive random variable ?
Answer
Only when is constant (with probability 1).
Solution
is strictly concave, so Jensen's inequality is strict unless all the probability sits on one value.
Exercise 3: Coarse-graining (code)
For and , compute the KL divergence, then merge outcomes 1–2 and 3–4 and compute it again.
Answer
About 0.1536 bits before merging and 0 after.
Solution
import numpy as np
kl = lambda p, q: float(np.sum(p * np.log2(p / q)))
P = np.array([0.1, 0.4, 0.3, 0.2]); Q = np.ones(4) / 4
merge = lambda v: np.array([v[0] + v[1], v[2] + v[3]])
print(round(kl(P, Q), 4), round(kl(merge(P), merge(Q)), 4))0.1536 0.0
Both merged distributions are , so the coarse view cannot tell them apart at all.
Test yourself
For a concave function f, Jensen's inequality says…
- nothing
Gibbs' inequality states that…
- KL divergence is non-negative
- entropy is non-negative
- mutual information is symmetric
- cross-entropy is below entropy
Which result does NOT follow from Gibbs' inequality?