プリンキピア

第22章付録:深層学習のための数学

22.11.2. Entropy22.11.2 エントロピー

As self-information only measures the information of a single discrete event, we need a more generalized measure for any random variable of either discrete or continuous distribution.
英語のヒント
自己情報量は一つの離散的な事象の情報しか測らないので、離散分布か連続分布に従う任意の確率変数について、もっと一般化された尺度が必要である。

22.11.2.1. Motivating Entropy22.11.2.1 エントロピーの動機づけ

Let’s try to get specific about what we want. This will be an informal statement of what are known as the axioms of Shannon entropy. It will turn out that the following collection of common-sense statements force us to a unique definition of information. A formal version of these axioms, along with several others may be found in Csiszár (2008).
英語のヒント
何を望んでいるのかを具体的にしてみよう。これは、シャノンエントロピーの公理として知られるものの非形式的な言明になる。次の常識的な言明の集まりによって、情報の定義はただ一つに決まることがわかる。これらの公理の形式的な版は、ほかのいくつかの公理とともにCsiszár(2008)にある。
  1. The information we gain by observing a random variable does not depend on what we call the elements, or the presence of additional elements which have probability zero.
    英語のヒント
    確率変数を観測して得る情報は、要素を何と呼ぶかにも、確率0の追加の要素があるかどうかにも依存しない。
  2. The information we gain by observing two random variables is no more than the sum of the information we gain by observing them separately. If they are independent, then it is exactly the sum.
    英語のヒント
    二つの確率変数を観測して得る情報は、それらを別々に観測して得る情報の和を超えない。それらが独立なら、ちょうど和になる。
  3. The information gained when observing (nearly) certain events is (nearly) zero.
    英語のヒント
    (ほぼ)確実な事象を観測したときに得られる情報は、(ほぼ)0である。
While proving this fact is beyond the scope of our text, it is important to know that this uniquely determines the form that entropy must take. The only ambiguity that these allow is in the choice of fundamental units, which is most often normalized by making the choice we saw before that the information provided by a single fair coin flip is one bit.
英語のヒント
この事実を証明するのは本書の範囲を超えるが、これによってエントロピーがとるべき形がただ一つに決まることを知っておくのは重要である。これらが許す唯一のあいまいさは基本単位の選び方であり、それは、前に見たように公正なコイン投げ1回が与える情報を1ビットとする選び方によって正規化されることが最も多い。

22.11.2.2. Definition22.11.2.2 定義

For any random variable X that follows a probability distribution P with a probability density function (p.d.f.) or a probability mass function (p.m.f.) p(x), we measure the expected amount of information through entropy (or Shannon entropy)
英語のヒント
確率密度関数(p.d.f.)あるいは確率質量関数(p.m.f.)p(x)をもつ確率分布Pに従う任意の確率変数Xについて、期待される情報量をエントロピー(あるいはシャノンエントロピー)で測る。
H(X)=−Ex∼P[log⁡p(x)].(22.11.3)
To be specific, if X is discrete,
英語のヒント
具体的には、Xが離散なら、
H(X)=−∑ipilog⁡pi, where pi=P(Xi).(22.11.4)
Otherwise, if X is continuous, we also refer entropy as differential entropy
英語のヒント
そうでなく、Xが連続なら、エントロピーを微分エントロピーとも呼ぶ。
H(X)=−∫xp(x)log⁡p(x)dx.(22.11.5)
We can define entropy as below.
英語のヒント
エントロピーは以下のように定義できる。
def entropy(p):
    entropy = - p * torch.log2(p)
    # Operator `nansum` will sum up the non-nan number
    out = nansum(entropy)
    return out

entropy(torch.tensor([0.1, 0.5, 0.1, 0.3]))
tensor(1.6855)

22.11.2.3. Interpretations22.11.2.3 解釈

