RecapsKayavak

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.

Open the volume

01

Start Here: What Information Is

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): N equally likely possibilities carry logN.
  • Surprise (self-information): I=−log2p bits; 0 for certainty; adds for independent events.
  • Only a logarithm makes surprises of independent events add.
  • Units: bit (log2), nat (ln), ban (log10); 1 nat ≈ 1.443 bits, 1 ban ≈ 3.322 bits.
  • Questions: ⌈log2N⌉ yes-or-no questions always find one of N 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 p, −log2p 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 p between 0 and 1; percentages give negative "bits".
"int(math.log2(n)) questions are enough." It rounds down; the worst case needs ⌈log2n⌉.
"Compressing a message measures its information." Short messages grow, because of fixed headers and checksums.

02

Counting Possibilities: Bits, Logarithms and Questions

Key ideas

  • Multiplication principle: n choices from k each give kn sequences; bits add: nlog2k.
  • Factorial: n! orders; log252!≈225.6 bits in a shuffled deck.
  • Combinations: (nr) =n!r!(n−r)! ways to choose r from n.
  • Estimating: 210≈103; log210≈3.32.
  • Fixed-length code: ⌈log2K⌉ digits per symbol; efficiency = log2K ÷ digits.
  • Blocks: m symbols in ⌈mlog2K⌉ digits; under log2K+1m per symbol.
  • Question strategies are binary trees; a codeword is the path; depth = questions.
  • Sorting bound: any comparison sort needs ⌈log2n!⌉≈nlog2n−1.44n comparisons in the worst case.
  • Stirling: n!≈2πn(n/e)n.

Glossary

  • Multiplication principle: if one choice has a options and a second has b whatever the first was, together they have a×b.
  • Factorial: n! =n×(n−1)×⋯×1, the number of orders of n different things.
  • Binomial coefficient: (nr), the number of ways to choose r things from n 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 ⌈log2n!⌉ comparisons in the worst case.
  • Stirling's approximation: n!≈2πn(n/e)n, so log2n!≈nlog2n−1.44n.
  • 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 nn equally likely paths onto n! orders, unevenly.

03

The Probability You Need

Key ideas

  • Rules: 0≤P≤1; certain = 1; disjoint events add. Complement: 1−P(A). Overlap: P(A)+P(B)−P(A and B).
  • Equally likely: probability = favourable count ÷ total count.
  • Independent: P(A and B) =P(A)P(B), so surprises add.
  • Conditional: P(B∣A) =P(A and B)/P(A); product rule P(A and B) =P(A)P(B∣A).
  • Bayes: P(A∣B) =P(B∣A)P(A)/P(B); rare causes stay rare after weak evidence.
  • Expected value E[X]=∑kkP(X=k); always additive. Variance E[(X−E[X])2].
  • Law of large numbers: averages approach expectations; error shrinks like 1/n.
  • Binomial: (nk)pk(1−p)n−k, mean np. Geometric: wait 1/p on average.
  • Estimating: cx+1n+K (add-one); never zero.
  • Birthday: collisions likely after about M values; expected pairs n2/2M.

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: P(B∣A), the probability of B among the cases where A happened.
  • Bayes' theorem: P(A∣B) =P(B∣A)P(A)/P(B), 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 n 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 (c+1)/(n+K) so that no symbol gets probability zero; Laplace's rule of succession.
  • Birthday problem: the fact that among n random values from M, a repeat becomes likely once n is about M.

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

Entropy: the Average Surprise of a Source

Key ideas

  • Entropy H =∑xp(x)log21p(x): expected surprise, bits per symbol.
  • Binary entropy h(p) =−plog2p−(1−p)log2(1−p): 0 at the ends, 1 at 12, symmetric.
  • 0≤H≤log2K; H=0 only for certainty; H=log2K only for uniform.
  • Independent sources: H(X,Y)=H(X)+H(Y).
  • Grouping: decide the group, then within it; entropy adds up the stages, weighted.
  • Coding: no code averages fewer than H digits per symbol; good codes come within 1, or less with blocks.
  • Redundancy R=1−H/log2K; English letters 10.8 % on frequencies, about 75 % with context.
  • Plug-in estimates are biased low; Miller's correction adds (K−1)/(2nln2).

Glossary

  • Entropy (information): the expected surprise of a source, ∑plog21p bits per symbol; the average information it produces.
  • Binary entropy function: h(p), the entropy of a two-outcome source with probabilities p and 1−p.
  • Uniform distribution: one in which every possible value is equally likely; it has the largest entropy, log2K.
  • 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): 1−H/log2K, 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 (K−1)/(2nln2) 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

Codes: Prefix Codes, Kraft's Inequality and Huffman Coding

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 li are possible for a prefix code iff ∑2−li≤1; McMillan: the same for any uniquely decodable code. Sum = 1: complete.
  • Entropy bound: average length L¯≥H; equality iff li=log21pi for all i.
  • Shannon code: li =⌈log21pi⌉ gives H≤L¯<H+1.
  • 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 H; probabilities must be known.
  • Integer codes: unary; Elias gamma 2⌊log2n⌋+1 digits; Rice with 2k≈0.69× 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 ∑2−li≤1 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: ∑pili, the expected number of binary digits per symbol.
  • Shannon code: a code giving each symbol ⌈log21p⌉ 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 2k in unary, then the remainder in k binary digits.
  • Unary code: writing a whole number n as n−1 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 pmax+0.086, usually far less.
"Huffman codewords stay short." They can reach K−1 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

The Source Coding Theorem: Why Entropy Is the Limit

