第22章付録:深層学習のための数学
22.8.2. Discrete Uniform22.8.2 離散一様分布
The next commonly encountered random variable is a discrete uniform. For our discussion here, we will assume that it is supported on the integers , however any other set of values can be freely chosen. The meaning of the word uniform in this context is that every possible value is equally likely. The probability for each value is . We will denote a random variable with this distribution as
英語のヒント
次によく出会う確率変数は離散一様分布である。ここでの議論のため、これは整数の上に台をもつと仮定するが、ほかのどんな値の集合を自由に選んでもよい。この文脈での一様という語の意味は、ありうる値がどれも同じくらい起こりやすいということである。各値の確率はである。この分布に従う確率変数を次のように表す。
(22.8.3)
The cumulative distribution function is
英語のヒント
累積分布関数は次のとおりである。
(22.8.4)
Let’s first plot the probability mass function.
英語のヒント
まず、確率質量関数をプロットしよう。
n = 5
d2l.plt.stem([i+1 for i in range(n)], n*[1 / n], use_line_collection=True)
d2l.plt.xlabel('x')
d2l.plt.ylabel('p.m.f.')
d2l.plt.show()x = torch.arange(-1, 6, 0.01)
def F(x):
return 0 if x < 1 else 1 if x > n else torch.floor(x) / n
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 discrete uniform random variable as follows.
英語のヒント
離散一様分布の確率変数から、任意の形の配列を次のように抽出できる。
torch.randint(1, n, size=(10, 10))tensor([[1, 4, 3, 2, 1, 1, 3, 1, 1, 4],
[4, 1, 1, 4, 4, 1, 4, 3, 2, 4],
[2, 4, 4, 1, 4, 2, 4, 3, 2, 1],
[1, 2, 3, 1, 1, 4, 2, 4, 1, 3],
[1, 2, 4, 1, 4, 3, 3, 2, 2, 1],
[1, 2, 2, 4, 1, 3, 2, 4, 2, 3],
[1, 2, 3, 4, 1, 3, 4, 1, 4, 3],
[3, 1, 1, 4, 4, 1, 3, 1, 1, 2],
[2, 2, 4, 3, 4, 2, 3, 4, 2, 4],
[1, 4, 3, 3, 2, 3, 3, 4, 1, 3]])