← 全部示例All examples information-entropy.html
  • 信息论Information theory
  • 2D 交互模型2D interactive model
  • 约 6 分钟~6 min

一份天气预报,要问几个是非题?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

在一座沙漠气象站,90% 的报告都是“晴”,其余 7 种天气平分剩下的 10%。如果问法足够聪明,每份报告平均最少要问几个是非题?At a desert station, 90% of reports say “sunny”; the other 7 kinds share the remaining 10% equally. With the cleverest questions you can design, what is the fewest yes/no questions you need per report, on average?

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.

气候Climate

其余天气保持所选气候的相对比例。The other kinds keep the chosen climate’s proportions.

问法Question strategy

模拟使用固定随机种子,重置后会得到同一串天气。换问法时,同一串报告会重新编码,方便对比。The simulation uses a fixed seed, so a reset replays the same weather. Changing the strategy re-encodes the same reports so you can compare.

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?

每次一起问的报告数Reports per bundle

这个模型的适用范围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
Question tree: each weather’s width is its frequency, its depth the questions it takes

■ 是 □ 否■ yes □ no

    最近 24 份报告(一个方框 = 一个问题)Last 24 reports (one square = one question)

      熵 HEntropy H比特 / 份,下限bits per report, the floor
      你的平均提问数Your average个问题 / 份questions per report
      比下限多Above the floor个问题 / 份questions per report
      最近 24 份共问了Last 24 reports used—个问题(每份问 3 个是 72)questions (72 at 3 each)