【问题标题】:How to calculate the poisson random variable probability in scipy?如何计算scipy中的泊松随机变量概率?
【发布时间】:2019-05-14 22:06:58
【问题描述】:

我想使用 scipy 计算 sum(e λi/i!) 其中i=197,..., ∞ and λ=421.41

我浏览了scipy.stats.poisson 的scipy 文档,可以在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)。但是,我不太确定我是否选择了正确的方法。请让我知道你的想法。

如果需要,我很乐意提供更多详细信息。

【问题讨论】:

    标签: numpy scipy


    【解决方案1】:

    指数因子 (e-λ λi/i!) 是泊松分布的概率密度(质量)函数,而 sum 是累积概率(分布)函数。方法分别对应.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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-29
      • 1970-01-01
      • 2012-03-15
      • 2011-06-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多