numpy.random.gumbel#
- random.gumbel(loc=0.0, scale=1.0, size=None)#
从 Gumbel 分布中抽取样本。
从具有指定位置和尺度的 Gumbel 分布中抽取样本。有关 Gumbel 分布的更多信息,请参阅下面的“注释”和“参考文献”。
- 参数:
- loc浮点数或浮点数数组,可选
分布众数的位置。默认值为 0。
- scale浮点数或浮点数数组,可选
分布的尺度参数。默认值为 1。必须为非负数。
- size整数或整数元组,可选
输出形状。如果给定的形状是例如
(m, n, k)
,则会抽取m * n * k
个样本。如果 size 为None
(默认),则当loc
和scale
均为标量时,返回单个值。否则,抽取np.broadcast(loc, scale).size
个样本。
- 返回:
- outndarray 或标量
从参数化的 Gumbel 分布中抽取的样本。
另请参阅
注释
Gumbel(或最小极值 (SEV) 或第一类最小极值)分布是广义极值 (GEV) 分布中的一类,用于建模极值问题。Gumbel 分布是来自具有“指数型”尾部的分布的最大值的第一类极值分布的特例。
Gumbel 分布的概率密度为
\[p(x) = \frac{e^{-(x - \mu)/ \beta}}{\beta} e^{ -e^{-(x - \mu)/ \beta}},\]其中 \(\mu\) 是众数(一个位置参数),\(\beta\) 是尺度参数。
Gumbel 分布(以德国数学家 Emil Julius Gumbel 命名)很早就应用于水文学文献中,用于模拟洪水事件的发生。它也用于模拟最大风速和降雨量。它是一种“肥尾”分布——分布尾部事件的概率比使用高斯分布时要大,因此百年一遇的洪水事件发生频率出人意料地高。洪水最初被建模为高斯过程,但这低估了极端事件的频率。
它是极值分布中的一类,即广义极值 (GEV) 分布,其中还包括 Weibull 和 Frechet 分布。
该函数的均值为 \(\mu + 0.57721\beta\),方差为 \(\frac{\pi^2}{6}\beta^2\)。
参考文献
[1]Gumbel, E. J., “Statistics of Extremes,” New York: Columbia University Press, 1958.
[2]Reiss, R.-D. and Thomas, M., “Statistical Analysis of Extreme Values from Insurance, Finance, Hydrology and Other Fields,” Basel: Birkhauser Verlag, 2001.
示例
从分布中抽取样本
>>> mu, beta = 0, 0.1 # location and scale >>> s = np.random.gumbel(mu, beta, 1000)
显示样本的直方图以及概率密度函数
>>> import matplotlib.pyplot as plt >>> count, bins, ignored = plt.hist(s, 30, density=True) >>> plt.plot(bins, (1/beta)*np.exp(-(bins - mu)/beta) ... * np.exp( -np.exp( -(bins - mu) /beta) ), ... linewidth=2, color='r') >>> plt.show()
展示极值分布如何从高斯过程中产生并与高斯分布进行比较
>>> means = [] >>> maxima = [] >>> for i in range(0,1000) : ... a = np.random.normal(mu, beta, 1000) ... means.append(a.mean()) ... maxima.append(a.max()) >>> count, bins, ignored = plt.hist(maxima, 30, density=True) >>> beta = np.std(maxima) * np.sqrt(6) / np.pi >>> mu = np.mean(maxima) - 0.57721*beta >>> plt.plot(bins, (1/beta)*np.exp(-(bins - mu)/beta) ... * np.exp(-np.exp(-(bins - mu)/beta)), ... linewidth=2, color='r') >>> plt.plot(bins, 1/(beta * np.sqrt(2 * np.pi)) ... * np.exp(-(bins - mu)**2 / (2 * beta**2)), ... linewidth=2, color='g') >>> plt.show()