1.3.18 · D3Probability & Statistics

Worked examples — Entropy and KL divergence

2,621 words12 min readBack to topic

This page is the workbook for the parent topic. We will not re-derive the formulas from scratch — instead we hunt down every kind of input these formulas can meet and work each one to the last decimal. Think of it as a checklist: after this page, no probability distribution should ever surprise you.

Before we start, let us re-anchor the two symbols we will use over and over, in plain words.

Everywhere below, without a base means (answers in bits) unless we say "nats", in which case it is the natural log .


The scenario matrix

Here is the full landscape of cases a problem in this topic can hand you. Every worked example below is tagged with the cell(s) it covers, and together they fill the whole grid.

Cell What makes it special Covered by
A. Uniform all outcomes equally likely → entropy hits its maximum Ex 1
B. Skewed / biased one outcome dominates → entropy shrinks Ex 2
C. Degenerate (certain) one probability , rest → entropy , and the trap Ex 2, Ex 3
D. KL both directions vs → asymmetry made concrete Ex 4
E. KL degenerate some where → divergence blows up to Ex 5
F. Identity → KL (the sanity floor) Ex 4 (check)
G. Cross-entropy = KL + H one-hot label vs prediction → classification loss Ex 6
H. Limiting behaviour continuous knob or : where does entropy peak? Ex 7
I. Word problem real-world compression / surprise story Ex 8
J. Exam twist combine additivity + independence in one shot Ex 9
Figure — Entropy and KL divergence

The blue curve above (call it the binary entropy curve ) is the map we will keep returning to. Read it left to right: at the edges and the curve touches the floor (certainty, cell C), and at the middle it reaches the ceiling of bit (cell A). Cell B lives on the slopes; cell H is the whole shape of the curve.


Cell A — the uniform maximum


Cells B & C — skew and the zero-probability trap


Cell C again — the true floor


Cells D & F — KL both directions and the identity floor


Cell E — the divergence explodes


Cell G — cross-entropy, KL, and classification loss


Cell H — limiting behaviour, where the peak lives


Cell I — a word problem


Cell J — the exam twist


Where this leads

  • The waste-bits idea generalises: KL is one member of the F-divergences family, and its symmetrized cousin is Jensen-Shannon Divergence.
  • Choosing the distribution of maximum entropy subject to constraints is the Maximum Entropy Principle.
  • In deep generative models, minimizing a KL term against a prior is the heart of Variational Autoencoders and the Evidence Lower Bound (ELBO).
  • Decision trees split on the entropy drop called Information Gain.
Recall Self-test (reveal after answering)

Fair 4-sided die entropy ::: bits () Loaded coin entropy ::: bits for ::: bits Same but reversed ::: bits (asymmetric!) KL when assigns to an event with ::: Cross-entropy of , ::: nats Weather for ::: bits KL of that weather to uniform ::: bits Joint entropy of fair 4-die + fair coin ::: bits