def cdf(self, q, lower_tail=True, log_p=False): """ The cdf of the distribution. Parameters ---------- q : array_like Variates at which to calculate the cdf. If any of `shape`, `a`, `b` or `xmin` are arrays, `q` must have the same length. lower_tail : logical, optional If `True` (default), probabilities are P[X <= q], otherwise, P[X > q]. log_p : logical, optional If `True`, probabilities *p* are interpreted as log(*p*). Returns ------- p : array_like The integrated probability of a variate being smaller than *q*. """ qt = self._xt(q) p = sp.gammainc(self._z, qt**self.b)/sp.gammainc(self._z, self._xmintb) return self._cdf_convert(p, lower_tail, log_p)
def raw_moments(self, n): """ Calculate the nth raw moment, E[X^n]. Parameters ---------- n : array_like The order(s) of the moment desired. Returns ------- mu_n : array_like The raw moment(s) corresponding to the order(s) `n`. Notes ----- The 1st raw moment is equivalent to the mean. Examples -------- >>> from mrpy.base.stats import TGGD >>> t = TGGD() >>> mean = t.raw_moments(1) >>> ten_moments = t.raw_moments(np.arange(10)) #doctest: +SKIP """ zn = (self.a + 1 + n)/self.b z0 = (self.a + 1)/self.b x = (self.xmin/self.scale)**self.b return self.scale**n*sp.gammainc(zn, x)/sp.gammainc(z0, x)
def central_moments(self, n): """ Calculate the nth central moment, E[(X-mu)^n]. Parameters ---------- n : integer The order of the moment desired. Returns ------- mu_n : float The nth central moment. Notes ----- The 2nd central moment is equivalent to the variance. Examples -------- >>> from mrpy.base.stats import TGGD >>> t = TGGD() >>> variance = t.central_moments(2) >>> t.raw_moments(10) 199064.8037313875 """ k = np.arange(n + 1) sign = (-1)**(n - k) zk = (self.a + 1 + k)/self.b z0 = (self.a + 1)/self.b z1 = (self.a + 2)/self.b x = (self.xmin/self.scale)**self.b coeffs = _comb(n, k) return self.scale**n*np.sum(coeffs*sp.gammainc(z1, x)**(n - k)* sp.gammainc(zk, x)*sign/sp.gammainc(z0, x)**(n - k + 1))
def rho_gtm(m, logHs, alpha, beta, mmin=None, norm="pdf", log=False, **Arhom_kw): """ The mass-weighted integral of the MRP, in reverse (ie. from high to low mass) %s """ _, A = _head(m, logHs, alpha, beta, mmin, norm, log, **Arhom_kw) shape = 10**(2 * logHs) * sp.gammainc((alpha + 2) / beta, (m / 10**logHs)**beta) if log: shape = np.log(shape) return _tail(shape, A, log)
def test_gammainc_float_vec(): ans = np.array([0.8683608186150055, 0.4956391690487021]) assert np.all(np.isclose(s.gammainc(1.2,np.linspace(0.1,0.8,2)),ans))
def test_gammainc_negpos_int(): assert np.isclose(s.gammainc(-1,1),0.1484955067759)
def test_gammainc_pospos_int(): assert np.isclose(s.gammainc(1,1),1/np.e)
def test_gammainc_negpos_float(): assert np.isclose(s.gammainc(-1.2,1.2),0.0839714)
def test_gammainc_pospos_float(): assert np.isclose(s.gammainc(1.2,1.2),0.3480611830)
def _qd(self): """ The normalisation of the MRP (ie. integral of g) (truncation masses) """ return sp.gammainc(self._zd, self._xd) * self.Hsd * self.Ad
def gammainc_z1xd(self): return sp.gammainc(self._zd + self.beta / self.betad, self._xd)
def gammainc_z1x(self): return sp.gammainc(self._z + 1, self._x)
def _gammainc_zx_(self): """ The incomplete gamma function, Gamma(z,x), where z,x are as specified in this class. """ return sp.gammainc(self._z, self._x_)
def _pdf_norm(self, log=False): a = sp.gammainc(self._z, self._xmintb) if not log: return a else: return np.log(a)
def test_gammainc_vec_float(): ans = np.array([0.10238660549891246, 0.262160799331728]) assert np.all(np.isclose(s.gammainc(np.array([-0.8,0.8]),1.2),ans))
def test_gammainc_vec_vec(): ans = np.array([5.277378904974033, 0.41093548285294645]) assert np.all(np.isclose(s.gammainc(np.array([-0.8,0.8]),np.array([0.1,0.8])),ans))
def gammainc_zxd(self): return sp.gammainc(self._zd, self._xd)