# Conditional entropy

In information theory, the conditional entropy quantifies the amount of information needed to describe the outcome of a random variable $Y$ given that the value of another random variable $X$ is known. Here, information is measured in shannons, nats, or hartleys. The entropy of $Y$ conditioned on $X$ is written as $\mathrm {H} (Y|X)$.

## Definition

The conditional entropy of $Y$ given $X$ is defined as
where ${\mathcal {X}}$ and ${\mathcal {Y}}$ denote the support sets of $X$ and $Y$.
Note: Here, the convention is that the expression $0\log 0$ should be treated as being equal to zero. This is because $\lim _{\theta \to 0^{+}}\theta \,\log \theta =0$.
Intuitively, notice that by definition of expected value and of conditional probability, $\displaystyle H(Y|X)$ can be written as $H(Y|X)=\mathbb {E} [f(X,Y)]$, where $f$ is defined as $\displaystyle f(x,y):=-\log \left({\frac {p(x,y)}{p(x)}}\right)=-\log(p(y|x))$. One can think of $\displaystyle f$ as associating each pair $\displaystyle (x,y)$ with a quantity measuring the information content of $\displaystyle (Y=y)$ given $\displaystyle (X=x)$. This quantity is directly related to the amount of information needed to describe the event $\displaystyle (Y=y)$ given $(X=x)$. Hence by computing the expected value of $\displaystyle f$ over all pairs of values $(x,y)\in {\mathcal {X}}\times {\mathcal {Y}}$, the conditional entropy $\displaystyle H(Y|X)$ measures how much information, on average, the variable $X$ encodes about $Y$.

## Motivation

Let $\mathrm {H} (Y|X=x)$ be the entropy of the discrete random variable $Y$ conditioned on the discrete random variable $X$ taking a certain value $x$. Denote the support sets of $X$ and $Y$ by ${\mathcal {X}}$ and ${\mathcal {Y}}$. Let $Y$ have probability mass function $p_{Y}{(y)}$. The unconditional entropy of $Y$ is calculated as $\mathrm {H} (Y):=\mathbb {E} [\operatorname {I} (Y)]$, i.e.
    $\mathrm {H} (Y)=\sum _{y\in {\mathcal {Y}}}{\mathrm {Pr} (Y=y)\,\mathrm {I} (y)}=-\sum _{y\in {\mathcal {Y}}}{p_{Y}(y)\log _{2}{p_{Y}(y)}},$
where $\operatorname {I} (y_{i})$ is the information content of the outcome of $Y$ taking the value $y_{i}$. The entropy of $Y$ conditioned on $X$ taking the value $x$ is defined by:
    $\mathrm {H} (Y|X=x)=-\sum _{y\in {\mathcal {Y}}}{\Pr(Y=y|X=x)\log _{2}{\Pr(Y=y|X=x)}}.$
Note that $\mathrm {H} (Y|X)$ is the result of averaging $\mathrm {H} (Y|X=x)$ over all possible values $x$ that $X$ may take. Also, if the above sum is taken over a sample $y_{1},\dots ,y_{n}$, the expected value $E_{X}[\mathrm {H} (y_{1},\dots ,y_{n}\mid X=x)]$ is known in some domains as equivocation.
Given discrete random variables $X$ with image ${\mathcal {X}}$ and $Y$ with image ${\mathcal {Y}}$, the conditional entropy of $Y$ given $X$ is defined as the weighted sum of $\mathrm {H} (Y|X=x)$ for each possible value of $x$, using $p(x)$ as the weights:$^{:15}$
    ${\begin{aligned}\mathrm {H} (Y|X)\ &\equiv \sum _{x\in {\mathcal {X}}}\,p(x)\,\mathrm {H} (Y|X=x)\\&=-\sum _{x\in {\mathcal {X}}}p(x)\sum _{y\in {\mathcal {Y}}}\,p(y|x)\,\log _{2}\,p(y|x)\\&=-\sum _{x\in {\mathcal {X}},y\in {\mathcal {Y}}}\,p(x)p(y|x)\,\log _{2}\,p(y|x)\\&=-\sum _{x\in {\mathcal {X}},y\in {\mathcal {Y}}}p(x,y)\log _{2}{\frac {p(x,y)}{p(x)}}.\end{aligned}}$

## Properties
### Conditional entropy equals zero

$\mathrm {H} (Y|X)=0$ if and only if the value of $Y$ is completely determined by the value of $X$.

### Conditional entropy of independent random variables

Conversely, $\mathrm {H} (Y|X)=\mathrm {H} (Y)$ if and only if $Y$ and $X$ are independent random variables.

### Chain rule

Assume that the combined system determined by two random variables $X$ and $Y$ has joint entropy $\mathrm {H} (X,Y)$, that is, we need $\mathrm {H} (X,Y)$ bits of information on average to describe its exact state. Now if we first learn the value of $X$, we have gained $\mathrm {H} (X)$ bits of information. Once $X$ is known, we only need $\mathrm {H} (X,Y)-\mathrm {H} (X)$ bits to describe the state of the whole system. This quantity is exactly $\mathrm {H} (Y|X)$, which gives the chain rule of conditional entropy:
    $\mathrm {H} (Y|X)\,=\,\mathrm {H} (X,Y)-\mathrm {H} (X).$$^{:17}$
