第22章付録:深層学習のための数学
22.8.1. Bernoulli22.8.1 ベルヌーイ分布
This is the simplest random variable usually encountered. This random variable encodes a coin flip which comes up with probability and with probability . If we have a random variable with this distribution, we will write
英語のヒント
これはふつう出会う最も単純な確率変数である。この確率変数は、確率で、確率でが出るコイン投げを表す。この分布に従う確率変数があるとき、次のように書く。
(22.8.1)
The cumulative distribution function is
英語のヒント
累積分布関数は次のとおりである。
(22.8.2)
The probability mass function is plotted below.
英語のヒント
確率質量関数を以下にプロットする。
p = 0.3
d2l.set_figsize()
d2l.plt.stem([0, 1], [1 - p, p], use_line_collection=True)
d2l.plt.xlabel('x')
d2l.plt.ylabel('p.m.f.')
d2l.plt.show()x = torch.arange(-1, 2, 0.01)
def F(x):
return 0 if x < 0 else 1 if x > 1 else 1 - p
d2l.plot(x, torch.tensor([F(y) for y in x]), 'x', 'c.d.f.')If , then:
英語のヒント
なら、次が成り立つ。
We can sample an array of arbitrary shape from a Bernoulli random variable as follows.
英語のヒント
ベルヌーイ確率変数から、任意の形の配列を次のように抽出できる。
1*(torch.rand(10, 10) < p)tensor([[0, 1, 0, 0, 1, 0, 0, 0, 0, 0],
[0, 1, 0, 0, 0, 0, 1, 0, 0, 0],
[0, 1, 0, 0, 1, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 1, 0, 0, 1, 0, 0, 1],
[0, 0, 0, 0, 0, 0, 1, 1, 0, 0],
[1, 1, 0, 0, 1, 1, 1, 1, 1, 0],
[1, 0, 0, 0, 1, 0, 1, 1, 0, 0],
[0, 0, 0, 0, 1, 0, 0, 0, 0, 0],
[1, 0, 1, 1, 1, 1, 0, 1, 0, 0]])