我想计算 sum(e -λλ i / i!),其中i=197,..., ∞ and λ=421.41
使用scipy。
我浏览了scipy.stats.poisson
的科学文档,可以在https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.poisson.html中找到
但是,他们有scipy.stats.poisson
的多种方法,在选择最适合我的方法时有些困惑。
例如
rvs(mu, loc=0, size=1, random_state=None) Random variates.
pmf(k, mu, loc=0) Probability mass function.
logpmf(k, mu, loc=0) Log of the probability mass function.
cdf(k, mu, loc=0) Cumulative distribution function.
logcdf(k, mu, loc=0) Log of the cumulative distribution function.
sf(k, mu, loc=0) Survival function (also defined as 1 - cdf, but sf is sometimes more accurate).
logsf(k, mu, loc=0) Log of the survival function.
ppf(q, mu, loc=0) Percent point function (inverse of cdf — percentiles).
isf(q, mu, loc=0) Inverse survival function (inverse of sf).
stats(mu, loc=0, moments=’mv’) Mean(‘m’), variance(‘v’), skew(‘s’), and/or kurtosis(‘k’).
entropy(mu, loc=0) (Differential) entropy of the RV.
expect(func, args=(mu,), loc=0, lb=None, ub=None, conditional=False) Expected value of a function (of one argument) with respect to the distribution.
median(mu, loc=0) Median of the distribution.
mean(mu, loc=0) Mean of the distribution.
var(mu, loc=0) Variance of the distribution.
std(mu, loc=0) Standard deviation of the distribution.
interval(alpha, mu, loc=0) Endpoints of the range that contains alpha percent of the distribution
当前,我正在使用sf(197, 421.41, loc=0)
。但是,我不确定是否选择了正确的方法。请让我知道您的想法。
很高兴在需要时提供更多详细信息。
答案 0 :(得分:1)
指数因子(e-λλi/ i!)是泊松分布的概率密度(质量)函数,而总和是累积概率(分布)函数。方法分别对应于.pmf
和.cdf
。
示例:
from scipy.stats import poisson
k, mu = 1, 2
print(poisson.pmf(k, mu)) #k, mu
print(np.exp(-mu) * mu**k / np.math.factorial(k))
print(poisson.cdf(k, mu))
print(sum(np.exp(-mu) * mu**j / np.math.factorial(j) for j in range(k + 1)))
>>0.2706705664732254
0.2706705664732254
0.40600584970983794
0.4060058497098381
在您的情况下:
k, mu = 197, 421.41
print(1 - poisson.cdf(k - 1, mu))
请注意,由于数值精度,它将给出1.0