プリンキピア

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

22.6.1. Continuous Random Variables22.6.1 連続確率変数

Continuous random variables are a significantly more subtle topic than discrete random variables. A fair analogy to make is that the technical jump is comparable to the jump between adding lists of numbers and integrating functions. As such, we will need to take some time to develop the theory.
英語のヒント
連続確率変数は、離散確率変数よりかなり微妙な話題である。ほどよいたとえを挙げるなら、技術的な飛躍は、数のリストを足し合わせることと関数を積分することの間の飛躍に匹敵する。そのため、理論を展開するのに少し時間をかける必要がある。

22.6.1.1. From Discrete to Continuous22.6.1.1 離散から連続へ

To understand the additional technical challenges encountered when working with continuous random variables, let’s perform a thought experiment. Suppose that we are throwing a dart at the dart board, and we want to know the probability that it hits exactly 2cm from the center of the board.
英語のヒント
連続確率変数を扱うときに出会う、追加の技術的な難しさを理解するため、思考実験をしよう。ダーツボードにダーツを投げていて、それがボードの中心からちょうど2cmのところに当たる確率を知りたいとする。
To start with, we imagine measuring a single digit of accuracy, that is to say with bins for 0cm, 1cm, 2cm, and so on. We throw say 100 darts at the dart board, and if 20 of them fall into the bin for 2cm we conclude that 20% of the darts we throw hit the board 2cm away from the center.
英語のヒント
まず、1桁の精度で測ること、つまり0cm、1cm、2cmなどのビンで測ることを想像する。ダーツボードにたとえば100本のダーツを投げ、そのうち20本が2cmのビンに入ったら、投げたダーツの20%が中心から2cm離れたところに当たったと結論する。
However, when we look closer, this does not match our question! We wanted exact equality, whereas these bins hold all that fell between say 1.5cm and 2.5cm.
英語のヒント
しかし、もっとよく見ると、これは問いに合っていない。ちょうど等しいことを求めていたのに、これらのビンには、たとえば1.5cmから2.5cmの間に落ちたものがすべて入っている。
Undeterred, we continue further. We measure even more precisely, say 1.9cm, 2.0cm, 2.1cm, and now see that perhaps 3 of the 100 darts hit the board in the 2.0cm bucket. Thus we conclude the probability is 3%.
英語のヒント
ひるまずに、さらに続ける。もっと精密に、たとえば1.9cm、2.0cm、2.1cmと測ると、100本のダーツのうちおそらく3本が2.0cmのバケツに当たったことがわかる。したがって、確率は3%だと結論する。
However, this does not solve anything! We have just pushed the issue down one digit further. Let’s abstract a bit. Imagine we know the probability that the first k digits match with 2.00000… and we want to know the probability it matches for the first k+1 digits. It is fairly reasonable to assume that the k+1th digit is essentially a random choice from the set {0,1,2,…,9}. At least, we cannot conceive of a physically meaningful process which would force the number of micrometers away form the center to prefer to end in a 7 vs a 3.
英語のヒント
しかし、これでは何も解決しない。問題を1桁先に押しやっただけである。少し抽象化しよう。最初のk桁が2.00000…と一致する確率がわかっていて、最初のk+1桁で一致する確率を知りたいとする。k+1thの桁は、本質的に集合{0,1,2,…,9}からのランダムな選択だと仮定するのは、かなり妥当である。少なくとも、中心からのマイクロメートル単位の距離の末尾が3より7になることを好むように強いる、物理的に意味のある過程は思いつかない。
What this means is that in essence each additional digit of accuracy we require should decrease probability of matching by a factor of 10. Or put another way, we would expect that
英語のヒント
これが意味するのは、本質的に、求める精度の桁が1つ増えるごとに、一致する確率は10分の1に減るはずだということである。別の言い方をすれば、次を期待する。
P(distance is2.00…,tokdigits)≈p⋅10−k.(22.6.1)
The value p essentially encodes what happens with the first few digits, and the 10−k handles the rest.
英語のヒント
値pは本質的に最初の数桁で何が起きるかを表し、10−kが残りを扱う。
Notice that if we know the position accurate to k=4 digits after the decimal, that means we know the value falls within the interval say [1.99995,2.00005] which is an interval of length 2.00005−1.99995=10−4. Thus, if we call the length of this interval ϵ, we can say
英語のヒント
小数点以下k=4桁まで正確に位置がわかっているなら、それは値がたとえば区間[1.99995,2.00005]の中に入ることがわかっているということであり、これは長さ2.00005−1.99995=10−4の区間であることに注意しよう。したがって、この区間の長さをϵと呼ぶと、次のように言える。
P(distance is in anϵ-sized interval around2)≈ϵ⋅p.(22.6.2)
Let’s take this one final step further. We have been thinking about the point 2 the entire time, but never thinking about other points. Nothing is different there fundamentally, but it is the case that the value p will likely be different. We would at least hope that a dart thrower was more likely to hit a point near the center, like 2cm rather than 20cm. Thus, the value p is not fixed, but rather should depend on the point x. This tells us that we should expect
英語のヒント
これをもう一歩だけ進めよう。ここまでずっと点2について考えてきたが、ほかの点については考えてこなかった。根本的に違うことは何もないが、値pはおそらく違うだろう。少なくとも、ダーツを投げる人は、20cmよりも2cmのような中心に近い点に当たりやすいことを期待したい。したがって、値pは固定されたものではなく、点xに依存するはずである。これにより、次を期待すべきだとわかる。
P(distance is in anϵ-sized interval aroundx)≈ϵ⋅p(x).(22.6.3)
Indeed, (22.6.3) precisely defines the probability density function. It is a function p(x) which encodes the relative probability of hitting near one point vs. another. Let’s visualize what such a function might look like.
英語のヒント
実際、式(22.6.3)は確率密度関数をまさに定義している。これは、ある点の近くに当たる確率と別の点の近くに当たる確率の相対的な大きさを表す関数p(x)である。このような関数がどう見えるかを視覚化しよう。
%matplotlib inline
import torch
from IPython import display
from d2l import torch as d2l

torch.pi = torch.acos(torch.zeros(1)).item() * 2  # Define pi in torch

# Plot the probability density function for some random variable
x = torch.arange(-5, 5, 0.01)
p = 0.2*torch.exp(-(x - 3)**2 / 2)/torch.sqrt(2 * torch.tensor(torch.pi)) + \
    0.8*torch.exp(-(x + 1)**2 / 2)/torch.sqrt(2 * torch.tensor(torch.pi))

d2l.plot(x, p, 'x', 'Density')
The locations where the function value is large indicates regions where we are more likely to find the random value. The low portions are areas where we are unlikely to find the random value.
英語のヒント
関数の値が大きい場所は、ランダムな値が見つかりやすい領域を示している。低い部分は、ランダムな値が見つかりにくい領域である。

