1.3.18 · D1Probability & Statistics

Foundations — Entropy and KL divergence

1,876 words9 min readBack to topic

This page builds every piece of notation the parent note topic note leans on, starting from a smart 12-year-old who has never seen a sign. Read it top to bottom; each symbol is earned before it is used.


1. A probability — a slice of certainty

Before any formula, we need the raw material: probability.

The picture. Imagine a bar of total length . You cut it into pieces, one piece per possible outcome. The width of a piece is its probability. All widths together must exactly fill the bar — nothing missing, nothing overflowing.

Figure — Entropy and KL divergence

Why the topic needs it. Entropy and KL divergence are averages weighted by these widths. A wide (likely) outcome pulls the average toward its value; a thin (rare) outcome barely nudges it. Without probabilities there is nothing to weigh.


2. The random variable and its alphabet

Read as " is one item chosen from the list ." The symbol just means "belongs to."

The picture. is the set of labels written under each slice of the certainty bar in §1. If the bar has three slices, then and — the vertical bars mean "count how many items are inside."

Why the topic needs it. The maximum-entropy property literally counts how many outcomes exist. That is exactly this list-length.


3. The sum sign — "add up over every slice"

Every formula on the parent page begins with . It is not scary.

For :

The picture. Go slice by slice along the certainty bar, drop each slice's contribution into a bucket, and read off the bucket at the end.


4. The logarithm — turning "how many halvings?" into a number

This is the tool the whole topic is built on, so we install it carefully.

Examples you can check by hand:

  • (already there, no doublings).
  • , , .
  • (one halving — negative because we shrank).
Figure — Entropy and KL divergence

The additivity that earns the log. If event has probability and independent event has probability , the pair happens with probability . Then Surprise of the pair = surprise of each, added. That single line is why (called surprisal) is the right meter, and why sits at the heart of entropy.


5. Surprisal — the height of one slice's shock

The picture. Rare slice (thin, small ) → tall surprise spike. Certain slice () → flat zero. Plot surprisal against probability and you get a curve diving to at and shooting to as .

Why the topic needs it. Entropy is nothing but the average of these spike heights, and cross-entropy is the average of spikes computed with the wrong meter — so surprisal is the atom both are built from.


6. Expectation — the weighted average

The picture. Balance point of a see-saw: place a weight at position for every outcome; the expectation is where the plank balances. Wide slices sit heavier and drag the balance toward their value.

Why the topic needs it. With this one symbol the parent's two headline formulas collapse into plain English:


7. Two distributions and — truth vs. your guess

The picture. Two certainty bars stacked. Where the -slice is narrower than the -slice, your model under-expects a common event — and you pay for it. KL divergence is the running tally of that payment.

Figure — Entropy and KL divergence

8. The conventions that stop the formulas from exploding

The picture. As a slice's width shrinks toward zero, its surprisal spike grows tall, but the width multiplying it shrinks faster — the product (a thin, tall sliver of area) collapses to nothing. The see-saw feels no weight from a zero-width slice.


Prerequisite map

probability p of x

random variable X and alphabet

logarithm base 2

sum over outcomes

surprisal minus log p

expectation weighted average

Entropy H of X

two distributions p and q

ratio and log difference

KL divergence and cross entropy

parent topic Entropy and KL divergence

This map shows the dependency order used above: probabilities and logs are the roots; expectation fuses surprisal into entropy; two distributions plus the log-ratio give KL divergence; both feed the parent topic. Downstream, these same tools power Cross-Entropy Loss, Mutual Information, Information Gain, the Maximum Entropy Principle, Jensen-Shannon Divergence, F-divergences, and the Evidence Lower Bound (ELBO) used in Variational Autoencoders.


Equipment checklist

Cover the right side and test yourself. If you can answer all of these, you are ready for the parent note.

What must all the slice-widths add up to, and why?
Exactly — the certainty bar has total length ; every outcome is accounted for once.
What does mean in words?
" is one outcome taken from the list of all possible outcomes ."
How many terms does produce for a coin?
Two — one for heads, one for tails; the sum visits outcomes, not numbers.
Why is a logarithm the right surprise meter and not ?
Because turns multiplication of independent probabilities into addition of surprises, and sends to zero surprise.
Compute by counting doublings.
, since .
Rewrite without a fraction.
.
State surprisal and its value at .
; at it is (a certain event is no surprise).
Write entropy as an expectation.
— the average surprisal.
In , which distribution is the truth and which does the weighting?
is the truth and is the weight; is the model/guess.
What is by convention, and why?
, because — a never-occurring outcome adds no surprise.
When does ?
When some outcome has but — the model called a real event impossible.