Key ideas

  • Typical sequences: probability ≈2−nH; about 2nH of them; together almost all the probability (law of large numbers).
  • log2(npn)≈nh(p).
  • Source coding theorem: achievable at H+ε per symbol; impossible below H.
  • Counting: 2n files of n bits, 2n−1 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 K−12log2n 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 2nH members holding almost all the probability.
  • Asymptotic equipartition property: the fact that long sequences from a source have probability close to 2−nH, shared almost equally among about 2nH 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 211 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

Joint and Conditional Entropy, Mutual Information

Key ideas

  • Joint entropy H(X,Y): entropy of the pair; ≤H(X)+H(Y), equal iff independent.
  • Conditional entropy H(Y∣X) =∑xp(x)H(Y∣X =x): average uncertainty left.
  • Chain rule: H(X,Y)=H(X)+H(Y∣X); for sequences, the sum of each symbol given the past.
  • Conditioning reduces entropy on average: H(Y∣X)≤H(Y).
  • Mutual information I(X;Y) =H(Y)−H(Y∣X) =H(X)+H(Y)−H(X,Y): symmetric, ≥0, =0 iff independent, ≤min(H(X),H(Y)).
  • Data processing inequality: X→Y→Z gives I(X;Z)≤I(X;Y).
  • Entropy rate H∞ =limH(Xn∣X1…Xn−1); the limit of compression for sources with memory.
  • Markov model of order k: predict from the last k symbols; on unseen text, longer isn't always better (overfitting).
  • Fano's inequality: H(X∣Y)≤h(Pe)+Pelog2(K−1) limits how well X can be guessed from Y.

Glossary

  • Joint entropy: the entropy of two (or more) random variables taken together, H(X,Y).
  • Conditional entropy: H(Y∣X), the average uncertainty about Y remaining once X is known.
  • Chain rule (entropy): H(X,Y)=H(X)+H(Y∣X): the information in a pair is the first plus the second given the first.
  • Mutual information: I(X;Y), 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, H(X∣Y).
  • 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; X→Y→Z.
  • 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 k 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 H(X∣Y) to the best possible probability of error in guessing X from Y.

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 x's 1.945 bits about x2.
"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

Channels and Noise

Key ideas

  • Channel: the probabilities p(y∣x); memoryless if uses are independent.
  • Binary symmetric channel: each bit flipped with probability p; I=1−h(p) with equally likely inputs (0.531 for p=0.1).
  • Binary erasure channel: each bit lost (marked) with probability ε; I=1−ε.
  • Errors in a block: binomial, mean np; P(no errors) =(1−p)n≈e−np.
  • Rate: data bits per transmitted bit.
  • Repetition-3: rate 13, P(wrong) =3p2−2p3.
  • Minimum distance d: detects d−1 errors, corrects ⌊(d−1)/2⌋.
  • 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 p 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

Channel Capacity and the Noisy-Channel Coding Theorem

Key ideas

  • Capacity C=maxp(x)I(X;Y), in bits per use.
  • Binary symmetric: 1−h(p) (0.531 at p=0.1); erasure: 1−ε; Z channel: computed (0.3219, 40 % ones); noisy typewriter with 26 keys: log213.
  • Blahut–Arimoto: an algorithm that computes capacity for any discrete channel.
  • Noisy-channel coding theorem: below C, errors can be made arbitrarily small; above C, they can't.
  • Why: about 2nh(p) typical noise patterns per codeword, so about 2n(1−h(p)) codewords fit; random codes achieve it on average.
  • Converse: Fano gives Pe≥1−C/R−1/(nR).
  • Separation: compress to H, then code for C; works if H<C.
  • Gaussian channel: C=12log2(1+P/N) per use, Blog2(1+SNR) per second.
  • Shannon limit: Eb/N0≥ln2, −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, Blog2(1+SNR) bits per second.
  • Shannon limit: the least energy per bit relative to the noise, Eb/N0=ln2 (−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

Information Everywhere: Language, DNA, Randomness and Passwords

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 nn+t, 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 H∞=−log2maxp: what a single guess faces; ≤H.
  • 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, −log2maxxp(x); 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

Information in Machine Learning: Cross-Entropy and KL Divergence

Key ideas

  • Cross-entropy H(p,q) =∑plog21q: a model's average surprise; the code length using q.
  • KL divergence D(p‖q) =∑plog2pq =H(p,q)−H(p): the cost of the wrong model.
  • Gibbs' inequality: D≥0, zero only for p=q; not symmetric; infinite if q rules out what happens.
  • Mutual information =D(p(x,y)‖p(x)p(y)).
  • Log loss: maximum likelihood = minimum cross-entropy; a proper scoring rule; unbounded for confident mistakes.
  • Perplexity =2H(p,q): effective number of choices.
  • Drift: D(window‖reference), with a noise floor of about k−12nln2 and natural variation; calibrate.
  • Direction: D(p‖q) covers (maximum likelihood); D(q‖p) stays inside (variational inference).
  • Evidence: D(p‖q) bits per observation on average; Stein's lemma, Sanov's theorem.
  • Rate–distortion: R(d)=1−h(d) for random bits.

Glossary

  • Cross-entropy: the average surprise of a model q on data from p, ∑xp(x)log21q(x).
  • Kullback–Leibler divergence: D(p‖q) =∑xp(x)log2p(x)q(x), the extra bits per symbol for coding data from p with a code built for q.
  • 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, −logq(the right answer) 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: 2cross-entropy, 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: logp(x)q(x), how much an observation favours p over q.
  • Stein's lemma: the result that the best error probability in testing p against q falls exponentially at rate D(p‖q).
  • 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.