# Quantities of information

A misleading[1] information diagram showing additive and subtractive relationships among Shannon's basic quantities of information for correlated variables ${\displaystyle X}$ and ${\displaystyle Y}$. The area contained by both circles is the joint entropy ${\displaystyle \mathrm {H} (X,Y)}$. The circle on the left (red and violet) is the individual entropy ${\displaystyle \mathrm {H} (X)}$, with the red being the conditional entropy ${\displaystyle \mathrm {H} (X|Y)}$. The circle on the right (blue and violet) is ${\displaystyle \mathrm {H} (Y)}$, with the blue being ${\displaystyle \mathrm {H} (Y|X)}$. The violet is the mutual information ${\displaystyle \operatorname {I} (X;Y)}$.

The mathematical theory of information is based on probability theory and statistics, and measures information with several quantities of information. The choice of logarithmic base in the following formulae determines the unit of information entropy that is used. The most common unit of information is the bit, based on the binary logarithm. Other units include the nat, based on the natural logarithm, and the hartley, based on the base 10 or common logarithm.

In what follows, an expression of the form ${\displaystyle p\log p\,}$ is considered by convention to be equal to zero whenever ${\displaystyle p}$ is zero. This is justified because ${\displaystyle \lim _{p\rightarrow 0+}p\log p=0}$ for any logarithmic base.

## Self-information

Shannon derived a measure of information content called the self-information or "surprisal" of a message ${\displaystyle m}$:

${\displaystyle \operatorname {I} (m)=\log \left({\frac {1}{p(m)}}\right)=-\log(p(m))\,}$

where ${\displaystyle p(m)=\mathrm {Pr} (M=m)}$ is the probability that message ${\displaystyle m}$ is chosen from all possible choices in the message space ${\displaystyle M}$. The base of the logarithm only affects a scaling factor and, consequently, the units in which the measured information content is expressed. If the logarithm is base 2, the measure of information is expressed in units of bits.

Information is transferred from a source to a recipient only if the recipient of the information did not already have the information to begin with. Messages that convey information that is certain to happen and already known by the recipient contain no real information. Infrequently occurring messages contain more information than more frequently occurring messages. This fact is reflected in the above equation - a certain message, i.e. of probability 1, has an information measure of zero. In addition, a compound message of two (or more) unrelated (or mutually independent) messages would have a quantity of information that is the sum of the measures of information of each message individually. That fact is also reflected in the above equation, supporting the validity of its derivation.

An example: The weather forecast broadcast is: "Tonight's forecast: Dark. Continued darkness until widely scattered light in the morning." This message contains almost no information. However, a forecast of a snowstorm would certainly contain information since such does not happen every evening. There would be an even greater amount of information in an accurate forecast of snow for a warm location, such as Miami. The amount of information in a forecast of snow for a location where it never snows (impossible event) is the highest (infinity).

## Entropy

The entropy of a discrete message space ${\displaystyle M}$ is a measure of the amount of uncertainty one has about which message will be chosen. It is defined as the average self-information of a message ${\displaystyle m}$ from that message space:

${\displaystyle \mathrm {H} (M)=\mathbb {E} \left[\operatorname {I} (M)\right]=\sum _{m\in M}p(m)\operatorname {I} (m)=-\sum _{m\in M}p(m)\log p(m).}$

where

${\displaystyle \mathbb {E} [-]}$ denotes the expected value operation.

An important property of entropy is that it is maximized when all the messages in the message space are equiprobable (e.g. ${\displaystyle p(m)=1/|M|}$). In this case ${\displaystyle \mathrm {H} (M)=\log |M|}$.

Sometimes the function ${\displaystyle \mathrm {H} }$ is expressed in terms of the probabilities of the distribution:

${\displaystyle \mathrm {H} (p_{1},p_{2},\ldots ,p_{k})=-\sum _{i=1}^{k}p_{i}\log p_{i},}$ where each ${\displaystyle p_{i}\geq 0}$ and ${\displaystyle \sum _{i=1}^{k}p_{i}=1.}$

An important special case of this is the binary entropy function:

${\displaystyle \mathrm {H} _{\mbox{b}}(p)=\mathrm {H} (p,1-p)=-p\log p-(1-p)\log(1-p).\,}$

## Joint entropy

The joint entropy of two discrete random variables ${\displaystyle X}$ and ${\displaystyle Y}$ is defined as the entropy of the joint distribution of ${\displaystyle X}$ and ${\displaystyle Y}$:

${\displaystyle \mathrm {H} (X,Y)=\mathbb {E} _{X,Y}\left[-\log p(x,y)\right]=-\sum _{x,y}p(x,y)\log p(x,y)\,}$

If ${\displaystyle X}$ and ${\displaystyle Y}$ are independent, then the joint entropy is simply the sum of their individual entropies.

(Note: The joint entropy should not be confused with the cross entropy, despite similar notations.)

## Conditional entropy (equivocation)

Given a particular value of a random variable ${\displaystyle Y}$, the conditional entropy of ${\displaystyle X}$ given ${\displaystyle Y=y}$ is defined as:

${\displaystyle \mathrm {H} (X|y)=\mathbb {E} _{\left[X|Y\right]}[-\log p(x|y)]=-\sum _{x\in X}p(x|y)\log p(x|y)}$

where ${\displaystyle p(x|y)={\frac {p(x,y)}{p(y)}}}$ is the conditional probability of ${\displaystyle x}$ given ${\displaystyle y}$.

