core22 min studyLesson 20 in Mathematics

Information and entropy

Measure uncertainty and predictive mismatch in bits without confusing information with meaning or thermodynamic entropy.

On this page

What you’ll understand

  • Calculate discrete Shannon entropy in bits.
  • Separate entropy, cross-entropy, and KL divergence.
  • Interpret uncertainty measures without claiming they capture semantic value or physical entropy automatically.

Predictable and unpredictable symbols carry different average surprise. Information theory quantifies this using probabilities and logarithms. Entropy underlies coding and many machine-learning objectives, but measures distributional uncertainty rather than meaning or usefulness. Begin with finite symbols so normalization, logarithm base, and zero-probability cases stay visible.

From surprise to average uncertainty

Define the surprise of an event with positive probability as minus the logarithm of its probability. Independent events have multiplying probabilities, so their surprises add. With logarithms base two, the unit is a bit. A certain event has zero surprise, while a rare event has more. Entropy averages this surprise over the possible outcomes, weighting each by how often the model says it occurs.

For a finite distribution, adopt the limiting convention 0log⁡0=00\log 0=0: impossible outcomes contribute nothing to the average. Entropy is nonnegative and is largest for a uniform distribution on a fixed finite support. A deterministic symbol has zero entropy; a fair binary symbol has one bit. Adding unused zero-probability labels does not create uncertainty. These are statements about a distribution, not a measure of the importance of the symbol names.

I(x)=−log⁡2p(x),H(p)=−∑x:p(x)>0p(x)log⁡2p(x),0≤H(p)≤log⁡2mI(x)=-\log_2 p(x),\qquad H(p)=-\sum_{x:p(x)>0}p(x)\log_2p(x),\qquad 0\le H(p)\le\log_2 m
For a normalized distribution on m finite possible labels, entropy is in bits. The upper bound is attained by the uniform distribution; natural logarithms instead produce nats.↔ Scroll wide equations horizontally.

A predictive distribution can waste information

Suppose outcomes are drawn from distribution pp while predictions assign probabilities using qq. Cross-entropy is the expected surprise measured using qq. It separates into the unavoidable entropy of pp plus a mismatch penalty called KL divergence. In classification, minimizing average negative log probability corresponds to this type of objective; the data distribution and the model's allowed family determine what can actually be learned.

KL divergence is nonnegative but generally asymmetric, so it is not a distance metric. If pp assigns positive probability where qq assigns zero, the divergence is infinite: the predictor declares a possible event impossible. A small KL value also does not automatically guarantee acceptable errors for every rare subgroup or decision cost. The logarithmic objective evaluates a particular form of probabilistic mismatch rather than every practical notion of model quality.

H(p,q)=−∑xp(x)log⁡2q(x)=H(p)+DKL(p∥q),DKL(p∥q)=∑xp(x)log⁡2p(x)q(x)H(p,q)=-\sum_xp(x)\log_2q(x)=H(p)+D_{\mathrm{KL}}(p\|q),\qquad D_{\mathrm{KL}}(p\|q)=\sum_xp(x)\log_2\frac{p(x)}{q(x)}
Use normalized discrete distributions and omit zero-p terms. Finite values require q(x)>0 wherever p(x)>0; otherwise the relevant cross-entropy and KL divergence are infinite.↔ Scroll wide equations horizontally.

Keep the scope of entropy explicit

Evidence reduces uncertainty on average; mutual information quantifies dependence through joint and marginal distributions. Correlated symbols can have less joint entropy than their separate entropies sum to. Thus a stream's one-symbol frequencies do not determine its full compressibility: relationships across time matter. This observation motivates a complete source model without proving a coding theorem here.

For continuous variables, a density integral defines differential entropy, which can be negative and changes under coordinate scaling. Thermodynamic entropy requires a physical microstate model with appropriate constants and units; quantum von Neumann entropy uses density operators. These structures share valuable mathematics, but their physical interpretations do not follow solely from the finite-symbol formula.

Separate source uncertainty from prediction mismatch

A source emits three symbols with probabilities p=(1/2,1/4,1/4)p=(1/2,1/4,1/4). A predictor uses q=(1/3,1/3,1/3)q=(1/3,1/3,1/3). Compute entropy, cross-entropy, and KL divergence in bits.

  1. The surprise under p is 1 bit for the first symbol and 2 bits for either other symbol. Average them: H(p)=12(1)+14(2)+14(2)=1.5H(p)=\tfrac12(1)+\tfrac14(2)+\tfrac14(2)=1.5 bits.

  2. The predictor assigns the same surprise −log⁡2(1/3)=log⁡23≈1.584963-\log_2(1/3)=\log_2 3\approx1.584963 to every symbol, so that is also its cross-entropy.

  3. Subtract source entropy from cross-entropy: DKL(p∥q)=log⁡23−1.5≈0.084963D_{\mathrm{KL}}(p\|q)=\log_2 3-1.5\approx0.084963 bits. The nonnegative difference measures this particular mismatch.

The result

The source entropy is 1.5 bits per symbol, while the uniform predictor incurs about 1.585 bits of expected surprise. Its excess is about 0.085 bits per symbol.

Explore the model

Interactive lab

Interactive lab · probability

Compare a certain bit with an uncertain bit

Set n=1 so the two binomial bars are 1−p and p. Compare p near zero, 0.5, and one; the fair case maximizes binary entropy. Calculate entropy alongside the probability display. Larger n describes a count, not the complete string of labeled trial outcomes.

Compare a certain bit with an uncertain bitThese are exact binomial probabilities for independent trials with one fixed success probability. Playback tours the distribution; it does not resample outcomes. Current readings: Mean · np: 5; Variance · np(1−p): 2.5; Total probability: 1. All parameters are adjustable with the labeled controls below.03581000.070.150.220.3Successes kP(X = k)k = 0 · P = 9.77e-4
Exact probabilityHighlighted outcomeMean np
Mean · np
5
Variance · np(1−p)
2.5
Total probability
1
t = 0 s

These are exact binomial probabilities for independent trials with one fixed success probability. Playback tours the distribution; it does not resample outcomes. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.

Look forBalanced binary probabilities maximize uncertainty; a count distribution differs from the full distribution of trial sequences.

Check your understanding

Why is KL divergence not an ordinary distance metric?

Try it yourself

A binary source has p=(1,0), while a predictor uses q=(0.5,0.5). Find the source entropy, cross-entropy, and KL divergence in bits. What happens if the predictor instead gives zero probability to the first symbol?

Take a moment to make a prediction or work it out on paper. Open a hint when you need one.

Give me a hint

Only the first symbol contributes under p. Remember the zero-probability limiting cases.

Compare with the solution

The source is certain, so H(p)=0H(p)=0. The predictor gives the actual symbol surprise −log⁡2(0.5)=1-\log_2(0.5)=1, hence cross-entropy and KL are both 1 bit. If q assigns zero probability to that symbol, its surprise and the KL divergence become infinite; the zero-weight second symbol does not cancel that failure.

Take it with you

  • Shannon entropy is average model-based surprise, with the logarithm base specifying units.
  • Cross-entropy equals source entropy plus a nonnegative predictive mismatch penalty.
  • Discrete, differential, thermodynamic, and quantum entropy require distinct structures and interpretations.

Read further

Original sources and deeper explanations to follow at your own pace.

Optional progress, saved in this browser when available. Revisit any lesson at any time.

Lesson not marked complete.