Information and Entropy
Entropy measures the average surprise of a random outcome, in bits: the shortest average code length.
Needs a step first: 7
An outcome of probability carries bits of information (a fair coin flip is 1 bit, a 1-in-8 event 3 bits), and entropy is the expected value of that surprise. Shannon showed it is the least number of bits per symbol any code can average, so it sets the limit on compression. It is largest when all outcomes are equally likely and zero when one is certain. Cross-entropy, the loss that language models and classifiers are trained on, is built directly from it.
Where it shows up: It leads to cross-entropy and KL divergence, the losses most models are trained to minimise.
How to hold it: In your head
See entropy as average surprise in bits, largest when the outcomes are equally likely, and know that it is the floor under the average length of any code.
What knowing it looks like
- Compute the entropy of a small distribution in bits.
- Build a prefix code whose average length matches the entropy for probabilities that are powers of .
- Explain why a uniform distribution has the most entropy.
Test yourself
A source emits A, B, C, D with probabilities . Find its entropy in bits, and give a binary prefix code whose average length equals it.
Show the worked answer
Needs a step first: 7
Learn it with an AI
Copy this prompt into any AI assistant. It will take you through step by step at your level and finish with the test above.
Be my maths tutor. I'm learning "Information and Entropy" (Undergraduate I tier): Entropy $H = -\sum p_i\log_2 p_i$ measures the average surprise of a random outcome, in bits: the shortest average code length. I already know: Random Variables, Expectation and Variance, Exponentials and Logarithms. Teach it Socratically: first ask what I already know; then explain the core idea with one concrete example and why it's true; then give me three problems, one at a time, easy to hard. Wait for my answer, check every step, and point out mistakes without giving the answer away. Finish by testing me with this: A source emits A, B, C, D with probabilities $\tfrac12, \tfrac14, \tfrac18, \tfrac18$. Find its entropy in bits, and give a binary prefix code whose average length equals it. Use LaTeX for formulas. When you say where it's used later (machine learning, quantum mechanics), be specific.
Needs first
- Random Variables, Expectation and VarianceA number decided by chance, summed up by its expectation (the long-run average) and its variance (how far it typically strays).Core · Probability & Statistics
- Exponentials and LogarithmsExponential functions, which grow or shrink by a fixed factor per step, and logarithms, which undo them; with the special base .Bridge · Functions & Calculus
Leads to
On the way to
Recommended
- Mathematics for Machine LearningDeisenroth, Faisal and Ong (Cambridge University Press) · BookA free book that gathers exactly the linear algebra, vector calculus, probability and optimisation machine learning uses, then applies them to regression, PCA and classification.
- Convex OptimizationStephen Boyd and Lieven Vandenberghe · BookThe standard text on convex sets, duality and Lagrange multipliers, free as a PDF from Stanford along with lecture slides and exercises.
- Information Theory, Inference, and Learning AlgorithmsDavid MacKay · BookMacKay's book connecting entropy, coding, Bayesian inference and neural networks, free to read online and still the one recommended for information theory with intuition.