mrpy.base.stats.TGGD

class mrpy.base.stats.TGGD(scale=1, a=-1.0, b=1.0, xmin=0.1)

The Truncated Generalised Gamma Distribution.

The TGGD has the following PDF:

\[f(x) = \frac{b \left(\frac{x}{s}\right)^a \exp\left(-\left(\frac{m}{s}\right)^b\right)}{\Gamma\left(\frac{a+1}{b},\left(\frac{x_{\rm min}}{s}\right)^b\right)}\]

where \(s>0\) corresponds to the scale argument of this class, \(a \in \Re\), \(b>0\), \(x_{\rm min}>0\) is the truncation value, and \(\Gamma\) is the incomplete gamma function, provided by mpmath.

Parameters:

scale : array_like, optional

Transition scale from power-law to exponential cut-off. Analogous to the scale parameter for the standard Gamma distribution.

a : float or array_like, optional

Power-law slope of the TGGD.

b : float or array_like, optional

Exponential cut-off parameter of the TGGD.

xmin : float or array_like, optional

Truncation value of the TGGD.

Examples

The following should create a sample and plot its histogram. The histogram should have a slope of -1.

>>> from mrpy.base.stats import TGGD
>>> import matplotlib.pyplot as plt
>>> tggd = TGGD(a=-2)
>>> r = tggd.rvs(100)
>>> plt.hist(np.log10(r)) 

Taking the quantile of the cumulative probability at each variate should return something close to the variate.

>>> a = tggd.quantile(tggd.cdf(r))/r  #should be close to 1
>>> np.all(np.isclose(a,1))
True

Show that the numerical integral is equal to the CDF. The following uses a scale more appropriate to halo mass functions.

>>> from scipy.integrate import quad
>>> tggd = TGGD(scale=1e14,a=-1.5,b=0.7,xmin=1e10)
>>> a = quad(tggd.pdf,1e10,1e11)[0]/tggd.cdf(1e11) # should be close to 1
>>> np.isclose(a,1)
True

The CDF should approach unity when x >> scale

>>> a = tggd.cdf(1e18) #Should be close to 1
>>> np.isclose(a,1)
True

To show the link to the log and ln variants, the following should be a sequence from 0 to 1 (by 0.1)

>>> from mrpy.base.stats import TGGDlog, TGGDln
>>> tggd = TGGD()
>>> tggd_log = TGGDlog()
>>> tggd_ln = TGGDln()
>>> tggd.cdf(10**tggd_log.quantile(np.arange(0,1,0.1))) 
array([ 0. ,  0.1,  0.2,  0.3,  0.4,  0.5,  0.6,  0.7,  0.8,  0.9])
>>> b = tggd.cdf(np.exp(tggd_ln.quantile(np.arange(0,1,0.1))))
>>> np.all(np.isclose(b,np.arange(0,1,0.1)))
True

Methods

__init__([scale, a, b, xmin])
cdf(q[, lower_tail, log_p]) The cdf of the distribution.
central_moments(n) Calculate the nth central moment, E[(X-mu)^n].
normalised_central_moments(n) Calculate the nth standardized central moment, E[(X-mu)^n]/sigma^n.
pdf(x[, log]) The pdf of the distribution.
quantile(p[, lower_tail, log_p, res_approx]) The quantile of the distribution.
raw_moments(n) Calculate the nth raw moment, E[X^n].
rvs(n[, res_approx]) Generate random variates from the distribution.