SciPy-1-12-中文文档-四十二-

74 阅读27分钟

SciPy 1.12 中文文档(四十二)

原文:docs.scipy.org/doc/scipy-1.12.0/index.html

scipy.special.btdtr

原文链接:docs.scipy.org/doc/scipy-1.12.0/reference/generated/scipy.special.btdtr.html#scipy.special.btdtr

scipy.special.btdtr(a, b, x, out=None)

beta 分布的累积分布函数。

返回 beta 概率密度函数从零到 x 的积分,

[I = \int_0^x \frac{\Gamma(a + b)}{\Gamma(a)\Gamma(b)} t^{a-1} (1-t)^{b-1},dt]

其中 (\Gamma) 是 gamma 函数。

自 1.12.0 版本起已弃用:此函数已弃用,并将在 SciPy 1.14.0 中移除。请改用 scipy.special.betainc

参数:

aarray_like

形状参数 (a > 0)。

barray_like

形状参数 (b > 0)。

xarray_like

积分的上限,取值范围为 [0, 1]。

outndarray, 可选

用于函数值的可选输出数组

返回:

I标量或 ndarray

beta 分布的累积分布函数,参数为 ab,在 x 处。

另请参阅

betainc

注意事项

此函数与不完全贝塔积分函数 betainc 相同。

Cephes 的包装器 [1] 例程 btdtr

参考文献

[1]

Cephes 数学函数库,www.netlib.org/cephes/

scipy.special.btdtri

原文:docs.scipy.org/doc/scipy-1.12.0/reference/generated/scipy.special.btdtri.html#scipy.special.btdtri

scipy.special.btdtri(a, b, p, out=None)

Beta 分布的第 p 分位数。

此函数是贝塔累积分布函数的反函数,btdtr,返回满足 btdtr(a, b, x) = px 值,或

[p = \int_0^x \frac{\Gamma(a + b)}{\Gamma(a)\Gamma(b)} t^{a-1} (1-t)^{b-1},dt]

自 1.12.0 版本起弃用:此函数已弃用,并将在 SciPy 1.14.0 中移除。请使用 scipy.special.betaincinv 替代。

参数:

a array_like

形状参数(a > 0)。

b array_like

形状参数(b > 0)。

p array_like

累积概率,位于 [0, 1] 区间内。

out ndarray,可选

可选的函数值输出数组

返回:

x 标量或 ndarray

对应于 p 的分位数。

另请参阅

betaincinv

btdtr

注意事项

x 的值通过区间二分或牛顿迭代法找到。

