Let XX and YY be two discrete random variables.

Relative Entropy

Given a distribution pp, if we encode it with a distribution qq (with the same support), the expected coding length is roughly

∑ipilog⁡1qi \sum_i p_i \log \frac{1}{q_i}

The cost over the optimal coding is given by

D(p∣∣q)≐∑ipilog⁡1qi−∑ipilog⁡1pi=∑ipilog⁡piqi \mathbf{D} (p || q) \doteq \sum_i p_i \log \frac{1}{q_i} - \sum_i p_i \log \frac{1}{p_i} = \sum_i p_i \log \frac{p_i}{q_i}

By definition, we know that this gap is always non-negative. We can prove it rigorously algebraically. We show two different approaches here.

  1. By that f(x)=xlog⁡xf(x) = x \log x is convex for x≥0x \ge 0, we haveD(p∣∣q)=∑ipilog⁡piqi=∑iqi⋅piqilog⁡piqi≥(∑iqi⋅piqi)log⁡(∑iqi⋅piqi)=0 \begin{aligned} \mathbf{D}(p || q) &= \sum_i p_i \log \frac{p_i}{q_i} \\ &= \sum_i q_i \cdot \frac{p_i}{q_i} \log \frac{p_i}{q_i} \\ &\ge \left( \sum_i q_i \cdot \frac{p_i}{q_i} \right) \log \left( \sum_i q_i \cdot \frac{p_i}{q_i} \right) \\ &= 0 \end{aligned}
  2. By that f(x)=−log⁡xf(x) = -\log x is convex (for x≥0x \ge 0 ), we haveD(p∣∣q)=∑i−pilog⁡qipi≥−log⁡(∑ipi⋅qipi)=0 \begin{aligned} \mathbf{D}(p || q) &= \sum_i - p_i \log \frac{q_i}{p_i} \\ &\ge -\log \left( \sum_i p_i \cdot \frac{q_i}{p_i} \right) \\ &= 0 \end{aligned}

Theorem (Maximum Value). Let XX be a random variable taking values in an alphabet Ω\Omega. Then

H(X)≤log⁡∣Ω∣ \mathbf{H}(X) \le \log | \Omega |

The inequality is saturated if and only if XX is a uniform random variable on Ω\Omega.

Proof. Let UU be a uniform random variable on Ω\Omega. Then

D(X∥U)=∑p(x)log⁡p(x)1/∣Ω∣=log⁡∣Ω∣−H(x)≥0. \mathbf{D}( X \Vert U ) = \sum p(x) \log \frac{ p(x) }{ 1 / | \Omega | } = \log | \Omega | - \mathbf{H}(x) \ge 0.

□\square

Joint Entropy

Definition. The joint entropy of XX and YY is

H(X,Y)=∑x,yp(x,y)log⁡1p(x,y) \mathbf{H}(X, Y) = \sum_{x, y} p(x, y) \log \frac{1}{ p(x, y) }

If XX and YY are independent, then

H(X,Y)=H(X)+H(Y). \mathbf{H}(X, Y) = \mathbf{H}(X) + \mathbf{H}(Y).

Conditional Entropy

Definition. The conditional entropy of XX given Y=yY = y is the entropy of the probability distribution p(X∣Y=y)p(X \mid Y = y)

H(X∣Y=y)=∑xp(x∣y)log⁡1p(x∣y) \mathbf{H}(X \mid Y = y) = \sum_x p(x \mid y) \log \frac{1}{ p(x \mid y) }

Definition. The conditional entropy of XX given YY, is the average, over yy, the conditional entropy of XX given yy

H(X∣Y)=∑yp(y)H(X∣Y=y)=∑x,yp(x,y)log⁡1p(x∣y). \mathbf{H}(X \mid Y) = \sum_y p(y) \mathbf{H}(X \mid Y = y) = \sum_{x, y} p(x , y) \log \frac{1}{ p(x \mid y) }.

Theorem (Zero Conditional Entropy). Suppose that XX and YY have the same support. H(X∣Y)=0\mathbf{H}(X \mid Y) = 0 if and only if XX is a function of YY.

Proof. If

H(X∣Y)=∑yp(y)H(X∣Y=y)=0. \mathbf{H}(X \mid Y) = \sum_y p(y) \mathbf{H}(X \mid Y = y) = 0.

Then either p(y)=0p(y) = 0 or H(X∣Y=y)=0\mathbf{H}(X \mid Y = y) = 0 for all yy. On the other hand, for each yy, if p(y)>0p(y) > 0, then

