Esempio n. 1
0
    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)
Esempio n. 2
0
    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)
Esempio n. 3
0
    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))
Esempio n. 4
0
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)
Esempio n. 5
0
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))
Esempio n. 6
0
def test_gammainc_negpos_int():
    assert np.isclose(s.gammainc(-1,1),0.1484955067759)
Esempio n. 7
0
def test_gammainc_pospos_int():
    assert np.isclose(s.gammainc(1,1),1/np.e)
Esempio n. 8
0
def test_gammainc_negpos_float():
    assert np.isclose(s.gammainc(-1.2,1.2),0.0839714)
Esempio n. 9
0
def test_gammainc_pospos_float():
    assert np.isclose(s.gammainc(1.2,1.2),0.3480611830)
Esempio n. 10
0
 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
Esempio n. 11
0
 def gammainc_z1xd(self):
     return sp.gammainc(self._zd + self.beta / self.betad, self._xd)
Esempio n. 12
0
 def gammainc_z1x(self):
     return sp.gammainc(self._z + 1, self._x)
Esempio n. 13
0
 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_)
Esempio n. 14
0
 def _pdf_norm(self, log=False):
     a = sp.gammainc(self._z, self._xmintb)
     if not log:
         return a
     else:
         return np.log(a)
Esempio n. 15
0
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))
Esempio n. 16
0
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))
Esempio n. 17
0
 def gammainc_zxd(self):
     return sp.gammainc(self._zd, self._xd)