Log inStart free
LESSON 2.22 · 6 STAGES · 3 CONTROLS · 3 CHECKSPRO · PREVIEW

Entropy, cross-entropy and KL divergence

Send 16 weather reports in bits, and count the bits a wrong code wastes.


Pro lesson. Stage 1 is free to watch. Pro opens all 6 stages, 3 controls and 3 checks, in this lesson and every other.

Go Pro · $8.25/mo
EXPLAINER · 2.22 · ENTROPY BAYSUN 1 BIT · CLOUD 2 · RAIN 3 · SNOW 3
01
Stage 1 of 6 · Surprisal
Rare outcomes carry more surprisal: log₂ 1/p bits. Sun (1/2) needs 1, snow (1/8) needs 3.
Explain it simply

Each teal bar is the chance of one kind of weather. The cells under it are its code word, one bit per yes-or-no question. Sun comes half the time, so one question finds it. Each time the chance halves, it takes one more bit, so snow, at 1 in 8, takes 3 bits.

Four outcomes with chances 1/2, 1/4, 1/8, 1/8. Their code words under p: sun 1 bits, cloud 2 bits, rain 3 bits, snow 3 bits.

source p, its codemodel q, its codeextra bits, lossa symbol
4 outcomeschancep's codesun1/201 bitcloud1/4102 bitsrain1/81103 bitssnow1/81113 bits4 outcomeschancep's codesun1/201 bitcloud1/4102 bitsrain1/81103 bitssnow1/81113 bits
Toy: one weather source · 4 outcomes · chances in eighths · a Huffman code per distribution · 16 symbols
STAGE 1 / 6
MATH · STAGE 1HOVER A SYMBOL OR A SHAPE
I(x)=log⁡21p(x)\sy{I}{data}{I(x)} = \log_2 \frac{1}{\sy{p}{data}{p(x)}}
I(sun)=log⁡22=1,    I(cloud)=log⁡24=2,    I(rain)=log⁡28=3,    I(snow)=log⁡28=3I(\text{sun}) = \log_2 2 = 1,\;\; I(\text{cloud}) = \log_2 4 = 2,\;\; I(\text{rain}) = \log_2 8 = 3,\;\; I(\text{snow}) = \log_2 8 = 3

Each halving of the chance adds one bit.

Common mix-ups

MYTHKL divergence is a distance: the same in both directions.

The fix, and 1 more mix-up with the diagram to show them, come with Pro.

Predict, then reveal
3 CHECKS · PRO
Q01If the source becomes even, does the entropy go up or down?

Make your guess, then test it in the diagram. All 3 checks come with Pro.

PRO LESSON · YOU WATCHED STAGE 1 OF 6
Unlock the full explainer
  • 5 more stages and 3 live controls
  • 2 mix-up cards and 3 predict-then-reveal checks
  • Watch it as a narrated video, in three voices
  • Every Pro lesson and capstone · 656 in total

$99 a year, or $15 a month. Cancel any time.