scipy.special.gdtrc#

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

Gamma 分佈存活函數。

x 到無限大的 Gamma 機率密度函數的積分,

\[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,optional

函數值的選用性輸出陣列

回傳值:
F純量或 ndarray

x 評估的、帶有參數 ab 的 Gamma 分佈存活函數。

另請參閱

gdtr

Gamma 分佈累積分布函數

scipy.stats.gamma

Gamma 分佈

gdtrix

註解

評估是使用與不完全 Gamma 積分(正規化 Gamma 函數)的關係進行的。

Cephes [1] 常式 gdtrc 的包裝函式。直接呼叫 gdtrc 可以提高效能,相較於 scipy.stats.gammasf 方法(請參閱下方的最後一個範例)。

參考文獻

[1]

Cephes Mathematical Functions Library, http://www.netlib.org/cephes/

範例

計算 a=1b=2x=5 時的函數值。

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

透過為 x 提供 NumPy 陣列,計算 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=fr"$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