numpy.random.RandomState.logseries#

方法

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

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

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

注意

新代码应使用 Generator 实例的 logseries 方法;请参阅 快速入门

参数:
p浮点数或类数组的浮点数

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

sizeint 或 int 的元组,可选

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

返回:
outndarray 或标量

从参数化的对数系列分布中抽取的样本。

另请参阅

scipy.stats.logser

概率密度函数、分布或累积密度函数等。

random.Generator.logseries

新代码应使用此方法。

备注

对数系列分布的概率密度为

\[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
>>> s = np.random.logseries(a, 10000)
>>> import matplotlib.pyplot as plt
>>> count, bins, ignored = plt.hist(s)

# 与分布绘制

>>> def logseries(k, p):
...     return -p**k/(k*np.log(1-p))
>>> plt.plot(bins, logseries(bins, a)*count.max()/
...          logseries(bins, a).max(), 'r')
>>> plt.show()
../../../_images/numpy-random-RandomState-logseries-1.png