maxframe.tensor.random.gumbel#

maxframe.tensor.random.gumbel(loc=0.0, scale=1.0, size=None, chunk_size=None, gpu=None, dtype=None)[源代码]#

从 Gumbel 分布中抽取样本。

从具有指定位置和尺度参数的 Gumbel 分布中抽取样本。有关 Gumbel 分布的更多信息,请参见下面的说明和参考文献。

参数:
  • loc (float or array_like of floats, optional) -- 分布众数的位置。默认值为 0。

  • scale (float or array_like of floats, optional) -- 分布的尺度参数。默认值为 1。

  • size (int or tuple of ints, optional) -- 输出形状。如果给定形状,例如 (m, n, k),则抽取 m * n * k 个样本。如果 size 为 None``(默认),并且 ``locscale 都是标量,则返回单个值。否则抽取 np.broadcast(loc, scale).size 个样本。

  • chunk_size (int or tuple of int or tuple of ints, optional) -- 每一维度上期望的分块大小

  • gpu (bool, optional) -- 如果为 True,则在 GPU 上分配张量,默认为 False

  • dtype (data-type, optional) -- 返回张量的数据类型。

返回:

out -- 从参数化的 Gumbel 分布中抽取的样本。

返回类型:

Tensor or scalar

备注

Gumbel(或最小极值(SEV)或最小极值 I 型)分布是一类用于建模极值问题的广义极值(GEV)分布之一。Gumbel 是来自具有“指数类”尾部分布的最大值的极值 I 型分布的特殊情况。

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\)

引用

示例

从分布中抽取样本:

>>> import maxframe.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()