scipy.special.gdtrc#
- scipy.special.gdtrc(a, b, x, out=None) = <ufunc 'gdtrc'>#
- 伽马分布生存函数。 - 伽马概率密度函数从 x 到无穷的积分, \[F = \int_x^\infty \frac{a^b}{\Gamma(b)} t^{b-1} e^{-at}\,dt,\]- 其中 \(\Gamma\) 是伽马函数。 - 参数:
- aarray_like
- 伽马分布的速率参数,有时记作 \(\beta\) (浮点数)。它也是尺度参数 \(\theta\) 的倒数。 
- barray_like
- 伽马分布的形状参数,有时记作 \(\alpha\) (浮点数)。 
- xarray_like
- 分位数(积分下限;浮点数)。 
- outndarray, optional
- 可选的函数值输出数组 
 
- 返回:
- Fscalar or ndarray
- 在 x 处评估的参数为 a 和 b 的伽马分布的生存函数。 
 
 - 另请参阅 - gdtr
- 伽马分布累积分布函数 
- scipy.stats.gamma
- 伽马分布 
- gdtrix
 - 备注 - 评估是利用与不完全伽马积分(正则化伽马函数)的关系进行的。 - Cephes [1] 例程 - gdtrc的封装器。直接调用- gdtrc可以比调用- scipy.stats.gamma的- sf方法提高性能(参见下面的最后一个示例)。- 参考文献 [1]- Cephes 数学函数库, http://www.netlib.org/cephes/ - 示例 - 计算 - a=1和- b=2在- x=5处的值。- >>> import numpy as np >>> from scipy.special import gdtrc >>> import matplotlib.pyplot as plt >>> gdtrc(1., 2., 5.) 0.04042768199451279 - 通过为 x 提供 NumPy 数组,计算 - a=1、- b=2在多个点处的值。- >>> xvalues = np.array([1., 2., 3., 4]) >>> gdtrc(1., 1., xvalues) array([0.36787944, 0.13533528, 0.04978707, 0.01831564]) - gdtrc可以通过为 a、b 和 x 提供具有广播兼容形状的数组来评估不同的参数集。这里我们计算三个不同的 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,)) - >>> 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=fr"$a= {a},\, b={b}$", ls=style) >>> ax.legend() >>> ax.set_xlabel("$x$") >>> ax.set_title("Gamma distribution survival function") >>> plt.show()   - 伽马分布也可以通过 - scipy.stats.gamma获得。直接使用- gdtrc比调用- scipy.stats.gamma的- sf方法快得多,特别是对于小型数组或单个值。要获得相同的结果,必须使用以下参数化:- 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