mars.tensor.random.standard_gamma#

mars.tensor.random.standard_gamma(shape, size=None, chunk_size=None, gpu=None, dtype=None)[来源]#

从标准伽马分布中抽取样本。

样本是从指定参数的伽玛分布中抽取的,形状(有时称为“k”)和尺度=1。

Parameters
  • shape (floatarray_like浮点数) – 参数,应该大于 > 0。

  • size (inttupleints, 可选) – 输出形状。如果给定的形状是,例如,(m, n, k),那么 m * n * k 个样本将被提取。如果 size 是 None (默认), 如果 shape 是标量,则返回单个值。否则, mt.array(shape).size 个样本将被提取。

  • chunk_size (inttupleinttupleints, 可选) – 每个维度上所需的块大小

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

  • dtype (数据类型, 可选) – 返回的张量的数据类型。

Returns

out – 从参数化的标准伽马分布中抽取的样本。

Return type

张量或标量

另请参阅

scipy.stats.gamma

概率密度函数,分布或累积分布函数等。

备注

伽马分布的概率密度为

\[p(x) = x^{k-1}\frac{e^{-x/\theta}}{\theta^k\Gamma(k)},\]

其中 \(k\) 是形状参数,\(\theta\) 是尺度参数,\(\Gamma\) 是伽马函数。

伽马分布常用于建模电子元件的故障时间,并在与泊松分布事件之间的等待时间相关的过程中自然出现。

参考文献

1

韦斯坦,埃里克 W. “伽马分布。”来自 MathWorld–A Wolfram 网络资源。 http://mathworld.wolfram.com/GammaDistribution.html

2

维基百科,“伽马分布”, http://en.wikipedia.org/wiki/Gamma_distribution

示例

从分布中抽样:

>>> import mars.tensor as mt
>>> shape, scale = 2., 1. # mean and width
>>> s = mt.random.standard_gamma(shape, 1000000)

显示样本的直方图,以及概率密度函数:

>>> import matplotlib.pyplot as plt
>>> import scipy.special as sps
>>> count, bins, ignored = plt.hist(s.execute(), 50, normed=True)
>>> y = bins**(shape-1) * ((mt.exp(-bins/scale))/ \
...                       (sps.gamma(shape) * scale**shape))
>>> plt.plot(bins, y.execute(), linewidth=2, color='r')
>>> plt.show()