22.6.1.2. Probability Density Functions22.6.1.2 確率密度関数

Let’s now investigate this further. We have already seen what a probability density function is intuitively for a random variable X, namely the density function is a function p(x) so that
英語のヒント
では、これをさらに調べよう。確率変数Xについての確率密度関数が直観的に何であるかはすでに見た。すなわち、密度関数とは次を満たす関数p(x)である。
P(Xis in anϵ-sized interval aroundx)≈ϵ⋅p(x).(22.6.4)
But what does this imply for the properties of p(x)?
英語のヒント
しかし、これはp(x)の性質について何を意味するのだろうか。
First, probabilities are never negative, thus we should expect that p(x)≥0 as well.
英語のヒント
まず、確率は決して負にならないので、p(x)≥0も期待すべきである。
Second, let’s imagine that we slice up the ℝ into an infinite number of slices which are ϵ wide, say with slices (ϵ⋅i,ϵ⋅(i+1)]. For each of these, we know from (22.6.4) the probability is approximately
英語のヒント
次に、ℝを幅ϵの無限個の細切れ、たとえば細切れ(ϵ⋅i,ϵ⋅(i+1)]に切り分けることを想像しよう。これらのそれぞれについて、式(22.6.4)から確率はおよそ次のとおりであることがわかる。
P(Xis in anϵ-sized interval aroundx)≈ϵ⋅p(ϵ⋅i),(22.6.5)
so summed over all of them it should be
英語のヒント
したがって、それらすべてについて和をとると、次のようになるはずである。
P(X∈ℝ)≈∑iϵ⋅p(ϵ⋅i).(22.6.6)
This is nothing more than the approximation of an integral discussed in Section 22.5, thus we can say that
英語のヒント
これは22.5節で論じた積分の近似にほかならないので、次のように言える。
P(X∈ℝ)=∫−∞∞p(x)dx.(22.6.7)
We know that P(X∈ℝ)=1, since the random variable must take on some number, we can conclude that for any density
英語のヒント
確率変数は何らかの数をとらなければならないのでP(X∈ℝ)=1であることがわかっており、任意の密度について次のように結論できる。
∫−∞∞p(x)dx=1.(22.6.8)
Indeed, digging into this further shows that for any a, and b, we see that
英語のヒント
実際、これをさらに掘り下げると、任意のaとbについて次がわかる。
P(X∈(a,b])=∫abp(x)dx.(22.6.9)
We may approximate this in code by using the same discrete approximation methods as before. In this case we can approximate the probability of falling in the blue region.
英語のヒント
前と同じ離散的な近似の方法を使って、これをコードで近似できる。この場合、青い領域に入る確率を近似できる。
# Approximate probability using numerical integration
epsilon = 0.01
x = torch.arange(-5, 5, 0.01)
p = 0.2*torch.exp(-(x - 3)**2 / 2) / torch.sqrt(2 * torch.tensor(torch.pi)) +\
    0.8*torch.exp(-(x + 1)**2 / 2) / torch.sqrt(2 * torch.tensor(torch.pi))

d2l.set_figsize()
d2l.plt.plot(x, p, color='black')
d2l.plt.fill_between(x.tolist()[300:800], p.tolist()[300:800])
d2l.plt.show()

f'approximate Probability: {torch.sum(epsilon*p[300:800])}'
'approximate Probability: 0.773617148399353'
It turns out that these two properties describe exactly the space of possible probability density functions (or p.d.f.’s for the commonly encountered abbreviation). They are non-negative functions p(x)≥0 such that
英語のヒント
この二つの性質が、ありうる確率密度関数(よく出会う略称ではp.d.f.)の空間をちょうど記述していることがわかる。それは、次を満たす非負の関数p(x)≥0である。
∫−∞∞p(x)dx=1.(22.6.10)
We interpret this function by using integration to obtain the probability our random variable is in a specific interval:
英語のヒント
確率変数がある特定の区間に入る確率を得るため、積分を使ってこの関数を解釈する。
P(X∈(a,b])=∫abp(x)dx.(22.6.11)
In Section 22.8 we will see a number of common distributions, but let’s continue working in the abstract.
英語のヒント
22.8節でよくある分布をいくつか見るが、ここでは抽象的なまま続けよう。

22.6.1.3. Cumulative Distribution Functions22.6.1.3 累積分布関数

In the previous section, we saw the notion of the p.d.f. In practice, this is a commonly encountered method to discuss continuous random variables, but it has one significant pitfall: that the values of the p.d.f. are not themselves probabilities, but rather a function that we must integrate to yield probabilities. There is nothing wrong with a density being larger than 10, as long as it is not larger than 10 for more than an interval of length 1/10. This can be counter-intuitive, so people often also think in terms of the cumulative distribution function, or c.d.f., which is a probability.
英語のヒント
前の節では、p.d.f.という概念を見た。実際、これは連続確率変数を論じるのによく使われる方法だが、一つ大きな落とし穴がある。p.d.f.の値はそれ自体は確率ではなく、確率を得るために積分しなければならない関数だということである。密度が10より大きくても、長さ1/10より長い区間で10より大きくならないかぎり、何も問題はない。これは直観に反することがあるので、人々はよく、確率である累積分布関数、つまりc.d.f.でも考える。
In particular, by using (22.6.11), we define the c.d.f. for a random variable X with density p(x) by
英語のヒント
とくに、式(22.6.11)を使って、密度p(x)をもつ確率変数Xのc.d.f.を次のように定義する。
F(x)=∫−∞xp(x)dx=P(X≤x).(22.6.12)
Let’s observe a few properties.
英語のヒント
いくつかの性質を観察しよう。
  • F(x)→0 as x→−∞.
    英語のヒント
    x→−∞のときF(x)→0。
  • F(x)→1 as x→∞.
    英語のヒント
    x→∞のときF(x)→1。
  • F(x) is non-decreasing (y>x⟹F(y)≥F(x)).
    英語のヒント
    F(x)は非減少である(y>x⟹F(y)≥F(x))。
  • F(x) is continuous (has no jumps) if X is a continuous random variable.
    英語のヒント
    Xが連続確率変数なら、F(x)は連続である(跳びがない)。
