Varentropy (source code)

= Varentropy
{title2=$V_H(X)$}
{wiki}

The <varentropy> of a discrete <random variable> $X$ is the <variance> of its <information content>:
$$
V_H(X)=\operatorname{Var}[-\log_2P(X)].
$$
It measures variation in surprise across outcomes, while <Shannon entropy> is the <expected value> of that surprise. Assuming finite <Shannon entropy>, the <variance> may still be infinite; finite <varentropy> requires an <integrable> squared logarithm.

For a <Bernoulli random variable> with success <probability> $0<p<1$,
$$
V_H(X)=p(1-p)\left(\log_2\frac{1-p}{p}\right)^2.
$$
Indeed the <information content> takes values $-\log_2p$ and $-\log_2(1-p)$, and the <variance> of a two-valued <random variable> is $p(1-p)$ times the squared difference. At $p=1/2$, every outcome supplies one <bit>, so <Shannon entropy> is maximal but <varentropy> is zero. For <independent and identically distributed random variables>, the <information content> of a length-$n$ word is a sum, giving <variance> $nV_H(X)$ when finite.