Vous êtes un professionnel et vous avez besoin d'une formation ?
Programmation Python
Les compléments
Voir le programme détaillé
Module « scipy.special »
Signature de la fonction gdtr
def gdtr(*args, **kwargs)
Description
help(scipy.special.gdtr)
gdtr(x1, x2, x3, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
gdtr(a, b, x, out=None)
Gamma distribution cumulative distribution function.
Returns the integral from zero to `x` of the gamma probability density
function,
.. math::
F = \int_0^x \frac{a^b}{\Gamma(b)} t^{b-1} e^{-at}\,dt,
where :math:`\Gamma` is the gamma function.
Parameters
----------
a : array_like
The rate parameter of the gamma distribution, sometimes denoted
:math:`\beta` (float). It is also the reciprocal of the scale
parameter :math:`\theta`.
b : array_like
The shape parameter of the gamma distribution, sometimes denoted
:math:`\alpha` (float).
x : array_like
The quantile (upper limit of integration; float).
out : ndarray, optional
Optional output array for the function values
Returns
-------
F : scalar or ndarray
The CDF of the gamma distribution with parameters `a` and `b`
evaluated at `x`.
See Also
--------
gdtrc : 1 - CDF of the gamma distribution.
scipy.stats.gamma: Gamma distribution
Notes
-----
The evaluation is carried out using the relation to the incomplete gamma
integral (regularized gamma function).
Wrapper for the Cephes [1]_ routine `gdtr`. Calling `gdtr` directly can
improve performance compared to the ``cdf`` method of `scipy.stats.gamma`
(see last example below).
References
----------
.. [1] Cephes Mathematical Functions Library,
http://www.netlib.org/cephes/
Examples
--------
Compute the function for ``a=1``, ``b=2`` at ``x=5``.
>>> import numpy as np
>>> from scipy.special import gdtr
>>> import matplotlib.pyplot as plt
>>> gdtr(1., 2., 5.)
0.9595723180054873
Compute the function for ``a=1`` and ``b=2`` at several points by
providing a NumPy array for `x`.
>>> xvalues = np.array([1., 2., 3., 4])
>>> gdtr(1., 1., xvalues)
array([0.63212056, 0.86466472, 0.95021293, 0.98168436])
`gdtr` can evaluate different parameter sets by providing arrays with
broadcasting compatible shapes for `a`, `b` and `x`. Here we compute the
function for three different `a` at four positions `x` and ``b=3``,
resulting in a 3x4 array.
>>> 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 ]])
Plot the function for four different parameter sets.
>>> 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=fr"$a= {a},\, b={b}$", ls=style)
>>> ax.legend()
>>> ax.set_xlabel("$x$")
>>> ax.set_title("Gamma distribution cumulative distribution function")
>>> plt.show()
The gamma distribution is also available as `scipy.stats.gamma`. Using
`gdtr` directly can be much faster than calling the ``cdf`` method of
`scipy.stats.gamma`, especially for small arrays or individual values.
To get the same results one must use the following parametrization:
``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
Vous êtes un professionnel et vous avez besoin d'une formation ?
Deep Learning avec Python
et Keras et Tensorflow
Voir le programme détaillé
Améliorations / Corrections
Vous avez des améliorations (ou des corrections) à proposer pour ce document : je vous remerçie par avance de m'en faire part, cela m'aide à améliorer le site.
Emplacement :
Description des améliorations :