Gambling and Data Compression
- 01Doubling ratemaximize expected log wealth, not expected wealth
- 02Kelly gamblingbetting in proportion to belief is log-optimal, whatever the odds
- 03Conservation lawunder uniform fair odds, doubling rate plus entropy is
- 04Side informationa tip raises the doubling rate by exactly
- 05Dependent racespast results are a free tip, and growth is set by the entropy rate
- 06Gambler as compressoreach doubling of wealth is one bit saved
Motivation: the telegraph office next door to the racetrack
In the late 19th century, a large share of telegraph traffic was race results. Bookmakers in one city took bets on races being run in another, and the wire was how the results arrived. So the telecom company had two kinds of customers in the same building: the operator who wanted cheap descriptions of messages, and the gambler who wanted to profit from predicting them.
These look like unrelated businesses. One minimizes pulses on a wire, the other maximizes money in a pocket. This note shows they are the same problem:
| Compression engineer | Gambler |
|---|---|
| Builds a codebook from an estimate of the source distribution | Places bets according to an estimate of the race distribution |
| Pays bits per symbol | Grows wealth at a rate that drops by per race |
| Saves bits per symbol versus a naive code | Doubles wealth times per race at uniform odds |
| Best possible: use | Best possible: bet |
IntuitionThe central claim
A good gambler is a good compressor, and vice versa. Both are scored by how close their probability estimate is to the truth, with relative entropy as the score. Every bit of predictability in a source is worth either one bit saved on the wire or one doubling of a gambler’s wealth.
The horse race
Setup. horses run. Horse wins with probability . A bet of 1 dollar on horse returns dollars if it wins and nothing if it loses.
Convention“For” versus “to” odds
- -for-1 is settled before the race: you hand over 1 dollar, and get dollars back if your horse wins.
- -to-1 is settled after the race: you pay 1 dollar if you lose, and collect dollars if you win.
They are equivalent when . Fair odds on a coin flip are 2-for-1, or 1-to-1 (“even odds”). This note uses -for-1 throughout: is what you get back per dollar bet.
DefinitionBetting strategy (portfolio)
The gambler splits all their wealth across the horses, with fraction on horse and . We write and interchangeably.
DefinitionWealth relative
If horse wins, the gambler’s wealth is multiplied by
| Component | Detail |
|---|---|
| Signature | , a random variable through |
| Domain | The winning horse. |
| Codomain | The factor by which wealth is multiplied in this race. means ruin. |
Why “maximize expected wealth” is the wrong goal
The tempting strategy is to put everything on the horse with the largest expected return . That maximizes for one race. But gambling is repeated, and winnings are reinvested, so wealth compounds multiplicatively:
WarningThe expected-value bettor goes broke
Two horses at even odds (2-for-1), with . Going all-in on horse 1 every race gives , which grows exponentially. But unless horse 1 wins every race, which has probability . The expectation is carried entirely by one astronomically unlikely winning streak. Almost surely, the expected-value bettor is ruined.
IntuitionProducts want logarithms
A product of i.i.d. factors is governed by the average of their logarithms: is a sum, and the law of large numbers controls sums. This is exactly the move that turned the joint probability of a tape into a sample mean in the AEP.
DefinitionDoubling rate
| Component | Detail |
|---|---|
| Signature | |
| Domain | A betting strategy and the true win probabilities (the odds are fixed). |
| Codomain | Expected wealth growth per race. means wealth doubles each race; means some winning horse has , so ruin is possible. |
TheoremWealth grows at the doubling rate
If race outcomes are i.i.d. , the wealth of a gambler using strategy satisfies
in the sense of first-order exponential equality.
ProofWeak law on the log wealth
The are i.i.d., and is a fixed function, so are i.i.d. By the weak law of large numbers,
So .
∎
So the gambler should maximize the exponent over portfolios.
DefinitionOptimum doubling rate
Kelly gambling
DerivationA Lagrange multiplier suggests
Changing the log base doesn’t move the maximizer, so use natural logs:
The constraint forces , so . This is only a stationary point. Instead of checking second derivatives, we guess and verify, as in the entropy bound for codes.
TheoremProportional gambling is log-optimal
achieved by proportional (Kelly) gambling, .
ProofPull out a relative entropy
Step 1: Insert inside the log.
Step 2: Split into three sums.
Step 3: Drop the relative entropy. by the information inequality, with equality iff .
∎
ImportantThe optimal bet ignores the odds
When the gambler must be fully invested, whatever the odds are. The odds only enter through the constant . A horse paying 100-for-1 gets exactly its win probability, no more. Long odds affect how fast you get rich, not how you should bet.
IntuitionThe same decomposition as wrong-codebook compression
The gambler’s penalty for a wrong belief is in the doubling rate. The compression engineer’s penalty for a wrong codebook is in bits per symbol (wrong-code theorem). It is the same quantity, charged in two currencies.
ExampleTwo horses at even odds
. Then , and
For : , so bits per race. Wealth doubles about every 34 races, slowly but surely. This is the bettor that was ruined above, now betting 60/40 instead of all-in. With the race is a fair coin and : no edge, no growth.
Fair odds: beating the bookie
DefinitionFair odds and the bookie’s estimate
Odds are fair when (no track take). Then is a probability distribution: the bookie’s implied estimate of the win probabilities.
FormulaDoubling rate as a difference of relative entropies
With fair odds ,
IntuitionThe gambler profits only by out-predicting the bookie
is how wrong the bookie is. is how wrong the gambler is. Wealth grows iff the gambler’s estimate is closer to the truth than the bookie’s. Relative entropy is literally the scoreboard.
Uniform odds and the conservation law
With -for-1 odds on every horse (fair with respect to the uniform distribution ):
TheoremConservation theorem
For uniform fair odds,
IntuitionEvery bit of entropy is a doubling foregone
The doubling rate plus the entropy is a constant. Each bit of predictability (each bit by which falls below its maximum ) doubles the gambler’s wealth once more per race. Low-entropy races are the most profitable. Compare the maximum entropy bound: is also exactly the number of bits per symbol a compressor saves over the naive -bit code. Predictability is worth the same amount to the gambler and to the telecom.
Keeping some cash
Now let the gambler hold back a fraction as cash. The wealth relative becomes
and the optimal strategy depends on the odds:
| Odds | Condition | Optimal behavior |
|---|---|---|
| Fair | Cash is redundant. Betting returns exactly 1 whatever horse wins, which is a synthetic cash position. Proportional betting stays optimal. | |
| Superfair | Better than fair, so stay fully invested; proportional betting is optimal. A Dutch book also exists: bet with , and whatever happens. It is risk-free, but it does not maximize the doubling rate. | |
| Subfair | The realistic case: the track takes a cut. Hold some cash. Proportional betting is no longer optimal; the optimum (from Kuhn–Tucker conditions) has a “water-filling” form (Problem 6.2). |
Gambling with side information
The problem. The gambler has a tip, a past-performance sheet, or a cousin who works in the stables. That is side information correlated with the winner . What is the tip worth in money?
Setup. has joint pmf . Horse pays -for-1. A conditional strategy , with , bets fraction on horse after seeing .
DefinitionDoubling rates with and without the tip
For i.i.d. pairs , wealth grows like with the tip and like without it.
TheoremThe financial value of side information is mutual information
ProofConditionally proportional betting, then subtract
Step 1: With the tip. For each the problem is an ordinary horse race with win probabilities , so the optimum is conditionally proportional betting, :
Step 2: Without the tip. By the Kelly theorem, .
Step 3: Subtract. The odds terms cancel:
∎
IntuitionMutual information, in dollars
Mutual information was introduced as the reduction in uncertainty about the sender’s symbol after reading the receiver’s tape. Here it is the exact number of extra doublings per race a tip buys. A useless (independent) tip is worth nothing. A tip can never hurt the optimal gambler, because , which is the betting version of “conditioning reduces entropy”.
ExampleA perfect tip
If the tipster always names the winner (), then . At uniform odds, , so : bet everything on the named horse and multiply wealth by every race.
NoteGeneral stock markets
For a general stock market (Chapter 16) one only gets , with equality iff the market is a horse race.
Dependent horse races and entropy rate
The problem. The most common side information is the past results themselves. For independent races they are worthless. But if races depend on each other (fatigue, track conditions, the same horses running every week), the past is a free tip.
Let be a stochastic process of winners, with uniform -for-1 odds, and let the bet on race depend on the previous results. The conditionally proportional bet achieves
DerivationSum the per-race rates with the chain rule
Wealth after races is , so
The last step is the chain rule for entropy.
RemarkRemoving the expectation
For an ergodic process (Chapter 16), with probability 1, where . This is the betting counterpart of the general AEP.
IntuitionGrammar is money
An operator with grammar has entropy rate below , and the gap is exactly what a gambler who knows the grammar can extract. The compression engineer and the gambler are paid by the same quantity: , in bits saved per symbol or doublings per race.
Example: red and black
ExampleBetting on the colour of the next card
A deck holds 26 red and 26 black cards. Before each card is turned, bet on its colour at 2-for-1 (fair if red and black were equally likely). Unlike horses, the outcomes become more predictable as the deck thins: with one card left, you know its colour.
Scheme 1 (sequential). Bet proportionally to the conditional probability of the next card: on the first; on (red, black) for the second if the first was black; and so on.
Scheme 2 (all at once). There are equally likely colour sequences. Put of the money on each, and let every bet ride through all 52 cards.
They are the same strategy. In Scheme 2, the fraction of money riding on sequences whose next card is red always equals the conditional probability that the next card is red. For example, half of all sequences start with red. A bet on a sequence multiplies by if it is the one dealt and loses otherwise, so
IntuitionEvery deal is typical
The final wealth is whatever order the cards come in, with zero variance. All sequences are equally likely, so every one is “typical”, like an exaggerated typical set that covers everything. Sequential proportional betting is equivalent to betting on whole sequences: this equivalence is the key to the twin compressor below.
The entropy of English
English, simplified to 26 letters and a space (), is the natural source to try all this on. It is probably not stationary or ergodic (styles and topics drift), but we can still estimate its entropy rate by building better and better stochastic models.
RemarkEnglish is far from uniform
Ehas frequency about 13%;QandZabout 0.1%. (The 267-page novel Gadsby by Ernest Vincent Wright avoidsEentirely, which is a remarkable feat.)- Pairs are also far from uniform:
Qis always followed byU, andTHis the most common pair at about 3.7%.
WarningHigher-order models run out of data
A third-order Markov model needs , a table with entries. Estimating it accurately takes millions of letters of text. Each step up in order multiplies the data needed by 27.
RemarkSampling a model without building it
To generate second-order text from a book: open it at random and pick a letter. Then open it at random again, read until you meet that letter, and take the letter after it. Repeat. The output has the book’s pair statistics, without anyone tabulating them.
Shannon’s approximations
| Model | Sample (from Shannon 1948 and Lucky) |
|---|---|
| Zero order: independent, equiprobable | XFOML RXKHRJFFJUJ ZLPWCFWKCYJ |
| First order: independent, English letter frequencies | OCRO HLI RGWR NMIELWIS EU LL NBNESEBYA TH EEI |
| Second order: English pair frequencies | ON IE ANTSOUTINYS ARE T INCTORE ST BE S DEAMY |
| Third order: English triple frequencies | IN NO IST LAT WHEY CRATICT FROURE BERS GROCID |
| Fourth order: English quadruple frequencies | THE GENERATED JOB PROVIDUAL BETTER TRAND THE DISPLAYED CODE |
| First-order word model | REPRESENTING AND SPEEDILY IS AN GOOD APT OR COME CAN DIFFERENT NATURAL |
| Second-order word model | THE HEAD AND IN FRONTAL ATTACK ON AN ENGLISH WRITER THAT THE CHARACTER OF THIS POINT |
| Model | Entropy estimate (bits per letter) |
|---|---|
| Zero order | |
| First order | |
| Fourth order |
IntuitionEach model is a better gambler
Every step up in model order captures more structure, lowers the conditional uncertainty of the next letter, and therefore both compresses better and bets better. Even the fourth-order model misses most of English’s structure. The gambling estimates below come in near 1.3 bits.
ExampleRedundancy fills in the blanks
Delete the vowels from a sentence:
TH R S NLY N W Y T F LL N TH V W LS N TH S S NT NC
Most readers recover it at once. This redundancy is what breaks simple
substitution ciphers: guess the most frequent cipher letter is E, then
let the structure of English fill in the rest. Much of Shannon’s
information theory grew out of his wartime cryptography work.
RemarkLanguage models in speech recognition
Speech recognizers combine the acoustic signal with a stochastic language model, commonly a trigram (second-order Markov) word model that predicts the next word from the previous two. Such models work surprisingly well without encoding any explicit grammar.
Data compression and gambling
The problem. We claimed a good gambler is a good compressor. Here is the construction. If a gambler makes a lot of money on a sequence, that sequence can be compressed by a correspondingly large amount.
Setup. Binary outcomes , uniform 2-for-1 odds. The gambler places sequential bets with .
FormulaSequential betting assigns a probability to whole sequences
The product is a probability distribution on the sequences. So gambling elicits the gambler’s probability estimate, , and an entropy estimate .
IntuitionWealth and compressed length are the same number
If is the gambler’s probability for the actual sequence, a code built from it should spend about bits. Every doubling of wealth saves one bit.
The identical-twin compressor
flowchart LR X["Text x^n"] --> E["Encoder: gambler computes wealth on every sequence up to x^n"] E -->|"k = ceil(n - log S_n) bits"| W[Wire] W --> D["Decoder: identical twin replays the same bets"] D --> R["Recovered x^n"]
AlgorithmEncoding with a gambler
Both ends know and run identical, deterministic gamblers.
- Order all binary sequences lexicographically
(e.g.
0100101 < 0101101). - The encoder computes what its wealth would have been on every sequence , and forms the cumulative sum
- Let . Send the first binary digits of .
- The decoder twin computes the same cumulative sums over all sequences in order, and outputs the first sequence whose cumulative sum falls in .
IntuitionWhy it decodes
The terms cut into consecutive intervals, one per sequence, and the interval for has width . Choosing makes the precision fine enough to land inside ‘s interval. This is Shannon–Fano–Elias coding with the gambler’s distribution in place of the true , which is to say arithmetic coding driven by a gambler.
TheoremBits saved equals log wealth
The twin scheme uses bits, saving about bits relative to sending the raw bits. With proportional gambling (), , so
which achieves the Shannon limit.
NoteWhat the book’s construction glosses over
Cover & Thomas present the decoder informally (“the size of guarantees…”). They don’t address boundary cases, where a truncated could land at an interval edge (the reason Shannon–Fano–Elias spends one extra bit and uses the midpoint of each step). They also assume the decoder knows where the -bit codeword ends. Treat the scheme as a demonstration of the duality, not a production codec. The careful version is arithmetic coding (Chapter 13).
ImportantThe duality in one sentence
Gambling and compression both reduce to estimating the true distribution. The better the estimate, the faster the wealth grows and the shorter the code. Each doubling is one bit saved.
Gambling estimates of the entropy of English
The duality gives a way to measure English’s entropy rate using humans as the probability model. Humans know far more about English than any fourth-order table.
The Shannon guessing game
DefinitionGuessing game
A subject reads English text and guesses the next letter, trying the most likely letter first, then the next most likely, and so on. The experimenter records how many guesses each letter took. Many letters take one guess; word and sentence beginnings take many.
IntuitionThe guess counts are a lossless re-encoding of the text
Model the subject as a deterministic machine (the same past always produces the same guess order). Given an identical machine and the sequence of guess counts, you can regenerate the text: run the machine, and if position took guesses, output the machine’s -th guess. The map is invertible, so the guess sequence carries exactly the information in the text, and its entropy is the entropy of English.
RemarkFrom histogram to bound
Treating successive guess counts as independent can only overestimate their joint entropy (by the independence bound). So the entropy of the guess-count histogram is an upper bound. Shannon’s 1950 experiment gave about 1.3 bits per letter.
The gambling estimate
Guessing only records a rank. Betting lets the subject express graded confidence. The subject bets on the next letter at 27-for-1 on the correct letter. Sequential betting equals betting on whole sequences, so after letters
DerivationThe bettor’s wealth bounds the entropy rate from above
Step 1: Expected log wealth.
Step 2: Insert and split.
Step 3: Drop the relative entropy. , so .
Step 4: Compare the block average with the rate. For a stationary source the conditional entropies are nonincreasing with limit . Their running average is therefore at least the limit. Hence
(Cover & Thomas state this last inequality without the justification in Step 4.)
TheoremGambling estimate of the entropy rate
is an upper bound on the entropy rate of English, in expectation. If English is ergodic and the gambler bets , then with probability 1.
IntuitionWhy it can only overestimate
A gambler cannot extract more than the true predictability. Any modelling error () shows up as lost wealth, which makes larger. So a low estimate is believable, and better gamblers push it down toward the truth.
ExampleThe experiment
Twelve subjects gambled on a 75-letter passage from Jefferson the Virginian by Dumas Malone (the same source Shannon used). The estimate was 1.34 bits per letter, close to Shannon’s guessing-game 1.3 and far below the 2.8 of a fourth-order letter model.
| Method | Estimate (bits/letter) |
|---|---|
| Zero-order model | 4.76 |
| First-order model | 4.03 |
| Fourth-order model | 2.8 |
| Shannon guessing game | 1.3 |
| Gambling (12 subjects, 75 letters) | 1.34 |
IntuitionWhat 1.3 bits means for the telegraph
A naive 27-symbol code spends bits per letter. An ideal compressor that understood English as well as a human reader would spend about 1.3: roughly 72% of a plain-English telegram is redundancy. That is also how many doublings per letter a perfect English-predicting gambler could extract at 27-for-1 odds.
Quick reference
| Object | Statement | Reads as |
|---|---|---|
| Wealth relative | Wealth multiplier for one race. | |
| Doubling rate | Expected log growth per race. | |
| Growth | Wealth grows exponentially at rate . | |
| Kelly | at | Bet in proportion to belief, whatever the odds. |
| Penalty | A wrong belief costs doublings per race. | |
| Fair odds | , | Win only by out-predicting the bookie. |
| Conservation | (uniform odds) | Each bit of entropy is a doubling foregone. |
| Side information | A tip is worth its mutual information. | |
| Dependent races | Grammar is money. | |
| Red and black | Same payoff on every deal. | |
| Twin compressor | bits | Each doubling saves one bit. |
| Gambling estimate | Human bettors upper-bound English’s entropy. |
Constants and identities to keep to hand:
- -for-1 equals -to-1. Even odds = 2-for-1 = 1-to-1.
- Fair: . Superfair: (a Dutch book exists). Subfair: (hold cash).
- Maximizing goes broke; maximizing grows surely.
- English: bits; first order 4.03, fourth order 2.8, humans about 1.3.
- for stationary sources: block averages overestimate the rate.
References
- Cover & Thomas, Elements of Information Theory — Chapter 6