第22章付録:深層学習のための数学
22.8.6. Gaussian22.8.6 ガウス分布
Now Let’s try a different, but related experiment. Let’s say we again are performing independent measurements . The distribution of the sum of these is . Rather than taking a limit as increases and decreases, Let’s fix , and then send . In this case and , so there is no reason to think this limit should be well defined.
英語のヒント
では、別の、しかし関係のある実験をしてみよう。再び、回の独立なの測定を行っているとする。これらの和の分布はである。を増やしてを減らす極限をとる代わりに、を固定してとしよう。この場合かつなので、この極限がきちんと定義されると考える理由はない。
However, not all hope is lost! Let’s just make the mean and variance be well behaved by defining
英語のヒント
しかし、望みがすべて失われたわけではない。次のように定義して、平均と分散の性質をよくしよう。
(22.8.15)
This can be seen to have mean zero and variance one, and so it is plausible to believe that it will converge to some limiting distribution. If we plot what these distributions look like, we will become even more convinced that it will work.
英語のヒント
これは平均0、分散1をもつことがわかるので、何らかの極限分布に収束すると信じるのはもっともらしい。これらの分布がどう見えるかをプロットすると、うまくいくことをさらに確信できる。
p = 0.2
ns = [1, 10, 100, 1000]
d2l.plt.figure(figsize=(10, 3))
for i in range(4):
n = ns[i]
pmf = torch.tensor([p**i * (1-p)**(n-i) * binom(n, i)
for i in range(n + 1)])
d2l.plt.subplot(1, 4, i + 1)
d2l.plt.stem([(i - n*p)/torch.sqrt(torch.tensor(n*p*(1 - p)))
for i in range(n + 1)], pmf,
use_line_collection=True)
d2l.plt.xlim([-4, 4])
d2l.plt.xlabel('x')
d2l.plt.ylabel('p.m.f.')
d2l.plt.title("n = {}".format(n))
d2l.plt.show()One thing to note: compared to the Poisson case, we are now dividing by the standard deviation which means that we are squeezing the possible outcomes into smaller and smaller areas. This is an indication that our limit will no longer be discrete, but rather continuous.
英語のヒント
注意すべきことが一つある。ポアソン分布の場合と比べて、今度は標準偏差で割っているので、ありうる結果をどんどん小さな領域に押し込んでいることになる。これは、極限がもはや離散ではなく連続になることのしるしである。
A derivation of what occurs is beyond the scope of this document, but the central limit theorem states that as , this will yield the Gaussian Distribution (or sometimes normal distribution). More explicitly, for any :
英語のヒント
何が起きるかの導出はこの文書の範囲を超えるが、中心極限定理は、とすると、これがガウス分布(あるいは正規分布とも呼ばれる)を生むと述べている。もっと明示的には、任意のについて次が成り立つ。
(22.8.16)
where we say a random variable is normally distributed with given mean and variance , written if has density
英語のヒント
ここで、確率変数が次の密度をもつとき、その確率変数は与えられた平均と分散で正規分布に従うといい、と書く。
(22.8.17)
mu, sigma = 0, 1
x = torch.arange(-3, 3, 0.01)
p = 1 / torch.sqrt(2 * torch.pi * sigma**2) * torch.exp(
-(x - mu)**2 / (2 * sigma**2))
d2l.plot(x, p, 'x', 'p.d.f.')Now, let’s plot the cumulative distribution function. It is beyond the scope of this appendix, but the Gaussian c.d.f. does not have a closed-form formula in terms of more elementary functions. We will use
erf which provides a way to compute this integral numerically.英語のヒント
では、累積分布関数をプロットしよう。この付録の範囲を超えるが、ガウス分布のc.d.f.は、もっと初等的な関数による閉じた形の式をもたない。この積分を数値的に計算する方法を与える
erfを使う。def phi(x):
return (1.0 + erf((x - mu) / (sigma * torch.sqrt(torch.tensor(2.))))) / 2.0
d2l.plot(x, torch.tensor([phi(y) for y in x.tolist()]), 'x', 'c.d.f.')Keen-eyed readers will recognize some of these terms. Indeed, we encountered this integral in Section 22.5. Indeed we need exactly that computation to see that this has total area one and is thus a valid density.
英語のヒント
目ざとい読者は、これらの項のいくつかに気づくだろう。実際、この積分には22.5節で出会った。実際、このの全面積が1であり、したがって有効な密度であることを見るには、まさにその計算が必要である。
Our choice of working with coin flips made computations shorter, but nothing about that choice was fundamental. Indeed, if we take any collection of independent identically distributed random variables , and form
英語のヒント
コイン投げを扱うことにしたので計算が短くなったが、その選択に本質的なことは何もなかった。実際、独立で同一の分布に従う確率変数の任意の集まりをとり、次を作ると、
(22.8.18)
Then
英語のヒント
次は、
(22.8.19)
will be approximately Gaussian. There are additional requirements needed to make it work, most commonly , but the philosophy is clear.
英語のヒント
近似的にガウス分布になる。うまくいくためには追加の条件が必要で、最もよくあるのはだが、考え方ははっきりしている。
The central limit theorem is the reason why the Gaussian is fundamental to probability, statistics, and machine learning. Whenever we can say that something we measured is a sum of many small independent contributions, we can assume that the thing being measured will be close to Gaussian.
英語のヒント
中心極限定理こそ、ガウス分布が確率、統計学、機械学習にとって基本的である理由である。測ったものが多くの小さな独立な寄与の和であると言えるときはいつでも、測られているものはガウス分布に近いと仮定できる。
There are many more fascinating properties of Gaussians, and we would like to discuss one more here. The Gaussian is what is known as a maximum entropy distribution. We will get into entropy more deeply in Section 22.11, however all we need to know at this point is that it is a measure of randomness. In a rigorous mathematical sense, we can think of the Gaussian as the most random choice of random variable with fixed mean and variance. Thus, if we know that our random variable has some mean and variance, the Gaussian is in a sense the most conservative choice of distribution we can make.
英語のヒント
ガウス分布には魅力的な性質がほかにもたくさんあり、ここでもう一つ論じたい。ガウス分布は、最大エントロピー分布として知られるものである。エントロピーには22.11節でもっと深く入るが、この時点で知っておく必要があるのは、それがランダムさの尺度だということだけである。厳密な数学的な意味で、ガウス分布は、平均と分散が固定された確率変数の中で最もランダムな選択だと考えられる。したがって、確率変数がある平均と分散をもつとわかっているなら、ガウス分布はある意味で選べる最も保守的な分布である。
To close the section, let’s recall that if , then:
英語のヒント
節を締めくくるため、なら次が成り立つことを思い出そう。
We can sample from the Gaussian (or standard normal) distribution as shown below.
英語のヒント
ガウス分布(あるいは標準正規分布)からは、以下のように抽出できる。
torch.normal(mu, sigma, size=(10, 10))tensor([[ 1.3588, 0.0473, -1.5805, -0.0108, 0.4253, 0.7924, -0.6547, 0.7313,
-0.3038, 1.1935],
[ 0.0089, 0.8951, 1.0055, 0.0956, -1.1109, -0.6342, 1.6772, 1.0314,
0.3819, -1.7822],
[-0.0604, -1.0318, 0.9113, 1.3118, -1.8370, -0.9023, 1.0365, 0.9052,
-0.6411, -0.8949],
[-0.1713, -0.2347, 0.0767, -0.6375, -0.4612, -1.6875, -0.1570, 1.0591,
0.8377, 0.5097],
[ 0.2762, -0.6213, -0.3422, 0.9449, -0.7544, -0.2150, 1.0240, 1.0253,
-0.9182, 1.1536],
[ 0.0614, 0.2758, -0.3610, -1.0577, -0.5513, -0.9158, 0.7539, 0.9204,
-0.5908, 0.9113],
[ 1.6190, -0.9213, -0.7944, -2.2621, 0.5826, -1.8287, 1.4097, -0.5744,
-0.0668, 1.2074],
[-0.0624, 0.1928, 1.3002, 0.6756, 1.1590, 1.0144, 1.1840, -0.5010,
0.6026, -0.7722],
[-2.0148, 0.6958, 0.9940, 0.8477, 1.0957, -0.5253, 0.2353, -0.2663,
1.2275, 0.5993],
[ 0.4651, -0.8218, -0.5441, -2.0338, -0.6930, -0.0674, -0.4448, -0.8397,
0.0360, -0.7089]])