H(X∣Y=y)=∑xp(x∣y)log⁡1p(x∣y)=0, \mathbf{H}(X \mid Y = y) = \sum_x p(x \mid y) \log \frac{1}{ p(x \mid y) } = 0,

Then either p(x∣y)=0p(x \mid y) = 0 or log⁡1p(x∣y)=0\log \frac{1}{ p(x \mid y) } = 0. It follows that there is a unique xx, for which p(x∣y)=1p(x \mid y) = 1.

Conversely, if XX is a function of YY, for each yy such that p(y)>0p(y) > 0, there is a unique xx such that p(x∣y)=1p(x \mid y) = 1. Hence, H(X∣Y=y)=0\mathbf{H}(X \mid Y = y) = 0 and H(X∣Y)=0H(X \mid Y) = 0.

□\square

Mutual Information

Definition. The mutual information between XX and YY is

I(X;Y)=Ep(x,y)[log⁡p(x,y)p(x)p(y)]=D(p(x,y)∥p(x)p(y)). I(X; Y) = \mathbb{E}_{p(x, y) } \left[ \log \frac{ p(x, y)}{p(x) p(y) } \right] = \mathbf{D}( p(x, y) \Vert p(x) p(y) ).

The definition is symmetric and it holds that I(X;Y)=I(Y;X)I(X; Y) = I(Y; X). If we know p(x,y)p(x,y), we use in expectation Ep(x,y)[log⁡1p(x,y)]\mathbb{E}_{p(x, y) } \left[ \log \frac{1} { p(x, y)} \right] bits to describe them. If we know only p(x)p(x) and p(y)p(y), the mutual information measures the bits we waste.

∑p(x,y)log⁡p(x,y)p(x)p(y)=∑p(x,y)(log⁡1p(x)+log⁡1p(y)−log⁡1p(x,y))=H(X)+H(Y)−H(X,Y) \small \begin{aligned} &\sum p(x, y) \log \frac{ p(x, y)}{p(x) p(y) } \\ =& \sum p(x, y) \left( \log \frac{ 1 }{p(x)} + \log \frac{ 1 }{p(y)} - \log \frac{ 1 }{p(x, y)} \right) \\ =& \mathbf{H} ( X ) + \mathbf{H} ( Y ) - \mathbf{H} ( X, Y ) \end{aligned}

Further, mutual information measures the average reduction of randomness of XX that results from learning the value of YY.

∑p(x,y)log⁡p(x,y)p(x)p(y)=∑p(x,y)log⁡p(x∣y)p(x)=H(X)−H(X∣Y). \small \begin{aligned} \sum p(x, y) \log \frac{ p(x, y)}{p(x) p(y) } &=\sum p(x, y) \log \frac{ p(x | y)}{p(x) } \\ &= \mathbf{H} ( X ) - \mathbf{H} ( X \mid Y). \end{aligned}

In this sense, the mutual information quantifies the dependence between XX and YY. It measures how much knowing one random variable reduces the uncertainty about the other random variable.

Similarly, we can prove that

∑p(x,y)log⁡p(x,y)p(x)p(y)=∑p(x,y)log⁡p(x∣y)p(x)=H(Y)−H(X∣Y). \small \begin{aligned} \sum p(x, y) \log \frac{ p(x, y)}{p(x) p(y) } &=\sum p(x, y) \log \frac{ p(x | y)}{ p(x) } \\ &=\mathbf{H} ( Y ) - \mathbf{H} ( X \mid Y). \end{aligned}

I(X;Y)≥0\mathbf{I}(X; Y) \ge 0.

Proof.

I(X;Y)=D(p(x,y)∣p(x)p(y))≥0 \mathbf{I}(X; Y) = \mathbf{D}( p(x, y) \mid p(x) p(y) ) \ge 0

Or

∑p(x,y)log⁡p(x,y)p(x)p(y)=−∑p(x,y)log⁡p(x)p(y)p(x,y)≥−log⁡∑p(x,y)p(x)p(y)p(x,y)=0 \begin{aligned} \sum p(x, y) \log \frac{ p(x, y)}{p(x) p(y) } &= -\sum p(x, y) \log \frac{p(x) p(y) }{ p(x, y)} \\ &\ge - \log \sum p(x, y) \frac{p(x) p(y) }{ p(x, y)} \\ &=0 \end{aligned}

□\square

Corollary. H(Y)−H(X∣Y)=H(X)−H(X∣Y)≥0\mathbf{H} ( Y ) - \mathbf{H} ( X \mid Y) = \mathbf{H} ( X ) - \mathbf{H} ( X \mid Y) \ge 0.

