Kayavak / Recaps / Information Theory
Recaps · Book 1
Information Theory
The revision sheet of every chapter, on one page: the key ideas, the numbers worth knowing, the pitfalls and the words. Use it before an interview, after a chapter, or to find which chapter to reread. Each title opens its chapter; below each sheet are its exercises, companion and TiffinBox stage, and the misconceptions the companion corrects.
01
Key ideas
- Information is resolved uncertainty; a message is a choice from a set of possibilities.
- Shannon's system: source → transmitter → channel (with noise) → receiver → destination; source coding removes redundancy, channel coding adds it back to fight noise.
- Hartley (1928): equally likely possibilities carry .
- Surprise (self-information): bits; 0 for certainty; adds for independent events.
- Only a logarithm makes surprises of independent events add.
- Units: bit (), nat (), ban (); 1 nat ≈ 1.443 bits, 1 ban ≈ 3.322 bits.
- Questions: yes-or-no questions always find one of possibilities.
- Binary digit ≠ bit of information: predictable data carries less than its size.
Glossary
- Information: what a message provides by resolving uncertainty about which of several possibilities happened.
- Self-information / Surprise: the information carried by an outcome of probability , bits.
- Bit (of information): the unit of information; the surprise of one outcome of a fair coin toss, or the answer to one fair yes-or-no question.
- Binary digit: a stored 0 or 1, which carries up to one bit of information.
- Nat: the unit of information measured with natural logarithms; about 1.443 bits.
- Ban / Hartley: the unit of information measured with base-10 logarithms; about 3.322 bits.
- Information source: whatever chooses the messages to be sent, described by the possible messages and their probabilities.
- Channel: the medium a signal crosses from transmitter to receiver, where noise can change it.
- Noise: random disturbance that changes a signal in a channel.
- Source coding: turning messages into as few symbols as possible by removing redundancy.
- Channel coding: adding structured redundancy to a signal so the receiver can correct errors caused by noise.
- Redundancy: the part of a message's length that carries no information, because it could have been predicted.
Practise: Exercises · Companion · Squeeze stage
Misconceptions (from the companion)
| Misconception |
What's actually true |
| "A letter always carries the same information." |
It depends on the model: "u" carries 4.83 bits alone and 0 after "q". |
| "If no compressor can shrink it, it's random." |
Pseudo-random bytes from a 60-byte program defeat zlib, bz2 and lzma. |
| "Finding one of N needs log₂ N questions, always." |
That's the worst case for equal odds; unequal odds allow fewer on average. |
| "A 32-character hex token has 256 bits of security." |
It carries 128 bits: each hex character is 4 bits stored in 8. |
"math.log gives bits." |
It gives nats; bits need math.log2. |
| "Percentages work as probabilities." |
Surprise needs between 0 and 1; percentages give negative "bits". |
"int(math.log2(n)) questions are enough." |
It rounds down; the worst case needs . |
| "Compressing a message measures its information." |
Short messages grow, because of fixed headers and checksums. |
02
Key ideas
- Multiplication principle: choices from each give sequences; bits add: .
- Factorial: orders; bits in a shuffled deck.
- Combinations: ways to choose from .
- Estimating: ; .
- Fixed-length code: digits per symbol; efficiency = ÷ digits.
- Blocks: symbols in digits; under per symbol.
- Question strategies are binary trees; a codeword is the path; depth = questions.
- Sorting bound: any comparison sort needs comparisons in the worst case.
- Stirling: .
Glossary
- Multiplication principle: if one choice has options and a second has whatever the first was, together they have .
- Factorial: , the number of orders of different things.
- Binomial coefficient: , the number of ways to choose things from when order doesn't matter.
- Fixed-length code: a code giving every symbol a codeword of the same number of binary digits.
- Codeword: the string of symbols a code assigns to one message or symbol.
- Code efficiency: the information a code carries per symbol divided by the binary digits it spends per symbol.
- Block coding (of a source): encoding several source symbols together as one, so rounding costs less per symbol.
- Bit writer: code that packs values of any number of binary digits into a stream of bytes, and its reader unpacks them.
- Decision tree: a binary tree drawing a strategy of yes-or-no questions, with an outcome at each leaf.
- Comparison sort: a sorting method that learns about its input only by comparing pairs of items.
- Sorting lower bound: the fact that any comparison sort needs at least comparisons in the worst case.
- Stirling's approximation: , so .
- ASCII: the American Standard Code for Information Interchange (1963), a 7-bit fixed-length code for 128 characters.
Practise: Exercises · Companion · Squeeze stage
Misconceptions (from the companion)
| Misconception |
What's actually true |
| "Sorting always costs n log₂ n comparisons." |
Only for inputs with that much disorder; sorted input took 9,999. |
| "Converting a big decimal number to binary is free." |
Python limits it to 4,300 digits by default; the cost grows faster than the length. |
| "Sorting n items means telling apart n! orders." |
With duplicates there are far fewer: n!/(c₁! c₂! …). |
| "A shuffle uses as many random bits as it has information." |
Python's spends about 380 bits on a 226-bit shuffle. |
"math.ceil(math.log2(n)) is always right." |
For n just above a large power of two, floating point rounds it wrong. |
| "Compute a combination's bits from factorials." |
Dividing huge factorials as floats overflows; use math.comb or lgamma. |
| "A number's digits survive a round trip through int." |
Leading zeros vanish unless the width is restored. |
| "Swapping each item with a random position shuffles fairly." |
It makes equally likely paths onto orders, unevenly. |
03
Key ideas
- Rules: ; certain = 1; disjoint events add. Complement: . Overlap: .
- Equally likely: probability = favourable count ÷ total count.
- Independent: , so surprises add.
- Conditional: ; product rule .
- Bayes: ; rare causes stay rare after weak evidence.
- Expected value ; always additive. Variance .
- Law of large numbers: averages approach expectations; error shrinks like .
- Binomial: , mean . Geometric: wait on average.
- Estimating: (add-one); never zero.
- Birthday: collisions likely after about values; expected pairs .
Glossary
- Possible outcome: one possible result of an experiment, such as a die showing 4.
- Random event: a set of possible outcomes, such as "the die shows an even number", whose probability can be asked about.
- Probability: a number from 0 to 1 assigned to each event, following Kolmogorov's rules.
- Probability distribution: the list of probabilities of each value a random quantity can take; non-negative and adding to 1.
- Independent events: events where knowing one happened doesn't change the probability of the other; their probabilities multiply.
- Conditional probability: , the probability of among the cases where happened.
- Bayes' theorem: , reversing a conditional probability.
- Random variable: a number whose value depends on the outcome of an experiment.
- Expected value: the probability-weighted average of a random variable's values; its long-run average.
- Variance: the expected squared distance of a random variable from its mean.
- Law of large numbers: averages of many independent repetitions approach the expected value.
- Binomial distribution: the distribution of the number of successes in independent trials with the same success probability.
- Geometric distribution: the distribution of the number of trials up to the first success.
- Add-one smoothing: estimating a probability as so that no symbol gets probability zero; Laplace's rule of succession.
- Birthday problem: the fact that among random values from , a repeat becomes likely once is about .
Practise: Exercises · Companion · Squeeze stage
Misconceptions (from the companion)
| Misconception |
What's actually true |
| "A word's frequency in a file is its probability." |
Frequencies drift through a file: "king" from 0 to 12 per thousand words. |
| "Unseen things are rare enough to ignore." |
7.8 % of the second half's words were absent from the first half. |
| "The expected wait is the typical wait." |
Mean 6, median 4, most common 1, longest 71. |
| "Weighted random choice checks its weights." |
random.choices accepts a negative weight and silently never picks some items. |
| "Probabilities that should add to 1 will compare equal to 1.0." |
Ten 0.1s added in a loop give 0.9999999999999999. |
| "P(h after t) is count(th) ÷ count(h)." |
It's count(th) ÷ count(t followed by anything). |
| "Two servers fail together with the product of their chances." |
Only if independent; a shared cause makes it 23 times likelier. |
| "A million random ids are plenty for 5,000 users." |
About 12 collisions are expected; the test failed every time. |
04
Key ideas
- Entropy : expected surprise, bits per symbol.
- Binary entropy : 0 at the ends, 1 at , symmetric.
- ; only for certainty; only for uniform.
- Independent sources: .
- Grouping: decide the group, then within it; entropy adds up the stages, weighted.
- Coding: no code averages fewer than digits per symbol; good codes come within 1, or less with blocks.
- Redundancy ; English letters 10.8 % on frequencies, about 75 % with context.
- Plug-in estimates are biased low; Miller's correction adds .
Glossary
- Entropy (information): the expected surprise of a source, bits per symbol; the average information it produces.
- Binary entropy function: , the entropy of a two-outcome source with probabilities and .
- Uniform distribution: one in which every possible value is equally likely; it has the largest entropy, .
- Grouping property: the rule that entropy can be computed in stages, first choosing a group and then a member, weighting each stage by its probability.
- Redundancy (of a source): , the fraction of its symbols' capacity a source doesn't use.
- Order-0 entropy: the entropy computed from symbol frequencies alone, ignoring any dependence on earlier symbols.
- Plug-in estimate: an entropy computed by putting observed frequencies into the formula; biased low for small samples.
- Miller–Madow correction: adding bits to a plug-in entropy estimate to reduce its bias.
Practise: Exercises · Companion · Squeeze stage
Misconceptions (from the companion)
| Misconception |
What's actually true |
| "Same entropy means equally compressible." |
The plays, shuffled and sorted have equal order-0 entropy; lzma gives 2.61, 4.91 and 0.004 bits. |
| "A code for a 0.08-bit source can use 0.08 bits per symbol." |
Not one symbol at a time: at least 1 digit each; blocks approach 0.08 slowly. |
| "Enough text gives the entropy of words." |
The estimate kept rising with all 208,503 words; heavy tails defeat plug-in estimates. |
| "scipy.stats.entropy returns bits." |
Its default is nats; pass base=2. |
| "Pass counts or probabilities, whichever: same result." |
SciPy normalises, but your own function may not. |
| "An entropy function can just skip zero probabilities." |
Only if it's written to: log2(0) raises an error. |
| "Output that looks random has high entropy." |
Hashes of a counter score 4.0 bits per hex character and are fully predictable. |
05
Key ideas
- Uniquely decodable: every coded string has one reading. Prefix code: no codeword is a prefix of another; decodable instantly, down a tree.
- Kraft: lengths are possible for a prefix code iff ; McMillan: the same for any uniquely decodable code. Sum = 1: complete.
- Entropy bound: average length ; equality iff for all .
- Shannon code: gives .
- Huffman: merge the two lightest trees until one remains; optimal; always complete.
- Canonical codes: codewords determined by lengths, counting up; the decoder needs only lengths.
- Limits: at least 1 bit per symbol; up to 1 bit above ; probabilities must be known.
- Integer codes: unary; Elias gamma digits; Rice with mean.
Glossary
- Variable-length code: a code whose codewords have different lengths, so likely symbols can get short ones.
- Uniquely decodable code: a code in which every string of codewords can be split back into symbols in only one way.
- Prefix code: a code in which no codeword is the beginning of another; it can be decoded symbol by symbol as the digits arrive.
- Kraft's inequality: the condition on codeword lengths, necessary and sufficient for a prefix code to exist.
- Complete code: a prefix code whose Kraft sum is exactly 1, so no binary string is wasted.
- Average codeword length: , the expected number of binary digits per symbol.
- Shannon code: a code giving each symbol digits; within one bit of the entropy.
- Shannon–Fano coding: building a code by splitting the symbols into two groups of nearly equal probability, recursively; good but not always optimal.
- Huffman code: the optimal prefix code for given probabilities, built by repeatedly merging the two least likely subtrees.
- Canonical Huffman code: a Huffman code whose codewords are assigned from the lengths alone by a fixed rule, so only the lengths need sending.
- Elias gamma code: a prefix code for whole numbers: the binary form preceded by one fewer zeros than it has digits.
- Rice code: a code for whole numbers: the quotient by in unary, then the remainder in binary digits.
- Unary code: writing a whole number as ones followed by a zero (or the reverse).
Practise: Exercises · Companion · Squeeze stage
Misconceptions (from the companion)
| Misconception |
What's actually true |
| "A Huffman code built once works for similar data." |
Symbols it never saw have no codeword at all. |
| "Huffman usually wastes up to a bit per symbol." |
For spread-out distributions the excess is at most , usually far less. |
| "Huffman codewords stay short." |
They can reach digits; formats cap them. |
| "Huffman codewords are written high bit first in DEFLATE." |
zlib reverses them: DEFLATE packs bits from the least significant end. |
| "Any priority queue implementation will do." |
Without a tie-breaker, Python's heap compares the trees and crashes. |
| "Canonical codes are just counting upwards." |
Without shifting when the length grows, the code isn't prefix-free. |
| "A one-symbol file needs no special case." |
Zero-length codewords carry nothing; the decoder can't count symbols. |
| "Rice codes work for any whole number." |
Negative numbers collide with positive ones unless mapped first. |
06
Key ideas
- Typical sequences: probability ; about of them; together almost all the probability (law of large numbers).
- .
- Source coding theorem: achievable at per symbol; impossible below .
- Counting: files of bits, shorter files: no compressor shrinks all; random data doesn't compress.
- Arithmetic coding: interval width = message probability; length ≈ total surprise + 2 bits; model and coder separate.
- Adaptive coding: learning costs about bits in total.
- Lempel–Ziv: LZ77 (pointers to earlier copies), LZ78 (growing dictionary); universal for stationary sources.
- ANS: arithmetic-coding efficiency at Huffman speed.
Glossary
- Typical sequence: a sequence whose surprise per symbol is close to the source's entropy; long sequences are almost always typical.
- Typical set: the set of typical sequences of a given length; about members holding almost all the probability.
- Asymptotic equipartition property: the fact that long sequences from a source have probability close to , shared almost equally among about typical sequences.
- Source coding theorem: Shannon's result that a source can be losslessly compressed to its entropy per symbol, and no further.
- Counting argument (compression): the proof that no lossless compressor shortens every file, because there are fewer shorter files than files.
- Arithmetic coding: coding a whole message as a number inside an interval whose width is the message's probability, so it costs about its total surprise.
- Model (compression): the part of a compressor that predicts the probabilities of the next symbol.
- Coder (compression): the part of a compressor that turns predicted probabilities into bits.
- Adaptive coding: coding with probabilities learned from the symbols seen so far, updated identically by encoder and decoder.
- Universal compression: compression that approaches the entropy of any source in a broad class without being told which source it is.
- Lempel–Ziv compression: dictionary methods (LZ77, LZ78) that replace repeated strings with references to earlier occurrences.
- Asymmetric numeral systems (ANS): a family of entropy coders with arithmetic coding's efficiency and table-driven speed.
Practise: Exercises · Companion · Squeeze stage
Misconceptions (from the companion)
| Misconception |
What's actually true |
| "Long blocks get steadily closer to the entropy." |
Gains shrink and wobble while tables grow exponentially. |
| "An adaptive coder should remember everything it has seen." |
For changing data, forgetting cut 5.10 to 4.21 bits per byte. |
| "Universal compressors reach the entropy of any data." |
zlib stayed 13 % above it on 4 MB of independent bytes. |
| "Real coders use exact probabilities." |
Zstandard rounds them to a table of size or so, at a measurable cost. |
| "Any precision works for an arithmetic coder." |
Too few bits let rare symbols' slices round to zero, and the coder hangs. |
| "The decoder can tweak the model it receives." |
Encoder and decoder must use identical probabilities, or the output is garbage. |
| "The last few bits don't matter." |
Without the final bits, the last symbol came out wrong. |
| "A model trained on a sample covers the data." |
A byte unseen in the sample has no slice at all. |
07
Key ideas
- Joint entropy : entropy of the pair; , equal iff independent.
- Conditional entropy : average uncertainty left.
- Chain rule: ; for sequences, the sum of each symbol given the past.
- Conditioning reduces entropy on average: .
- Mutual information : symmetric, , iff independent, .
- Data processing inequality: gives .
- Entropy rate ; the limit of compression for sources with memory.
- Markov model of order : predict from the last symbols; on unseen text, longer isn't always better (overfitting).
- Fano's inequality: limits how well can be guessed from .
Glossary
- Joint entropy: the entropy of two (or more) random variables taken together, .
- Conditional entropy: , the average uncertainty about remaining once is known.
- Chain rule (entropy): : the information in a pair is the first plus the second given the first.
- Mutual information: , how much knowing one variable reduces uncertainty about the other; symmetric and zero only for independent variables.
- Information diagram: a picture of entropies as overlapping regions, with mutual information as the overlap.
- Equivocation: Shannon's name for the uncertainty about the sent message that remains after receiving, .
- Data processing inequality: the theorem that processing data can't increase the information it carries about a third variable.
- Markov chain (information): a sequence of variables in which each depends on the past only through the one before it; .
- Entropy rate: the long-run information per symbol of a source with memory, the limit of the conditional entropy of the next symbol given the past.
- Markov model of order k: a model that predicts each symbol from the symbols before it.
- Overfitting: a model fitting the accidents of its training data so closely that it predicts new data worse.
- Fano's inequality: a bound relating the conditional entropy to the best possible probability of error in guessing from .
Practise: Exercises · Companion · Squeeze stage
Misconceptions (from the companion)
| Misconception |
What's actually true |
| "If no pair of variables is related, none of them are." |
Parity: every pair shares 0 bits, the three together are fully dependent. |
| "High mutual information means a model will predict well." |
A straight line used none of 's 1.945 bits about . |
| "A binned estimate of continuous mutual information is the value." |
2 bins gave 0.27 bits, 1,024 gave 3.9, for a true 0.737. |
| "scikit-learn's mutual information is in bits." |
It uses natural logarithms: nats. |
| "Raw mutual information compares fairly across label sets." |
Independent 50-value labels scored 1.65 bits; the adjusted score was about 0. |
| "Sorting each column of a table doesn't change its statistics." |
It invents dependence: 0.02 bits became 2.87. |
| "H(Y given X) is H(Y) minus H(X)." |
It's H(X, Y) minus H(X); the wrong formula even goes negative. |
| "Add a small count to each symbol" is enough for smoothing. |
The denominator must add it for every symbol too, or probabilities don't add to 1. |
| "Mutual information functions accept measurements." |
Given floats, each value is its own label, and the score is log₂ n. |
08
Key ideas
- Channel: the probabilities ; memoryless if uses are independent.
- Binary symmetric channel: each bit flipped with probability ; with equally likely inputs (0.531 for ).
- Binary erasure channel: each bit lost (marked) with probability ; .
- Errors in a block: binomial, mean ; .
- Rate: data bits per transmitted bit.
- Repetition-3: rate , .
- Minimum distance : detects errors, corrects .
- Hamming(7,4): 4 data bits, 3 parity bits, distance 3; the syndrome is the error's position.
- Check digits: weighted sums catch swaps; ISBN-10 (mod 11) catches all single errors and swaps; Luhn misses 09 ↔ 90.
- CRC: remainder of polynomial division by exclusive or; catches every burst up to its degree.
- Compressed data: no redundancy left, so one bit can ruin the rest: always add a check.
Glossary
- Channel: a model of transmission, giving the probability of each output for each input.
- Memoryless channel: a channel whose uses are independent of each other.
- Binary symmetric channel: a channel that flips each bit with the same probability, whichever bit was sent.
- Crossover probability: the probability that a binary symmetric channel flips a bit.
- Binary erasure channel: a channel that delivers each bit correctly or marks it as lost, never wrong.
- Rate (of a code): the fraction of transmitted bits that carry the message.
- Repetition code: a code that sends each bit several times and decodes by majority.
- Hamming distance: the number of positions in which two blocks differ.
- Minimum distance: the smallest Hamming distance between two codewords of a code.
- Parity bit: a bit making the number of 1s in a block even (or odd).
- Hamming(7,4) code: the code sending 4 data bits with 3 parity bits, correcting any single error.
- Syndrome: the pattern of failed checks, which locates the error in a Hamming code.
- Check digit: a digit appended to a number so that common mistakes in copying it can be detected.
- Checksum: a short value computed from data to detect accidental changes.
- Cyclic redundancy check (CRC): a checksum given by the remainder of dividing the data, as a polynomial, by a generator polynomial.
- Burst error: damage to several bits in a row.
Practise: Exercises · Companion · Squeeze stage
Misconceptions (from the companion)
| Misconception |
What's actually true |
| "Any 32-bit checksum spreads over 2³² values." |
8-letter messages got 31,251 Adler-32 values; CRC-32 behaved like chance. |
| "A valid CRC means the data wasn't altered." |
A changed amount was given a matching CRC by choosing 4 bytes. |
| "Hamming(7,4) gets close to the channel's limit." |
At p = 0.01 it runs at 0.571 with errors left; the limit is 0.919 with none. |
| "zlib computes a modulo for every byte." |
It delays the modulo for 5,552 bytes, the most before the sums could overflow. |
| "A Hamming decoder either works or crashes." |
With its check bits in the wrong order, it 'corrected' as many bits as it broke. |
| "If the CRC matches, the file is fine; if not, it's damaged." |
Read as a signed number, half of undamaged files failed. |
| "A check digit routine that accepts test cards is correct." |
It accepted every 16-digit number and rejected 9 in 10 valid 15-digit ones. |
| "Data that passes its CRC was transmitted correctly." |
A CRC computed after the damage made 102 corrupt files pass. |
09
Key ideas
- Capacity , in bits per use.
- Binary symmetric: (0.531 at ); erasure: ; Z channel: computed (0.3219, 40 % ones); noisy typewriter with 26 keys: .
- Blahut–Arimoto: an algorithm that computes capacity for any discrete channel.
- Noisy-channel coding theorem: below , errors can be made arbitrarily small; above , they can't.
- Why: about typical noise patterns per codeword, so about codewords fit; random codes achieve it on average.
- Converse: Fano gives .
- Separation: compress to , then code for ; works if .
- Gaussian channel: per use, per second.
- Shannon limit: , −1.59 dB.
- Codes near capacity: turbo (1993), LDPC (1960, 1996), polar (2009).
Glossary
- Channel capacity: the largest mutual information between a channel's input and output over all input distributions; the highest rate at which information can be sent reliably.
- Noisy-channel coding theorem: Shannon's theorem that every rate below capacity can be achieved with arbitrarily small error and no rate above it can.
- Random coding: choosing codewords at random to prove that good codes exist.
- Converse (of a coding theorem): the part that shows rates above the limit are impossible.
- Z channel: a binary channel in which one input is always received correctly and the other is sometimes received as the first.
- Noisy typewriter: a channel in which each input produces either itself or the next symbol, equally often.
- Blahut–Arimoto algorithm: an iterative algorithm for computing the capacity of a discrete memoryless channel.
- Source–channel separation theorem: the theorem that compressing and then channel coding, designed independently, is optimal in the limit of long blocks.
- Differential entropy: the counterpart of entropy for continuous variables, defined with a probability density.
- Gaussian channel: a channel that adds normally distributed noise to a power-limited input.
- Signal-to-noise ratio (SNR): the ratio of signal power to noise power, often in decibels.
- Shannon–Hartley theorem: the capacity of a band-limited Gaussian channel, bits per second.
- Shannon limit: the least energy per bit relative to the noise, (−1.59 dB), with which reliable communication is possible.
- LDPC code: a low-density parity-check code, whose checks each involve only a few bits, decoded by passing probabilities between bits and checks.
- Turbo code: a code built from two simple codes on interleaved data, decoded by exchanging probabilities between two decoders.
- Polar code: a code that, by combining and splitting channels recursively, provably achieves capacity.
Practise: Exercises · Companion · Squeeze stage
Misconceptions (from the companion)
| Misconception |
What's actually true |
| "A mobile link's capacity is one number." |
At 10 dB average, a fixed rate of 1 bit per use fails 26 % of moments. |
| "Any signal set can reach the Gaussian capacity." |
Equally spaced levels need up to 1.53 dB more. |
| "Reaching capacity always needs complex codes." |
With feedback, resending lost bits reached 0.7984 of 0.8 with no code. |
| "An iterative capacity algorithm's latest value is the answer." |
dit stops only when certified lower and upper bounds meet. |
| "The formula gives capacity in bits." |
With natural logarithms it gives nats: 0.368 instead of 0.531. |
| "Any matrix of probabilities describes a channel." |
Rows must be P(output given input) and add to 1; transposed, the answer was 0.0007. |
| "SNR in the formula can be in decibels." |
It must be a ratio: 20 dB is 100, not 20. |
| "The smaller file is the better design." |
Protecting before compressing was smaller and lost everything to one bit in 10,000. |
10
Key ideas
- Cross-entropy of a model on unseen data ≥ the source's entropy rate: every model is an upper bound.
- Blending (PPM, Witten–Bell): trust a context by , fall back to shorter ones.
- Shannon's guessing game: guess counts bound the entropy; English ≈ 0.6 to 1.3 bits per letter for people.
- Scripts: information per character varies; UTF-8 bytes measure encoding, not information.
- DNA: ≤ 2 bits per base; near 2 for general methods; reverse-complement repeats are biological structure.
- Min-entropy : what a single guess faces; .
- CSPRNG vs PRNG: unpredictable from earlier output vs merely statistically random.
- Passwords: min-entropy about 6.8 bits in RockYou; guess curves; breached-list checks, rate limits, managers, passphrases.
Glossary
- Cross-entropy (of a model): a model's average surprise, in bits per symbol, on data from a source; never less than the source's entropy rate.
- Upper bound (on entropy): a value the true entropy can't exceed; every model and compressor gives one.
- Shannon's guessing game: estimating a text's entropy from how many guesses a person needs for each next letter.
- Prediction by partial matching (PPM): a compression method that predicts from the longest matching context and escapes to shorter ones.
- Witten–Bell smoothing: weighting a context by how often it was seen against how many different symbols followed it.
- UTF-8: the variable-length encoding of Unicode characters into one to four bytes.
- Inverted repeat: a stretch of DNA that appears again elsewhere reversed and with each base replaced by its pair.
- Min-entropy: the surprise of the most likely value, ; the measure of how guessable a secret is.
- Cryptographically secure pseudorandom generator (CSPRNG): a generator whose output can't feasibly be predicted from earlier output.
- Mersenne Twister: a widely used pseudorandom generator with excellent statistics and a state that can be recovered from 624 outputs.
- Seed: the starting value of a pseudorandom generator, which determines all its output.
- Guess curve: the fraction of accounts an attacker breaks as a function of the number of guesses, trying the most likely passwords first.
- Passphrase: a password made of several words, strong when the words are chosen at random.
Practise: Exercises · Companion · Squeeze stage
Misconceptions (from the companion)
| Misconception |
What's actually true |
| "With enough data, the plug-in estimate of password entropy settles." |
It rose about 2 bits per tenfold more data, from 14.6 to 21.1. |
| "Equal entropy means equally hard to guess." |
6 bits each: 32.5 expected guesses for one, 257.2 for the other. |
| "A compressor's bits per character is a fixed property of the text." |
lzma: 5.34 after 1,000 bytes, 2.61 after 1.1 MB. |
| "A fair number below n is a random number modulo n." |
secrets draws again when the value is too large; draws per number ranged from 1.02 to 2.00. |
| "Length times log of the character pool measures strength." |
'Password1!' scored 65.5 bits by the formula. |
| "A long random-looking token is strong." |
A 20-character token seeded with the time was found in about 2,400 guesses. |
| "A text in a language the model knows gets a finite score." |
A character outside a model's alphabet gave infinite surprise. |
| "DNA can't exceed 2 bits per base." |
Counted with masking case and gaps, it 'had' 2.62. |
11
Key ideas
- Cross-entropy : a model's average surprise; the code length using .
- KL divergence : the cost of the wrong model.
- Gibbs' inequality: , zero only for ; not symmetric; infinite if rules out what happens.
- Mutual information .
- Log loss: maximum likelihood = minimum cross-entropy; a proper scoring rule; unbounded for confident mistakes.
- Perplexity : effective number of choices.
- Drift: , with a noise floor of about and natural variation; calibrate.
- Direction: covers (maximum likelihood); stays inside (variational inference).
- Evidence: bits per observation on average; Stein's lemma, Sanov's theorem.
- Rate–distortion: for random bits.
Glossary
- Cross-entropy: the average surprise of a model on data from , .
- Kullback–Leibler divergence: , the extra bits per symbol for coding data from with a code built for .
- Gibbs' inequality: the theorem that KL divergence is never negative and is zero only for identical distributions.
- Log loss: the cross-entropy loss of a classifier, averaged over examples.
- Maximum likelihood: choosing a model's parameters to make the observed data most probable; equivalent to minimising cross-entropy on that data.
- Calibration: agreement between a model's stated probabilities and how often it's right.
- Proper scoring rule: a way of scoring probabilistic predictions under which reporting your true probabilities is optimal.
- Perplexity: , the effective number of equally likely choices a model faces per symbol.
- Drift: a change over time in the distribution of the data a system receives.
- Jensen–Shannon divergence: a symmetric, bounded divergence built from KL divergences to the average of two distributions.
- Weight of evidence: , how much an observation favours over .
- Stein's lemma: the result that the best error probability in testing against falls exponentially at rate .
- Rate–distortion function: the fewest bits per symbol needed to describe a source within a given average distortion.
Practise: Exercises · Companion · Squeeze stage
Misconceptions (from the companion)
| Misconception |
What's actually true |
| "KL between two samples is a well-defined number." |
Unsmoothed it was infinite; smoothed, it ranged from 0.277 to 0.872 at 100 letters. |
| "A perplexity of 2,572 is far worse than 4.38." |
Per word against per character: 2.240 against 2.130 bits per character. |
| "A larger KL always means a larger shift." |
Moving 30 bins or 60 gave the same 19.21 bits. |
| "Log loss can be arbitrarily large in scikit-learn." |
It clips probabilities, so one certain mistake costs 36.04 nats, 52 bits. |
| "If accuracy is fine, the probabilities are fine." |
The wrong column gave 96.5 % accuracy and 12.9 bits per case. |
| "KL is KL, whichever way it's computed." |
Reversed, every normal window scored infinity. |
| "Perplexity is 2 to the power of the loss." |
Only if the loss is in bits; in nats it's e to the loss. |
| "A random split gives an honest test set." |
741 of 3,278 test lines were also in the training lines. |