numpy.random.Generator.logseries#

method

random.Generator.logseries(p, size=None)#

从对数级数分布中抽取样本.

样本从具有指定形状参数的对数级数分布中抽取,0 <= p < 1.

参数:
pfloat 或 floats 的类数组对象

分布的形状参数.必须在范围 [0, 1) 内.

sizeint 或 int 的元组,可选.

输出形状.如果给定的形状是例如 (m, n, k) ,则抽取 m * n * k 个样本.如果 size 为 None (默认),如果 p 是标量,则返回单个值.否则,抽取 np.array(p).size 个样本.

返回:
outndarray 或标量

从参数化的对数级数分布中抽取的样本.

参见

scipy.stats.logser

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

注释

对数级数分布的概率质量函数为

\[P(k) = \frac{-p^k}{k \ln(1-p)},\]

其中 p = 概率.

对数级数分布经常用于表示物种的丰富度和出现率,最初由 Fisher,Corbet 和 Williams 在 1943 年提出 [2].它也可以用于建模汽车中看到的人数 [3].

参考

[1]

Buzas, Martin A.; Culver, Stephen J., Understanding regional species diversity through the log series distribution of occurrences: BIODIVERSITY RESEARCH Diversity & Distributions, Volume 5, Number 5, September 1999 , pp. 187-195(9).

[2]

Fisher, R.A,, A.S. Corbet, and C.B. Williams. 1943. The relation between the number of species and the number of individuals in a random sample of an animal population. Journal of Animal Ecology, 12:42-58.

[3]

D. J. Hand, F. Daly, D. Lunn, E. Ostrowski, A Handbook of Small Data Sets, CRC Press, 1994.

[4]

Wikipedia, “Logarithmic distribution”, https://en.wikipedia.org/wiki/Logarithmic_distribution

示例

从分布中抽取样本:

>>> a = .6
>>> rng = np.random.default_rng()
>>> s = rng.logseries(a, 10000)
>>> import matplotlib.pyplot as plt
>>> bins = np.arange(-.5, max(s) + .5 )
>>> count, bins, _ = plt.hist(s, bins=bins, label='Sample count')

# 绘制与分布的对比图

>>> def logseries(k, p):
...     return -p**k/(k*np.log(1-p))
>>> centres = np.arange(1, max(s) + 1)
>>> plt.plot(centres, logseries(centres, a) * s.size, 'r', label='logseries PMF')
>>> plt.legend()
>>> plt.show()
../../../_images/numpy-random-Generator-logseries-1.png