Theorem. The entropy H(X)\mathbf{H}(X) is concave in the probability density p(x)p(x).

Proof. Let λ1,λ2∈[0,1]\lambda_1, \lambda_2 \in [0, 1] such that λ1+λ2=1\lambda_1 + \lambda_2 = 1. Suppose that Z1,Z2Z_1, Z_2 are random variables with density functions p1(z)p_1(z) and p2(z)p_2(z) respectively. Define the random variable

Y={1,w.p λ1,2,w.p λ2, Y = \begin{cases} 1, &\text{w.p } \lambda_1,\\ 2, &\text{w.p } \lambda_2, \end{cases}

and let X=ZYX = Z_Y.

Then

H(X)=H(λ1p1+λ2p2) \mathbf{H}(X) = \mathbf{H}( \lambda_1 p_1 + \lambda_2 p_2)

On the other hand,

H(X∣Y)=λ1H(p1)+λ2H(p2). \mathbf{H}(X \mid Y) = \lambda_1 \mathbf{H}( p_1 ) + \lambda_2 \mathbf{H}( p_2 ).

We finish the proof by observing that H(X)≥H(X∣Y)\mathbf{H}(X) \ge \mathbf{H}(X \mid Y).

□\square

Definition. Let XX be a Bernoulli random variable with mean p∈[0,1]p \in [0, 1]. Denote H(p)=H(X)=plog⁡1p+(1−p)log⁡11−p\mathbf{H}(p) = \mathbf{H}(X) = p \log \frac{1}{p} + (1 - p) \log \frac{1}{1 - p}.
Corollary. H(p)\mathbf{H}(p) is concave in pp.

Conditional Mutual Information

Definition. The conditional mutual information between XX and YY given Z=zZ = z is the mutual information between the random variables XX and YY in the joint ensemble Pr⁡(X,Y∣Z=z)\Pr (X, Y | Z = z),

I(X;Y∣Z=z)=H(X∣Z=z)−H(X∣Y,Z=z) I(X ; Y \mid Z = z) = \mathbf{H}(X \mid Z = z) - \mathbf{H}(X \mid Y, Z = z)

Definition. The conditional mutual information between XX and YY given ZZ is average over zz of I(X;Y∣Z=z)I(X; Y \mid Z = z),

I(X;Y∣Z)=H(X∣Z)−H(X∣Y,Z)=H(Y∣Z)−H(Y∣X,Z)=H(X∣Z)+H(Y∣Z)−H(X,Y∣Z)=EX,Y,Zlog⁡p(X,Y∣Z)p(X∣Z)⋅p(Y∣Z). \begin{aligned} I(X; Y \mid Z) &= \mathbf{H}(X \mid Z) - \mathbf{H}(X \mid Y, Z) \\ &= \mathbf{H}(Y \mid Z) - \mathbf{H}(Y \mid X, Z) \\ &= \mathbf{H}(X \mid Z) + \mathbf{H}(Y \mid Z) - \mathbf{H}(X, Y \mid Z) \\ &= \mathbb{E}_{X, Y, Z} \log \frac{ p(X, Y \mid Z )}{ p(X \mid Z) \cdot p(Y \mid Z)}. \end{aligned}

Conditional Relative Entropy

Definition (Conditional Relative Entropy).

D(p(y∣x)∣∣q(y∣x))≐Ep(x,y)[log⁡p(Y∣X)q(Y∣X)]=∑x∑yp(y∣x)log⁡p(y∣x)q(y∣x) \begin{aligned} \mathbf{D}( p(y \mid x) || q(y \mid x) ) &\doteq \mathbb{E}_{p(x, y) } \left[ \log \frac{ p(Y \mid X) }{ q(Y \mid X) } \right]\\ &=\sum_{x} \sum_{ y } p(y \mid x) \log \frac{ p(y \mid x) }{ q(y \mid x) } \end{aligned}

Lemma. Relative entropy D(p∣∣q)\mathbf{D}( p || q ) is convex in the pair (p,q)(p, q): if there are two distribution pairs (p1,q1)(p_1, q_1) and (p2,q2)(p_2, q_2), then for α1,α2∈[0,1]\alpha_1, \alpha_2 \in [0, 1], s.t., α1+α2=1\alpha_1 + \alpha_2 = 1, it holds that

D(α1p1+α2p2∣∣α1q1+α2q2)≤α1D(p1∣∣q1)+α2D(p2∣∣q2) \mathbf{D}( \alpha_1 p_1 + \alpha_2 p_2 || \alpha_1 q_1 + \alpha_2 q_2 ) \le \alpha_1 \mathbf{D}( p_1 || q_1 ) + \alpha_2 \mathbf{D}( p_2 || q_2 )

Proof. For any fix value xx, let s(x)s(x) be a shorthand for α1p1(x)+α2p2(x)\alpha_1 p_1(x) + \alpha_2 p_2(x). It holds that

s(x)log⁡s(x)α1q1(x)+α2q2(x)=−s(x)log⁡α1q1(x)+α2q2(x)s(x)=−s(x)log⁡(α1p1(x)s(x)α1q1(x)α1p1(x)+α2p2(x)s(x)α2q2(x)α2p2(x))≤−α1p1(x)log⁡q1(x)p1(x)−α2p2(x)log⁡q2(x)p2(x) \small \begin{aligned} s(x) \log \frac{ s(x) }{ \alpha_1 q_1(x) + \alpha_2 q_2(x) } &=-s(x) \log \frac { \alpha_1 q_1(x) + \alpha_2 q_2(x) } { s(x) } \\ &= -s(x) \log \left( \frac { \alpha_1 p_1(x) } { s(x) } \frac { \alpha_1 q_1(x) } { \alpha_1 p_1(x) } + \frac { \alpha_2 p_2(x) } { s(x) } \frac { \alpha_2 q_2(x) } { \alpha_2 p_2(x) } \right) \\ &\le -\alpha_1 p_1(x) \log \frac { q_1(x) } { p_1(x) } - \alpha_2 p_2(x) \log \frac { q_2(x) } { p_2(x) } \end{aligned}

□\square

Chain Rules

Chain Rule for Information Content

log⁡1p(x,y)=log⁡1p(x)+log⁡1p(y∣x)\log \frac{1}{ p(x, y) } = \log \frac{1}{p(x) } + \log \frac{1}{p(y | x) }.

Chain Rule for Entropy

Let X1,…,XnX_1, \ldots, X_n be random variables whose density function is p(x1…,xn)p(x_1 \ldots, x_n).

H(X1,…,Xn)=∑i=1nH(Xi∣X1,…,Xi−1)\mathbf{H}(X_1, \ldots, X_n) = \sum_{i = 1}^n \mathbf{H}(X_i \mid X_1, \ldots, X_{i - 1})

Proof.

H(X1,…,Xn)=∑x1…,xnp(x1…,xn)log⁡1∏i=1np(xi∣x1,…,xi−1)=∑x1…,xnp(x1…,xn)∑i=1nlog⁡1p(xi∣x1,…,xi−1)=∑i=1nH(Xi∣X1,…,Xi−1) \small \begin{aligned} \mathbf{H}(X_1, \ldots, X_n) &= \sum_{x_1 \ldots, x_n} p(x_1 \ldots, x_n) \log \frac{1}{\prod_{i = 1}^n p(x_i \mid x_1, \ldots, x_{i - 1}) } \\ &= \sum_{x_1 \ldots, x_n} p(x_1 \ldots, x_n) \sum_{i = 1}^n \log \frac{1}{ p(x_i \mid x_1, \ldots, x_{i - 1}) } \\ &=\sum_{i = 1}^n \mathbf{H}(X_i \mid X_1, \ldots, X_{i - 1}) \\ \end{aligned}

□\square

Corollary. $ \mathbf{H} ( X_1, \ldots, X_n) \le \sum_{i = 1}^n \mathbf{H}(X_i). $

□\square

Chain Rule for Mutual Information

I(Y;X1,…,Xn)=∑i=1nI(Y;Xi∣X1,…,Xi−1)\mathbf{I}(Y; X_1, \ldots, X_n) = \sum_{i = 1}^n \mathbf{I}( Y; X_i \mid X_1, \ldots, X_{i - 1})

Proof 1.

I(X1,…,Xn;Y)=H(X1,…,Xn)−H(X1,…,Xn∣Y)=∑i=1nH(Xi∣X1,…,Xi−1)−∑i=1nH(Xi∣X1,…,Xi−1,Y)=∑i=1nI(Xi;Y∣X1,…,Xi−1) \small \begin{aligned} \mathbf{I}(X_1, \ldots, X_n; Y) &= \mathbf{H}(X_1, \ldots, X_n) - \mathbf{H}(X_1, \ldots, X_n \mid Y) \\ &= \sum_{i = 1}^n \mathbf{H}(X_i \mid X_1, \ldots, X_{i - 1}) - \sum_{i = 1}^n \mathbf{H}(X_i \mid X_1, \ldots, X_{i - 1}, Y) \\ &= \sum_{i = 1}^n \mathbf{I}(X_i ; Y\mid X_1, \ldots, X_{i - 1}) \end{aligned}

□\square

Proof 2.

I(Y;X1,…,Xn)=D(p(x1,…,xn,y)∥p(x1,…,xn)p(y))=∑x1,…,xn,yp(x1,…,xn,y)log⁡p(x1,…,xn,y)p(x1,…,xn)p(y)=∑x1,…,xn,yp(x1,…,xn,y)(log⁡1p(x1,…,xn)−log⁡1p(x1,…,xn∣y))=∑x1,…,xn,yp(x1,…,xn,y)log⁡1p(x1)⋅p(x2∣x1)⋅…⋅p(xn∣x1,…,xn−1)−∑x1,…,xn,yp(x1,…,xn,y)log⁡1p(x1∣y)⋅p(x2∣x1,y)⋅…⋅p(xn∣x1,…,xn−1,y)=∑x1,…,xn,yp(x1,…,xn,y)(∑i∈[n]log⁡p(xi∣x1,…,xi−1,y)p(xi∣x1,…,xi−1))=∑i=1nI(Y;Xi∣X1,…,Xi−1) \small \begin{aligned} \mathbf{I}( Y ; X_1, \ldots, X_n ) &= \mathbf{D} ( p(x_1, \ldots, x_n, y) \Vert p(x_1, \ldots, x_n) p(y)) \\ &= \sum_{x_1, \ldots, x_n, y } p(x_1, \ldots, x_n, y) \log \frac{ p( x_1, \ldots, x_n, y) }{ p( x_1, \ldots, x_n ) p(y) } \\ &= \sum_{x_1, \ldots, x_n, y } p(x_1, \ldots, x_n, y) \left( \log \frac{1}{ p(x_1, \ldots, x_n) } - \log \frac{1}{ p(x_1, \ldots, x_n \mid y ) } \right) \\ &= \sum_{x_1, \ldots, x_n, y } p(x_1, \ldots, x_n, y) \log \frac{1}{ p(x_1) \cdot p(x_2 \mid x_1) \cdot \ldots \cdot p(x_n \mid x_1, \ldots, x_{n - 1} ) } \\ & - \sum_{x_1, \ldots, x_n, y } p(x_1, \ldots, x_n, y) \log \frac{1}{ p(x_1 \mid y) \cdot p(x_2 \mid x_1, y) \cdot \ldots \cdot p(x_n \mid x_1, \ldots, x_{n - 1}, y ) } \\ &= \sum_{x_1, \ldots, x_n, y } p(x_1, \ldots, x_n, y) \left( \sum_{i \in [n] } \log \frac{ p(x_i \mid x_1, \ldots, x_{i - 1}, y) }{ p(x_i \mid x_1, \ldots, x_{i - 1}) } \right) \\ &= \sum_{i = 1}^n \mathbf{I}( Y ; X_i \mid X_1, \ldots, X_{i - 1}) \end{aligned}

□\square

Convexity of Relative Entropy.

D(p(x,y)∣∣q(x,y))=D(p(x)∣∣q(x))+D(p(y∣x)∣∣q(y∣x)). \mathbf{D}( p(x, y) || q(x, y) ) = \mathbf{D}( p(x) || q(x) ) + \mathbf{D}( p(y \mid x) || q(y \mid x) ).

Proof.

D(p(x,y)∣∣q(x,y))=∑x,yp(x,y)log⁡p(x)p(y∣x)q(x)q(y∣x)=∑x,yp(x,y)log⁡p(x)q(x)+∑x,yp(x,y)log⁡p(y∣x)q(y∣x)=D(p(x)∣∣q(x))+D(p(y∣x)∣∣q(y∣x)) \begin{aligned} \mathbf{D}( p(x, y) || q(x, y) ) &= \sum_{x, y} p(x, y) \log \frac{ p(x) p(y \mid x) }{q(x) q (y \mid x) } \\ &= \sum_{x, y} p(x, y) \log \frac{ p(x) }{q(x) } + \sum_{x, y} p(x, y) \log \frac{ p(y \mid x) }{ q (y \mid x) } \\ &= \mathbf{D}( p(x) || q(x) ) + \mathbf{D}( p(y \mid x) || q(y \mid x) ) \end{aligned}

□\square