TExcelTAD
Home › Information Theory › Jensen's and Gibbs' Inequalities

Jensen's and Gibbs' Inequalities

Almost every inequality in information theory, from "entropy is at most log⁡2N\log_2 N" to "mutual information is non-negative", comes from one source: Jensen's inequality for convex functions. Applied to the logarithm it gives Gibbs' inequality, DKL(P∥Q)≥0D_{\text{KL}}(P \parallel Q) \ge 0.

Jensen's inequality

A function ff is convex if its graph lies below every chord (Convex Functions). Jensen's inequality says that for convex ff and any random variable XX,

f(E[X])≤E[f(X)]f(E[X]) \le E[f(X)]

For concave ff, such as log⁡\log, the inequality flips: E[log⁡X]≤log⁡E[X]E[\log X] \le \log E[X]. Equality holds only when XX is constant (for strictly convex or concave ff).

python · try it yourself
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 E[X2]−E[X]2E[X^2] - E[X]^2 is non-negative.

Gibbs' inequality

For any two distributions PP and QQ,

DKL(P∥Q)=∑xP(x)log⁡2P(x)Q(x)≥0D_{\text{KL}}(P \parallel Q) = \sum_x P(x)\log_2 \frac{P(x)}{Q(x)} \ge 0

with equality if and only if P=QP = Q.

Proof. Let Z=Q(x)P(x)Z = \frac{Q(x)}{P(x)} for xx drawn from PP. By Jensen's inequality for the concave log⁡\log:

−DKL(P∥Q)=E[log⁡2Z]≤log⁡2E[Z]=log⁡2∑x:P(x)>0Q(x)≤log⁡21=0-D_{\text{KL}}(P \parallel Q) = E\left[\log_2 Z\right] \le \log_2 E[Z] = \log_2 \sum_{x : P(x) > 0} Q(x) \le \log_2 1 = 0
python · try it yourself
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
H(X)≤log⁡2NH(X) \le \log_2 N QQ uniform: DKL(P∥U)=log⁡2N−H(X)D_{\text{KL}}(P \parallel U) = \log_2 N - H(X)
I(X;Y)≥0I(X; Y) \ge 0 Q=PXPYQ = P_X P_Y
H(Y∣X)≤H(Y)H(Y \mid X) \le H(Y) because I(X;Y)=H(Y)−H(Y∣X)≥0I(X; Y) = H(Y) - H(Y \mid X) \ge 0
H(P,Q)≥H(P)H(P, Q) \ge H(P) the cross-entropy decomposition
Kraft-optimal code lengths are log⁡21P(x)\log_2 \frac{1}{P(x)} Optimal Code Lengths

The log-sum inequality

A useful corollary: for non-negative numbers ai,bia_i, b_i,

∑iailog⁡aibi≥(∑iai)log⁡∑iai∑ibi\sum_i a_i\log\frac{a_i}{b_i} \ge \left(\sum_i a_i\right)\log\frac{\sum_i a_i}{\sum_i b_i}

It proves that KL divergence is convex and that merging outcomes (coarse-graining) can only decrease the divergence.

python · try it yourself
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-17 are rounding; clip them to 0 before taking square roots or logs.

Exercises

Exercise 1: Jensen for the square

XX takes values 1 and 3 with probability 12\frac{1}{2} each. Compute E[X]2E[X]^2 and E[X2]E[X^2].

Answer

4 and 5.

Solution

E[X]=2E[X] = 2 so E[X]2=4E[X]^2 = 4; E[X2]=1+92=5E[X^2] = \frac{1 + 9}{2} = 5. The gap 1 is the variance.

Exercise 2: Equality case

When is E[log⁡2X]=log⁡2E[X]E[\log_2 X] = \log_2 E[X] for a positive random variable XX?

Answer

Only when XX is constant (with probability 1).

Solution

log⁡\log is strictly concave, so Jensen's inequality is strict unless all the probability sits on one value.

Exercise 3: Coarse-graining (code)

For P=(0.1,0.4,0.3,0.2)P = (0.1, 0.4, 0.3, 0.2) and Q=(0.25,0.25,0.25,0.25)Q = (0.25, 0.25, 0.25, 0.25), 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
python · try it yourself
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 (12,12)(\frac{1}{2}, \frac{1}{2}), so the coarse view cannot tell them apart at all.

Test yourself

For a concave function f, Jensen's inequality says…

  1. f(E[X])≥E[f(X)]f(E[X]) \ge E[f(X)]
  2. f(E[X])≤E[f(X)]f(E[X]) \le E[f(X)]
  3. f(E[X])=E[f(X)]f(E[X]) = E[f(X)]
  4. nothing

Gibbs' inequality states that…

  1. KL divergence is non-negative
  2. entropy is non-negative
  3. mutual information is symmetric
  4. cross-entropy is below entropy

Which result does NOT follow from Gibbs' inequality?

  1. H(X)≤log⁡2NH(X) \le \log_2 N
  2. I(X;Y)≥0I(X; Y) \ge 0
  3. H(X)≥0H(X) \ge 0
  4. H(P,Q)≥H(P)H(P, Q) \ge H(P)