压缩性示例

发布于 2024-09-05 11:52:38 字数 1031 浏览 0 评论 0原文

来自我的算法教科书:

一年一度的县赛马比赛将带来三匹从未相互竞争过的纯种马。您兴奋地研究了他们过去 200 场比赛,并将其总结为四种结果的概率分布:第一(“第一名”)、第二、第三和其他。

                       Outcome     Aurora   Whirlwind    Phantasm
                        first        0.15      0.30          0.20

                        second       0.10      0.05          0.30

                        third        0.70      0.25          0.30

                        other        0.05      0.40          0.20

哪匹马最容易预测?解决这个问题的一种定量方法是查看可压缩性。将每匹马的历史记录为包含 200 个值的字符串(第一、第二、第三、其他)。然后可以使用霍夫曼算法计算对这些跟踪记录字符串进行编码所需的总位数。 Aurora 的计算结果为 290 位,Whirlwind 的计算结果为 380 位,Phantasm 的计算结果为 420 位(检查一下!)。 Aurora 的编码最短,因此在很大程度上是最可预测的。

《Phantasm》的420分是怎么来的?我不断获得 400 字节,如下所示:

组合第一,其他 = 0.4,组合第二,第三 = 0.6。最终每个位置都有 2 位进行编码。

我对霍夫曼编码算法有什么误解吗?

教科书可在此处获取:http://www.cs.berkeley.edu/~vazirani/algorithms .html(第 156 页)。

From my algorithms textbook:

The annual county horse race is bringing in three thoroughbreds who have never competed against one another. Excited, you study their past 200 races and summarize these as probability distributions over four outcomes: first (“first place”), second, third, and other.

                       Outcome     Aurora   Whirlwind    Phantasm
                        first        0.15      0.30          0.20

                        second       0.10      0.05          0.30

                        third        0.70      0.25          0.30

                        other        0.05      0.40          0.20

Which horse is the most predictable? One quantitative approach to this question is to look at compressibility. Write down the history of each horse as a string of 200 values (first, second, third, other). The total number of bits needed to encode these track-record strings can then be computed using Huffman’s algorithm. This works out to 290 bits for Aurora, 380 for Whirlwind, and 420 for Phantasm (check it!). Aurora has the shortest encoding and is therefore in a strong sense the most predictable.

How did they get 420 for Phantasm? I keep getting 400 bytes, as so:

Combine first, other = 0.4, combine second, third = 0.6. End up with 2 bits encoding each position.

Is there something I've misunderstood about the Huffman encoding algorithm?

Textbook available here: http://www.cs.berkeley.edu/~vazirani/algorithms.html (page 156).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

空心↖ 2024-09-12 11:52:38

我认为你是对的:Phantasm 的 200 个结果可以使用 400 位(而不是字节)来表示。极光 290 和旋风 380 是正确的。

正确的霍夫曼代码是通过以下方式生成的:

  1. 组合两个最不可能的结果:0.2 和 0.2。得到0.4。
  2. 将接下来的两个最不可能的结果组合起来:0.3 和 0.3。得到0.6。
  3. 将 0.4 和 0.6 结合起来。获取 1.0。

如果您这样做,您将得到 420 位:

  1. 组合两个最不可能的结果:0.2 和 0.2。得到0.4。
  2. 将 0.4 和 0.3 结合起来。 (错误!)得到 0.7。
  3. 将 0.7 和 0.3 结合起来。获得1.0

I think you're right: Phantasm's 200 outcomes can be represented using 400 bits (not bytes). 290 for Aurora and 380 for Whirlwind are correct.

The correct Huffman code is generated in the following manner:

  1. Combine the two least probable outcomes: 0.2 and 0.2. Get 0.4.
  2. Combine the next two least probable outcomes: 0.3 and 0.3. Get 0.6.
  3. Combine 0.4 and 0.6. Get 1.0.

You would get 420 bits if you did this instead:

  1. Combine the two least probable outcomes: 0.2 and 0.2. Get 0.4.
  2. Combine 0.4 and 0.3. (Wrong!) Get 0.7.
  3. Combine 0.7 and 0.3. Get 1.0
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文