dask.array.random.standard_gamma
dask.array.random.standard_gamma¶
- dask.array.random.standard_gamma(*args, **kwargs)¶
从标准Gamma分布中抽取样本。
此文档字符串是从 numpy.random.mtrand.RandomState.standard_gamma 复制的。
Dask 版本可能存在一些不一致性。
样本是从具有指定参数的伽玛分布中抽取的,形状(有时指定为“k”)和尺度=1。
备注
新代码应使用 ~numpy.random.Generator 实例的 ~numpy.random.Generator.standard_gamma 方法;请参阅 Quick start。
- 参数
- 形状浮点数或浮点数的类数组对象
参数,必须为非负数。
- 大小int 或 int 的元组,可选
输出形状。如果给定的形状是,例如,
(m, n, k),那么会抽取m * n * k个样本。如果大小是None``(默认),当 ``shape是标量时,返回单个值。否则,会抽取np.array(shape).size个样本。
- 返回
- 出ndarray 或标量
从参数化的标准伽马分布中抽取样本。
参见
scipy.stats.gamma概率密度函数、分布或累积密度函数等。
random.Generator.standard_gamma应用于新代码。
注释
Gamma 分布的概率密度为
\[p(x) = x^{k-1}\frac{e^{-x/\theta}}{\theta^k\Gamma(k)},\]其中 \(k\) 是形状参数,\(\theta\) 是尺度参数,而 \(\Gamma\) 是伽马函数。
伽马分布常用于建模电子元件的故障时间,并且在泊松分布事件之间的等待时间相关的进程中自然出现。
参考文献
- 1
Weisstein, Eric W. “伽玛分布” 来自 MathWorld–A Wolfram Web 资源。 https://mathworld.wolfram.com/GammaDistribution.html
- 2
维基百科,“伽马分布”,https://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, density=True) >>> y = bins**(shape-1) * ((np.exp(-bins/scale))/ ... (sps.gamma(shape) * scale**shape)) >>> plt.plot(bins, y, linewidth=2, color='r') >>> plt.show()