numpy.random.standard_gamma

原文:https://docs.scipy.org/doc/numpy/reference/generated/numpy.random.standard_gamma.html

译者:飞龙 UsyiyiCN

校对:(虚位以待)

numpy.random.standard_gamma(shape, size=None)

从标准Gamma分布绘制样本。

样品从具有指定参数,形状(有时称为“k”)和scale = 1的Gamma分布绘制。

参数:

shape:float

参数,应> 0。

size:int或tuple的整数,可选

输出形状。如果给定形状是例如(m, n, k),则 m * n * k默认值为None,在这种情况下返回单个值。

返回:

samples:ndarray或scalar

绘制样本。

也可以看看

scipy.stats.distributions.gamma
概率密度函数,分布或累积密度函数等。

笔记

Gamma分布的概率密度为

其中k是形状,\theta标度,\Gamma是伽玛函数。

Gamma分布通常用于模拟电子部件故障的时间,并且在Poisson分布式事件之间的等待时间相关的过程中自然出现。

参考文献

[R265]Weisstein,Eric W.“Gamma Distribution。”来自MathWorld-Wolfram Web资源。http://mathworld.wolfram.com/GammaDistribution.html
[R266]维基百科,“Gamma分布”,http://en.wikipedia.org/wiki/Gamma-distribution

例子

从分布绘制样本:

>>> shape, scale = 2., 1. # mean and width
>>> s = np.random.standard_gamma(shape, 1000000)

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

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

源代码pngpdf

../../_images/numpy-random-standard_gamma-1.png