Cephes 的包装器[[1]](#r2c6599992aae-1] 路径 incbi,解决了寻找不完整贝塔积分的反函数等价问题。

参考文献

[1]

Cephes 数学函数库, www.netlib.org/cephes/

scipy.special.btdtria

原文:docs.scipy.org/doc/scipy-1.12.0/reference/generated/scipy.special.btdtria.html#scipy.special.btdtria

scipy.special.btdtria(p, b, x, out=None) = <ufunc 'btdtria'>

a 相关的btdtr的反函数。

这是贝塔累积分布函数btdtr的反函数,作为关于 a 的函数,返回使得 btdtr(a, b, x) = pa 的值,或

[p = \int_0^x \frac{\Gamma(a + b)}{\Gamma(a)\Gamma(b)} t^{a-1} (1-t)^{b-1},dt]

参数:

parray_like

累积概率,在[0, 1]之间。

barray_like

形状参数(b > 0)。

xarray_like

分位数,在[0, 1]之间。

outndarray,可选

用于函数值的可选输出数组

返回:

a标量或 ndarray

形状参数 a 的值,使得 btdtr(a, b, x) = p

另请参阅

btdtr

贝塔分布的累积分布函数。

btdtri

关于 x 的反函数。

btdtrib

关于 b 的反函数。

注意事项

CDFLIB 的 C 语言库的包装器[1] Fortran 例程cdfbet

使用 DiDinato 和 Morris 的例程[2]计算累积分布函数 p。计算 a 包括搜索产生期望 p 值的值的过程。搜索依赖于 pa 的单调性。

参考文献

[1]

Barry Brown, James Lovato 和 Kathy Russell,CDFLIB:用于累积分布函数、反函数和其他参数的 Fortran 例程库。

[2]

DiDinato, A. R.和 Morris, A. H.,算法 708:不完全贝塔函数比的有效数字计算。ACM Trans. Math. Softw. 18 (1993), 360-373。

scipy.special.btdtr

原文:docs.scipy.org/doc/scipy-1.12.0/reference/generated/scipy.special.btdtr.html#scipy.special.btdtr

scipy.special.btdtr(a, b, x, out=None)

贝塔分布的累积分布函数。

返回从零到x的贝塔概率密度函数的积分,

[I = \int_0^x \frac{\Gamma(a + b)}{\Gamma(a)\Gamma(b)} t^{a-1} (1-t)^{b-1},dt]

其中(\Gamma)是伽玛函数。

自 1.12.0 版本起不推荐使用:此函数已被弃用,并将在 SciPy 1.14.0 中删除。请改用scipy.special.betainc

参数:

aarray_like

形状参数(a > 0)。

barray_like

形状参数(b > 0)。

xarray_like

积分的上限,在[0, 1]之间。

outndarray,可选

可选的输出数组,用于函数值

返回:

I标量或 ndarray

贝塔分布的累积分布函数,参数为ab,在x处。

另请参阅

betainc

注意事项

此函数与不完全贝塔积分函数betainc完全相同。

Cephes 的包装器[1]例程btdtr

参考文献

[1]

Cephes 数学函数库,www.netlib.org/cephes/

scipy.special.btdtrib

原文链接:docs.scipy.org/doc/scipy-1.12.0/reference/generated/scipy.special.btdtrib.html#scipy.special.btdtrib

scipy.special.btdtrib(a, p, x, out=None) = <ufunc 'btdtrib'>

相对于 bbtdtr 的逆。

这是 beta 累积分布函数的逆,btdtr 作为 b 的函数,返回使 btdtr(a, b, x) = pb 的值,或者

[p = \int_0^x \frac{\Gamma(a + b)}{\Gamma(a)\Gamma(b)} t^{a-1} (1-t)^{b-1},dt]

参数:

aarray_like

形状参数(a > 0)。

parray_like

累积概率,在 [0, 1] 区间内。

xarray_like

分位数,在 [0, 1] 区间内。

outndarray, optional

可选输出数组用于函数值

返回:

bscalar 或 ndarray

形状参数 b 的值,使得 btdtr(a, b, x) = p

另请参见

btdtr

beta 分布的累积分布函数。

btdtri

相对于 x 的逆。

btdtria

相对于 a 的逆。

注意事项

CDFLIB 的 C 语言库包装器 [1] Fortran routine cdfbet

使用 DiDinato 和 Morris 的例程计算累积分布函数 p [2]。计算 b 涉及搜索产生所需 p 值的值。搜索依赖于 pb 的单调性。

参考资料

[1]

Barry Brown, James Lovato 和 Kathy Russell, CDFLIB: 用于累积分布函数、逆函数和其他参数的 Fortran 例程库。

[2]

DiDinato, A. R. 和 Morris, A. H., Algorithm 708: Incomplete Beta Function Ratios 的有效数字计算。ACM Trans. Math. Softw. 18 (1993), 360-373.

scipy.special.btdtr

原文链接:docs.scipy.org/doc/scipy-1.12.0/reference/generated/scipy.special.btdtr.html#scipy.special.btdtr

scipy.special.btdtr(a, b, x, out=None)

贝塔分布的累积分布函数。

返回从零到x的贝塔概率密度函数的积分,

[I = \int_0^x \frac{\Gamma(a + b)}{\Gamma(a)\Gamma(b)} t^{a-1} (1-t)^{b-1},dt]

其中(\Gamma)是 Gamma 函数。

自 SciPy 1.12.0 版本起弃用:此函数已弃用,将在 SciPy 1.14.0 中移除。请使用scipy.special.betainc代替。

参数:

a类似数组

形状参数(a > 0)。

b类似数组

形状参数(b > 0)。

x类似数组

积分的上限,位于[0, 1]内。

out数组,可选

函数值的可选输出数组

返回:

I标量或类似数组

x处参数为ab的贝塔分布的累积分布函数。

另请参阅

betainc,这是不完全贝塔积分函数的别名。

注释

此函数与不完全贝塔积分函数betainc完全相同。

Cephes 库的包装器[1] btdtr例程。

参考文献

[1]

Cephes 数学函数库,www.netlib.org/cephes/

scipy.special.fdtr

原文链接:docs.scipy.org/doc/scipy-1.12.0/reference/generated/scipy.special.fdtr.html#scipy.special.fdtr

scipy.special.fdtr(dfn, dfd, x, out=None) = <ufunc 'fdtr'>

F 累积分布函数。

返回 F 分布的累积分布函数值,也称为 Snedecor's F 分布或 Fisher-Snedecor 分布。

具有参数(d_n)和(d_d)的 F 分布是随机变量的分布,

[X = \frac{U_n/d_n}{U_d/d_d},]

其中(U_n)和(U_d)是分布为(\chi²)的随机变量,分别具有(d_n)和(d_d)自由度。

参数:

dfnarray_like

第一个参数(正浮点数)。

dfdarray_like

第二个参数(正浮点数)。

xarray_like

参数(非负浮点数)。

输出ndarray,可选

函数值的可选输出数组

返回:

y标量或 ndarray

x处具有参数dfndfd的 F 分布的累积分布函数。

参见

fdtrc

F 分布生存函数

fdtri

F 分布反函数累积分布

scipy.stats.f

F 分布

注意事项

根据公式使用正则化的不完全贝塔函数,

[F(d_n, d_d; x) = I_{xd_n/(d_d + xd_n)}(d_n/2, d_d/2).]

包装器用于 Cephes [1] 程序 fdtr。 F 分布也可作为 scipy.stats.f。 直接调用 fdtr 相比 scipy.stats.fcdf 方法可以提高性能(请参见下面的最后一个示例)。

参考文献

[1]

Cephes 数学函数库,www.netlib.org/cephes/

示例

计算dfn=1dfd=2x=1时的函数。

>>> import numpy as np
>>> from scipy.special import fdtr
>>> fdtr(1, 2, 1)
0.5773502691896258 

通过为x提供一个 NumPy 数组来计算几个点上的函数。

>>> x = np.array([0.5, 2., 3.])
>>> fdtr(1, 2, x)
array([0.4472136 , 0.70710678, 0.77459667]) 

绘制几组参数集的函数图。

>>> import matplotlib.pyplot as plt
>>> dfn_parameters = [1, 5, 10, 50]
>>> dfd_parameters = [1, 1, 2, 3]
>>> linestyles = ['solid', 'dashed', 'dotted', 'dashdot']
>>> parameters_list = list(zip(dfn_parameters, dfd_parameters,
...                            linestyles))
>>> x = np.linspace(0, 30, 1000)
>>> fig, ax = plt.subplots()
>>> for parameter_set in parameters_list:
...     dfn, dfd, style = parameter_set
...     fdtr_vals = fdtr(dfn, dfd, x)
...     ax.plot(x, fdtr_vals, label=rf"$d_n={dfn},\, d_d={dfd}$",
...             ls=style)
>>> ax.legend()
>>> ax.set_xlabel("$x$")
>>> ax.set_title("F distribution cumulative distribution function")
>>> plt.show() 

../../_images/scipy-special-fdtr-1_00_00.png

F 分布也可以作为 scipy.stats.f。 对于小数组或单个值,直接使用 fdtr 可能比调用 scipy.stats.fcdf 方法快得多。 要获得相同的结果,必须使用以下参数化:stats.f(dfn, dfd).cdf(x)=fdtr(dfn, dfd, x)

>>> from scipy.stats import f
>>> dfn, dfd = 1, 2
>>> x = 1
>>> fdtr_res = fdtr(dfn, dfd, x)  # this will often be faster than below
>>> f_dist_res = f(dfn, dfd).cdf(x)
>>> fdtr_res == f_dist_res  # test that results are equal
True 

scipy.special.fdtrc

原文:docs.scipy.org/doc/scipy-1.12.0/reference/generated/scipy.special.fdtrc.html#scipy.special.fdtrc

scipy.special.fdtrc(dfn, dfd, x, out=None) = <ufunc 'fdtrc'>

F 生存函数。

返回补充 F 分布函数(从 x 到无穷的密度积分)。

参数:

dfn array_like

第一个参数(正浮点数)。

dfd array_like

第二个参数(正浮点数)。

x array_like

参数(非负浮点数)。

out ndarray,可选

函数值的可选输出数组

返回:

y 标量或者 ndarray

补充 F 分布函数,带有参数 dfndfdx 处。

另请参阅

fdtr

F 分布的累积分布函数

fdtri

F 分布的逆累积分布函数

scipy.stats.f

F 分布

注意

根据公式使用常规不完全 Beta 函数,

[F(d_n, d_d; x) = I_{d_d/(d_d + xd_n)}(d_d/2, d_n/2).]

Cephes 的包装器[1],使用 Cephes 中的 fdtrc 程序。F 分布也可作为 scipy.stats.f 调用。直接调用 fdtrc 可以提高性能,与 scipy.stats.fsf 方法相比(请参阅下面的最后一个示例)。

参考文献

[1]

Cephes 数学函数库,www.netlib.org/cephes/

示例

计算dfn=1dfd=2x=1时的函数。

>>> import numpy as np
>>> from scipy.special import fdtrc
>>> fdtrc(1, 2, 1)
0.42264973081037427 

通过为 x 提供 NumPy 数组在几个点上计算函数。

>>> x = np.array([0.5, 2., 3.])
>>> fdtrc(1, 2, x)
array([0.5527864 , 0.29289322, 0.22540333]) 

绘制几个参数集的函数。

>>> import matplotlib.pyplot as plt
>>> dfn_parameters = [1, 5, 10, 50]
>>> dfd_parameters = [1, 1, 2, 3]
>>> linestyles = ['solid', 'dashed', 'dotted', 'dashdot']
>>> parameters_list = list(zip(dfn_parameters, dfd_parameters,
...                            linestyles))
>>> x = np.linspace(0, 30, 1000)
>>> fig, ax = plt.subplots()
>>> for parameter_set in parameters_list:
...     dfn, dfd, style = parameter_set
...     fdtrc_vals = fdtrc(dfn, dfd, x)
...     ax.plot(x, fdtrc_vals, label=rf"$d_n={dfn},\, d_d={dfd}$",
...             ls=style)
>>> ax.legend()
>>> ax.set_xlabel("$x$")
>>> ax.set_title("F distribution survival function")
>>> plt.show() 

../../_images/scipy-special-fdtrc-1_00_00.png

F 分布也可作为 scipy.stats.f 调用。直接使用 fdtrc 可比调用 scipy.stats.fsf 方法更快,特别是对于小数组或单个值。为了获得相同的结果,必须使用以下参数化方式:stats.f(dfn, dfd).sf(x)=fdtrc(dfn, dfd, x)

>>> from scipy.stats import f
>>> dfn, dfd = 1, 2
>>> x = 1
>>> fdtrc_res = fdtrc(dfn, dfd, x)  # this will often be faster than below
>>> f_dist_res = f(dfn, dfd).sf(x)
>>> f_dist_res == fdtrc_res  # test that results are equal
True 

scipy.special.fdtri

原文:docs.scipy.org/doc/scipy-1.12.0/reference/generated/scipy.special.fdtri.html#scipy.special.fdtri

scipy.special.fdtri(dfn, dfd, p, out=None) = <ufunc 'fdtri'>

F 分布的p-th 分位数。

该函数是 F 分布 CDF 的逆函数,fdtr,返回x,使得fdtr(dfn, dfd, x) = p

参数:

dfn类似数组

第一个参数(正浮点数)。

dfd类似数组

第二个参数(正浮点数)。

p类似数组

累积概率,在[0, 1]区间内。

out ndarray,可选

函数值的可选输出数组

返回:

x标量或 ndarray

p对应的分位数。

另请参见

fdtr

F 分布累积分布函数

fdtrc

F 分布生存函数

scipy.stats.f

F 分布

注意事项

计算是通过与逆正则化贝塔函数的关系进行的,即(I^{-1}_x(a, b))。令(z = I^{-1}_p(d_d/2, d_n/2))。然后,

[x = \frac{d_d (1 - z)}{d_n z}.]

如果p使得(x < 0.5),则改为使用以下关系以提高稳定性:令(z' = I^{-1}_{1 - p}(d_n/2, d_d/2))。然后,

[x = \frac{d_d z'}{d_n (1 - z')}.]

Cephes 的包装器[1]函数fdtri

F 分布同样可以作为scipy.stats.f获取。直接调用fdtri相比scipy.stats.fppf方法可以提高性能(见下面的最后一个示例)。

参考

[1]

Cephes 数学函数库,www.netlib.org/cephes/

示例

fdtri表示 F 分布 CDF 的逆函数,可以作为fdtr获得。在这里,我们计算df1=1df2=2时在x=3处的 CDF。fdtri然后返回3,给定相同的df1df2和计算的 CDF 值。

>>> import numpy as np
>>> from scipy.special import fdtri, fdtr
>>> df1, df2 = 1, 2
>>> x = 3
>>> cdf_value =  fdtr(df1, df2, x)
>>> fdtri(df1, df2, cdf_value)
3.000000000000006 

通过为x提供一个 NumPy 数组,在几个点上计算函数。

>>> x = np.array([0.1, 0.4, 0.7])
>>> fdtri(1, 2, x)
array([0.02020202, 0.38095238, 1.92156863]) 

绘制几个参数集的函数图。

>>> import matplotlib.pyplot as plt
>>> dfn_parameters = [50, 10, 1, 50]
>>> dfd_parameters = [0.5, 1, 1, 5]
>>> linestyles = ['solid', 'dashed', 'dotted', 'dashdot']
>>> parameters_list = list(zip(dfn_parameters, dfd_parameters,
...                            linestyles))
>>> x = np.linspace(0, 1, 1000)
>>> fig, ax = plt.subplots()
>>> for parameter_set in parameters_list:
...     dfn, dfd, style = parameter_set
...     fdtri_vals = fdtri(dfn, dfd, x)
...     ax.plot(x, fdtri_vals, label=rf"$d_n={dfn},\, d_d={dfd}$",
...             ls=style)
>>> ax.legend()
>>> ax.set_xlabel("$x$")
>>> title = "F distribution inverse cumulative distribution function"
>>> ax.set_title(title)
>>> ax.set_ylim(0, 30)
>>> plt.show() 

../../_images/scipy-special-fdtri-1_00_00.png

F 分布也可以通过 scipy.stats.f 获得。直接使用 fdtri 可比调用 scipy.stats.fppf 方法要快得多,特别是对于小数组或单个值。要获得相同的结果,必须使用以下参数化形式:stats.f(dfn, dfd).ppf(x)=fdtri(dfn, dfd, x)

>>> from scipy.stats import f
>>> dfn, dfd = 1, 2
>>> x = 0.7
>>> fdtri_res = fdtri(dfn, dfd, x)  # this will often be faster than below
>>> f_dist_res = f(dfn, dfd).ppf(x)
>>> f_dist_res == fdtri_res  # test that results are equal
True 

scipy.special.fdtri

原文:docs.scipy.org/doc/scipy-1.12.0/reference/generated/scipy.special.fdtridfd.html#scipy.special.fdtridfd

scipy.special.fdtridfd(dfn, p, x, out=None) = <ufunc 'fdtridfd'>

fdtr 相反的 dfd

找到 F 密度参数 dfd,使得 fdtr(dfn, dfd, x) == p

参数:

dfn 数组样式

第一个参数(正浮点数)。

p 数组样式

累积概率,在 [0, 1] 区间内。

x 数组样式

参数(非负浮点数)。

out ndarray,可选

函数值的可选输出数组

返回:

dfd 标量或 ndarray

dfd,使得 fdtr(dfn, dfd, x) == p

另请参阅

fdtr

F 分布累积分布函数

fdtrc

F 分布生存函数

fdtri

F 分布分位函数

scipy.stats.f

F 分布

示例

计算一个参数集的 F 分布累积分布函数。

>>> from scipy.special import fdtridfd, fdtr
>>> dfn, dfd, x = 10, 5, 2
>>> cdf_value = fdtr(dfn, dfd, x)
>>> cdf_value
0.7700248806501017 

验证 fdtridfd 能够恢复 dfd 的原始值:

>>> fdtridfd(dfn, cdf_value, x)
5.0 

scipy.special.fdtr

原文:docs.scipy.org/doc/scipy-1.12.0/reference/generated/scipy.special.fdtr.html#scipy.special.fdtr

scipy.special.fdtr(dfn, dfd, x, out=None) = <ufunc 'fdtr'>

F 累积分布函数。

返回 F 分布的累积分布函数值,也称为斯内德科尔 F 分布或费舍尔-斯内德科尔分布。

参数 (d_n) 和 (d_d) 的 F 分布是随机变量的分布,

[X = \frac{U_n/d_n}{U_d/d_d},]

其中 (U_n) 和 (U_d) 是分别具有 (d_n) 和 (d_d) 自由度的随机变量 (\chi²) 分布。

参数:

dfn 数组类

第一个参数(正浮点数)。

dfd 数组类

第二个参数(正浮点数)。

x 数组类

参数(非负浮点数)。

out ndarray,可选

可选输出数组用于函数值。

返回:

y 标量或 ndarray

F-分布的累积分布函数,参数为 dfndfd,在 x 处的值。

另请参阅

fdtrc

F 分布的生存函数。

fdtri

F 分布的反累积分布函数。

scipy.stats.f

F 分布

注意

根据以下公式使用正则化不完全贝塔函数,

[F(d_n, d_d; x) = I_{xd_n/(d_d + xd_n)}(d_n/2, d_d/2).]

Cephes 的包装器 [1],用于调用 fdtr 函数。F 分布也可以通过 scipy.stats.f 获得。直接调用 fdtr 可以提高性能,与 scipy.stats.fcdf 方法相比(见下面的最后一个例子)。

参考文献

[1]

Cephes 数学函数库,www.netlib.org/cephes/

示例

计算 dfn=1dfd=2x=1 处的函数值。

>>> import numpy as np
>>> from scipy.special import fdtr
>>> fdtr(1, 2, 1)
0.5773502691896258 

通过提供 NumPy 数组 x 来计算多个点的函数值。

>>> x = np.array([0.5, 2., 3.])
>>> fdtr(1, 2, x)
array([0.4472136 , 0.70710678, 0.77459667]) 

绘制多个参数集的函数。

>>> import matplotlib.pyplot as plt
>>> dfn_parameters = [1, 5, 10, 50]
>>> dfd_parameters = [1, 1, 2, 3]
>>> linestyles = ['solid', 'dashed', 'dotted', 'dashdot']
>>> parameters_list = list(zip(dfn_parameters, dfd_parameters,
...                            linestyles))
>>> x = np.linspace(0, 30, 1000)
>>> fig, ax = plt.subplots()
>>> for parameter_set in parameters_list:
...     dfn, dfd, style = parameter_set
...     fdtr_vals = fdtr(dfn, dfd, x)
...     ax.plot(x, fdtr_vals, label=rf"$d_n={dfn},\, d_d={dfd}$",
...             ls=style)
>>> ax.legend()
>>> ax.set_xlabel("$x$")
>>> ax.set_title("F distribution cumulative distribution function")
>>> plt.show() 

../../_images/scipy-special-fdtr-1_00_00.png

F 分布也可以通过 scipy.stats.f 获得。直接使用 fdtr 比调用 scipy.stats.fcdf 方法更快,特别是对于小数组或单个值。为了获得相同的结果,必须使用以下参数化形式:stats.f(dfn, dfd).cdf(x)=fdtr(dfn, dfd, x)

>>> from scipy.stats import f
>>> dfn, dfd = 1, 2
>>> x = 1
>>> fdtr_res = fdtr(dfn, dfd, x)  # this will often be faster than below
>>> f_dist_res = f(dfn, dfd).cdf(x)
>>> fdtr_res == f_dist_res  # test that results are equal
True 

scipy.special.gdtr

原文链接:docs.scipy.org/doc/scipy-1.12.0/reference/generated/scipy.special.gdtr.html#scipy.special.gdtr

scipy.special.gdtr(a, b, x, out=None) = <ufunc 'gdtr'>

伽马分布的累积分布函数。

返回从零到x的伽马概率密度函数的积分,

[F = \int_0^x \frac{a^b}{\Gamma(b)} t^{b-1} e^{-at},dt,]

其中(\Gamma)为伽马函数。

参数:

a 类型为 array_like

伽马分布的率参数,有时标记为(\beta)(浮点数)。它也是尺度参数(\theta)的倒数。

b 类型为 array_like

伽马分布的形状参数,有时标记为(\alpha)(浮点数)。

x 类型为 array_like

分位数(积分的上限;浮点数)。

out ndarray,可选

可选的输出数组用于函数值

返回:

F标量或者 ndarray

参数为ab的伽马分布的累积分布函数在x处的值。

参见

gdtrc

伽马分布的累积分布的补函数。

scipy.stats.gamma

伽马分布

注意事项

评估使用到不完全伽马积分(正则化伽马函数)的关系。

Cephes 库的包装器[1] gdtr 函数。直接调用gdtr 可以改善性能,与scipy.stats.gammacdf方法相比(见下面的最后一个示例)。

参考文献

[1]

Cephes 数学函数库,www.netlib.org/cephes/

示例

计算a=1b=2x=5处的函数值。

>>> import numpy as np
>>> from scipy.special import gdtr
>>> import matplotlib.pyplot as plt
>>> gdtr(1., 2., 5.)
0.9595723180054873 

通过提供 NumPy 数组x,计算a=1b=2的函数值在几个点上。

>>> xvalues = np.array([1., 2., 3., 4])
>>> gdtr(1., 1., xvalues)
array([0.63212056, 0.86466472, 0.95021293, 0.98168436]) 

gdtr 可以通过提供适合广播的形状的数组来评估不同的参数集合,用于abx。在这里,我们计算三个不同a在四个位置xb=3的函数值,得到一个 3x4 数组。

>>> a = np.array([[0.5], [1.5], [2.5]])
>>> x = np.array([1., 2., 3., 4])
>>> a.shape, x.shape
((3, 1), (4,)) 
>>> gdtr(a, 3., x)
array([[0.01438768, 0.0803014 , 0.19115317, 0.32332358],
 [0.19115317, 0.57680992, 0.82642193, 0.9380312 ],
 [0.45618688, 0.87534798, 0.97974328, 0.9972306 ]]) 

绘制四组不同参数设置下的函数图。

>>> a_parameters = [0.3, 1, 2, 6]
>>> b_parameters = [2, 10, 15, 20]
>>> linestyles = ['solid', 'dashed', 'dotted', 'dashdot']
>>> parameters_list = list(zip(a_parameters, b_parameters, linestyles))
>>> x = np.linspace(0, 30, 1000)
>>> fig, ax = plt.subplots()
>>> for parameter_set in parameters_list:
...     a, b, style = parameter_set
...     gdtr_vals = gdtr(a, b, x)
...     ax.plot(x, gdtr_vals, label=f"$a= {a},\, b={b}$", ls=style)
>>> ax.legend()
>>> ax.set_xlabel("$x$")
>>> ax.set_title("Gamma distribution cumulative distribution function")
>>> plt.show() 

../../_images/scipy-special-gdtr-1_00_00.png

伽马分布也可以使用scipy.stats.gamma 获得。直接使用gdtr 比调用scipy.stats.gammacdf方法要快得多,特别是对于小数组或单个值。要获得相同的结果,必须使用以下参数化方法:stats.gamma(b, scale=1/a).cdf(x)=gdtr(a, b, x)

>>> from scipy.stats import gamma
>>> a = 2.
>>> b = 3
>>> x = 1.
>>> gdtr_result = gdtr(a, b, x)  # this will often be faster than below
>>> gamma_dist_result = gamma(b, scale=1/a).cdf(x)
>>> gdtr_result == gamma_dist_result  # test that results are equal
True 

scipy.special.gdtrc

原文链接:docs.scipy.org/doc/scipy-1.12.0/reference/generated/scipy.special.gdtrc.html#scipy.special.gdtrc

scipy.special.gdtrc(a, b, x, out=None) = <ufunc 'gdtrc'>

Gamma 分布生存函数。

gamma 概率密度函数的从 x 到无穷大的积分,

[F = \int_x^\infty \frac{a^b}{\Gamma(b)} t^{b-1} e^{-at},dt,]

这里 (\Gamma) 是 gamma 函数。

参数:

aarray_like

gamma 分布的率参数,有时表示为 (\beta)(float)。它也是尺度参数 (\theta) 的倒数。

barray_like

gamma 分布的形状参数,有时表示为 (\alpha)(float)。

xarray_like

分位数(积分下限;float)。

outndarray,可选

可选的输出数组用于函数值

返回:

F标量或 ndarray

评估在参数为 ab 的 gamma 分布的生存函数在 x 处的值。

另请参见

gdtr

Gamma 分布累积分布函数

scipy.stats.gamma

Gamma 分布

gdtrix

注意事项

使用与不完全 gamma 积分(正则化 gamma 函数)的关系进行评估。

Cephes 的包装器 [1] gdtrc 程序。直接调用 gdtrc 可以提高性能,相比于 scipy.stats.gammasf 方法(参见下面的最后一个示例)。

参考文献

[1]

Cephes 数学函数库,www.netlib.org/cephes/

示例

x=5 处计算 a=1b=2 的函数。

>>> import numpy as np
>>> from scipy.special import gdtrc
>>> import matplotlib.pyplot as plt
>>> gdtrc(1., 2., 5.)
0.04042768199451279 

通过提供一个 NumPy 数组 x 在几个点上计算 a=1b=2 的函数。

>>> xvalues = np.array([1., 2., 3., 4])
>>> gdtrc(1., 1., xvalues)
array([0.36787944, 0.13533528, 0.04978707, 0.01831564]) 

gdtrc 可以通过提供与 abx 的广播兼容形状的数组来评估不同的参数集。这里我们计算了三个不同 a 和四个位置 xb=3 的函数,得到一个 3x4 的数组。

>>> a = np.array([[0.5], [1.5], [2.5]])
>>> x = np.array([1., 2., 3., 4])
>>> a.shape, x.shape
((3, 1), (4,)) 
>>> gdtrc(a, 3., x)
array([[0.98561232, 0.9196986 , 0.80884683, 0.67667642],
 [0.80884683, 0.42319008, 0.17357807, 0.0619688 ],
 [0.54381312, 0.12465202, 0.02025672, 0.0027694 ]]) 

绘制四组不同参数设置的函数。

>>> a_parameters = [0.3, 1, 2, 6]
>>> b_parameters = [2, 10, 15, 20]
>>> linestyles = ['solid', 'dashed', 'dotted', 'dashdot']
>>> parameters_list = list(zip(a_parameters, b_parameters, linestyles))
>>> x = np.linspace(0, 30, 1000)
>>> fig, ax = plt.subplots()
>>> for parameter_set in parameters_list:
...     a, b, style = parameter_set
...     gdtrc_vals = gdtrc(a, b, x)
...     ax.plot(x, gdtrc_vals, label=f"$a= {a},\, b={b}$", ls=style)
>>> ax.legend()
>>> ax.set_xlabel("$x$")
>>> ax.set_title("Gamma distribution survival function")
>>> plt.show() 

../../_images/scipy-special-gdtrc-1_00_00.png

gamma 分布也可以通过 scipy.stats.gamma 获取。直接使用 gdtrc 比调用 scipy.stats.gammasf 方法要快得多,尤其对于小数组或单个值。要获得相同的结果,必须使用以下参数化方式:stats.gamma(b, scale=1/a).sf(x)=gdtrc(a, b, x)

>>> from scipy.stats import gamma
>>> a = 2
>>> b = 3
>>> x = 1.
>>> gdtrc_result = gdtrc(a, b, x)  # this will often be faster than below
>>> gamma_dist_result = gamma(b, scale=1/a).sf(x)
>>> gdtrc_result == gamma_dist_result  # test that results are equal
True 

scipy.special.gdtria

原文链接:docs.scipy.org/doc/scipy-1.12.0/reference/generated/scipy.special.gdtria.html#scipy.special.gdtria

scipy.special.gdtria(p, b, x, out=None) = <ufunc 'gdtria'>

gdtr的反函数相对于a

返回伽玛分布累积分布函数gdtr(a, b, x)关于参数a的反函数。

参数:

parray_like

概率值。

barray_like

gdtr(a, b, x)b参数值。b是伽玛分布的“形状”参数。

xarray_like

伽玛分布域内的非负实数值。

outndarray,可选

如果给出第四个参数,必须是 numpy.ndarray,其大小与abx的广播结果匹配。此时out是函数返回的数组。

返回:

a标量或 ndarray

参数a的取值使得*p = gdtr(a, b, x)*成立。1/a是伽玛分布的“尺度”参数。

另见

gdtr

伽玛分布的累积分布函数。

gdtrib

gdtr(a, b, x)关于b的反函数。

gdtrix

gdtr(a, b, x)关于x的反函数。

注意事项

cdfgam的 Fortran 库 CDFLIB [1]的封装器。

使用 DiDinato 和 Morris 的例程[2]计算累积分布函数p。计算参数a涉及搜索产生期望p值的值。该搜索依赖于pa的单调性。

参考文献

[1]

Barry Brown, James Lovato, 和 Kathy Russell,CDFLIB: 用于累积分布函数、反函数和其他参数的 Fortran 库。

[2]

DiDinato, A. R. 和 Morris, A. H.,计算不完全伽玛函数比率及其反函数。ACM Trans. Math. Softw. 12 (1986), 377-393.

示例

首先计算gdtr

>>> from scipy.special import gdtr, gdtria
>>> p = gdtr(1.2, 3.4, 5.6)
>>> print(p)
0.94378087442 

验证反函数。

>>> gdtria(p, 3.4, 5.6)
1.2 

scipy.special.gdtr

原文:docs.scipy.org/doc/scipy-1.12.0/reference/generated/scipy.special.gdtr.html#scipy.special.gdtr

scipy.special.gdtr(a, b, x, out=None) = <ufunc 'gdtr'>

伽玛分布的累积分布函数。

返回从零到 x 的伽玛概率密度函数的积分,

[F = \int_0^x \frac{a^b}{\Gamma(b)} t^{b-1} e^{-at},dt,]

其中 (\Gamma) 是伽玛函数。

参数:

a 数组样式

伽玛分布的速率参数,有时表示为 (\beta)(浮点数)。也是尺度参数 (\theta) 的倒数。

b 数组样式

伽玛分布的形状参数,有时用 (\alpha) 表示(浮点数)。

x 数组样式

分位数(积分的上限;浮点数)。

out 数组,可选

用于函数值的可选输出数组

返回:

F标量或者数组

以参数 ab 评估在 x 处的伽玛分布的累积分布函数。

参见

gdtrc

1 - 伽玛分布的累积分布函数。

scipy.stats.gamma

伽玛分布

注意

通过与不完全伽玛积分(正则化伽玛函数)的关系进行评估。

Cephes 的包装器 [1] gdtr 例程。直接调用 gdtr 可以比 scipy.stats.gammacdf 方法提高性能(见下面的最后一个例子)。

参考文献

[1]

Cephes 数学函数库,www.netlib.org/cephes/

示例

计算 a=1b=2x=5 处的函数。

>>> import numpy as np
>>> from scipy.special import gdtr
>>> import matplotlib.pyplot as plt
>>> gdtr(1., 2., 5.)
0.9595723180054873 

通过提供 NumPy 数组的 x,计算 a=1b=2 在多个点上的函数。

>>> xvalues = np.array([1., 2., 3., 4])
>>> gdtr(1., 1., xvalues)
array([0.63212056, 0.86466472, 0.95021293, 0.98168436]) 

gdtr 可以通过提供广播兼容形状的数组来评估不同的参数集,用于 a, bx。这里我们计算三个不同 a 在四个位置 x 上的函数,且 b=3,结果是一个 3x4 的数组。

>>> a = np.array([[0.5], [1.5], [2.5]])
>>> x = np.array([1., 2., 3., 4])
>>> a.shape, x.shape
((3, 1), (4,)) 
>>> gdtr(a, 3., x)
array([[0.01438768, 0.0803014 , 0.19115317, 0.32332358],
 [0.19115317, 0.57680992, 0.82642193, 0.9380312 ],
 [0.45618688, 0.87534798, 0.97974328, 0.9972306 ]]) 

绘制四种不同参数集的函数。

>>> a_parameters = [0.3, 1, 2, 6]
>>> b_parameters = [2, 10, 15, 20]
>>> linestyles = ['solid', 'dashed', 'dotted', 'dashdot']
>>> parameters_list = list(zip(a_parameters, b_parameters, linestyles))
>>> x = np.linspace(0, 30, 1000)
>>> fig, ax = plt.subplots()
>>> for parameter_set in parameters_list:
...     a, b, style = parameter_set
...     gdtr_vals = gdtr(a, b, x)
...     ax.plot(x, gdtr_vals, label=f"$a= {a},\, b={b}$", ls=style)
>>> ax.legend()
>>> ax.set_xlabel("$x$")
>>> ax.set_title("Gamma distribution cumulative distribution function")
>>> plt.show() 

../../_images/scipy-special-gdtr-1_00_00.png

伽玛分布也可用 scipy.stats.gamma。直接使用 gdtr 比调用 scipy.stats.gammacdf 方法更快,尤其适用于小数组或单个值。要获得相同的结果,必须使用以下参数化方法:stats.gamma(b, scale=1/a).cdf(x)=gdtr(a, b, x)

>>> from scipy.stats import gamma
>>> a = 2.
>>> b = 3
>>> x = 1.
>>> gdtr_result = gdtr(a, b, x)  # this will often be faster than below
>>> gamma_dist_result = gamma(b, scale=1/a).cdf(x)
>>> gdtr_result == gamma_dist_result  # test that results are equal
True 

scipy.special.gdtrib

原文:docs.scipy.org/doc/scipy-1.12.0/reference/generated/scipy.special.gdtrib.html#scipy.special.gdtrib

scipy.special.gdtrib(a, p, x, out=None) = <ufunc 'gdtrib'>

gdtr 的逆与 b

返回与 p = gdtr(a, b, x),伽玛分布的累积分布函数的参数 b 相对应的逆。

参数:

a 类似数组

gdtr(a, b, x)a 参数值。1/a 是伽玛分布的“尺度”参数。

p 类似数组

概率值。

x 类似数组

非负实值,来自伽玛分布的定义域。

out ndarray,可选

如果给出第四个参数,它必须是一个 numpy.ndarray,其大小与 abx 的广播结果匹配。out 然后是函数返回的数组。

返回:

b 标量或 ndarray

b 参数值,使得 p = gdtr(a, b, x)b 是伽玛分布的“形状”参数。

另请参阅

gdtr

伽玛分布的累积分布函数。

gdtria

gdtr(a, b, x) 相对于 a 的逆。

gdtrix

x 相对于 gdtr(a, b, x) 的逆。

注意

封装了 CDFLIB [1] 中 Fortran 例程 cdfgam 的包装器。

使用 DiDinato 和 Morris 的例程计算累积分布函数 p [2]。计算 b 包括搜索一个值,该值产生所需的 p 值。搜索依赖于 pb 的单调性。

参考文献

[1]

Barry Brown, James Lovato, 和 Kathy Russell,CDFLIB:用于累积分布函数、逆和其他参数的 Fortran 例程库。

[2]

DiDinato, A. R. 和 Morris, A. H.,不完全伽玛函数比值及其逆的计算。ACM Trans. Math. Softw. 12 (1986), 377-393。

示例

首先评估 gdtr

>>> from scipy.special import gdtr, gdtrib
>>> p = gdtr(1.2, 3.4, 5.6)
>>> print(p)
0.94378087442 

验证逆。

>>> gdtrib(1.2, p, 5.6)
3.3999999999723882 

scipy.special.gdtr

原文链接:docs.scipy.org/doc/scipy-1.12.0/reference/generated/scipy.special.gdtr.html#scipy.special.gdtr

scipy.special.gdtr(a, b, x, out=None) = <ufunc 'gdtr'>

伽马分布累积分布函数。

返回伽马概率密度函数从零到 x 的积分,

[F = \int_0^x \frac{a^b}{\Gamma(b)} t^{b-1} e^{-at},dt,]

其中 (\Gamma) 是伽马函数。

参数:

a:array_like

伽马分布的速率参数,有时表示为 (\beta)(浮点数)。它也是比例参数 (\theta) 的倒数。

b:array_like

伽马分布的形状参数,有时表示为 (\alpha)(浮点数)。

x:array_like

伽马分布的分位数(积分的上限;浮点数)。

out:ndarray,可选

可选输出数组的函数值

返回:

F:标量或 ndarray

在参数 ab 下评估的伽马分布累积分布函数 x 处的累积分布函数。

参见

gdtrc

伽马分布的 1 - CDF。

scipy.stats.gamma

伽马分布

注意

评估是通过与不完全伽马积分(正则化伽马函数)的关系进行的。

对 Cephes 的包装 [1] 例程 gdtr。直接调用 gdtr 可以提高性能,相较于 scipy.stats.gammacdf 方法(参见下面的最后一个例子)。

参考

[1]

Cephes 数学函数库,www.netlib.org/cephes/

示例

计算 a=1b=2x=5 的函数。

>>> import numpy as np
>>> from scipy.special import gdtr
>>> import matplotlib.pyplot as plt
>>> gdtr(1., 2., 5.)
0.9595723180054873 

通过提供一个 NumPy 数组 x,计算 a=1b=2 在几个点的函数。

>>> xvalues = np.array([1., 2., 3., 4])
>>> gdtr(1., 1., xvalues)
array([0.63212056, 0.86466472, 0.95021293, 0.98168436]) 

gdtr 可以通过提供广播兼容形状的数组评估不同的参数集 abx。在这里,我们计算三个不同 a 在四个位置 xb=3 的函数,结果是一个 3x4 的数组。

>>> a = np.array([[0.5], [1.5], [2.5]])
>>> x = np.array([1., 2., 3., 4])
>>> a.shape, x.shape
((3, 1), (4,)) 
>>> gdtr(a, 3., x)
array([[0.01438768, 0.0803014 , 0.19115317, 0.32332358],
 [0.19115317, 0.57680992, 0.82642193, 0.9380312 ],
 [0.45618688, 0.87534798, 0.97974328, 0.9972306 ]]) 

为四组不同参数集绘制函数图。

>>> a_parameters = [0.3, 1, 2, 6]
>>> b_parameters = [2, 10, 15, 20]
>>> linestyles = ['solid', 'dashed', 'dotted', 'dashdot']
>>> parameters_list = list(zip(a_parameters, b_parameters, linestyles))
>>> x = np.linspace(0, 30, 1000)
>>> fig, ax = plt.subplots()
>>> for parameter_set in parameters_list:
...     a, b, style = parameter_set
...     gdtr_vals = gdtr(a, b, x)
...     ax.plot(x, gdtr_vals, label=f"$a= {a},\, b={b}$", ls=style)
>>> ax.legend()
>>> ax.set_xlabel("$x$")
>>> ax.set_title("Gamma distribution cumulative distribution function")
>>> plt.show() 

../../_images/scipy-special-gdtr-1_00_00.png

伽马分布也可以作为 scipy.stats.gamma 获取。直接使用 gdtr 比调用 scipy.stats.gammacdf 方法要快得多,尤其对于小数组或单个值。为了获得相同的结果,必须使用以下参数化方法:stats.gamma(b, scale=1/a).cdf(x)=gdtr(a, b, x)

>>> from scipy.stats import gamma
>>> a = 2.
>>> b = 3
>>> x = 1.
>>> gdtr_result = gdtr(a, b, x)  # this will often be faster than below
>>> gamma_dist_result = gamma(b, scale=1/a).cdf(x)
>>> gdtr_result == gamma_dist_result  # test that results are equal
True 

scipy.special.gdtrix

原文链接:docs.scipy.org/doc/scipy-1.12.0/reference/generated/scipy.special.gdtrix.html#scipy.special.gdtrix

scipy.special.gdtrix(a, b, p, out=None) = <ufunc 'gdtrix'>

gdtr的反函数 vs x。

返回与伽玛分布的累积分布函数p = gdtr(a, b, x)的参数x相关的反函数,也称为分布的第p分位数。

参数:

aarray_like

gdtr(a, b, x)a参数值。1/a是伽玛分布的“尺度”参数。

barray_like

gdtr(a, b, x)b参数值。b是伽玛分布的“形状”参数。

parray_like

概率值。

outndarray,可选

如果给出第四个参数,则必须是大小与abx广播结果匹配的 numpy.ndarray。out然后是函数返回的数组。

返回:

x标量或 ndarray

p = gdtr(a, b, x)x参数值。

另请参阅

gdtr

伽玛分布的累积分布函数。

gdtria

gdtr(a, b, x)a相关的反函数。

gdtrib

gdtr(a, b, x)b相关的反函数。

注意事项

对 CDFLIB [1] Fortran 例程cdfgam的包装器。

使用 DiDinato 和 Morris 的例程[2]计算累积分布函数p。计算x涉及搜索产生所需p值的值。搜索依赖于px的单调性。

参考文献

[1]

Barry Brown, James Lovato, and Kathy Russell, CDFLIB: 用于累积分布函数、反函数和其他参数的 Fortran 例程库。

[2]

DiDinato, A. R.和 Morris, A. H.,计算不完全伽玛函数比率及其反函数。ACM Trans. Math. Softw. 12 (1986), 377-393。

示例

首先评估gdtr

>>> from scipy.special import gdtr, gdtrix
>>> p = gdtr(1.2, 3.4, 5.6)
>>> print(p)
0.94378087442 

验证反函数。

>>> gdtrix(1.2, 3.4, p)
5.5999999999999996 

scipy.special.gdtr

原文链接:docs.scipy.org/doc/scipy-1.12.0/reference/generated/scipy.special.gdtr.html#scipy.special.gdtr

scipy.special.gdtr(a, b, x, out=None) = <ufunc 'gdtr'>

伽玛分布累积分布函数。

返回从零到x的伽玛概率密度函数的积分,

[F = \int_0^x \frac{a^b}{\Gamma(b)} t^{b-1} e^{-at},dt,]

其中(\Gamma)是伽玛函数。

参数:

a类似数组

伽玛分布的速率参数,有时表示为(\beta)(浮点数)。它也是比例参数(\theta)的倒数。

b类似数组

伽玛分布的形状参数,有时表示为(\alpha)(浮点数)。

x类似数组

分位数(积分的上限;浮点数)。

outndarray,可选

函数值的可选输出数组

返回:

F标量或 ndarray

具有参数abx处评估的伽玛分布的 CDF。

另请参阅

gdtrc

1 - 伽玛分布的 CDF。

scipy.stats.gamma

伽玛分布

注意

评估是通过与不完全伽玛积分(正则化伽玛函数)的关系进行的。

Cephes [1]例程gdtr的包装器。直接调用gdtr可以提高性能,与scipy.stats.gammacdf方法相比(请参见下面的最后一个示例)。

参考

[1]

Cephes 数学函数库,www.netlib.org/cephes/

示例

计算a=1b=2x=5处的函数。

>>> import numpy as np
>>> from scipy.special import gdtr
>>> import matplotlib.pyplot as plt
>>> gdtr(1., 2., 5.)
0.9595723180054873 

通过为x提供一个 NumPy 数组,在几个点上计算a=1b=2的函数。

>>> xvalues = np.array([1., 2., 3., 4])
>>> gdtr(1., 1., xvalues)
array([0.63212056, 0.86466472, 0.95021293, 0.98168436]) 

通过提供广播兼容形状的数组来评估不同参数设置的gdtr。在这里,我们为三个不同的a在四个位置xb=3计算函数,得到一个 3x4 数组。

>>> a = np.array([[0.5], [1.5], [2.5]])
>>> x = np.array([1., 2., 3., 4])
>>> a.shape, x.shape
((3, 1), (4,)) 
>>> gdtr(a, 3., x)
array([[0.01438768, 0.0803014 , 0.19115317, 0.32332358],
 [0.19115317, 0.57680992, 0.82642193, 0.9380312 ],
 [0.45618688, 0.87534798, 0.97974328, 0.9972306 ]]) 

为四组不同参数设置绘制函数。

>>> a_parameters = [0.3, 1, 2, 6]
>>> b_parameters = [2, 10, 15, 20]
>>> linestyles = ['solid', 'dashed', 'dotted', 'dashdot']
>>> parameters_list = list(zip(a_parameters, b_parameters, linestyles))
>>> x = np.linspace(0, 30, 1000)
>>> fig, ax = plt.subplots()
>>> for parameter_set in parameters_list:
...     a, b, style = parameter_set
...     gdtr_vals = gdtr(a, b, x)
...     ax.plot(x, gdtr_vals, label=f"$a= {a},\, b={b}$", ls=style)
>>> ax.legend()
>>> ax.set_xlabel("$x$")
>>> ax.set_title("Gamma distribution cumulative distribution function")
>>> plt.show() 

../../_images/scipy-special-gdtr-1_00_00.png

伽玛分布也可以作为scipy.stats.gamma使用。直接使用gdtr可能比调用scipy.stats.gammacdf方法更快,特别是对于小数组或单个值。要获得相同的结果,必须使用以下参数化:stats.gamma(b, scale=1/a).cdf(x)=gdtr(a, b, x).

>>> from scipy.stats import gamma
>>> a = 2.
>>> b = 3
>>> x = 1.
>>> gdtr_result = gdtr(a, b, x)  # this will often be faster than below
>>> gamma_dist_result = gamma(b, scale=1/a).cdf(x)
>>> gdtr_result == gamma_dist_result  # test that results are equal
True 

scipy.special.nbdtr

原文:docs.scipy.org/doc/scipy-1.12.0/reference/generated/scipy.special.nbdtr.html#scipy.special.nbdtr

scipy.special.nbdtr(k, n, p, out=None) = <ufunc 'nbdtr'>

负二项分布累积分布函数。

返回负二项分布概率质量函数从 0 到k项的总和,

[F = \sum_{j=0}^k {{n + j - 1}\choose{j}} p^n (1 - p)^j.]

在一系列伯努利试验中,单次成功概率为p,这是k或更少次失败在第n次成功之前发生的概率。

参数:

karray_like

允许的最大失败次数(非负整数)。

narray_like

成功次数的目标数(正整数)。

parray_like

单次事件中成功的概率(浮点数)。

outndarray, 可选

可选的函数结果输出数组

返回:

F标量或 ndarray

在一系列事件中,成功概率为p,在n次成功之前发生k或更少次失败的概率。

参见

nbdtrc

负二项分布生存函数

nbdtrik

负二项分布分位数函数

scipy.stats.nbinom

负二项分布

注意事项

如果将浮点数值传递给kn,它们将被截断为整数。

这些项不直接求和;相反,使用正则化不完全贝塔函数,根据公式,

[\mathrm{nbdtr}(k, n, p) = I_{p}(n, k + 1).]

Cephes 的包装器[1]例程nbdtr

负二项分布也可以作为scipy.stats.nbinom获得。直接使用nbdtr相对于scipy.stats.nbinomcdf方法可以提高性能(见最后一个示例)。

参考文献

[1]

Cephes 数学函数库,www.netlib.org/cephes/

示例

计算在p=0.5k=10n=5的函数。

>>> import numpy as np
>>> from scipy.special import nbdtr
>>> nbdtr(10, 5, 0.5)
0.940765380859375 

通过提供 NumPy 数组或列表用于k,计算p=0.5n=10的函数的多个点。

>>> nbdtr([5, 10, 15], 10, 0.5)
array([0.15087891, 0.58809853, 0.88523853]) 

绘制四组不同参数集的函数图。

>>> import matplotlib.pyplot as plt
>>> k = np.arange(130)
>>> n_parameters = [20, 20, 20, 80]
>>> p_parameters = [0.2, 0.5, 0.8, 0.5]
>>> linestyles = ['solid', 'dashed', 'dotted', 'dashdot']
>>> parameters_list = list(zip(p_parameters, n_parameters,
...                            linestyles))
>>> fig, ax = plt.subplots(figsize=(8, 8))
>>> for parameter_set in parameters_list:
...     p, n, style = parameter_set
...     nbdtr_vals = nbdtr(k, n, p)
...     ax.plot(k, nbdtr_vals, label=rf"$n={n},\, p={p}$",
...             ls=style)
>>> ax.legend()
>>> ax.set_xlabel("$k$")
>>> ax.set_title("Negative binomial cumulative distribution function")
>>> plt.show() 

../../_images/scipy-special-nbdtr-1_00_00.png

负二项分布也可作为scipy.stats.nbinom来使用。直接使用nbdtr比调用scipy.stats.nbinomcdf方法要快得多,特别是对于小数组或单个值。要获得相同的结果,必须使用以下参数化:nbinom(n, p).cdf(k)=nbdtr(k, n, p)

>>> from scipy.stats import nbinom
>>> k, n, p = 5, 3, 0.5
>>> nbdtr_res = nbdtr(k, n, p)  # this will often be faster than below
>>> stats_res = nbinom(n, p).cdf(k)
>>> stats_res, nbdtr_res  # test that results are equal
(0.85546875, 0.85546875) 

nbdtr可以通过提供与knp的广播兼容形状的数组来评估不同的参数集。在这里,我们计算了三个不同的k和四个p的函数值,结果是一个 3x4 数组。

>>> k = np.array([[5], [10], [15]])
>>> p = np.array([0.3, 0.5, 0.7, 0.9])
>>> k.shape, p.shape
((3, 1), (4,)) 
>>> nbdtr(k, 5, p)
array([[0.15026833, 0.62304687, 0.95265101, 0.9998531 ],
 [0.48450894, 0.94076538, 0.99932777, 0.99999999],
 [0.76249222, 0.99409103, 0.99999445, 1\.        ]])