With the fourth bullet point, note that this would not be true if X were discrete, say taking the values 0 and 1 both with probability 1/2. In that case
英語のヒント
4番目の項目について、Xが離散的で、たとえば値0と1をどちらも確率1/2でとるなら、これは成り立たないことに注意しよう。その場合、
F(x)={0x<0,12x<1,1x≥1.(22.6.13)
In this example, we see one of the benefits of working with the c.d.f., the ability to deal with continuous or discrete random variables in the same framework, or indeed mixtures of the two (flip a coin: if heads return the roll of a die, if tails return the distance of a dart throw from the center of a dart board).
英語のヒント
この例で、c.d.f.を扱うことの利点の一つがわかる。連続確率変数も離散確率変数も、さらには両者の混合(コインを投げて、表ならサイコロの目を返し、裏ならダーツボードの中心からダーツが当たった距離を返す)も、同じ枠組みで扱えることである。

22.6.1.4. Means22.6.1.4 平均

Suppose that we are dealing with a random variables X. The distribution itself can be hard to interpret. It is often useful to be able to summarize the behavior of a random variable concisely. Numbers that help us capture the behavior of a random variable are called summary statistics. The most commonly encountered ones are the mean, the variance, and the standard deviation.
英語のヒント
確率変数Xを扱っているとする。分布そのものは解釈しにくいことがある。確率変数のふるまいを簡潔に要約できると役に立つことが多い。確率変数のふるまいをとらえるのに役立つ数は、要約統計量と呼ばれる。最もよく出会うのは、平均、分散、標準偏差である。
The mean encodes the average value of a random variable. If we have a discrete random variable X, which takes the values xi with probabilities pi, then the mean is given by the weighted average: sum the values times the probability that the random variable takes on that value:
英語のヒント
平均は、確率変数の平均的な値を表す。値xiを確率piでとる離散確率変数Xがあるとき、平均は重み付き平均で与えられる。つまり、値に、確率変数がその値をとる確率を掛けて和をとる。
μX=E[X]=∑ixipi.(22.6.14)
The way we should interpret the mean (albeit with caution) is that it tells us essentially where the random variable tends to be located.
英語のヒント
平均の解釈のしかたは(注意は必要だが)、本質的に確率変数がどこに位置しがちかを教えてくれるというものである。
As a minimalistic example that we will examine throughout this section, let’s take X to be the random variable which takes the value a−2 with probability p, a+2 with probability p and a with probability 1−2p. We can compute using (22.6.14) that, for any possible choice of a and p, the mean is
英語のヒント
この節を通じて調べる最小限の例として、Xを、値a−2を確率pで、a+2を確率pで、aを確率1−2pでとる確率変数としよう。式(22.6.14)を使うと、aとpのどんな選び方についても、平均は次のように計算できる。
μX=E[X]=∑ixipi=(a−2)p+a(1−2p)+(a+2)p=a.(22.6.15)
Thus we see that the mean is a. This matches the intuition since a is the location around which we centered our random variable.
英語のヒント
したがって、平均はaであることがわかる。aは確率変数の中心に置いた位置なので、これは直観に合う。
Because they are helpful, let’s summarize a few properties.
英語のヒント
役に立つので、いくつかの性質をまとめよう。
  • For any random variable X and numbers a and b, we have that μaX+b=aμX+b.
    英語のヒント
    任意の確率変数Xと数a、bについて、μaX+b=aμX+bが成り立つ。
  • If we have two random variables X and Y, we have μX+Y=μX+μY.
    英語のヒント
    二つの確率変数XとYがあるとき、μX+Y=μX+μYが成り立つ。
Means are useful for understanding the average behavior of a random variable, however the mean is not sufficient to even have a full intuitive understanding. Making a profit of $10±$1 per sale is very different from making $10±$15 per sale despite having the same average value. The second one has a much larger degree of fluctuation, and thus represents a much larger risk. Thus, to understand the behavior of a random variable, we will need at minimum one more measure: some measure of how widely a random variable fluctuates.
英語のヒント
平均は確率変数の平均的なふるまいを理解するのに役立つが、平均だけでは十分な直観的理解を得るのにさえ足りない。1回の販売あたり$10±$1の利益を上げることは、平均値が同じでも、1回の販売あたり$10±$15を上げることとはまったく違う。2番目のほうが変動の度合いがはるかに大きく、したがってはるかに大きなリスクを表す。したがって、確率変数のふるまいを理解するには、最低でももう一つの尺度、つまり確率変数がどれだけ広く変動するかの何らかの尺度が必要である。

22.6.1.5. Variances22.6.1.5 分散

This leads us to consider the variance of a random variable. This is a quantitative measure of how far a random variable deviates from the mean. Consider the expression X−μX. This is the deviation of the random variable from its mean. This value can be positive or negative, so we need to do something to make it positive so that we are measuring the magnitude of the deviation.
英語のヒント
これにより、確率変数の分散を考えることになる。これは、確率変数が平均からどれだけ外れるかの定量的な尺度である。式X−μXを考えよう。これは確率変数の平均からの偏差である。この値は正にも負にもなりうるので、偏差の大きさを測れるように、正にするために何かをする必要がある。
A reasonable thing to try is to look at |X−μX|, and indeed this leads to a useful quantity called the mean absolute deviation, however due to connections with other areas of mathematics and statistics, people often use a different solution.
英語のヒント
試してみるのにもっともなのは|X−μX|を見ることであり、実際これは平均絶対偏差と呼ばれる役に立つ量につながるが、数学や統計学のほかの分野とのつながりのため、人々はよく別の解決策を使う。
In particular, they look at (X−μX)2. If we look at the typical size of this quantity by taking the mean, we arrive at the variance
英語のヒント
とくに、(X−μX)2を見る。この量の典型的な大きさを平均をとって見ると、分散にたどり着く。
σX2=Var(X)=E[(X−μX)2]=E[X2]−μX2.(22.6.16)
The last equality in (22.6.16) holds by expanding out the definition in the middle, and applying the properties of expectation.
英語のヒント
式(22.6.16)の最後の等号は、真ん中の定義を展開し、期待値の性質を適用すれば成り立つ。
Let’s look at our example where X is the random variable which takes the value a−2 with probability p, a+2 with probability p and a with probability 1−2p. In this case μX=a, so all we need to compute is E[X2]. This can readily be done:
英語のヒント
Xが値a−2を確率pで、a+2を確率pで、aを確率1−2pでとる確率変数である例を見よう。この場合μX=aなので、計算する必要があるのはE[X2]だけである。これはすぐにできる。
E[X2]=(a−2)2p+a2(1−2p)+(a+2)2p=a2+8p.(22.6.17)
Thus, we see that by (22.6.16) our variance is
英語のヒント
したがって、式(22.6.16)により、分散は次のようになる。
σX2=Var(X)=E[X2]−μX2=a2+8p−a2=8p.(22.6.18)
This result again makes sense. The largest p can be is 1/2 which corresponds to picking a−2 or a+2 with a coin flip. The variance of this being 4 corresponds to the fact that both a−2 and a+2 are 2 units away from the mean, and 22=4. On the other end of the spectrum, if p=0, this random variable always takes the value 0 and so it has no variance at all.
英語のヒント
この結果もまた理にかなっている。pがとりうる最大の値は1/2であり、これはコイン投げでa−2かa+2を選ぶことに対応する。このときの分散が4であることは、a−2とa+2がどちらも平均から2単位離れていて、22=4であるという事実に対応する。反対の極では、p=0なら、この確率変数はいつも値0をとるので、分散はまったくない。
We will list a few properties of variance below:
英語のヒント
分散のいくつかの性質を以下に挙げる。
  • For any random variable X, Var(X)≥0, with Var(X)=0 if and only if X is a constant.
    英語のヒント
    任意の確率変数XについてVar(X)≥0であり、Var(X)=0となるのはXが定数であるとき、かつそのときに限る。
  • For any random variable X and numbers a and b, we have that Var(aX+b)=a2Var(X).
    英語のヒント
    任意の確率変数Xと数a、bについて、Var(aX+b)=a2Var(X)が成り立つ。
  • If we have two independent random variables X and Y, we have Var(X+Y)=Var(X)+Var(Y).
    英語のヒント
    二つの独立な確率変数XとYがあるとき、Var(X+Y)=Var(X)+Var(Y)が成り立つ。
When interpreting these values, there can be a bit of a hiccup. In particular, let’s try imagining what happens if we keep track of units through this computation. Suppose that we are working with the star rating assigned to a product on the web page. Then a, a−2, and a+2 are all measured in units of stars. Similarly, the mean μX is then also measured in stars (being a weighted average). However, if we get to the variance, we immediately encounter an issue, which is we want to look at (X−μX)2, which is in units of squared stars. This means that the variance itself is not comparable to the original measurements. To make it interpretable, we will need to return to our original units.
英語のヒント
これらの値を解釈するとき、少し引っかかることがある。とくに、この計算を通じて単位を追いかけると何が起きるかを想像してみよう。ウェブページ上の製品につけられた星の評価を扱っているとする。すると、a、a−2、a+2はどれも星の単位で測られる。同様に、平均μXも(重み付き平均なので)星で測られる。しかし、分散にたどり着くと、すぐに問題に出会う。見たいのは(X−μX)2であり、これは星の2乗の単位なのである。これは、分散そのものはもとの測定値と比べられないことを意味する。解釈できるようにするには、もとの単位に戻る必要がある。

22.6.1.6. Standard Deviations22.6.1.6 標準偏差

This summary statistics can always be deduced from the variance by taking the square root! Thus we define the standard deviation to be
英語のヒント
この要約統計量は、平方根をとることで分散からいつでも導ける。したがって、標準偏差を次のように定義する。
σX=Var(X).(22.6.19)
In our example, this means we now have the standard deviation is σX=22p. If we are dealing with units of stars for our review example, σX is again in units of stars.
英語のヒント
この例では、これは標準偏差がσX=22pになることを意味する。評価の例で星の単位を扱っているなら、σXもまた星の単位である。
The properties we had for the variance can be restated for the standard deviation.
英語のヒント
分散について見た性質は、標準偏差についても言い直せる。
  • For any random variable X, σX≥0.
    英語のヒント
    任意の確率変数XについてσX≥0である。
  • For any random variable X and numbers a and b, we have that σaX+b=|a|σX
    英語のヒント
    任意の確率変数Xと数a、bについて、σaX+b=|a|σXが成り立つ。
  • If we have two independent random variables X and Y, we have σX+Y=σX2+σY2.
    英語のヒント
    二つの独立な確率変数XとYがあるとき、σX+Y=σX2+σY2が成り立つ。
It is natural at this moment to ask, “If the standard deviation is in the units of our original random variable, does it represent something we can draw with regards to that random variable?” The answer is a resounding yes! Indeed much like the mean told us the typical location of our random variable, the standard deviation gives the typical range of variation of that random variable. We can make this rigorous with what is known as Chebyshev’s inequality:
英語のヒント
ここで「標準偏差がもとの確率変数の単位をもつなら、それはその確率変数について引き出せる何かを表しているのか」と問うのは自然である。答えははっきりとイエスである。実際、平均が確率変数の典型的な位置を教えてくれたのとよく似て、標準偏差はその確率変数の変動の典型的な範囲を与える。これは、チェビシェフの不等式として知られるもので厳密にできる。
P(X∉[μX−ασX,μX+ασX])≤1α2.(22.6.20)
Or to state it verbally in the case of α=10, 99% of the samples from any random variable fall within 10 standard deviations of the mean. This gives an immediate interpretation to our standard summary statistics.
英語のヒント
言葉で言えば、α=10の場合、どんな確率変数からの標本でもその99%が平均から標準偏差の10倍以内に入るということである。これは、標準的な要約統計量にすぐに使える解釈を与える。
To see how this statement is rather subtle, let’s take a look at our running example again where X is the random variable which takes the value a−2 with probability p, a+2 with probability p and a with probability 1−2p. We saw that the mean was a and the standard deviation was 22p. This means, if we take Chebyshev’s inequality (22.6.20) with α=2, we see that the expression is
英語のヒント
この言明がかなり微妙であることを見るため、Xが値a−2を確率pで、a+2を確率pで、aを確率1−2pでとる確率変数である、おなじみの例をもう一度見よう。平均はa、標準偏差は22pであることを見た。これは、チェビシェフの不等式(式(22.6.20))をα=2でとると、式が次のようになることを意味する。
P(X∉[a−42p,a+42p])≤14.(22.6.21)
This means that 75% of the time, this random variable will fall within this interval for any value of p. Now, notice that as p→0, this interval also converges to the single point a. But we know that our random variable takes the values a−2,a, and a+2 only so eventually we can be certain a−2 and a+2 will fall outside the interval! The question is, at what p does that happen. So we want to solve: for what p does a+42p=a+2, which is solved when p=1/8, which is exactly the first p where it could possibly happen without violating our claim that no more than 1/4 of samples from the distribution would fall outside the interval (1/8 to the left, and 1/8 to the right).
英語のヒント
これは、pのどんな値についても、この確率変数が時間の75%はこの区間に入ることを意味する。ここで、p→0とすると、この区間も一点aに収束することに注意しよう。しかし、確率変数は値a−2,aとa+2しかとらないことがわかっているので、最終的にはa−2とa+2が区間の外に出ることは確実である。問題は、どのpでそれが起きるかである。そこで、どのpでa+42p=a+2となるかを解きたい。これはp=1/8のときに解けて、これはちょうど、分布からの標本のうち区間の外に出るのは1/4以下(左に1/8、右に1/8)であるという主張に反することなく、それが起こりうる最初のpである。
Let’s visualize this. We will show the probability of getting the three values as three vertical bars with height proportional to the probability. The interval will be drawn as a horizontal line in the middle. The first plot shows what happens for p>1/8 where the interval safely contains all points.
英語のヒント
これを視覚化しよう。三つの値をとる確率を、確率に比例する高さの3本の縦棒として示す。区間は真ん中の横線として描く。1枚目のプロットは、区間がすべての点を余裕をもって含むp>1/8の場合に何が起きるかを示している。
# Define a helper to plot these figures
def plot_chebyshev(a, p):
    d2l.set_figsize()
    d2l.plt.stem([a-2, a, a+2], [p, 1-2*p, p], use_line_collection=True)
    d2l.plt.xlim([-4, 4])
    d2l.plt.xlabel('x')
    d2l.plt.ylabel('p.m.f.')

    d2l.plt.hlines(0.5, a - 4 * torch.sqrt(2 * p),
                   a + 4 * torch.sqrt(2 * p), 'black', lw=4)
    d2l.plt.vlines(a - 4 * torch.sqrt(2 * p), 0.53, 0.47, 'black', lw=1)
    d2l.plt.vlines(a + 4 * torch.sqrt(2 * p), 0.53, 0.47, 'black', lw=1)
    d2l.plt.title(f'p = {p:.3f}')

    d2l.plt.show()

# Plot interval when p > 1/8
plot_chebyshev(0.0, torch.tensor(0.2))
The second shows that at p=1/8, the interval exactly touches the two points. This shows that the inequality is sharp, since no smaller interval could be taken while keeping the inequality true.
英語のヒント
2枚目は、p=1/8では区間がちょうど二つの点に触れることを示している。不等式を成り立たせたままでより小さい区間はとれないので、これは不等式が鋭いことを示している。
# Plot interval when p = 1/8
plot_chebyshev(0.0, torch.tensor(0.125))
The third shows that for p<1/8 the interval only contains the center. This does not invalidate the inequality since we only needed to ensure that no more than 1/4 of the probability falls outside the interval, which means that once p<1/8, the two points at a−2 and a+2 can be discarded.
英語のヒント
3枚目は、p<1/8では区間が中心だけを含むことを示している。区間の外に出る確率が1/4以下であることを保証しさえすればよかったので、これは不等式を無効にはしない。つまり、いったんp<1/8となれば、a−2とa+2の二つの点は捨ててよいのである。
# Plot interval when p < 1/8
plot_chebyshev(0.0, torch.tensor(0.05))

22.6.1.7. Means and Variances in the Continuum22.6.1.7 連続の場合の平均と分散

This has all been in terms of discrete random variables, but the case of continuous random variables is similar. To intuitively understand how this works, imagine that we split the real number line into intervals of length ϵ given by (ϵi,ϵ(i+1)]. Once we do this, our continuous random variable has been made discrete and we can use (22.6.14) say that
英語のヒント
ここまではすべて離散確率変数についてだったが、連続確率変数の場合も同様である。これがどう働くかを直観的に理解するため、実数直線を(ϵi,ϵ(i+1)]で与えられる長さϵの区間に分割することを想像しよう。いったんこうすれば、連続確率変数は離散化されたので、式(22.6.14)を使って次のように言える。
μX≈∑i(ϵi)P(X∈(ϵi,ϵ(i+1)])≈∑i(ϵi)pX(ϵi)ϵ,(22.6.22)
where pX is the density of X. This is an approximation to the integral of xpX(x), so we can conclude that
英語のヒント
ここでpXはXの密度である。これはxpX(x)の積分の近似なので、次のように結論できる。
μX=∫−∞∞xpX(x)dx.(22.6.23)
Similarly, using (22.6.16) the variance can be written as
英語のヒント
同様に、式(22.6.16)を使うと、分散は次のように書ける。
σX2=E[X2]−μX2=∫−∞∞x2pX(x)dx−(∫−∞∞xpX(x)dx)2.(22.6.24)
Everything stated above about the mean, the variance, and the standard deviation still applies in this case. For instance, if we consider the random variable with density
英語のヒント
平均、分散、標準偏差について上で述べたことは、この場合にもすべて当てはまる。たとえば、次の密度をもつ確率変数を考えると、
p(x)={1x∈[0,1],0otherwise.(22.6.25)
we can compute
英語のヒント
次が計算でき、
μX=∫−∞∞xp(x)dx=∫01xdx=12.(22.6.26)
and
英語のヒント
そして、
σX2=∫−∞∞x2p(x)dx−(12)2=13−14=112.(22.6.27)
As a warning, let’s examine one more example, known as the Cauchy distribution. This is the distribution with p.d.f. given by
英語のヒント
警告として、コーシー分布として知られるもう一つの例を調べよう。これは、次で与えられるp.d.f.をもつ分布である。
p(x)=11+x2.(22.6.28)
# Plot the Cauchy distribution p.d.f.
x = torch.arange(-5, 5, 0.01)
p = 1 / (1 + x**2)

d2l.plot(x, p, 'x', 'p.d.f.')
This function looks innocent, and indeed consulting a table of integrals will show it has area one under it, and thus it defines a continuous random variable.
英語のヒント
この関数は無害に見えるし、実際、積分の表を調べれば、その下の面積は1であることがわかり、したがって連続確率変数を定義する。
To see what goes astray, let’s try to compute the variance of this. This would involve using (22.6.16) computing
英語のヒント
何がおかしくなるかを見るため、これの分散を計算してみよう。これには、式(22.6.16)を使って次を計算する必要がある。
∫−∞∞x21+x2dx.(22.6.29)
The function on the inside looks like this:
英語のヒント
内側の関数は次のようになる。
# Plot the integrand needed to compute the variance
x = torch.arange(-20, 20, 0.01)
p = x**2 / (1 + x**2)

d2l.plot(x, p, 'x', 'integrand')
This function clearly has infinite area under it since it is essentially the constant one with a small dip near zero, and indeed we could show that
英語のヒント
この関数は本質的に、0の近くに小さなくぼみがある定数1なので、その下の面積は明らかに無限大であり、実際次を示せる。
∫−∞∞x21+x2dx=∞.(22.6.30)
This means it does not have a well-defined finite variance.
英語のヒント
これは、きちんと定義された有限の分散をもたないことを意味する。
However, looking deeper shows an even more disturbing result. Let’s try to compute the mean using (22.6.14). Using the change of variables formula, we see
英語のヒント
しかし、もっと深く見ると、さらに困った結果がわかる。式(22.6.14)を使って平均を計算してみよう。変数変換の公式を使うと、次がわかる。
μX=∫−∞∞x1+x2dx=12∫1∞1udu.(22.6.31)
The integral inside is the definition of the logarithm, so this is in essence log⁡(∞)=∞, so there is no well-defined average value either!
英語のヒント
内側の積分は対数の定義なので、これは本質的にlog⁡(∞)=∞であり、したがって、きちんと定義された平均値もない。
Machine learning scientists define their models so that we most often do not need to deal with these issues, and will in the vast majority of cases deal with random variables with well-defined means and variances. However, every so often random variables with heavy tails (that is those random variables where the probabilities of getting large values are large enough to make things like the mean or variance undefined) are helpful in modeling physical systems, thus it is worth knowing that they exist.
英語のヒント
機械学習の科学者は、たいていの場合こうした問題を扱わなくて済むようにモデルを定義しており、大多数の場合、平均と分散がきちんと定義された確率変数を扱う。しかし、ときおり、裾の重い確率変数(つまり、大きな値をとる確率が十分大きいために、平均や分散のようなものが定義されなくなる確率変数)が物理系をモデル化するのに役立つことがあるので、それらが存在することを知っておく価値はある。

22.6.1.8. Joint Density Functions22.6.1.8 同時密度関数

The above work all assumes we are working with a single real valued random variable. But what if we are dealing with two or more potentially highly correlated random variables? This circumstance is the norm in machine learning: imagine random variables like Ri,j which encode the red value of the pixel at the (i,j) coordinate in an image, or Pt which is a random variable given by a stock price at time t. Nearby pixels tend to have similar color, and nearby times tend to have similar prices. We cannot treat them as separate random variables, and expect to create a successful model (we will see in Section 22.9 a model that under-performs due to such an assumption). We need to develop the mathematical language to handle these correlated continuous random variables.
英語のヒント
上の作業はすべて、一つの実数値の確率変数を扱っていることを前提にしている。しかし、二つ以上の、潜在的に強く相関する確率変数を扱っている場合はどうだろうか。この状況は機械学習ではふつうのことである。画像の(i,j)座標の画素の赤の値を表すRi,jのような確率変数や、時刻tでの株価で与えられる確率変数Ptを想像しよう。近くの画素は似た色をもちがちで、近い時刻は似た価格をもちがちである。それらを別々の確率変数として扱って、うまくいくモデルを作れると期待することはできない(22.9節では、そのような仮定のために性能が出ないモデルを見る)。こうした相関のある連続確率変数を扱うための数学的な言語を築く必要がある。
Thankfully, with the multiple integrals in Section 22.5 we can develop such a language. Suppose that we have, for simplicity, two random variables X,Y which can be correlated. Then, similar to the case of a single variable, we can ask the question:
英語のヒント
ありがたいことに、22.5節の重積分を使えば、そのような言語を築ける。簡単にするため、相関しうる二つの確率変数X,Yがあるとする。すると、1変数の場合と同じように、次のように問える。
P(Xis in anϵ-sized interval aroundxandYis in anϵ-sized interval aroundy).(22.6.32)
Similar reasoning to the single variable case shows that this should be approximately
英語のヒント
1変数の場合と同じような推論から、これはおよそ次のようになるはずである。
P(Xis in anϵ-sized interval aroundxandYis in anϵ-sized interval aroundy)≈ϵ2p(x,y),(22.6.33)
for some function p(x,y). This is referred to as the joint density of X and Y. Similar properties are true for this as we saw in the single variable case. Namely:
英語のヒント
ここでp(x,y)はある関数である。これはXとYの同時密度と呼ばれる。これについても、1変数の場合に見たのと同じような性質が成り立つ。すなわち、
  • p(x,y)≥0;
  • ∫ℝ2p(x,y)dxdy=1;
  • P((X,Y)∈𝒟)=∫𝒟p(x,y)dxdy.
In this way, we can deal with multiple, potentially correlated random variables. If we wish to work with more than two random variables, we can extend the multivariate density to as many coordinates as desired by considering p(𝐱)=p(x1,…,xn). The same properties of being non-negative, and having total integral of one still hold.
英語のヒント
このようにして、複数の、潜在的に相関する確率変数を扱える。2個より多くの確率変数を扱いたいなら、p(𝐱)=p(x1,…,xn)を考えることで、多変量の密度を望むだけの座標に拡張できる。非負であることと、全体の積分が1であることという同じ性質が、やはり成り立つ。

22.6.1.9. Marginal Distributions22.6.1.9 周辺分布

When dealing with multiple variables, we oftentimes want to be able to ignore the relationships and ask, “how is this one variable distributed?” Such a distribution is called a marginal distribution.
英語のヒント
複数の変数を扱うとき、関係を無視して「この一つの変数はどう分布しているのか」と問いたいことがよくある。このような分布は周辺分布と呼ばれる。
To be concrete, let’s suppose that we have two random variables X,Y with joint density given by pX,Y(x,y). We will be using the subscript to indicate what random variables the density is for. The question of finding the marginal distribution is taking this function, and using it to find pX(x).
英語のヒント
具体的にするため、同時密度がpX,Y(x,y)で与えられる二つの確率変数X,Yがあるとしよう。密度がどの確率変数についてのものかを示すのに、添字を使う。周辺分布を求める問題とは、この関数をとり、それを使ってpX(x)を求めることである。
As with most things, it is best to return to the intuitive picture to figure out what should be true. Recall that the density is the function pX so that
英語のヒント
たいていのことと同じように、何が成り立つはずかを突き止めるには、直観的な描像に戻るのが最善である。密度とは次を満たす関数pXであったことを思い出そう。
P(X∈[x,x+ϵ])≈ϵ⋅pX(x).(22.6.34)
There is no mention of Y, but if all we are given is pX,Y, we need to include Y somehow. We can first observe that this is the same as
英語のヒント
Yについての言及はないが、与えられているのがpX,Yだけなら、何らかの形でYを含める必要がある。まず、これは次と同じであることがわかる。
P(X∈[x,x+ϵ], and Y∈ℝ)≈ϵ⋅pX(x).(22.6.35)
Our density does not directly tell us about what happens in this case, we need to split into small intervals in y as well, so we can write this as
英語のヒント
密度は、この場合に何が起きるかを直接は教えてくれないので、yについても小さな区間に分割する必要がある。すると、これは次のように書ける。
ϵ⋅pX(x)≈∑iP(X∈[x,x+ϵ], and Y∈[ϵ⋅i,ϵ⋅(i+1)])≈∑iϵ2pX,Y(x,ϵ⋅i).(22.6.36)
Fig. 22.6.1図22.6.1
By summing along the columns of our array of probabilities, we are able to obtain the marginal distribution for just the random variable represented along the 𝑥-axis.
英語のヒント
確率の配列の列に沿って和をとることで、𝑥軸に沿って表される確率変数だけの周辺分布を得られる。
This tells us to add up the value of the density along a series of squares in a line as is shown in Fig. 22.6.1. Indeed, after canceling one factor of epsilon from both sides, and recognizing the sum on the right is the integral over y, we can conclude that
英語のヒント
これは、図22.6.1に示すように、一列に並んだ一連の正方形に沿って密度の値を足し合わせることを教えてくれる。実際、両辺からイプシロンの因子を一つ打ち消し、右辺の和がyについての積分であることに気づけば、次のように結論できる。
pX(x)≈∑iϵpX,Y(x,ϵ⋅i)≈∫−∞∞pX,Y(x,y)dy.(22.6.37)
Thus we see
英語のヒント
したがって、次がわかる。
pX(x)=∫−∞∞pX,Y(x,y)dy.(22.6.38)
This tells us that to get a marginal distribution, we integrate over the variables we do not care about. This process is often referred to as integrating out or marginalized out the unneeded variables.
英語のヒント
これは、周辺分布を得るには、関心のない変数について積分すればよいことを教えてくれる。この過程は、不要な変数を積分消去する、あるいは周辺化するとよく呼ばれる。

22.6.1.10. Covariance22.6.1.10 共分散

When dealing with multiple random variables, there is one additional summary statistic which is helpful to know: the covariance. This measures the degree that two random variable fluctuate together.
英語のヒント
複数の確率変数を扱うときには、知っておくと役に立つ要約統計量がもう一つある。共分散である。これは、二つの確率変数がどの程度いっしょに変動するかを測る。
Suppose that we have two random variables X and Y, to begin with, let’s suppose they are discrete, taking on values (xi,yj) with probability pij. In this case, the covariance is defined as
英語のヒント
二つの確率変数XとYがあるとする。まず手始めに、それらが離散的で、値(xi,yj)を確率pijでとるとしよう。この場合、共分散は次のように定義される。
σXY=Cov(X,Y)=∑i,j(xi−μX)(yj−μY)pij.=E[XY]−E[X]E[Y].(22.6.39)
To think about this intuitively: consider the following pair of random variables. Suppose that X takes the values 1 and 3, and Y takes the values −1 and 3. Suppose that we have the following probabilities
英語のヒント
これを直観的に考えるため、次の確率変数の組を考えよう。Xは値1と3をとり、Yは値−1と3をとるとする。次の確率をもつとしよう。
P(X=1andY=−1)=p2,P(X=1andY=3)=1−p2,P(X=3andY=−1)=1−p2,P(X=3andY=3)=p2,(22.6.40)
where p is a parameter in [0,1] we get to pick. Notice that if p=1 then they are both always their minimum or maximum values simultaneously, and if p=0 they are guaranteed to take their flipped values simultaneously (one is large when the other is small and vice versa). If p=1/2, then the four possibilities are all equally likely, and neither should be related. Let’s compute the covariance. First, note μX=2 and μY=1, so we may compute using (22.6.39):
英語のヒント
ここでpは[0,1]の中から選べるパラメータである。p=1なら両者はいつも同時に最小値か最大値をとり、p=0なら同時に反転した値をとることが保証される(一方が大きいときは他方が小さく、その逆も成り立つ)ことに注意しよう。p=1/2なら、四つの可能性はすべて同じくらい起こりやすく、どちらも関係しないはずである。共分散を計算しよう。まず、μX=2とμY=1に注意すると、式(22.6.39)を使って次のように計算できる。
Cov(X,Y)=∑i,j(xi−μX)(yj−μY)pij=(1−2)(−1−1)p2+(1−2)(3−1)1−p2+(3−2)(−1−1)1−p2+(3−2)(3−1)p2=4p−2.(22.6.41)
When p=1 (the case where they are both maximally positive or negative at the same time) has a covariance of 2. When p=0 (the case where they are flipped) the covariance is −2. Finally, when p=1/2 (the case where they are unrelated), the covariance is 0. Thus we see that the covariance measures how these two random variables are related.
英語のヒント
p=1のとき(両者が同時に最大限に正か負になる場合)は、共分散は2になる。p=0のとき(両者が反転する場合)は、共分散は−2である。最後に、p=1/2のとき(両者が無関係な場合)は、共分散は0である。したがって、共分散はこれら二つの確率変数がどう関係しているかを測ることがわかる。
A quick note on the covariance is that it only measures these linear relationships. More complex relationships like X=Y2 where Y is randomly chosen from {−2,−1,0,1,2} with equal probability can be missed. Indeed a quick computation shows that these random variables have covariance zero, despite one being a deterministic function of the other.
英語のヒント
共分散について手短に注意しておくと、共分散はこうした線形の関係しか測らない。Yが{−2,−1,0,1,2}から等しい確率でランダムに選ばれるときのX=Y2のような、もっと複雑な関係は見逃されることがある。実際、手早く計算すると、一方が他方の決定論的な関数であるにもかかわらず、これらの確率変数の共分散は0であることがわかる。
For continuous random variables, much the same story holds. At this point, we are pretty comfortable with doing the transition between discrete and continuous, so we will provide the continuous analogue of (22.6.39) without any derivation.
英語のヒント
連続確率変数についても、ほとんど同じ話が成り立つ。この時点では、離散と連続の間の移行にかなり慣れているので、式(22.6.39)の連続版を導出なしで示す。
σXY=∫ℝ2(x−μX)(y−μY)p(x,y)dxdy.(22.6.42)
For visualization, let’s take a look at a collection of random variables with tunable covariance.
英語のヒント
視覚化のため、共分散を調整できる確率変数の集まりを見てみよう。
# Plot a few random variables adjustable covariance
covs = [-0.9, 0.0, 1.2]
d2l.plt.figure(figsize=(12, 3))
for i in range(3):
    X = torch.randn(500)
    Y = covs[i]*X + torch.randn(500)

    d2l.plt.subplot(1, 4, i+1)
    d2l.plt.scatter(X.numpy(), Y.numpy())
    d2l.plt.xlabel('X')
    d2l.plt.ylabel('Y')
    d2l.plt.title(f'cov = {covs[i]}')
d2l.plt.show()
Let’s see some properties of covariances:
英語のヒント
共分散のいくつかの性質を見よう。
  • For any random variable X, Cov(X,X)=Var(X).
    英語のヒント
    任意の確率変数XについてCov(X,X)=Var(X)である。
  • For any random variables X,Y and numbers a and b, Cov(aX+b,Y)=Cov(X,aY+b)=aCov(X,Y).
    英語のヒント
    任意の確率変数X,Yと数a、bについて、Cov(aX+b,Y)=Cov(X,aY+b)=aCov(X,Y)である。
  • If X and Y are independent then Cov(X,Y)=0.
    英語のヒント
    XとYが独立なら、Cov(X,Y)=0である。
In addition, we can use the covariance to expand a relationship we saw before. Recall that is X and Y are two independent random variables then
英語のヒント
さらに、共分散を使うと、前に見た関係を拡張できる。XとYが二つの独立な確率変数なら、次が成り立つことを思い出そう。
Var(X+Y)=Var(X)+Var(Y).(22.6.43)
With knowledge of covariances, we can expand this relationship. Indeed, some algebra can show that in general,
英語のヒント
共分散を知っていれば、この関係を拡張できる。実際、少し代数計算をすると、一般に次が成り立つことを示せる。
Var(X+Y)=Var(X)+Var(Y)+2Cov(X,Y).(22.6.44)
This allows us to generalize the variance summation rule for correlated random variables.
英語のヒント
これにより、相関のある確率変数について、分散の和の規則を一般化できる。

22.6.1.11. Correlation22.6.1.11 相関

As we did in the case of means and variances, let’s now consider units. If X is measured in one unit (say inches), and Y is measured in another (say dollars), the covariance is measured in the product of these two units inches×dollars. These units can be hard to interpret. What we will often want in this case is a unit-less measurement of relatedness. Indeed, often we do not care about exact quantitative correlation, but rather ask if the correlation is in the same direction, and how strong the relationship is.
英語のヒント
平均と分散の場合にしたように、今度は単位を考えよう。Xがある単位(たとえばインチ)で測られ、Yが別の単位(たとえばドル)で測られるなら、共分散はこの二つの単位の積inches×dollarsで測られる。こうした単位は解釈しにくいことがある。この場合によく欲しくなるのは、関係の度合いの単位をもたない測り方である。実際、正確な定量的な相関は気にせず、相関が同じ向きかどうか、そして関係がどれくらい強いかを問うことが多い。
To see what makes sense, let’s perform a thought experiment. Suppose that we convert our random variables in inches and dollars to be in inches and cents. In this case the random variable Y is multiplied by 100. If we work through the definition, this means that Cov(X,Y) will be multiplied by 100. Thus we see that in this case a change of units change the covariance by a factor of 100. Thus, to find our unit-invariant measure of correlation, we will need to divide by something else that also gets scaled by 100. Indeed we have a clear candidate, the standard deviation! Indeed if we define the correlation coefficient to be
英語のヒント
何が理にかなうかを見るため、思考実験をしよう。インチとドルの確率変数を、インチとセントのものに変換するとする。この場合、確率変数Yは100倍される。定義をたどれば、これはCov(X,Y)が100倍されることを意味する。したがって、この場合、単位の変更によって共分散は100倍に変わることがわかる。したがって、単位に依存しない相関の尺度を見つけるには、同じく100倍される別の何かで割る必要がある。実際、はっきりした候補がある。標準偏差である。実際、相関係数を次のように定義すると、
ρ(X,Y)=Cov(X,Y)σXσY,(22.6.45)
we see that this is a unit-less value. A little mathematics can show that this number is between −1 and 1 with 1 meaning maximally positively correlated, whereas −1 means maximally negatively correlated.
英語のヒント
これが単位をもたない値であることがわかる。少し数学を使えば、この数は−1と1の間にあり、1は最大限に正の相関を、−1は最大限に負の相関を意味することを示せる。
Returning to our explicit discrete example above, we can see that σX=1 and σY=2, so we can compute the correlation between the two random variables using (22.6.45) to see that
英語のヒント
上の明示的な離散の例に戻ると、σX=1とσY=2であることがわかるので、式(22.6.45)を使って二つの確率変数の相関を計算すると、次のようになる。
ρ(X,Y)=4p−21⋅2=2p−1.(22.6.46)
This now ranges between −1 and 1 with the expected behavior of 1 meaning most correlated, and −1 meaning minimally correlated.
英語のヒント
これは今や−1と1の間の範囲にあり、期待どおり、1は最も相関が強く、−1は相関が最小であることを意味する。
As another example, consider X as any random variable, and Y=aX+b as any linear deterministic function of X. Then, one can compute that
英語のヒント
別の例として、Xを任意の確率変数、Y=aX+bをXの任意の線形で決定論的な関数と考えよう。すると、次が計算できる。
σY=σaX+b=|a|σX,(22.6.47)
Cov(X,Y)=Cov(X,aX+b)=aCov(X,X)=aVar(X),(22.6.48)
and thus by (22.6.45) that
英語のヒント
そして、式(22.6.45)により次がわかる。
ρ(X,Y)=aVar(X)|a|σX2=a|a|=sign(a).(22.6.49)
Thus we see that the correlation is +1 for any a>0, and −1 for any a<0 illustrating that correlation measures the degree and directionality the two random variables are related, not the scale that the variation takes.
英語のヒント
したがって、相関は任意のa>0について+1、任意のa<0について−1であることがわかる。これは、相関が、変動の大きさではなく、二つの確率変数が関係している度合いと向きを測ることを示している。
Let’s again plot a collection of random variables with tunable correlation.
英語のヒント
もう一度、相関を調整できる確率変数の集まりをプロットしよう。
# Plot a few random variables adjustable correlations
cors = [-0.9, 0.0, 1.0]
d2l.plt.figure(figsize=(12, 3))
for i in range(3):
    X = torch.randn(500)
    Y = cors[i] * X + torch.sqrt(torch.tensor(1) -
                                 cors[i]**2) * torch.randn(500)

    d2l.plt.subplot(1, 4, i + 1)
    d2l.plt.scatter(X.numpy(), Y.numpy())
    d2l.plt.xlabel('X')
    d2l.plt.ylabel('Y')
    d2l.plt.title(f'cor = {cors[i]}')
d2l.plt.show()
Let’s list a few properties of the correlation below.
英語のヒント
相関のいくつかの性質を以下に挙げよう。
  • For any random variable X, ρ(X,X)=1.
    英語のヒント
    任意の確率変数Xについてρ(X,X)=1である。
  • For any random variables X,Y and numbers a and b, ρ(aX+b,Y)=ρ(X,aY+b)=ρ(X,Y).
    英語のヒント
    任意の確率変数X,Yと数a、bについて、ρ(aX+b,Y)=ρ(X,aY+b)=ρ(X,Y)である。
  • If X and Y are independent with non-zero variance then ρ(X,Y)=0.
    英語のヒント
    XとYが独立で分散が0でないなら、ρ(X,Y)=0である。
As a final note, you may feel like some of these formulae are familiar. Indeed, if we expand everything out assuming that μX=μY=0, we see that this is
英語のヒント
最後の注意として、これらの式のいくつかに見覚えがあると感じるかもしれない。実際、μX=μY=0と仮定してすべてを展開すると、これは次のようになる。
ρ(X,Y)=∑i,jxiyipij∑i,jxi2pij∑i,jyj2pij.(22.6.50)
This looks like a sum of a product of terms divided by the square root of sums of terms. This is exactly the formula for the cosine of the angle between two vectors 𝐯,𝐰 with the different coordinates weighted by pij:
英語のヒント
これは、項の積の和を、項の和の平方根で割ったもののように見える。これはまさに、異なる座標をpijで重み付けした、二つのベクトル𝐯,𝐰の間の角度のコサインの式である。
cos⁡(θ)=𝐯⋅𝐰∥𝐯∥∥𝐰∥=∑iviwi∑ivi2∑iwi2.(22.6.51)
Indeed if we think of norms as being related to standard deviations, and correlations as being cosines of angles, much of the intuition we have from geometry can be applied to thinking about random variables.
英語のヒント
実際、ノルムを標準偏差に関係するもの、相関を角度のコサインと考えれば、幾何学から得られる直観の多くを確率変数について考えるのに応用できる。