Probability and statistics

H(p)=−∑xp(x)log⁡p(x)H(p) = -\sum_x p(x) \log p(x) Entropy and cross-entropy

H(p) is the entropy of a distribution: its average surprise. H(p, q) is the cross-entropy.

In ML papers

H(X)H(X) or H(p)H(p) is the entropy: the expected value of −log⁡p(x)-\log p(x), so it measures how uncertain or spread out a distribution is. It is 0 for a distribution that always gives the same outcome and largest for a uniform one. With log⁡2\log_2 it is in bits, with the natural log in nats.

H(p,q)=−∑xp(x)log⁡q(x)H(p, q) = -\sum_x p(x) \log q(x) is the cross-entropy: the average surprise when outcomes come from pp but you score them with qq. The usual classification loss is the cross-entropy between the one-hot label and the model's softmax output, which reduces to −log⁡q(y)-\log q(y) for the true class yy. It splits as H(p,q)=H(p)+DKL(p∥q)H(p, q) = H(p) + D_{\mathrm{KL}}(p \| q) (KL divergence).

H(Y∣X)H(Y \mid X) is the conditional entropy: the uncertainty left in YY once XX is known.

Other meanings, by context

How to type it

LaTeXShows
H(X)H(X)H(X)
H(p, q) cross-entropyH(p,q)H(p, q)
\mathbb{H}[p] some papersH[p]\mathbb{H}[p]

A worked example

H=−(12log⁡212+12log⁡212)=1 bitH = -\left(\tfrac12 \log_2 \tfrac12 + \tfrac12 \log_2 \tfrac12\right) = 1 \text{ bit}

A fair coin has 1 bit of entropy; a coin that lands heads 90% of the time has about 0.470.47 bits.

Common confusions

Equations that use it

Related

DKL(q ∥ p)D_{\mathrm{KL}}(q \,\|\, p)KL divergenceI(X;Y)=H(X)−H(X∣Y)I(X; Y) = H(X) - H(X \mid Y)Mutual informationlog⁡pθ(x)\log p_\theta(x)LogarithmEx∼p[f(x)]\mathbb{E}_{x \sim p}[f(x)]Expectation

Decode this example →