Python scipy.special.expm1() Examples
The following are 30
code examples of scipy.special.expm1().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
scipy.special
, or try the search function
.
Example #1
Source File: _continuous_distns.py From Splunking-Crime with GNU Affero General Public License v3.0 | 6 votes |
def _stats(self, c): g = lambda n: sc.gamma(n*c + 1) g1 = g(1) g2 = g(2) g3 = g(3) g4 = g(4) g2mg12 = np.where(abs(c) < 1e-7, (c*np.pi)**2.0/6.0, g2-g1**2.0) gam2k = np.where(abs(c) < 1e-7, np.pi**2.0/6.0, sc.expm1(sc.gammaln(2.0*c+1.0)-2*sc.gammaln(c + 1.0))/c**2.0) eps = 1e-14 gamk = np.where(abs(c) < eps, -_EULER, sc.expm1(sc.gammaln(c + 1))/c) m = np.where(c < -1.0, np.nan, -gamk) v = np.where(c < -0.5, np.nan, g1**2.0*gam2k) # skewness sk1 = np.where(c < -1./3, np.nan, np.sign(c)*(-g3+(g2+2*g2mg12)*g1)/((g2mg12)**(3./2.))) sk = np.where(abs(c) <= eps**0.29, 12*np.sqrt(6)*_ZETA3/np.pi**3, sk1) # kurtosis ku1 = np.where(c < -1./4, np.nan, (g4+(-4*g3+3*(g2+g2mg12)*g1)*g1)/((g2mg12)**2)) ku = np.where(abs(c) <= (eps)**0.23, 12.0/5.0, ku1-3.0) return m, v, sk, ku
Example #2
Source File: test_basic.py From GraphicDesignPatternByPython with MIT License | 6 votes |
def test_expm1_complex_hard(self): # The real part of this function is difficult to evaluate when # z.real = -log(cos(z.imag)). y = np.array([0.1, 0.2, 0.3, 5, 11, 20]) x = -np.log(np.cos(y)) z = x + 1j*y # evaluate using mpmath.expm1 with dps=1000 expected = np.array([-5.5507901846769623e-17+0.10033467208545054j, 2.4289354732893695e-18+0.20271003550867248j, 4.5235500262585768e-17+0.30933624960962319j, 7.8234305217489006e-17-3.3805150062465863j, -1.3685191953697676e-16-225.95084645419513j, 8.7175620481291045e-17+2.2371609442247422j]) found = cephes.expm1(z) # this passes. assert_array_almost_equal_nulp(found.imag, expected.imag, 3) # this fails. assert_array_almost_equal_nulp(found.real, expected.real, 20)
Example #3
Source File: test_basic.py From GraphicDesignPatternByPython with MIT License | 6 votes |
def test_expm1_complex(self): expm1 = cephes.expm1 assert_equal(expm1(0 + 0j), 0 + 0j) assert_equal(expm1(complex(np.inf, 0)), complex(np.inf, 0)) assert_equal(expm1(complex(np.inf, 1)), complex(np.inf, np.inf)) assert_equal(expm1(complex(np.inf, 2)), complex(-np.inf, np.inf)) assert_equal(expm1(complex(np.inf, 4)), complex(-np.inf, -np.inf)) assert_equal(expm1(complex(np.inf, 5)), complex(np.inf, -np.inf)) assert_equal(expm1(complex(1, np.inf)), complex(np.nan, np.nan)) assert_equal(expm1(complex(0, np.inf)), complex(np.nan, np.nan)) assert_equal(expm1(complex(np.inf, np.inf)), complex(np.inf, np.nan)) assert_equal(expm1(complex(-np.inf, np.inf)), complex(-1, 0)) assert_equal(expm1(complex(-np.inf, np.nan)), complex(-1, 0)) assert_equal(expm1(complex(np.inf, np.nan)), complex(np.inf, np.nan)) assert_equal(expm1(complex(0, np.nan)), complex(np.nan, np.nan)) assert_equal(expm1(complex(1, np.nan)), complex(np.nan, np.nan)) assert_equal(expm1(complex(np.nan, 1)), complex(np.nan, np.nan)) assert_equal(expm1(complex(np.nan, np.nan)), complex(np.nan, np.nan))
Example #4
Source File: test_distributions.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def test_logcdf_logsf(self): x = np.linspace(-100, -4) y = stats.gumbel_l.logcdf(x) z = stats.gumbel_l.logsf(x) u = np.exp(y) v = -special.expm1(z) assert_allclose(u, v)
Example #5
Source File: _continuous_distns.py From Splunking-Crime with GNU Affero General Public License v3.0 | 5 votes |
def _sf(self, x, b): return np.exp(-sc.expm1(x**b))
Example #6
Source File: _continuous_distns.py From Splunking-Crime with GNU Affero General Public License v3.0 | 5 votes |
def _cdf(self, x, c): return -sc.expm1(-c * sc.expm1(x))
Example #7
Source File: _continuous_distns.py From Splunking-Crime with GNU Affero General Public License v3.0 | 5 votes |
def _cdf(self, x): return -sc.expm1(-np.exp(x))
Example #8
Source File: _continuous_distns.py From Splunking-Crime with GNU Affero General Public License v3.0 | 5 votes |
def _logpdf(self, x, c): return np.log(c) + x - c * sc.expm1(x)
Example #9
Source File: _continuous_distns.py From Splunking-Crime with GNU Affero General Public License v3.0 | 5 votes |
def _logpdf(self, x, a, b, c): return np.log(a+b*(-sc.expm1(-c*x))) + (-a-b)*x+b*(-sc.expm1(-c*x))/c
Example #10
Source File: _continuous_distns.py From Splunking-Crime with GNU Affero General Public License v3.0 | 5 votes |
def _cdf(self, x, a, b, c): return -sc.expm1((-a-b)*x + b*(-sc.expm1(-c*x))/c)
Example #11
Source File: _continuous_distns.py From Splunking-Crime with GNU Affero General Public License v3.0 | 5 votes |
def _pdf(self, x, a, b, c): return (a + b*(-sc.expm1(-c*x)))*np.exp((-a-b)*x + b*(-sc.expm1(-c*x))/c)
Example #12
Source File: _continuous_distns.py From Splunking-Crime with GNU Affero General Public License v3.0 | 5 votes |
def _sf(self, x, c): return -sc.expm1(-pow(-x, c))
Example #13
Source File: _continuous_distns.py From Splunking-Crime with GNU Affero General Public License v3.0 | 5 votes |
def _sf(self, x, c): return -sc.expm1(self._logcdf(x, c))
Example #14
Source File: test_mpmath.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def test_exprel(self): assert_mpmath_equal(sc.exprel, lambda x: mpmath.expm1(x)/x if x != 0 else mpmath.mpf('1.0'), [Arg(a=-np.log(np.finfo(np.double).max), b=np.log(np.finfo(np.double).max))]) assert_mpmath_equal(sc.exprel, lambda x: mpmath.expm1(x)/x if x != 0 else mpmath.mpf('1.0'), np.array([1e-12, 1e-24, 0, 1e12, 1e24, np.inf]), rtol=1e-11) assert_(np.isinf(sc.exprel(np.inf))) assert_(sc.exprel(-np.inf) == 0)
Example #15
Source File: test_basic.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def test_expm1more(self): ex1 = (special.expm1(2),special.expm1(2.1),special.expm1(2.2)) exrl1 = (exp(2)-1,exp(2.1)-1,exp(2.2)-1) assert_array_almost_equal(ex1,exrl1,8)
Example #16
Source File: test_basic.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def test_expm1(self): ex = (special.expm1(2),special.expm1(3),special.expm1(4)) exrl = (exp(2)-1,exp(3)-1,exp(4)-1) assert_array_almost_equal(ex,exrl,8)
Example #17
Source File: copula.py From Splunking-Crime with GNU Affero General Public License v3.0 | 5 votes |
def copula_bv_frank(u, v, theta): '''Cook, Johnson bivariate copula ''' if not theta > 0: raise ValueError('theta needs to be strictly positive') cdfv = -np.log(1 + expm1(-theta*u) * expm1(-theta*v) / expm1(-theta))/theta cdfv = np.minimum(cdfv, 1) #necessary for example if theta=100 return cdfv
Example #18
Source File: _continuous_distns.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def _munp(self, n, b): # wrong answer with formula, same as in continuous.pdf # return sc.gamman+1)-sc.gammainc1+n, b) if n == 1: return (1-(b+1)*np.exp(-b))/(-sc.expm1(-b)) elif n == 2: return 2*(1-0.5*(b*b+2*b+2)*np.exp(-b))/(-sc.expm1(-b)) else: # return generic for higher moments # return rv_continuous._mom1_sc(self, n, b) return self._mom1_sc(n, b)
Example #19
Source File: _continuous_distns.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def _ppf(self, q, b): return -sc.log1p(q*sc.expm1(-b))
Example #20
Source File: _continuous_distns.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def _cdf(self, x, b): return sc.expm1(-x)/sc.expm1(-b)
Example #21
Source File: _continuous_distns.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def _logpdf(self, x, b): return -x - np.log(-sc.expm1(-b))
Example #22
Source File: _continuous_distns.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def _cdf(self, r): return -sc.expm1(-0.5 * r**2)
Example #23
Source File: _continuous_distns.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def _ppf(self, q, c): return sc.expm1(-sc.log1p(-q)/c)
Example #24
Source File: _continuous_distns.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def _cdf(self, x, c): return -sc.expm1(-c*sc.log1p(x))
Example #25
Source File: _continuous_distns.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def _cdf(self, x): return -sc.expm1(-np.exp(x))
Example #26
Source File: _continuous_distns.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def _cdf(self, x, c): return -sc.expm1(-c * sc.expm1(x))
Example #27
Source File: _continuous_distns.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def _stats(self, c): g = lambda n: sc.gamma(n*c + 1) g1 = g(1) g2 = g(2) g3 = g(3) g4 = g(4) g2mg12 = np.where(abs(c) < 1e-7, (c*np.pi)**2.0/6.0, g2-g1**2.0) gam2k = np.where(abs(c) < 1e-7, np.pi**2.0/6.0, sc.expm1(sc.gammaln(2.0*c+1.0)-2*sc.gammaln(c + 1.0))/c**2.0) eps = 1e-14 gamk = np.where(abs(c) < eps, -_EULER, sc.expm1(sc.gammaln(c + 1))/c) m = np.where(c < -1.0, np.nan, -gamk) v = np.where(c < -0.5, np.nan, g1**2.0*gam2k) # skewness sk1 = _lazywhere(c >= -1./3, (c, g1, g2, g3, g2mg12), lambda c, g1, g2, g3, g2gm12: np.sign(c)*(-g3 + (g2 + 2*g2mg12)*g1)/g2mg12**1.5, fillvalue=np.nan) sk = np.where(abs(c) <= eps**0.29, 12*np.sqrt(6)*_ZETA3/np.pi**3, sk1) # kurtosis ku1 = _lazywhere(c >= -1./4, (g1, g2, g3, g4, g2mg12), lambda g1, g2, g3, g4, g2mg12: (g4 + (-4*g3 + 3*(g2 + g2mg12)*g1)*g1)/g2mg12**2, fillvalue=np.nan) ku = np.where(abs(c) <= (eps)**0.23, 12.0/5.0, ku1-3.0) return m, v, sk, ku
Example #28
Source File: _continuous_distns.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def _isf(self, q, c): x = -np.log(-sc.log1p(-q)) return _lazywhere((x == x) & (c != 0), (x, c), lambda x, c: -sc.expm1(-c * x) / c, x)
Example #29
Source File: _continuous_distns.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def _ppf(self, q, c): x = -np.log(-np.log(q)) return _lazywhere((x == x) & (c != 0), (x, c), lambda x, c: -sc.expm1(-c * x) / c, x)
Example #30
Source File: _continuous_distns.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def _sf(self, x, c): return -sc.expm1(self._logcdf(x, c))