转载自:https://colah.github.io/posts/2015-09-Visual-Information/
上
中
前文概要:
比如一个密文有50%的概率要使用,那么我们可以花50%的密文空间来让这个密文简短一些。如果这个密文只有1%的概率用到,那么只花1%的代价来表示这个密文。
Calculating Entropy
Recall that the cost of a message of length L is 1 2 L \frac{1}{ 2^L} 2L1. We can invert this to get the length of a message that costs a given amount: l o g 2 ( 1 c o s t ) log_2(\frac1{cost}) log2(cost1). Since we spend p(x) on a codeword for x, the length is l o g 2 ( 1 p ( x ) ) log_2(\frac1{p(x)}) log2(p(x)1). Those are the best choices of lengths.
回想一下,长度为L的消息的代价为 1 2 L \frac{1}{ 2^L} 2L1。 我们可以将其求反以获取代价给定数量的消息的长度: l o g 2 ( 1 c o s t ) log_2(\frac1{cost}) log2(cost1)。 由于我们在x的代码字上花费了 p ( x ) p(x) p(x),因此长度为 l o g 2 ( 1 p ( x ) ) log_2(\frac1{p(x)}) log2(p(x)1)。 这是长度的最佳选择。
Earlier, we discussed how there is a fundamental limit to how short one can get the average message to communicate events from a particular probability distribution, p. This limit, the average message length using the best possible code, is called the entropy of p, H§. Now that we know the optimal lengths of the codewords, we can actually calculate it!
之前,我们讨论了从一个特定的概率分布p获得一个平均消息来传达事件的时间有多短的基本限制。 这个限制,即使用最佳可能代码的平均消息长度,称为p的熵H(p)。 既然我们知道了码字的最佳长度,我们就可以实际计算出来了!
H ( p ) = ∑ x p ( x ) l o g 2 ( 1 p ( x ) ) H(p)=∑_xp(x)log_2(\frac1{p(x)}) H(p)=x∑p(x)log2(p(x)