Information and entropy
Measure uncertainty and predictive mismatch in bits without confusing information with meaning or thermodynamic entropy.
On this page
The question for today
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 : 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.
A predictive distribution can waste information
Suppose outcomes are drawn from distribution while predictions assign probabilities using . Cross-entropy is the expected surprise measured using . It separates into the unavoidable entropy of 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 assigns positive probability where 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.
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.
Work it through
Separate source uncertainty from prediction mismatch
A source emits three symbols with probabilities . A predictor uses . Compute entropy, cross-entropy, and KL divergence in bits.
The surprise under p is 1 bit for the first symbol and 2 bits for either other symbol. Average them: bits.
The predictor assigns the same surprise to every symbol, so that is also its cross-entropy.
Subtract source entropy from cross-entropy: bits. The nonnegative difference measures this particular mismatch.
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.
The living notebook
Explore the model
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.
- Mean · np
- 5
- Variance · np(1−p)
- 2.5
- Total probability
- 1
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.
Pause & reason
Check your understanding
Your turn
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 . The predictor gives the actual symbol surprise , 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.
Keep the idea
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.