The chain rule follows from the above definition of conditional entropy:
    ${\begin{aligned}\mathrm {H} (Y|X)&=\sum _{x\in {\mathcal {X}},y\in {\mathcal {Y}}}p(x,y)\log \left({\frac {p(x)}{p(x,y)}}\right)\\[4pt]&=\sum _{x\in {\mathcal {X}},y\in {\mathcal {Y}}}p(x,y)(\log(p(x))-\log(p(x,y)))\\[4pt]&=-\sum _{x\in {\mathcal {X}},y\in {\mathcal {Y}}}p(x,y)\log(p(x,y))+\sum _{x\in {\mathcal {X}},y\in {\mathcal {Y}}}{p(x,y)\log(p(x))}\\[4pt]&=\mathrm {H} (X,Y)+\sum _{x\in {\mathcal {X}}}p(x)\log(p(x))\\[4pt]&=\mathrm {H} (X,Y)-\mathrm {H} (X).\end{aligned}}$
In general, a chain rule for multiple random variables holds:
    $\mathrm {H} (X_{1},X_{2},\ldots ,X_{n})=\sum _{i=1}^{n}\mathrm {H} (X_{i}|X_{1},\ldots ,X_{i-1})$$^{:22}$
It has a similar form to chain rule in probability theory, except that addition instead of multiplication is used.

### Bayes' rule

Bayes' rule for conditional entropy states
    $\mathrm {H} (Y|X)\,=\,\mathrm {H} (X|Y)-\mathrm {H} (X)+\mathrm {H} (Y).$
Proof. $\mathrm {H} (Y|X)=\mathrm {H} (X,Y)-\mathrm {H} (X)$ and $\mathrm {H} (X|Y)=\mathrm {H} (Y,X)-\mathrm {H} (Y)$. Symmetry entails $\mathrm {H} (X,Y)=\mathrm {H} (Y,X)$. Subtracting the two equations implies Bayes' rule.
If $Y$ is conditionally independent of $Z$ given $X$ we have:
    $\mathrm {H} (Y|X,Z)\,=\,\mathrm {H} (Y|X).$

### Other properties

For any $X$ and $Y$:
    ${\begin{aligned}\mathrm {H} (Y|X)&\leq \mathrm {H} (Y)\,\\\mathrm {H} (X,Y)&=\mathrm {H} (X|Y)+\mathrm {H} (Y|X)+\operatorname {I} (X;Y),\qquad \\\mathrm {H} (X,Y)&=\mathrm {H} (X)+\mathrm {H} (Y)-\operatorname {I} (X;Y),\,\\\operatorname {I} (X;Y)&\leq \mathrm {H} (X),\,\end{aligned}}$
where $\operatorname {I} (X;Y)$ is the mutual information between $X$ and $Y$.
For independent $X$ and $Y$:
    $\mathrm {H} (Y|X)=\mathrm {H} (Y)$ and $\mathrm {H} (X|Y)=\mathrm {H} (X)\,$
Although the specific-conditional entropy $\mathrm {H} (X|Y=y)$ can be either less or greater than $\mathrm {H} (X)$ for a given random variate $y$ of $Y$, $\mathrm {H} (X|Y)$ can never exceed $\mathrm {H} (X)$.

## Conditional differential entropy
### Definition

The above definition is for discrete random variables. The continuous version of discrete conditional entropy is called conditional differential (or continuous) entropy. Let $X$ and $Y$ be a continuous random variables with a joint probability density function $f(x,y)$. The differential conditional entropy $h(X|Y)$ is defined as$^{:249}$

### Properties

In contrast to the conditional entropy for discrete random variables, the conditional differential entropy may be negative.
As in the discrete case there is a chain rule for differential entropy:
    $h(Y|X)\,=\,h(X,Y)-h(X)$$^{:253}$
Notice however that this rule may not be true if the involved differential entropies do not exist or are infinite.
Joint differential entropy is also used in the definition of the mutual information between continuous random variables:
    $\operatorname {I} (X,Y)=h(X)-h(X|Y)=h(Y)-h(Y|X)$
$h(X|Y)\leq h(X)$ with equality if and only if $X$ and $Y$ are independent.$^{:253}$

### Relation to estimator error

The conditional differential entropy yields a lower bound on the expected squared error of an estimator. For any Gaussian random variable $X$, observation $Y$ and estimator ${\widehat {X}}$ the following holds:$^{:255}$
    $\mathbb {E} \left[{\biglX-{\widehat {X}}{(Y)}{\bigr )}^{2}\right]\geq {\frac {1}{2\pi e}}e^{2h(X|Y)}$
This is related to the uncertainty principle from quantum mechanics.

## Generalization to quantum theory

In quantum information theory, the conditional entropy is generalized to the conditional quantum entropy. The latter can take negative values, unlike its classical counterpart.