mars.tensor.random.gumbel#
- mars.tensor.random.gumbel(loc=0.0, scale=1.0, size=None, chunk_size=None, gpu=None, dtype=None)[来源]#
从Gumbel分布中抽样。
从具有指定位置和尺度的Gumbel分布中抽取样本。有关Gumbel分布的更多信息,请参阅下面的备注和参考。
- Parameters
loc (float 或者 类似数组的 float, 可选) – 分布的众数的位置。默认值为 0。
scale (float 或 array_like 的 浮点数, 可选) – 分布的规模参数。默认值为 1。
size (int 或 tuple 的 ints, 可选) – 输出形状。 如果给定的形状是,例如,
(m, n, k),那么m * n * k个样本被抽取。如果 size 是None(默认), 如果loc和scale都是标量,则返回单个值。 否则,np.broadcast(loc, scale).size个样本被抽取。chunk_size (int 或 tuple 的 int 或 tuple 的 ints, 可选) – 每个维度上所需的块大小
gpu (bool, 可选) – 如果为True,则在GPU上分配张量,默认为False
dtype (数据类型, 可选) – 返回的张量的数据类型。
- Returns
out – 从参数化的Gumbel分布中抽取的样本。
- Return type
张量或标量
备注
Gumbel(或最小极值(SEV)或最小极值类型 I)分布是一类广义极值(GEV)分布中的一种,用于建模极值问题。Gumbel 是极值类型 I 分布的一个特例,用于来自具有“指数类”尾部的分布的最大值。
Gumbel分布的概率密度为
\[p(x) = \frac{e^{-(x - \mu)/ \beta}}{\beta} e^{ -e^{-(x - \mu)/ \beta}},\]其中 \(\mu\) 是众数,位置参数,以及\(\beta\) 是尺度参数。
甘布尔分布(以德国数学家埃米尔·尤利乌斯·甘布尔命名)在水文学文献中很早就被使用,用于建模洪水事件的发生。它也用于建模最大风速和降雨率。它是一种“肥尾”分布 - 分布尾部事件的概率比使用高斯分布要大,因此出现100年洪水的频率令人惊讶。洪水最初被建模为高斯过程,这低估了极端事件的频率。
它是一个极值分布类中的一种,广义极值(GEV)分布, 其中还包括韦布尔和弗雷歇。
该函数的均值为 \(\mu + 0.57721\beta\),方差为 \(\frac{\pi^2}{6}\beta^2\)。
参考文献
- 1
甘贝尔,E. J.,“极值统计”, 纽约:哥伦比亚大学出版社,1958。
- 2
Reiss, R.-D. 和 Thomas, M., “来自保险、金融、水文学和其他领域的极值统计分析,” 巴塞尔:Birkhauser Verlag,2001。
示例
从分布中抽样:
>>> import mars.tensor as mt
>>> mu, beta = 0, 0.1 # location and scale >>> s = mt.random.gumbel(mu, beta, 1000).execute()
显示样本的直方图,以及概率密度函数:
>>> import matplotlib.pyplot as plt >>> import numpy as np >>> count, bins, ignored = plt.hist(s, 30, normed=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 = mt.random.normal(mu, beta, 1000) ... means.append(a.mean().execute()) ... maxima.append(a.max().execute()) >>> count, bins, ignored = plt.hist(maxima, 30, normed=True) >>> beta = mt.std(maxima) * mt.sqrt(6) / mt.pi >>> mu = mt.mean(maxima) - 0.57721*beta >>> plt.plot(bins, ((1/beta)*mt.exp(-(bins - mu)/beta) ... * mt.exp(-mt.exp(-(bins - mu)/beta))).execute(), ... linewidth=2, color='r') >>> plt.plot(bins, (1/(beta * mt.sqrt(2 * mt.pi)) ... * mt.exp(-(bins - mu)**2 / (2 * beta**2))).execute(), ... linewidth=2, color='g') >>> plt.show()