一份天气预报,要问几个是非题?How many yes/no questions does a weather report cost?
一座气象站每小时报告 8 种天气之一。线路只能传“是”或“否”,所以你要用是非题猜出每份报告。你要设计一套问法,让平均提问次数尽量少。左图里,每种天气的宽度是它出现的频率,深度是猜中它要问几个问题。
A weather station reports one of 8 kinds of weather every hour. The line can only carry yes or no, so you find out each report by asking yes/no questions. Design questions that keep the average as low as possible. In the figure, each weather’s width is how often it happens and its depth is how many questions it takes.
01预测Predict
02设计你的问法Design your questions
先选“均匀”:怎么问都少不了 3 个。再换到“海边”:对半问还是 3 个,但先问最常见的天气,平均就降下来了。最后看“沙漠”,最好的问法也降不到 1 以下。
Start with Even: no strategy beats 3. Switch to Seaside: halving still costs 3, but asking about the likely weather first cuts the average. Then try Desert: even the best tree for a single report can’t go below 1.
03一次问几份报告Ask about several reports at once
单份报告至少要问 1 个问题,就算答案是“晴”、几乎没带来新消息也一样。如果把 2 份或 3 份报告打包,用一棵树一起问,会怎样?
A single report always costs at least one question, even when the answer is “sunny” and carries almost no news. What if you bundle 2 or 3 reports and ask about the bundle with one tree?
04解释Explain
1. 惊讶度:罕见的消息更值钱
概率为 p 的结果带来 log₂(1/p) 比特的惊讶度。90% 的晴天只有 0.15 比特,1.4% 的大风有 6.1 比特。图中每一列的橙线就画在它的惊讶度处。
2. 熵:平均惊讶度
把惊讶度按出现频率加权平均,就是熵 H = Σ p·log₂(1/p),等于图中橙线以上的总面积。问题树的平均提问数则等于灰色方块的总面积:每一行问题只由走到那里的报告“付费”。
3. 单份报告为什么降不到 1 以下
每份报告至少要占一个问题。晴天只值 0.15 比特,却要付整整 1 个问题,多出的 0.85 就是那条宽宽的斜线带。霍夫曼的规则是让最不可能的两组共用下一个问题,它给出单份报告的最优树,平均值总在 H 和 H+1 之间。所有概率都是 ½ 的幂时(海边),它正好等于 H。
4. 打包:把浪费摊薄
一次问 k 份报告,那“最多 1 个问题”的浪费就摊到 k 份上。k 越大,平均越接近 H,但永远不会低于 H。这就是香农的信源编码定理:熵是任何问法都打不破的下限,而且可以无限逼近。
1. Surprise: rare news is worth more
An outcome with probability p carries log₂(1/p) bits of surprise. Sunny at 90% carries 0.15 bits; a gale at 1.4% carries 6.1 bits. Each column’s orange line sits at its surprise.
2. Entropy: average surprise
Weight each surprise by how often it happens and you get the entropy H = Σ p·log₂(1/p), the total area above the orange lines. A question tree’s average is the total area of the grey blocks, because each row of questions is paid only by the reports that reach it.
3. Why one report can’t go below 1
Every report occupies at least one question. Sunny is worth 0.15 bits but pays a whole question; the extra 0.85 is the wide hatched band. Huffman’s rule, letting the two least likely groups share the next question, gives the best tree for a single report, and its average always lands between H and H + 1. When every probability is a power of ½ (Seaside), it equals H exactly.
4. Bundling spreads the waste
Ask about k reports at once and that “up to one question” of waste is shared by k reports. As k grows the average approaches H, but never goes below it. This is Shannon’s source coding theorem: entropy is a floor no questioning scheme can beat, and you can get as close to it as you like.
- 先看橙线:越罕见的天气,橙线越低,惊讶度越大。Start with the orange lines: the rarer the weather, the lower its line and the bigger its surprise.
- 把惊讶度按频率加权平均,得到熵 H:这是下限。Average the surprise, weighted by frequency: that is the entropy H, the floor.
- 再看灰色方块:它们的总面积就是你的平均提问数。Now the grey blocks: their total area is your average number of questions.
- 最后看斜线:常见天气被迫付整整 1 个问题,这就是比下限多出来的部分。Finally the hatching: common weather is forced to pay a whole question, and that is the gap above the floor.
H ≤ Lₖ / k < H + 1/k
一段历史
1948 年,克劳德·香农在《通信的数学理论》中定义了熵,并证明了这个下限。1951 年,MIT 研究生大卫·霍夫曼在罗伯特·法诺的信息论课上选择写学期论文来代替期末考试,题目是找出最省的编码。他自下而上合并的方法(1952 年发表)胜过了法诺参与提出的自上而下的香农–法诺编码。
A bit of history
In 1948 Claude Shannon defined entropy and proved this floor in “A Mathematical Theory of Communication.” In 1951 David Huffman, a graduate student in Robert Fano’s information theory class at MIT, chose a term paper over the final exam: find the most efficient code. His bottom-up merge, published in 1952, beat the top-down Shannon–Fano method his professor had helped devise.
“罕见的天气要问更多问题,因为 ___。打包报告能低于 1,因为 ___。”“Rare weather takes more questions because ___. Bundling reports gets below one because ___.”
迁移:换一个新情形Transfer question
这个模型的适用范围Where this model applies
三种气候是为教学编的分布,不是真实气象数据。模型假设每份报告相互独立、概率已知。真实天气前后相关,利用“上一小时的天气”可以比这里的 H 问得更少,因为条件熵更低。
这里的“比特”就是是非题的个数。打包很快会变得很大:一次问 3 份就有 8³ = 512 种组合。实际的压缩器用算术编码或自适应模型逼近熵,不必真的搭出这棵树。
读数里的平均值是精确的期望值。“最近 24 份”是一次抽样,会在平均值附近波动,单次抽样不能证明或推翻概率结论。
The three climates are teaching distributions, not weather data. The model assumes reports are independent and their probabilities are known. Real weather is correlated hour to hour; using the last hour’s weather can beat this H, because the conditional entropy is lower.
Here a “bit” is one yes/no question. Bundles grow fast: three reports already have 8³ = 512 combinations. Practical compressors approach entropy with arithmetic coding or adaptive models instead of building the tree.
The averages in the readouts are exact expected values. “Last 24 reports” is one sample that varies around the average; a single sample cannot prove or disprove a probability claim.
离线可用。全部控件都是原生单选框、滑块和按钮,可以用 Tab、方向键和空格操作。没有快捷键会干扰你的写作。Works offline. Every control is a native radio, slider or button, reachable with Tab, arrow keys and Space. No keyboard shortcuts override your writing.
- 问题:宽度 = 要问它的频率A question; width = how often it gets asked
- 惊讶度 log₂(1/p)Surprise, log₂(1/p)
- 多问的部分Questions beyond the surprise
■ 是 □ 否■ yes □ no
最近 24 份报告(一个方框 = 一个问题)Last 24 reports (one square = one question)