mars.tensor.random.power#

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

从具有正指数 a - 1 的幂分布中抽取 [0, 1] 之间的样本。

也称为功率函数分布。

Parameters
  • a (floatarray_likefloat) – 分布的参数。应该大于零。

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

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

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

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

Returns

out – 从参数化的幂分布中抽取的样本。

Return type

张量或标量

Raises

ValueError – 如果 a < 1。

备注

概率密度函数是

\[P(x; a) = ax^{a-1}, 0 \le x \le 1, a>0.\]

幂函数分布恰好是帕累托分布的逆。它也可以被视为Beta分布的一个特例。

例如,它用于模拟保险索赔的过度报告。

参考文献

1

Christian Kleiber, Samuel Kotz, “经济学和精算科学中的统计规模分布”, Wiley, 2003.

2

Heckert, N. A. 和 Filliben, James J. “NIST 手册 148: Dataplot 参考手册,第 2 卷:Let 子命令和库 函数”,美国国家标准与技术研究院 手册系列,2003年6月。 http://www.itl.nist.gov/div898/software/dataplot/refman2/auxillar/powpdf.pdf

示例

从分布中抽样:

>>> import mars.tensor as mt
>>> a = 5. # shape
>>> samples = 1000
>>> s = mt.random.power(a, samples)

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

>>> import matplotlib.pyplot as plt
>>> count, bins, ignored = plt.hist(s.execute(), bins=30)
>>> x = mt.linspace(0, 1, 100)
>>> y = a*x**(a-1.)
>>> normed_y = samples*mt.diff(bins)[0]*y
>>> plt.plot(x.execute(), normed_y.execute())
>>> plt.show()

将幂函数分布与帕累托的反函数进行比较。

>>> from scipy import stats
>>> rvs = mt.random.power(5, 1000000)
>>> rvsp = mt.random.pareto(5, 1000000)
>>> xx = mt.linspace(0,1,100)
>>> powpdf = stats.powerlaw.pdf(xx.execute(),5)
>>> plt.figure()
>>> plt.hist(rvs.execute(), bins=50, normed=True)
>>> plt.plot(xx.execute(),powpdf,'r-')
>>> plt.title('np.random.power(5)')
>>> plt.figure()
>>> plt.hist((1./(1.+rvsp)).execute(), bins=50, normed=True)
>>> plt.plot(xx.execute(),powpdf,'r-')
>>> plt.title('inverse of 1 + np.random.pareto(5)')
>>> plt.figure()
>>> plt.hist((1./(1.+rvsp)).execute(), bins=50, normed=True)
>>> plt.plot(xx.execute(),powpdf,'r-')
>>> plt.title('inverse of stats.pareto(5)')