プリンキピア

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

22.8.3. Continuous Uniform22.8.3 連続一様分布

Next, let’s discuss the continuous uniform distribution. The idea behind this random variable is that if we increase the n in the discrete uniform distribution, and then scale it to fit within the interval [a,b], we will approach a continuous random variable that just picks an arbitrary value in [a,b] all with equal probability. We will denote this distribution as
英語のヒント
次に、連続一様分布を論じよう。この確率変数の背後にある考えは、離散一様分布のnを増やし、それを区間[a,b]に収まるように尺度を変えると、[a,b]の中の任意の値をすべて等しい確率で選ぶだけの連続確率変数に近づくというものである。この分布を次のように表す。
X∼U(a,b).(22.8.5)
The probability density function is
英語のヒント
確率密度関数は次のとおりである。
p(x)={1b−ax∈[a,b],0x∉[a,b].(22.8.6)
The cumulative distribution function is
英語のヒント
累積分布関数は次のとおりである。
F(x)={0x<a,x−ab−ax∈[a,b],1x>=b.(22.8.7)
Let’s first plot the probability density function (22.8.6).
英語のヒント
まず、確率密度関数(式(22.8.6))をプロットしよう。
a, b = 1, 3

x = torch.arange(0, 4, 0.01)
p = (x > a).type(torch.float32)*(x < b).type(torch.float32)/(b-a)
d2l.plot(x, p, 'x', 'p.d.f.')
Now, let’s plot the cumulative distribution function (22.8.7).
英語のヒント
では、累積分布関数(式(22.8.7))をプロットしよう。
def F(x):
    return 0 if x < a else 1 if x > b else (x - a) / (b - a)

d2l.plot(x, torch.tensor([F(y) for y in x]), 'x', 'c.d.f.')
If X∼U(a,b), then:
英語のヒント
X∼U(a,b)なら、次が成り立つ。
  • μX=a+b2,
  • σX2=(b−a)212.
We can sample an array of arbitrary shape from a uniform random variable as follows. Note that it by default samples from a U(0,1), so if we want a different range we need to scale it.
英語のヒント
一様分布の確率変数から、任意の形の配列を次のように抽出できる。既定ではU(0,1)から抽出するので、別の範囲が欲しいなら尺度を変える必要があることに注意しよう。
(b - a) * torch.rand(10, 10) + a
tensor([[2.4857, 2.2461, 1.6809, 2.7434, 2.7072, 2.6190, 1.4883, 1.2517, 1.3454,
         2.4754],
        [1.0974, 1.5680, 1.8788, 2.8231, 2.1695, 2.6461, 1.4914, 1.4887, 1.3860,
         1.9090],
        [1.3746, 1.7773, 1.2412, 1.1950, 2.7281, 2.8356, 1.2266, 2.4724, 2.4641,
         2.8991],
        [2.4018, 2.6727, 1.0308, 1.1951, 1.9390, 1.6486, 2.8314, 1.1025, 1.3354,
         1.0130],
        [1.1281, 1.8000, 2.3788, 2.6580, 1.6750, 2.2081, 1.2705, 1.0757, 2.3311,
         2.6557],
        [2.9912, 1.2263, 1.8115, 1.5940, 1.9321, 1.6469, 2.2990, 2.1473, 1.8165,
         1.2806],
        [1.1672, 1.1536, 1.9649, 2.1655, 1.7170, 1.0284, 1.3305, 2.1904, 1.4036,
         2.1958],
        [2.5891, 2.5840, 2.2679, 2.0687, 2.9249, 1.6741, 1.2238, 2.4463, 2.2235,
         2.7038],
        [1.8697, 2.4965, 1.5785, 2.7890, 2.3319, 2.1434, 2.3333, 1.0286, 1.9245,
         1.7640],
        [1.2504, 1.7558, 1.4322, 1.5226, 1.3380, 1.1388, 1.8707, 2.2330, 2.3818,
         2.2087]])