You may be curious: in the entropy definition (22.11.3), why do we use an expectation of a negative logarithm? Here are some intuitions.
英語のヒント
エントロピーの定義(式(22.11.3))で、なぜ負の対数の期待値を使うのか、不思議に思うかもしれない。ここにいくつかの直観を挙げる。
First, why do we use a logarithm function log? Suppose that p(x)=f1(x)f2(x)…,fn(x), where each component function fi(x) is independent from each other. This means that each fi(x) contributes independently to the total information obtained from p(x). As discussed above, we want the entropy formula to be additive over independent random variables. Luckily, log can naturally turn a product of probability distributions to a summation of the individual terms.
英語のヒント
まず、なぜ対数関数logを使うのか。p(x)=f1(x)f2(x)…,fn(x)であり、各構成要素の関数fi(x)が互いに独立だとする。これは、各fi(x)がp(x)から得られる全体の情報に独立に寄与することを意味する。上で論じたように、エントロピーの式は独立な確率変数について加法的であってほしい。幸い、logは確率分布の積を個々の項の和に自然に変えられる。
Next, why do we use a negative log? Intuitively, more frequent events should contain less information than less common events, since we often gain more information from an unusual case than from an ordinary one. However, log is monotonically increasing with the probabilities, and indeed negative for all values in [0,1]. We need to construct a monotonically decreasing relationship between the probability of events and their entropy, which will ideally be always positive (for nothing we observe should force us to forget what we have known). Hence, we add a negative sign in front of log function.
英語のヒント
次に、なぜ負のlogを使うのか。直観的には、より頻繁な事象はあまり起きない事象よりも情報が少ないはずである。ふつうの場合よりも珍しい場合からのほうが多くの情報を得ることが多いからである。しかし、logは確率について単調増加であり、実際[0,1]のすべての値で負である。事象の確率とそのエントロピーの間に単調減少の関係を作る必要があり、そのエントロピーは理想的にはいつも正であるべきである(観測するものが何であれ、知っていたことを忘れさせられるべきではないので)。したがって、log関数の前に負の符号をつける。
Last, where does the expectation function come from? Consider a random variable X. We can interpret the self-information (−log⁡(p)) as the amount of surprise we have at seeing a particular outcome. Indeed, as the probability approaches zero, the surprise becomes infinite. Similarly, we can interpret the entropy as the average amount of surprise from observing X. For example, imagine that a slot machine system emits statistical independently symbols s1,…,sk with probabilities p1,…,pk respectively. Then the entropy of this system equals to the average self-information from observing each output, i.e.,
英語のヒント
最後に、期待値の関数はどこから来るのか。確率変数Xを考えよう。自己情報量(−log⁡(p))は、特定の結果を見たときの驚きの量と解釈できる。実際、確率が0に近づくにつれて、驚きは無限大になる。同様に、エントロピーはXを観測することによる驚きの平均の量と解釈できる。たとえば、スロットマシンのシステムが、記号s1,…,skをそれぞれ確率p1,…,pkで統計的に独立に出すと想像しよう。すると、このシステムのエントロピーは、各出力を観測することによる自己情報量の平均に等しい。つまり、
H(S)=∑ipi⋅I(si)=−∑ipi⋅log⁡pi.(22.11.6)

22.11.2.4. Properties of Entropy22.11.2.4 エントロピーの性質

By the above examples and interpretations, we can derive the following properties of entropy (22.11.3). Here, we refer to X as an event and P as the probability distribution of X.
英語のヒント
上の例と解釈から、エントロピー(式(22.11.3))の次の性質を導ける。ここで、Xを事象、PをXの確率分布と呼ぶ。
  • H(X)≥0 for all discrete X (entropy can be negative for continuous X).
    英語のヒント
    すべての離散なXについてH(X)≥0である(連続なXではエントロピーは負になりうる)。
  • If X∼P with a p.d.f. or a p.m.f. p(x), and we try to estimate P by a new probability distribution Q with a p.d.f. or a p.m.f. q(x), then
    英語のヒント
    X∼Pがp.d.f.あるいはp.m.f.p(x)をもち、p.d.f.あるいはp.m.f.q(x)をもつ新しい確率分布QでPを推定しようとするなら、次が成り立つ。
    H(X)=−Ex∼P[log⁡p(x)]≤−Ex∼P[log⁡q(x)], with equality if and only if P=Q.(22.11.7)
    Alternatively, H(X) gives a lower bound of the average number of bits needed to encode symbols drawn from P.
    英語のヒント
    あるいは、H(X)は、Pから抽出された記号を符号化するのに必要な平均ビット数の下界を与える。
  • If X∼P, then x conveys the maximum amount of information if it spreads evenly among all possible outcomes. Specifically, if the probability distribution P is discrete with k-class {p1,…,pk}, then
    英語のヒント
    X∼Pなら、xは、ありうるすべての結果に均等に広がっているときに最大の情報量を伝える。具体的には、確率分布Pがkクラスの{p1,…,pk}をもつ離散分布なら、次が成り立つ。
    H(X)≤log⁡(k), with equality if and only if pi=1k,∀i.(22.11.8)
    If P is a continuous random variable, then the story becomes much more complicated. However, if we additionally impose that P is supported on a finite interval (with all values between 0 and 1), then P has the highest entropy if it is the uniform distribution on that interval.
    英語のヒント
    Pが連続確率変数なら、話はずっと複雑になる。しかし、さらにPが有限の区間(すべての値が0と1の間にある)の上に台をもつと課せば、Pがその区間上の一様分布であるときに、エントロピーが最も高くなる。