Entropy
So far we have studied distributions, estimation, and inference. A complementary question is: how much information does a
random variable carry? Information Theory, founded by Claude Shannon, provides a mathematical framework for
quantifying uncertainty. It turns out to be deeply connected to machine learning, where the cross-entropy loss is the default
objective for classification.
Conventions. Throughout this page, \(\log\) denotes the natural logarithm (base \(e\)), so information is
measured in nats. The alternative base 2, giving bits, is standard in coding theory but less
convenient for calculus-based optimization. Except in the general statement of Jensen's inequality, every discrete random
variable on this page takes finitely many values, so every sum over its values has finitely many terms.
We further adopt the limiting conventions
\[
\begin{align*}
0 \log 0 &:= 0 \\\\
0 \log \tfrac{0}{0} &:= 0 \\\\
0 \log \tfrac{0}{q} &:= 0 \quad (q \gt 0) \\\\
p \log \tfrac{p}{0} &:= +\infty \quad (p \gt 0) \\\\
-p \log 0 &:= +\infty \quad (p \gt 0),
\end{align*}
\]
so that terms involving zero probabilities cause no ambiguity in the entropy, cross entropy, and KL divergence formulas
introduced below. The first three are justified either by the limit \(\lim_{x \to 0^+} x \log x = 0\) or by treating the
indeterminate form \(\tfrac{0}{0}\) as 0 within probability-theoretic contexts. The last two reflect that assigning zero
probability to an event that actually occurs incurs infinite description cost.
Consider a number guessing game in which we must identify a natural number between 1 and 100. Learning that the number is not 1
leaves 99 possibilities, which is not very helpful. Learning that the number is divisible by 11 shrinks the possibilities to 9,
which is far more informative. This intuition leads to a precise definition.
Definition: Information Content (Self-Information)
The information content of an event \(E\) with probability \(p(E)\) is
\[
I(E) = -\log p(E) \geq 0.
\]
Low-probability events carry high information. Certain events carry none.
The use of the logarithm is not arbitrary. It ensures additivity for independent events. If \(A\) and \(B\) are
independent, then \(p(A \cap B) = p(A) \, p(B)\), so
\[
I(A \cap B) = -\log p(A \cap B) = -\log\bigl(p(A) \, p(B)\bigr) = I(A) + I(B).
\]
This converts the multiplication of probabilities into the addition of information, a property essential for building
a consistent theory.
We now extend from a single event to the average information content
across all possible outcomes of a discrete random variable \(X\).
Definition: Shannon Entropy
The entropy of a discrete random variable \(X\) with distribution \(p\) over \(n\) states is
\[
\begin{align*}
\mathbb{H}(X) &= -\sum_{k=1}^n p(X = k)\,\log p(X = k) \\\\
&= \mathbb{E}_X[-\log p(X)].
\end{align*}
\]
The second equality is the expectation of
a function of a random variable applied to \(g = -\log p\).
Joint Entropy
Entropy quantifies the uncertainty of a single random variable. When we observe two (or more) variables
together, we need a measure of their combined uncertainty.
Definition: Joint Entropy
The joint entropy of two random variables \(X\) and \(Y\) taking finitely many values is
\[
\mathbb{H}(X, Y) = -\sum_{x,\, y} p(x, y)\,\log p(x, y).
\]
Theorem: Bounds on Joint Entropy
For random variables \(X\) and \(Y\) taking finitely many values,
\[
\mathbb{H}(X) + \mathbb{H}(Y) \geq \mathbb{H}(X, Y) \geq \max\{\mathbb{H}(X),\, \mathbb{H}(Y)\} \geq 0,
\]
with the following equality conditions:
-
\(\mathbb{H}(X) + \mathbb{H}(Y) = \mathbb{H}(X, Y)\) if and only if \(X\) and \(Y\) are independent.
-
\(\mathbb{H}(X, Y) = \mathbb{H}(X)\) if and only if \(Y = g(X)\) with probability one for some
function \(g\). Symmetrically, \(\mathbb{H}(X, Y) = \mathbb{H}(Y)\) if and only if \(X = h(Y)\)
with probability one for some function \(h\).
-
\(\mathbb{H}(X, Y) = 0\) if and only if both \(X\) and \(Y\) are constant with probability one, that is, the joint
distribution is concentrated on a single outcome.
Each of these bounds has a clear intuition. The left inequality says that joint uncertainty is largest when neither variable
carries information about the other. Any statistical dependence reduces \(\mathbb{H}(X, Y)\) below the sum.
The right inequality says that the joint uncertainty of \((X, Y)\) cannot be smaller than the uncertainty of either variable
alone. Adding a second variable to the picture can only preserve or expand the total uncertainty, and equality is reached
precisely when one variable is fully determined by the other. Non-negativity follows term-by-term, since \(p(x,y) \in [0,1]\)
gives \(-p(x,y) \log p(x,y) \geq 0\) (using the convention \(0 \log 0 := 0\) established above).
A complete proof is deferred to the tools developed below. The right inequality follows from the
chain rule for entropy, and the left inequality is equivalent to the
non-negativity of mutual information, which is in turn a consequence of
Gibbs' inequality.
These bounds extend to more than two variables:
\[
\mathbb{H}(X_1, \ldots, X_n) \leq \sum_{i=1}^n \mathbb{H}(X_i),
\]
with equality if and only if \(X_1, \ldots, X_n\) are mutually independent. The bound follows by combining the entropy chain rule
with the fact that conditioning reduces entropy on average, both established below.
Conditional Entropy
Joint entropy measures total uncertainty, but it does not tell us how much one variable reveals
about another. Conditional entropy answers: on average, how much uncertainty remains in \(Y\) after we observe \(X\)?
Definition: Conditional Entropy
For each \(x\) in the support of \(X\), the entropy of the conditional distribution \(p(Y \mid X = x)\) is
\[
\mathbb{H}(Y \mid X = x) := -\sum_{y} p(y \mid x) \log p(y \mid x).
\]
The conditional entropy of \(Y\) given \(X\) is the average of these quantities with respect to the
marginal of \(X\):
\[
\mathbb{H}(Y \mid X) := \sum_{x} p(x) \, \mathbb{H}(Y \mid X = x).
\]
Theorem: Joint-Conditional Decomposition
For random variables \(X\) and \(Y\) taking finitely many values,
\[
\mathbb{H}(X, Y) = \mathbb{H}(X) + \mathbb{H}(Y \mid X),
\]
or equivalently \(\mathbb{H}(Y \mid X) = \mathbb{H}(X, Y) - \mathbb{H}(X)\).
Read in the first form, the theorem decomposes the joint uncertainty of \((X, Y)\) into the uncertainty of \(X\) plus the
residual uncertainty of \(Y\) once \(X\) is known. The proof below establishes the second form by direct computation. The first
form is the algebraic rearrangement.
Proof:
\[
\begin{align*}
\mathbb{H}(Y \mid X) &= \sum_{x} p(x) \, \mathbb{H}(Y \mid X = x) \\\\
&= - \sum_{x} p(x) \sum_{y} p(y \mid x) \log p(y \mid x) \\\\
&= - \sum_{x, y} p(x, y) \log p(y \mid x) \\\\
&= - \sum_{x, y} p(x, y) \log \frac{p(x,y)}{p(x)}\\\\
&= - \sum_{x, y} p(x, y) \log p(x,y) + \sum_{x, y} p(x, y) \log p(x) \\\\
&= - \sum_{x, y} p(x, y) \log p(x,y) + \sum_{x} p(x) \log p(x) \\\\
&= \mathbb{H}(X, Y) - \mathbb{H}(X).
\end{align*}
\]
The penultimate step uses the marginal identity \(\sum_{y} p(x, y) = p(x)\) to collapse
the second sum from \((x, y)\) to \(x\) alone.
Theorem: Extremes of Conditional Entropy
For random variables \(X\) and \(Y\) taking finitely many values,
-
\(\mathbb{H}(Y \mid X) = \mathbb{H}(Y)\) if and only if \(X\) and \(Y\) are independent.
-
\(\mathbb{H}(Y \mid X) = 0\) if and only if \(Y = g(X)\) with probability one for some function \(g\).
Proof (second equivalence):
Since \(-t \log t \gt 0\) for \(0 \lt t \lt 1\) and \(-t \log t = 0\) for \(t \in \{0, 1\}\), each
\(\mathbb{H}(Y \mid X = x)\) is non-negative and vanishes if and only if the conditional distribution \(p(Y \mid X = x)\)
is concentrated on a single value, which we call \(g(x)\). As the weights \(p(x)\) are positive on the support of \(X\),
\(\mathbb{H}(Y \mid X) = 0\) if and only if this holds for every \(x\) in the support, that is, if and only if
\(Y = g(X)\) with probability one. The first equivalence is proved in the mutual information section below, as the
equality case of conditioning reducing entropy on average.
Together, the decomposition and the extremes above complete the proof of the right inequality of the
joint entropy bounds deferred in the previous section.
The inequality itself follows from non-negativity. Since
\(\mathbb{H}(Y \mid X) = \sum_{x} p(x) \, \mathbb{H}(Y \mid X = x) \geq 0\), the sum running over the support of \(X\) (each
term is the entropy of a probability distribution), the decomposition gives
\(\mathbb{H}(X, Y) = \mathbb{H}(X) + \mathbb{H}(Y \mid X) \geq \mathbb{H}(X)\), and symmetrically
\(\mathbb{H}(X, Y) \geq \mathbb{H}(Y)\). The equality \(\mathbb{H}(X, Y) = \mathbb{H}(X)\) holds precisely when
\(\mathbb{H}(Y \mid X) = 0\), which by the extremes above means \(Y = g(X)\) with probability one for some function \(g\). The
same argument applies to \(\mathbb{H}(X, Y) = \mathbb{H}(Y)\).
The left inequality \(\mathbb{H}(X) + \mathbb{H}(Y) \geq \mathbb{H}(X, Y)\) and its equality condition (independence) remain
pending until mutual information is introduced.
Theorem: Chain Rule of Entropy
For random variables \(X_1, \ldots, X_n\) taking finitely many values,
\[
\mathbb{H}(X_1, X_2, \ldots, X_n) = \mathbb{H}(X_1) + \sum_{i=2}^n \mathbb{H}(X_i \mid X_1, \ldots, X_{i-1}).
\]
Proof sketch (induction on \(n\)):
The case \(n = 2\) is the Joint-Conditional Decomposition above. For the inductive step, treat \((X_1, \ldots, X_{n-1})\) as a
single random variable and apply the two-variable decomposition:
\[
\mathbb{H}(X_1, \ldots, X_n) = \mathbb{H}(X_1, \ldots, X_{n-1}) + \mathbb{H}(X_n \mid X_1, \ldots, X_{n-1}),
\]
then expand the first term by the inductive hypothesis.
Cross Entropy
Conditional entropy measures how much uncertainty about one variable remains after observing another. A different but equally
important question is: what happens when we use an incorrect distribution \(q\) to encode data that actually follows
distribution \(p\)? The answer is the cross entropy.
Definition: Cross Entropy
For probability distributions \(p\) and \(q\) on the same finite sample space \(\{1, \ldots, n\}\),
the cross entropy of \(q\) relative to \(p\) is
\[
\mathbb{H}(p, q) = -\sum_{k=1}^n p_k \log q_k.
\]
Note that the order of arguments matters: \(\mathbb{H}(p, q) \neq \mathbb{H}(q, p)\) in general.
Here both arguments are distributions, unlike the joint entropy \(\mathbb{H}(X, Y)\), whose arguments are
random variables.
In machine learning, cross entropy is the standard loss function for
classification, especially with
neural networks. It measures the discrepancy between
the true label distribution and the model's predicted distribution. Smaller cross entropy means better predictions.
For example, consider binary classification (\(n = 2\)) with true label \(y \in \{0, 1\}\) and predicted
probability \(\hat{y} \in (0, 1)\) of class 1. Specializing cross entropy to this case gives the
binary cross-entropy loss (the subscript "ce" denotes the binary specialization of the general cross entropy
\(\mathbb{H}(p, q)\) above)
\[
\mathbb{H}_{\text{ce}}(y, \hat{y}) = -\bigl[\, y \log \hat{y} + (1 - y) \log(1 - \hat{y}) \,\bigr].
\]
For instance, when the true label is \(y = 1\), the loss reduces to \(-\log \hat{y}\).
If \(\hat{y}\) is close to 1 (the model is confident and correct), the penalty is small. If \(\hat{y}\) is close to 0
(the model is confident and wrong), the penalty is large. The higher penalty signals that the model needs to be
improved, and forces the optimization algorithm to adjust parameters to reduce future error.
KL Divergence (Relative Entropy, Information Gain)
Cross entropy measures the cost of encoding data from \(p\) using the model \(q\). A natural follow-up: how much
extra cost does the wrong model incur beyond the irreducible entropy \(\mathbb{H}(p)\) of \(p\)? This "excess cost"
is precisely the Kullback-Leibler divergence.
Definition: KL Divergence
The Kullback-Leibler divergence between two distributions \(p\) and \(q\) is
\[
\begin{align*}
D_{\mathbb{KL}}(p \| q) &= \sum_{k=1}^n p_k \log \frac{p_k}{q_k} \\\\
&= \sum_{k=1}^n p_k \log p_k - \sum_{k=1}^n p_k \log q_k \\\\
&= - \mathbb{H}(p) + \mathbb{H}(p, q) \tag{2}
\end{align*}
\]
where \(p\) and \(q\) are defined on a common finite sample space \(\mathcal{X} = \{1, \ldots, n\}\).
Following the conventions established at the beginning of the page, the sum is finite when \(q_k = 0 \Rightarrow p_k = 0\) for
all \(k\). Otherwise, that is, when some \(p_k \gt 0\) has \(q_k = 0\), we have \(D_{\mathbb{KL}}(p \| q) = +\infty\).
For example, \(D_{\mathbb{KL}}(p \| q)\) can measure how much an estimated distribution \(q\) is different from
a true distribution \(p\). If the estimation of \(p\) by \(q\) is "good," the KL divergence will be close to zero.
By the expression (2), the cross entropy can be written as:
\[
\mathbb{H}(p, q) = \mathbb{H}(p) + D_{\mathbb{KL}}(p \| q).
\]
So, if \(p\) is fixed, minimizing the cross entropy is equivalent to minimizing KL divergence.
Theorem: Jensen's Inequality
Let \(\phi: I \to \mathbb{R}\) be a convex function on an interval \(I \subseteq \mathbb{R}\), and let \(X\) be a random
variable taking values in \(I\) with finite expectation. Then
\[
\phi(\mathbb{E}[X]) \leq \mathbb{E}[\phi(X)].
\]
If moreover \(\phi\) is strictly convex, equality holds if and only if \(X = \mathbb{E}[X]\) almost surely.
For finitely many points \(x_1, \ldots, x_n \in I\) and weights \(\lambda_1, \ldots, \lambda_n \geq 0\) with
\(\sum_k \lambda_k = 1\), this specializes to the finite form
\[
\phi\Big(\sum_{k=1}^n \lambda_k x_k\Big) \leq \sum_{k=1}^n \lambda_k \, \phi(x_k).
\]
Proof:
We first prove the finite form by induction on \(n\). For \(n = 1\) there is nothing to prove. For \(n = 2\), the
inequality \(\phi(\lambda_1 x_1 + \lambda_2 x_2) \leq \lambda_1 \phi(x_1) + \lambda_2 \phi(x_2)\) with
\(\lambda_1 + \lambda_2 = 1\) is the very definition of convexity. For \(n \geq 3\), set
\(\Lambda = \sum_{k=1}^{n-1} \lambda_k\), so that \(\Lambda + \lambda_n = 1\). Assume \(\Lambda \gt 0\), since otherwise
the claim is trivial. With \(\bar{x} := \sum_{k=1}^{n-1} \tfrac{\lambda_k}{\Lambda} x_k\), we write
\[
\sum_{k=1}^n \lambda_k x_k = \Lambda \, \bar{x} + \lambda_n x_n.
\]
Since \(\bar{x}\) lies between the smallest and the largest of \(x_1, \ldots, x_{n-1}\), all of which belong to the
interval \(I\), we have \(\bar{x} \in I\). Applying the \(n = 2\) case to \((\bar{x}, x_n)\) and the inductive hypothesis
to \(\bar{x}\), we obtain
\[
\begin{align*}
\phi\Big(\sum_{k=1}^n \lambda_k x_k\Big)
&\leq \Lambda \, \phi(\bar{x}) + \lambda_n \phi(x_n) \\\\
&\leq \Lambda \sum_{k=1}^{n-1} \tfrac{\lambda_k}{\Lambda} \phi(x_k) + \lambda_n \phi(x_n) \\\\
&= \sum_{k=1}^n \lambda_k \phi(x_k).
\end{align*}
\]
We now prove the general statement by the supporting line argument. For each \(t \in \mathbb{R}\), the
sublevel set \(\{x \in I : \phi(x) \leq t\}\) is convex because \(\phi\) is convex, hence an interval, so \(\phi\) is
Borel measurable and \(\phi(X)\) is a random variable. Set \(\mu = \mathbb{E}[X]\), a real number since \(X\) has finite
expectation. Because \(X\) takes values in \(I\), the mean \(\mu\) lies between the endpoints of \(I\). If \(\mu\) is an
endpoint, say \(\mu = \inf I\), then \(X - \mu \geq 0\) and \(\mathbb{E}[X - \mu] = 0\), so \(X - \mu\)
vanishes almost surely,
that is, \(X = \mu\) almost surely. In particular, \(\mu \in I\), and Jensen's inequality holds with equality. The case
\(\mu = \sup I\) is the same with \(\mu - X\) in place of \(X - \mu\).
Assume now that \(\mu\) lies in the interior of \(I\). We claim that there is a constant \(m \in \mathbb{R}\) (a
subgradient at \(\mu\)) such that
\[
\phi(x) \geq \phi(\mu) + m\,(x - \mu) \quad \text{for all } x \in I.
\]
To prove the claim, set \(s(x) = (\phi(x) - \phi(\mu))/(x - \mu)\) for \(x \in I\) with \(x \neq \mu\). If
\(x \lt \mu \lt y\) are points of \(I\), then \(\mu = \lambda x + (1 - \lambda) y\) with
\(\lambda = (y - \mu)/(y - x) \in (0, 1)\), and convexity gives
\(\phi(\mu) \leq \lambda \phi(x) + (1 - \lambda) \phi(y)\). Multiplying by \((y - x)/((y - \mu)(\mu - x)) \gt 0\) and
rearranging, we rewrite this inequality as \(s(x) \leq s(y)\). Since \(\mu\) is interior, \(I\) contains points on both
sides of \(\mu\), so \(m = \sup \{ s(x) : x \in I, \, x \lt \mu \}\) is finite and \(s(x) \leq m \leq s(y)\) whenever
\(x \lt \mu \lt y\). Multiplying \(s(x) \leq m\) by \(x - \mu \lt 0\) and \(m \leq s(y)\) by \(y - \mu \gt 0\) gives the
inequality on each side of \(\mu\), and at \(x = \mu\) it is an equality.
With \(x\) replaced by \(X\) in the supporting line inequality, the right side is an integrable random variable because
\(X\) has finite expectation. Hence the negative part of \(\phi(X)\) is integrable, and \(\mathbb{E}[\phi(X)]\) is well
defined as an element of \((-\infty, +\infty]\). Taking expectations of both sides and using the
monotonicity and linearity of expectation
(linearity on the right), we find
\[
\mathbb{E}[\phi(X)] \geq \phi(\mu) + m \, (\mathbb{E}[X] - \mu) = \phi(\mu) = \phi(\mathbb{E}[X]).
\]
For the equality case, let \(\phi\) be strictly convex. When \(\mu\) is an endpoint of \(I\), both sides of the
equivalence hold, as already noted, so take \(\mu\) interior and \(m\) as above. Suppose
\(\phi(x_0) = \phi(\mu) + m\,(x_0 - \mu)\) for some \(x_0 \in I\) with \(x_0 \neq \mu\). The chord of \(\phi\) between
\(\mu\) and \(x_0\) is then a piece of the supporting line through \((\mu, \phi(\mu))\) with slope \(m\), so on the
segment between them \(\phi\) lies both below the line (by convexity) and above it (by the choice of \(m\)). Thus
\(\phi\) is affine on that segment, contradicting strict convexity. Hence \(\phi(x) \gt \phi(\mu) + m\,(x - \mu)\) for
every \(x \in I\) with \(x \neq \mu\).
If \(\mathbb{E}[\phi(X)] = \phi(\mu)\), then \(\phi(X)\) is integrable, since its negative part is integrable and its
expectation is finite. By linearity, the nonnegative random variable \(\phi(X) - \phi(\mu) - m\,(X - \mu)\) then has
expectation zero, so it
vanishes almost surely,
and therefore \(X = \mu\) almost surely. Conversely, if \(X = \mu\) almost surely, then \(\phi(X) = \phi(\mu)\) almost
surely and equality is immediate.
Theorem: Log Sum Inequality
For nonnegative reals \(a_1, \ldots, a_n\) and \(b_1, \ldots, b_n\),
\[
\sum_{k=1}^n a_k \log \frac{a_k}{b_k} \geq \Big(\sum_{k=1}^n a_k\Big) \log \frac{\sum_{k=1}^n a_k}{\sum_{k=1}^n b_k},
\]
with equality if and only if there is a constant \(c \geq 0\) such that \(a_k = c\,b_k\) for every \(k\), or \(b_k = 0\) for
every \(k\) (the conventions established at the beginning of the page apply, with \(p, q\) replaced by general nonnegative
reals \(a_k, b_k\)).
Proof:
Write \(A = \sum_k a_k\) and \(B = \sum_k b_k\). Using the conventions above, we first dispose of the cases involving
zeros. If \(A = 0\), every term on both sides vanishes, so equality holds, and \(a_k = 0 \cdot b_k\) for every \(k\). If
\(A \gt 0\) and \(B = 0\), both sides equal \(+\infty\). If \(A, B \gt 0\) and some \(k\) has \(b_k = 0 \lt a_k\), the
left side is \(+\infty\) while the right side is finite, so the inequality is strict. No constant \(c\) gives
\(a_k = c\,b_k\) for that \(k\), and since \(B \gt 0\), not every \(b_k\) vanishes.
It remains to treat the case \(A, B \gt 0\) with \(b_k \gt 0\) whenever \(a_k \gt 0\). Let \(S = \{k : a_k \gt 0\}\) and
\(B_S = \sum_{k \in S} b_k\), so \(0 \lt B_S \leq B\). The terms with \(k \notin S\) vanish on the left. Since \(\log\)
is strictly increasing, we have \(A \log (A/B_S) \geq A \log (A/B)\), with equality if and only if \(B_S = B\), that is,
\(b_k = 0\) for every \(k \notin S\). It therefore suffices to prove the inequality, with its equality case, for the
terms indexed by \(S\), where all \(a_k, b_k \gt 0\). Relabeling, we assume henceforth that all \(a_k, b_k \gt 0\).
The function \(f(x) = x \log x\) is strictly convex on \((0, \infty)\) by the
second-order condition,
since \(f''(x) = 1/x \gt 0\). Set \(\lambda_k = b_k / \sum_j b_j\), so \(\lambda_k \gt 0\) and
\(\sum_k \lambda_k = 1\). Then
\[
\begin{align*}
\sum_{k=1}^n a_k \log \frac{a_k}{b_k}
&= \sum_{k=1}^n b_k \cdot \tfrac{a_k}{b_k} \log \tfrac{a_k}{b_k} \\\\
&= \Big(\sum_j b_j\Big) \sum_{k=1}^n \lambda_k \, f\Big(\tfrac{a_k}{b_k}\Big) \\\\
&\geq \Big(\sum_j b_j\Big) \, f\Big(\sum_{k=1}^n \lambda_k \tfrac{a_k}{b_k}\Big) \quad \text{(Jensen's inequality)} \\\\
&= \Big(\sum_j b_j\Big) \, f\Big(\tfrac{\sum_k a_k}{\sum_j b_j}\Big) \\\\
&= \Big(\sum_k a_k\Big) \log \tfrac{\sum_k a_k}{\sum_j b_j}.
\end{align*}
\]
Since \(f\) is strictly convex, the equality case of Jensen's inequality applies to the random variable \(R\) on
\(\{1, \ldots, n\}\) with \(R(k) = a_k / b_k\), where the outcome \(k\) has probability \(\lambda_k \gt 0\). Equality in
the Jensen step therefore holds if and only if all \(a_k / b_k\) are equal. Combining this criterion with the reduction,
we see that equality holds in the remaining case if and only if \(b_k = 0\) whenever \(a_k = 0\) and the ratios
\(a_k / b_k\) over \(k \in S\) are all equal. These two conditions amount to \(a_k = c\,b_k\) for every \(k\), with
\(c = A/B \gt 0\). Together with the cases treated first, this gives the stated equality condition.
Theorem: Non-negativity of KL Divergence (Gibbs' Inequality)
For probability distributions \(p\) and \(q\) on the same sample space,
\[
D_{\mathbb{KL}}(p \| q) \geq 0,
\]
with equality if and only if \(p = q\).
Equivalently, the entropy of \(p\) is bounded above by its cross entropy with any distribution \(q\):
\[
\mathbb{H}(p) \leq \mathbb{H}(p, q).
\]
The latter form is known as Gibbs' inequality.
Proof:
If \(D_{\mathbb{KL}}(p \| q) = +\infty\), that is, if \(p_k \gt 0 = q_k\) for some \(k\), then the inequality holds
strictly and \(p \neq q\). Otherwise, apply the log sum inequality with \(a_k = p_k\) and \(b_k = q_k\):
\[
\begin{align*}
D_{\mathbb{KL}}(p \| q)
&= \sum_{k=1}^n p_k \log \frac{p_k}{q_k} \\\\
&\geq \Big(\sum_{k=1}^n p_k\Big) \log \frac{\sum_{k=1}^n p_k}{\sum_{k=1}^n q_k}.
\end{align*}
\]
Since \(p\) and \(q\) are probability distributions, we have \(\sum_k p_k = \sum_k q_k = 1\), so the right-hand side
becomes \(1 \cdot \log 1 = 0\). Therefore \(D_{\mathbb{KL}}(p \| q) \geq 0\). By the equality case of the log sum
inequality, equality holds if and only if some constant \(c \geq 0\) satisfies \(p_k = c\,q_k\) for every \(k\) (the
alternative that every \(q_k = 0\) is excluded because \(\sum_k q_k = 1\)). Summing over \(k\) gives \(c = 1\), that is,
\(p = q\). The equivalence with Gibbs' inequality follows immediately from the identity
\(D_{\mathbb{KL}}(p \| q) = \mathbb{H}(p, q) - \mathbb{H}(p)\) established above.
Proof:
Let \(u\) denote the uniform distribution on \(\mathcal{X}\), with \(u_k = 1/|\mathcal{X}|\) for each \(k\). Apply the
non-negativity of KL divergence to \(p\) (the distribution of \(X\)) and \(u\):
\[
\begin{align*}
0 \leq D_{\mathbb{KL}}(p \| u)
&= \sum_k p_k \log \frac{p_k}{1/|\mathcal{X}|} \\\\
&= \sum_k p_k \log p_k + \log |\mathcal{X}| \sum_k p_k \\\\
&= -\mathbb{H}(X) + \log |\mathcal{X}|.
\end{align*}
\]
Rearranging gives \(\mathbb{H}(X) \leq \log |\mathcal{X}|\), with equality if and only if \(p = u\), that is,
\(X\) is uniform.
If we identify \(\mathcal{X}\) with \(\{1, \ldots, n\}\), where \(n = |\mathcal{X}|\), the corollary is also the special
case of the
Gibbs variational principle
in which every score is \(0\) and the reference is \(u\), since \(-D_{\mathbb{KL}}(p \| u) = \mathbb{H}(p) - \log n\).
Despite measuring discrepancy between distributions, KL divergence is not a metric. It is not symmetric
(\(D_{\mathbb{KL}}(p \| q) \neq D_{\mathbb{KL}}(q \| p)\) in general) and does not satisfy the triangle inequality.
Mutual Information (MI)
KL divergence measures the cost of confusing one distribution for another. A particularly important special case arises when we
ask: how much does the joint distribution \(p(x,y)\) differ from the product of marginals \(p(x)p(y)\)? If \(X\) and \(Y\) are
independent, these are identical. Otherwise their divergence quantifies the shared information between the two variables.
Mutual information measures the reduction in uncertainty about one random variable given knowledge of another.
High mutual information means that knowing \(X\) says a great deal about \(Y\), and conversely. Zero mutual information means that
the two variables are completely independent.
Since mutual information is a KL divergence, the
non-negativity of KL divergence immediately gives \(\mathbb{I}(X; Y) \geq 0\),
with equality if and only if \(p(x, y) = p(x)\, p(y)\), that is, if and only if \(X\) and \(Y\) are independent.
The four forms admit complementary readings. The first is the sum of the marginal entropies minus the joint entropy. Next comes
the reduction in the uncertainty of \(X\) after observing \(Y\), and then the same reduction with the roles of \(X\) and \(Y\)
exchanged. The fourth reading is the joint uncertainty minus both residual conditional entropies \(\mathbb{H}(X \mid Y)\) and
\(\mathbb{H}(Y \mid X)\).
Proof:
For the first form, expand the logarithm in the definition of \(\mathbb{I}(X; Y)\):
\[
\begin{align*}
\mathbb{I}(X; Y) &= \sum_{x, y} p(x, y) \log p(x, y) - \sum_{x, y} p(x, y) \log p(x) - \sum_{x, y} p(x, y) \log p(y) \\\\
&= -\mathbb{H}(X, Y) + \mathbb{H}(X) + \mathbb{H}(Y),
\end{align*}
\]
where the marginal identities \(\sum_y p(x, y) = p(x)\) and \(\sum_x p(x, y) = p(y)\) collapse the last two double sums to the
single-variable entropies of \(X\) and \(Y\). The reduction forms follow by substituting the
joint-conditional decomposition
\(\mathbb{H}(X, Y) = \mathbb{H}(X) + \mathbb{H}(Y \mid X) = \mathbb{H}(Y) + \mathbb{H}(X \mid Y)\) into the first form. The
fourth form follows by adding the two chain-rule decompositions to obtain
\(2\,\mathbb{H}(X, Y) = \mathbb{H}(X) + \mathbb{H}(Y) + \mathbb{H}(X \mid Y) + \mathbb{H}(Y \mid X)\). Rearranging gives
\(\mathbb{H}(X, Y) - \mathbb{H}(X \mid Y) - \mathbb{H}(Y \mid X) = \mathbb{H}(X) + \mathbb{H}(Y) - \mathbb{H}(X, Y) = \mathbb{I}(X; Y)\)
by the first form.
These identities deliver two important consequences. First, combining the first form
\(\mathbb{I}(X; Y) = \mathbb{H}(X) + \mathbb{H}(Y) - \mathbb{H}(X, Y)\) with non-negativity completes the proof of the left
inequality of the joint entropy bounds previously deferred:
\[
\mathbb{H}(X) + \mathbb{H}(Y) \geq \mathbb{H}(X, Y),
\]
with equality if and only if \(X\) and \(Y\) are independent. Second, the reduction form
\(\mathbb{I}(X; Y) = \mathbb{H}(X) - \mathbb{H}(X \mid Y) \geq 0\) implies
\[
\mathbb{H}(X \mid Y) \leq \mathbb{H}(X)
\quad \text{(and symmetrically } \mathbb{H}(Y \mid X) \leq \mathbb{H}(Y) \text{)},
\]
that is, conditioning reduces entropy on average. Observing \(Y\) can never increase the average uncertainty of
\(X\). The residual uncertainty after observing \(Y\) is at most the prior uncertainty, with equality precisely when \(X\) and
\(Y\) are independent.
Connections to Machine Learning
Information-theoretic quantities are ubiquitous in machine learning. Cross-entropy loss is the standard
training objective for classification.
Minimizing it is equivalent to minimizing KL divergence from the true label distribution \(p\) to the model's
predictions, since \(\mathbb{H}(p)\) is constant with respect to model parameters. Mutual information
appears in feature selection (maximizing \(\mathbb{I}(\text{features}; \text{target})\)) and in the information
bottleneck method for deep learning. KL divergence also appears directly in
variational autoencoders, whose ELBO contains a KL divergence
term. The Fisher information matrix connects to KL divergence through the
local approximation \(D_{\mathbb{KL}}(p_\theta \| p_{\theta+\delta}) \approx \frac{1}{2}\delta^\top F(\theta)\delta\),
linking information theory to the geometry of statistical models.