maxframe.tensor.random.standard_gamma#
- maxframe.tensor.random.standard_gamma(shape, size=None, chunk_size=None, gpu=None, dtype=None)[源代码]#
从标准伽马分布中抽取样本。
样本是从具有指定参数的伽马分布中抽取的,形状参数(有时称为 "k")和尺度为 1。
- 参数:
shape (float or array_like of floats) -- 参数,应大于 0。
size (int or tuple of ints, optional) -- 输出形状。如果给定的形状是例如
(m, n, k),那么会抽取m * n * k个样本。如果 size 是None``(默认值),当 ``shape是标量时返回单个值。否则,抽取mt.array(shape).size个样本。chunk_size (int or tuple of int or tuple of ints, optional) -- 每个维度上期望的分块大小
gpu (bool, optional) -- 如果为 True,则将张量分配在 GPU 上,默认为 False
dtype (data-type, optional) -- 返回张量的数据类型。
- 返回:
out -- 从参数化的标准伽马分布中抽取的样本。
- 返回类型:
Tensor or scalar
参见
scipy.stats.gamma概率密度函数、分布或累积密度函数等。
备注
伽马分布的概率密度为
\[p(x) = x^{k-1}\frac{e^{-x/\theta}}{\theta^k\Gamma(k)},\]其中 \(k\) 是形状参数,\(\theta\) 是尺度参数,\(\Gamma\) 是伽马函数。
伽马分布常用于模拟电子元件的失效时间,并且在泊松分布事件之间等待时间相关的自然过程中出现。
引用
示例
从分布中抽取样本:
>>> import maxframe.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()