mrpy.base.stats.TGGDlog

class mrpy.base.stats.TGGDlog(scale=0.0, a=-1.0, b=1.0, xmin=-1.0)

The Truncated Generalised Gamma Distribution in log10 space.

Specifically, if 10**x is drawn from a TGGD distribution (in real space), this function gives the distribution of x, using the same parameter values.

The log10 TGGD has the following PDF:

\[\frac{\ln(10) b (10^{(x-s)(a+1)} \exp(-10^{b(x-s)})}{s \Gamma(\frac{a+1}{b},10^{b(m-s)})}\]

where s corresponds to the scale argument of this class, 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 TGGDlog
>>> import matplotlib.pyplot as plt
>>> tggdlog = TGGDlog(a=-2)
>>> r = tggdlog.rvs(100)
>>> plt.hist(r) 

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

>>> a = tggdlog.quantile(tggdlog.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. We use a scale appropriate for an example such as a halo mass function.

>>> from scipy.integrate import quad
>>> tggdlog = TGGDlog(scale=14,a=-1.5,b=0.7,xmin=10)
>>> a = quad(tggdlog.pdf,10,11)[0]/tggdlog.cdf(11) # should be close to 1
>>> np.isclose(a,1)
True

The CDF should approach unity when 10**x >> 10**scale

>>> a = tggdlog.cdf(18) #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()
>>> a = tggd_ln.cdf(np.log(tggd.quantile(np.arange(0,1,0.1)))) 
>>> np.all(np.isclose(a,np.arange(0,1,0.1)))
True
>>> b = tggd_ln.cdf(tggd_log.quantile(np.arange(0,1,0.1))*np.log(10))
>>> 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.