numpy.random.Generator.logseries#
方法
- random.Generator.logseries(p, size=None)#
从对数序列分布中抽取样本。
样本从具有指定形状参数(0 <=
p
< 1)的对数序列分布中抽取。- 参数:
- p浮点数或浮点数数组
分布的形状参数。必须在 [0, 1) 范围内。
- size整数或整数元组,可选
输出形状。如果给定的形状是,例如,
(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()