The conditional entropy of ${\displaystyle X}$ given ${\displaystyle Y}$, also called the equivocation of ${\displaystyle X}$ about ${\displaystyle Y}$ is then given by:

${\displaystyle \mathrm {H} (X|Y)=\mathbb {E} _{Y}\left[\mathrm {H} \left(X|y\right)\right]=-\sum _{y\in Y}p(y)\sum _{x\in X}p(x|y)\log p(x|y)=\sum _{x,y}p(x,y)\log {\frac {p(y)}{p(x,y)}}.}$

This uses the conditional expectation from probability theory.

A basic property of the conditional entropy is that:

${\displaystyle \mathrm {H} (X|Y)=\mathrm {H} (X,Y)-\mathrm {H} (Y).\,}$

## Kullback–Leibler divergence (information gain)

The Kullback–Leibler divergence (or information divergence, information gain, or relative entropy) is a way of comparing two distributions, a "true" probability distribution ${\displaystyle p}$, and an arbitrary probability distribution ${\displaystyle q}$. If we compress data in a manner that assumes ${\displaystyle q}$ is the distribution underlying some data, when, in reality, ${\displaystyle p}$ is the correct distribution, Kullback–Leibler divergence is the number of average additional bits per datum necessary for compression, or, mathematically,

${\displaystyle D_{\mathrm {KL} }{\bigl (}p(X)\|q(X){\bigr )}=\sum _{x\in X}p(x)\log {\frac {p(x)}{q(x)}}.}$

It is in some sense the "distance" from ${\displaystyle q}$ to ${\displaystyle p}$, although it is not a true metric due to its not being symmetric.

## Mutual information (transinformation)

It turns out that one of the most useful and important measures of information is the mutual information, or transinformation. This is a measure of how much information can be obtained about one random variable by observing another. The mutual information of ${\displaystyle X}$ relative to ${\displaystyle Y}$ (which represents conceptually the average amount of information about ${\displaystyle X}$ that can be gained by observing ${\displaystyle Y}$) is given by:

${\displaystyle \operatorname {I} (X;Y)=\sum _{y\in Y}p(y)\sum _{x\in X}{p(x|y)\log {\frac {p(x|y)}{p(x)}}}=\sum _{x,y}p(x,y)\log {\frac {p(x,y)}{p(x)\,p(y)}}.}$

A basic property of the mutual information is that:

${\displaystyle \operatorname {I} (X;Y)=\mathrm {H} (X)-\mathrm {H} (X|Y).\,}$

That is, knowing ${\displaystyle Y}$, we can save an average of ${\displaystyle \operatorname {I} (X;Y)}$ bits in encoding ${\displaystyle X}$ compared to not knowing ${\displaystyle Y}$. Mutual information is symmetric:

${\displaystyle \operatorname {I} (X;Y)=\operatorname {I} (Y;X)=\mathrm {H} (X)+\mathrm {H} (Y)-\mathrm {H} (X,Y).\,}$

Mutual information can be expressed as the average Kullback–Leibler divergence (information gain) of the posterior probability distribution of ${\displaystyle X}$ given the value of ${\displaystyle Y}$ to the prior distribution on ${\displaystyle X}$:

${\displaystyle \operatorname {I} (X;Y)=\mathbb {E} _{p(y)}\left[D_{\mathrm {KL} }{\bigl (}p(X|Y=y)\|p(X){\bigr )}\right].}$

In other words, this is a measure of how much, on the average, the probability distribution on ${\displaystyle X}$ will change if we are given the value of ${\displaystyle Y}$. This is often recalculated as the divergence from the product of the marginal distributions to the actual joint distribution:

${\displaystyle \operatorname {I} (X;Y)=D_{\mathrm {KL} }{\bigl (}p(X,Y)\|p(X)p(Y){\bigr )}.}$

Mutual information is closely related to the log-likelihood ratio test in the context of contingency tables and the multinomial distribution and to Pearson's χ2 test: mutual information can be considered a statistic for assessing independence between a pair of variables, and has a well-specified asymptotic distribution.

## Differential entropy

The basic measures of discrete entropy have been extended by analogy to continuous spaces by replacing sums with integrals and probability mass functions with probability density functions. Although, in both cases, mutual information expresses the number of bits of information common to the two sources in question, the analogy does not imply identical properties; for example, differential entropy may be negative.

The differential analogies of entropy, joint entropy, conditional entropy, and mutual information are defined as follows:

${\displaystyle h(X)=-\int _{X}f(x)\log f(x)\,dx}$
${\displaystyle h(X,Y)=-\int _{Y}\int _{X}f(x,y)\log f(x,y)\,dx\,dy}$
${\displaystyle h(X|y)=-\int _{X}f(x|y)\log f(x|y)\,dx}$
${\displaystyle h(X|Y)=\int _{Y}\int _{X}f(x,y)\log {\frac {f(y)}{f(x,y)}}\,dx\,dy}$
${\displaystyle \operatorname {I} (X;Y)=\int _{Y}\int _{X}f(x,y)\log {\frac {f(x,y)}{f(x)f(y)}}\,dx\,dy}$

where ${\displaystyle f(x,y)}$ is the joint density function, ${\displaystyle f(x)}$ and ${\displaystyle f(y)}$ are the marginal distributions, and ${\displaystyle f(x|y)}$ is the conditional distribution.