|
|
@ -15,12 +15,13 @@ from scipy.special import (gammaln as gamln, gamma as gam, boxcox, boxcox1p,
|
|
|
|
inv_boxcox, inv_boxcox1p, erfc, chndtr, chndtrix,
|
|
|
|
inv_boxcox, inv_boxcox1p, erfc, chndtr, chndtrix,
|
|
|
|
log1p, expm1,
|
|
|
|
log1p, expm1,
|
|
|
|
i0, i1, ndtr as _norm_cdf, log_ndtr as _norm_logcdf)
|
|
|
|
i0, i1, ndtr as _norm_cdf, log_ndtr as _norm_logcdf)
|
|
|
|
|
|
|
|
# from scipy._lib._numpy_compat import broadcast_to
|
|
|
|
|
|
|
|
|
|
|
|
from numpy import (where, arange, putmask, ravel, shape,
|
|
|
|
from numpy import (where, arange, putmask, ravel, shape,
|
|
|
|
log, sqrt, exp, arctanh, tan, sin, arcsin, arctan,
|
|
|
|
log, sqrt, exp, arctanh, tan, sin, arcsin, arctan,
|
|
|
|
tanh, cos, cosh, sinh)
|
|
|
|
tanh, cos, cosh, sinh)
|
|
|
|
|
|
|
|
|
|
|
|
from numpy import polyval, place, extract, asarray, nan, inf, pi
|
|
|
|
from numpy import polyval, place, extract, asarray, nan, inf, pi, broadcast_to
|
|
|
|
|
|
|
|
|
|
|
|
import numpy as np
|
|
|
|
import numpy as np
|
|
|
|
from scipy.stats.mstats_basic import mode
|
|
|
|
from scipy.stats.mstats_basic import mode
|
|
|
@ -35,9 +36,10 @@ from scipy.stats._tukeylambda_stats import (tukeylambda_variance as _tlvar,
|
|
|
|
from wafo.stats._distn_infrastructure import (
|
|
|
|
from wafo.stats._distn_infrastructure import (
|
|
|
|
rv_continuous, valarray, _skew, _kurtosis, _lazywhere,
|
|
|
|
rv_continuous, valarray, _skew, _kurtosis, _lazywhere,
|
|
|
|
_ncx2_log_pdf, _ncx2_pdf, _ncx2_cdf, get_distribution_names,
|
|
|
|
_ncx2_log_pdf, _ncx2_pdf, _ncx2_cdf, get_distribution_names,
|
|
|
|
|
|
|
|
_lazyselect
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
from wafo.stats._constants import _XMIN, _EULER, _ZETA3, _XMAX, _LOGXMAX, _EPS
|
|
|
|
from wafo.stats._constants import _XMIN, _EULER, _ZETA3, _XMAX, _LOGXMAX
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## Kolmogorov-Smirnov one-sided and two-sided test statistics
|
|
|
|
## Kolmogorov-Smirnov one-sided and two-sided test statistics
|
|
|
@ -215,6 +217,8 @@ class alpha_gen(rv_continuous):
|
|
|
|
%(example)s
|
|
|
|
%(example)s
|
|
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
|
|
|
|
_support_mask = rv_continuous._open_support_mask
|
|
|
|
|
|
|
|
|
|
|
|
def _pdf(self, x, a):
|
|
|
|
def _pdf(self, x, a):
|
|
|
|
return 1.0/(x**2)/_norm_cdf(a)*_norm_pdf(a-1.0/x)
|
|
|
|
return 1.0/(x**2)/_norm_cdf(a)*_norm_pdf(a-1.0/x)
|
|
|
|
|
|
|
|
|
|
|
@ -285,6 +289,8 @@ class arcsine_gen(rv_continuous):
|
|
|
|
%(example)s
|
|
|
|
%(example)s
|
|
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
|
|
|
|
_support_mask = rv_continuous._open_support_mask
|
|
|
|
|
|
|
|
|
|
|
|
def _pdf(self, x):
|
|
|
|
def _pdf(self, x):
|
|
|
|
return 1.0/pi/sqrt(x*(1-x))
|
|
|
|
return 1.0/pi/sqrt(x*(1-x))
|
|
|
|
|
|
|
|
|
|
|
@ -535,6 +541,8 @@ class betaprime_gen(rv_continuous):
|
|
|
|
%(example)s
|
|
|
|
%(example)s
|
|
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
|
|
|
|
_support_mask = rv_continuous._open_support_mask
|
|
|
|
|
|
|
|
|
|
|
|
def _rvs(self, a, b):
|
|
|
|
def _rvs(self, a, b):
|
|
|
|
sz, rndm = self._size, self._random_state
|
|
|
|
sz, rndm = self._size, self._random_state
|
|
|
|
u1 = gamma.rvs(a, size=sz, random_state=rndm)
|
|
|
|
u1 = gamma.rvs(a, size=sz, random_state=rndm)
|
|
|
@ -604,10 +612,10 @@ class bradford_gen(rv_continuous):
|
|
|
|
return c * exp(-log1p(c * x)) / log1p(c)
|
|
|
|
return c * exp(-log1p(c * x)) / log1p(c)
|
|
|
|
|
|
|
|
|
|
|
|
def _cdf(self, x, c):
|
|
|
|
def _cdf(self, x, c):
|
|
|
|
return log1p(c * x) / log1p(c)
|
|
|
|
return special.log1p(c * x) / special.log1p(c)
|
|
|
|
|
|
|
|
|
|
|
|
def _ppf(self, q, c):
|
|
|
|
def _ppf(self, q, c):
|
|
|
|
return expm1(q * log1p(c))/c # ((1.0+c)**q-1)/c
|
|
|
|
return special.expm1(q * special.log1p(c)) / c
|
|
|
|
|
|
|
|
|
|
|
|
def _stats(self, c, moments='mv'):
|
|
|
|
def _stats(self, c, moments='mv'):
|
|
|
|
k = log1p(c)
|
|
|
|
k = log1p(c)
|
|
|
@ -672,6 +680,8 @@ class burr_gen(rv_continuous):
|
|
|
|
%(example)s
|
|
|
|
%(example)s
|
|
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
|
|
|
|
_support_mask = rv_continuous._open_support_mask
|
|
|
|
|
|
|
|
|
|
|
|
def _pdf(self, x, c, d):
|
|
|
|
def _pdf(self, x, c, d):
|
|
|
|
return c * d * (x**(-c - 1.0)) * ((1 + x**(-c))**(-d - 1.0))
|
|
|
|
return c * d * (x**(-c - 1.0)) * ((1 + x**(-c))**(-d - 1.0))
|
|
|
|
|
|
|
|
|
|
|
@ -725,6 +735,8 @@ class burr12_gen(rv_continuous):
|
|
|
|
%(example)s
|
|
|
|
%(example)s
|
|
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
|
|
|
|
_support_mask = rv_continuous._open_support_mask
|
|
|
|
|
|
|
|
|
|
|
|
def _pdf(self, x, c, d):
|
|
|
|
def _pdf(self, x, c, d):
|
|
|
|
return np.exp(self._logpdf(x, c, d))
|
|
|
|
return np.exp(self._logpdf(x, c, d))
|
|
|
|
|
|
|
|
|
|
|
@ -732,7 +744,7 @@ class burr12_gen(rv_continuous):
|
|
|
|
return log(c) + log(d) + special.xlogy(c-1, x) + special.xlog1py(-d-1, x**c)
|
|
|
|
return log(c) + log(d) + special.xlogy(c-1, x) + special.xlog1py(-d-1, x**c)
|
|
|
|
|
|
|
|
|
|
|
|
def _cdf(self, x, c, d):
|
|
|
|
def _cdf(self, x, c, d):
|
|
|
|
return 1 - self._sf(x, c, d)
|
|
|
|
return -special.expm1(self._logsf(x, c, d))
|
|
|
|
|
|
|
|
|
|
|
|
def _logcdf(self, x, c, d):
|
|
|
|
def _logcdf(self, x, c, d):
|
|
|
|
return special.log1p(-(1 + x**c)**(-d))
|
|
|
|
return special.log1p(-(1 + x**c)**(-d))
|
|
|
@ -869,6 +881,7 @@ class chi_gen(rv_continuous):
|
|
|
|
%(example)s
|
|
|
|
%(example)s
|
|
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
def _rvs(self, df):
|
|
|
|
def _rvs(self, df):
|
|
|
|
sz, rndm = self._size, self._random_state
|
|
|
|
sz, rndm = self._size, self._random_state
|
|
|
|
return sqrt(chi2.rvs(df, size=sz, random_state=rndm))
|
|
|
|
return sqrt(chi2.rvs(df, size=sz, random_state=rndm))
|
|
|
@ -1338,6 +1351,8 @@ class fatiguelife_gen(rv_continuous):
|
|
|
|
%(example)s
|
|
|
|
%(example)s
|
|
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
|
|
|
|
_support_mask = rv_continuous._open_support_mask
|
|
|
|
|
|
|
|
|
|
|
|
def _rvs(self, c):
|
|
|
|
def _rvs(self, c):
|
|
|
|
z = self._random_state.standard_normal(self._size)
|
|
|
|
z = self._random_state.standard_normal(self._size)
|
|
|
|
x = 0.5*c*z
|
|
|
|
x = 0.5*c*z
|
|
|
@ -1584,6 +1599,7 @@ class frechet_r_gen(rv_continuous):
|
|
|
|
%(example)s
|
|
|
|
%(example)s
|
|
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
def _pdf(self, x, c):
|
|
|
|
def _pdf(self, x, c):
|
|
|
|
return c*pow(x, c-1)*exp(-pow(x, c))
|
|
|
|
return c*pow(x, c-1)*exp(-pow(x, c))
|
|
|
|
|
|
|
|
|
|
|
@ -1853,7 +1869,7 @@ class genexpon_gen(rv_continuous):
|
|
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
def _pdf(self, x, a, b, c):
|
|
|
|
def _pdf(self, x, a, b, c):
|
|
|
|
return (a + b*(-special.expm1(-c*x))) * exp((-a-b)*x +
|
|
|
|
return (a + b*(-special.expm1(-c*x)))*exp((-a-b)*x +
|
|
|
|
b*(-special.expm1(-c*x))/c)
|
|
|
|
b*(-special.expm1(-c*x))/c)
|
|
|
|
|
|
|
|
|
|
|
|
def _cdf(self, x, a, b, c):
|
|
|
|
def _cdf(self, x, a, b, c):
|
|
|
@ -1900,11 +1916,15 @@ class genextreme_gen(rv_continuous):
|
|
|
|
self.a = where(c < 0, 1.0 / min(c, -_XMIN), -inf)
|
|
|
|
self.a = where(c < 0, 1.0 / min(c, -_XMIN), -inf)
|
|
|
|
return where(abs(c) == inf, 0, 1)
|
|
|
|
return where(abs(c) == inf, 0, 1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _loglogcdf(self, x, c):
|
|
|
|
|
|
|
|
return _lazywhere((x == x) & (c != 0), (x, c),
|
|
|
|
|
|
|
|
lambda x, c: special.log1p(-c*x)/c, -x)
|
|
|
|
|
|
|
|
|
|
|
|
def _pdf(self, x, c):
|
|
|
|
def _pdf(self, x, c):
|
|
|
|
return exp(self._logpdf(x, c))
|
|
|
|
return exp(self._logpdf(x, c))
|
|
|
|
|
|
|
|
|
|
|
|
def _logpdf(self, x, c):
|
|
|
|
def _logpdf(self, x, c):
|
|
|
|
cx = _lazywhere((c != 0)*(x == x), (x, c), lambda x, c: c*x, 0.0)
|
|
|
|
cx = _lazywhere((x == x) & (c != 0), (x, c), lambda x, c: c*x, 0.0)
|
|
|
|
logex2 = special.log1p(-cx)
|
|
|
|
logex2 = special.log1p(-cx)
|
|
|
|
logpex2 = self._loglogcdf(x, c)
|
|
|
|
logpex2 = self._loglogcdf(x, c)
|
|
|
|
pex2 = exp(logpex2)
|
|
|
|
pex2 = exp(logpex2)
|
|
|
@ -1914,18 +1934,14 @@ class genextreme_gen(rv_continuous):
|
|
|
|
putmask(logpdf, (c == 1) & (x == 1), 0.0)
|
|
|
|
putmask(logpdf, (c == 1) & (x == 1), 0.0)
|
|
|
|
return logpdf
|
|
|
|
return logpdf
|
|
|
|
|
|
|
|
|
|
|
|
def _cdf(self, x, c):
|
|
|
|
|
|
|
|
return exp(self._logcdf(x, c))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _loglogcdf(self, x, c):
|
|
|
|
|
|
|
|
return _lazywhere((c != 0) & (x == x), (x, c),
|
|
|
|
|
|
|
|
lambda x, c: special.log1p(-c * x)/c, -x)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _logcdf(self, x, c):
|
|
|
|
def _logcdf(self, x, c):
|
|
|
|
return -exp(self._loglogcdf(x, c))
|
|
|
|
return -exp(self._loglogcdf(x, c))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _cdf(self, x, c):
|
|
|
|
|
|
|
|
return exp(self._logcdf(x, c))
|
|
|
|
|
|
|
|
|
|
|
|
def _sf(self, x, c):
|
|
|
|
def _sf(self, x, c):
|
|
|
|
return -expm1(self._logcdf(x, c))
|
|
|
|
return - expm1(self._logcdf(x, c))
|
|
|
|
|
|
|
|
|
|
|
|
def _ppf(self, q, c):
|
|
|
|
def _ppf(self, q, c):
|
|
|
|
x = -log(-log(q))
|
|
|
|
x = -log(-log(q))
|
|
|
@ -2233,7 +2249,7 @@ class gengamma_gen(rv_continuous):
|
|
|
|
|
|
|
|
|
|
|
|
gengamma.pdf(x, a, c) = abs(c) * x**(c*a-1) * exp(-x**c) / gamma(a)
|
|
|
|
gengamma.pdf(x, a, c) = abs(c) * x**(c*a-1) * exp(-x**c) / gamma(a)
|
|
|
|
|
|
|
|
|
|
|
|
for ``x > 0``, ``a > 0``, and ``c != 0``.
|
|
|
|
for ``x >= 0``, ``a > 0``, and ``c != 0``.
|
|
|
|
|
|
|
|
|
|
|
|
`gengamma` takes ``a`` and ``c`` as shape parameters.
|
|
|
|
`gengamma` takes ``a`` and ``c`` as shape parameters.
|
|
|
|
|
|
|
|
|
|
|
@ -2443,17 +2459,20 @@ class gumbel_l_gen(rv_continuous):
|
|
|
|
def _logpdf(self, x):
|
|
|
|
def _logpdf(self, x):
|
|
|
|
return x - exp(x)
|
|
|
|
return x - exp(x)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _cdf(self, x):
|
|
|
|
|
|
|
|
return -special.expm1(-exp(x))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _ppf(self, q):
|
|
|
|
|
|
|
|
return log(-special.log1p(-q))
|
|
|
|
|
|
|
|
|
|
|
|
def _logsf(self, x):
|
|
|
|
def _logsf(self, x):
|
|
|
|
return -exp(x)
|
|
|
|
return -exp(x)
|
|
|
|
|
|
|
|
|
|
|
|
def _sf(self, x):
|
|
|
|
def _sf(self, x):
|
|
|
|
return exp(-exp(x))
|
|
|
|
return exp(-exp(x))
|
|
|
|
|
|
|
|
|
|
|
|
def _cdf(self, x):
|
|
|
|
def _isf(self, x):
|
|
|
|
return -expm1(-exp(x))
|
|
|
|
return log(-log(x))
|
|
|
|
|
|
|
|
|
|
|
|
def _ppf(self, q):
|
|
|
|
|
|
|
|
return log(-log1p(-q))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _stats(self):
|
|
|
|
def _stats(self):
|
|
|
|
return -_EULER, pi*pi/6.0, \
|
|
|
|
return -_EULER, pi*pi/6.0, \
|
|
|
@ -2684,6 +2703,8 @@ class invgamma_gen(rv_continuous):
|
|
|
|
%(example)s
|
|
|
|
%(example)s
|
|
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
|
|
|
|
_support_mask = rv_continuous._open_support_mask
|
|
|
|
|
|
|
|
|
|
|
|
def _pdf(self, x, a):
|
|
|
|
def _pdf(self, x, a):
|
|
|
|
return exp(self._logpdf(x, a))
|
|
|
|
return exp(self._logpdf(x, a))
|
|
|
|
|
|
|
|
|
|
|
@ -2691,10 +2712,16 @@ class invgamma_gen(rv_continuous):
|
|
|
|
return (-(a+1) * log(x) - gamln(a) - 1.0/x)
|
|
|
|
return (-(a+1) * log(x) - gamln(a) - 1.0/x)
|
|
|
|
|
|
|
|
|
|
|
|
def _cdf(self, x, a):
|
|
|
|
def _cdf(self, x, a):
|
|
|
|
return 1.0 - special.gammainc(a, 1.0/x)
|
|
|
|
return special.gammaincc(a, 1.0 / x)
|
|
|
|
|
|
|
|
|
|
|
|
def _ppf(self, q, a):
|
|
|
|
def _ppf(self, q, a):
|
|
|
|
return 1.0 / special.gammaincinv(a, 1.-q)
|
|
|
|
return 1.0 / special.gammainccinv(a, q)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _sf(self, x, a):
|
|
|
|
|
|
|
|
return special.gammainc(a, 1.0 / x)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _isf(self, q, a):
|
|
|
|
|
|
|
|
return 1.0 / special.gammaincinv(a, q)
|
|
|
|
|
|
|
|
|
|
|
|
def _stats(self, a, moments='mvsk'):
|
|
|
|
def _stats(self, a, moments='mvsk'):
|
|
|
|
m1 = _lazywhere(a > 1, (a,), lambda x: 1. / (x - 1.), np.inf)
|
|
|
|
m1 = _lazywhere(a > 1, (a,), lambda x: 1. / (x - 1.), np.inf)
|
|
|
@ -2742,6 +2769,8 @@ class invgauss_gen(rv_continuous):
|
|
|
|
%(example)s
|
|
|
|
%(example)s
|
|
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
|
|
|
|
_support_mask = rv_continuous._open_support_mask
|
|
|
|
|
|
|
|
|
|
|
|
def _rvs(self, mu):
|
|
|
|
def _rvs(self, mu):
|
|
|
|
return self._random_state.wald(mu, 1.0, size=self._size)
|
|
|
|
return self._random_state.wald(mu, 1.0, size=self._size)
|
|
|
|
|
|
|
|
|
|
|
@ -2788,6 +2817,8 @@ class invweibull_gen(rv_continuous):
|
|
|
|
%(example)s
|
|
|
|
%(example)s
|
|
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
|
|
|
|
_support_mask = rv_continuous._open_support_mask
|
|
|
|
|
|
|
|
|
|
|
|
def _pdf(self, x, c):
|
|
|
|
def _pdf(self, x, c):
|
|
|
|
xc1 = np.power(x, -c - 1.0)
|
|
|
|
xc1 = np.power(x, -c - 1.0)
|
|
|
|
xc2 = np.power(x, -c)
|
|
|
|
xc2 = np.power(x, -c)
|
|
|
@ -2833,6 +2864,8 @@ class johnsonsb_gen(rv_continuous):
|
|
|
|
%(example)s
|
|
|
|
%(example)s
|
|
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
|
|
|
|
_support_mask = rv_continuous._open_support_mask
|
|
|
|
|
|
|
|
|
|
|
|
def _argcheck(self, a, b):
|
|
|
|
def _argcheck(self, a, b):
|
|
|
|
return (b > 0) & (a == a)
|
|
|
|
return (b > 0) & (a == a)
|
|
|
|
|
|
|
|
|
|
|
@ -2915,7 +2948,10 @@ class laplace_gen(rv_continuous):
|
|
|
|
return where(x > 0, 1.0-0.5*exp(-x), 0.5*exp(x))
|
|
|
|
return where(x > 0, 1.0-0.5*exp(-x), 0.5*exp(x))
|
|
|
|
|
|
|
|
|
|
|
|
def _ppf(self, q):
|
|
|
|
def _ppf(self, q):
|
|
|
|
return where(q > 0.5, -log(2) - log1p(-q), log(2 * q))
|
|
|
|
return where(q > 0.5, -log(2*(1-q)), log(2*q))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _isf(self, q):
|
|
|
|
|
|
|
|
return where(q < 0.5, -log(2*q), log(2*(1-q)))
|
|
|
|
|
|
|
|
|
|
|
|
def _stats(self):
|
|
|
|
def _stats(self):
|
|
|
|
return 0, 2, 0, 3
|
|
|
|
return 0, 2, 0, 3
|
|
|
@ -2949,6 +2985,8 @@ class levy_gen(rv_continuous):
|
|
|
|
%(example)s
|
|
|
|
%(example)s
|
|
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
|
|
|
|
_support_mask = rv_continuous._open_support_mask
|
|
|
|
|
|
|
|
|
|
|
|
def _pdf(self, x):
|
|
|
|
def _pdf(self, x):
|
|
|
|
return 1 / sqrt(2*pi*x) / x * exp(-1/(2*x))
|
|
|
|
return 1 / sqrt(2*pi*x) / x * exp(-1/(2*x))
|
|
|
|
|
|
|
|
|
|
|
@ -2990,6 +3028,8 @@ class levy_l_gen(rv_continuous):
|
|
|
|
%(example)s
|
|
|
|
%(example)s
|
|
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
|
|
|
|
_support_mask = rv_continuous._open_support_mask
|
|
|
|
|
|
|
|
|
|
|
|
def _pdf(self, x):
|
|
|
|
def _pdf(self, x):
|
|
|
|
ax = abs(x)
|
|
|
|
ax = abs(x)
|
|
|
|
return 1/sqrt(2*pi*ax)/ax*exp(-1/(2*ax))
|
|
|
|
return 1/sqrt(2*pi*ax)/ax*exp(-1/(2*ax))
|
|
|
@ -3026,29 +3066,47 @@ class levy_stable_gen(rv_continuous):
|
|
|
|
%(example)s
|
|
|
|
%(example)s
|
|
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
def _rvs(self, alpha, beta):
|
|
|
|
def _rvs(self, alpha, beta):
|
|
|
|
sz = self._size
|
|
|
|
|
|
|
|
TH = uniform.rvs(loc=-pi/2.0, scale=pi, size=sz)
|
|
|
|
|
|
|
|
W = expon.rvs(size=sz)
|
|
|
|
|
|
|
|
if alpha == 1:
|
|
|
|
|
|
|
|
return 2/pi*(pi/2+beta*TH)*tan(TH)-beta*log((pi/2*W*cos(TH))/(pi/2+beta*TH))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ialpha = 1.0/alpha
|
|
|
|
def alpha1func(alpha, beta, TH, aTH, bTH, cosTH, tanTH, W):
|
|
|
|
aTH = alpha*TH
|
|
|
|
return (2/pi*(pi/2 + bTH)*tanTH -
|
|
|
|
if beta == 0:
|
|
|
|
beta*log((pi/2*W*cosTH)/(pi/2 + bTH)))
|
|
|
|
return W/(cos(TH)/tan(aTH)+sin(TH))*((cos(aTH)+sin(aTH)*tan(TH))/W)**ialpha
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def beta0func(alpha, beta, TH, aTH, bTH, cosTH, tanTH, W):
|
|
|
|
|
|
|
|
return (W/(cosTH/tan(aTH) + sin(TH)) *
|
|
|
|
|
|
|
|
((cos(aTH) + sin(aTH)*tanTH)/W)**(1.0/alpha))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def otherwise(alpha, beta, TH, aTH, bTH, cosTH, tanTH, W):
|
|
|
|
|
|
|
|
# alpha is not 1 and beta is not 0
|
|
|
|
val0 = beta*tan(pi*alpha/2)
|
|
|
|
val0 = beta*tan(pi*alpha/2)
|
|
|
|
th0 = arctan(val0)/alpha
|
|
|
|
th0 = arctan(val0)/alpha
|
|
|
|
val3 = W/(cos(TH)/tan(alpha*(th0+TH))+sin(TH))
|
|
|
|
val3 = W/(cosTH/tan(alpha*(th0 + TH)) + sin(TH))
|
|
|
|
res3 = val3*((cos(aTH)+sin(aTH)*tan(TH)-val0*(sin(aTH)-cos(aTH)*tan(TH)))/W)**ialpha
|
|
|
|
res3 = val3*((cos(aTH) + sin(aTH)*tanTH - val0*(sin(aTH) -
|
|
|
|
|
|
|
|
cos(aTH)*tanTH))/W)**(1.0/alpha)
|
|
|
|
return res3
|
|
|
|
return res3
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def alphanot1func(alpha, beta, TH, aTH, bTH, cosTH, tanTH, W):
|
|
|
|
|
|
|
|
res = _lazywhere(beta == 0,
|
|
|
|
|
|
|
|
(alpha, beta, TH, aTH, bTH, cosTH, tanTH, W),
|
|
|
|
|
|
|
|
beta0func, f2=otherwise)
|
|
|
|
|
|
|
|
return res
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sz = self._size
|
|
|
|
|
|
|
|
alpha = broadcast_to(alpha, sz)
|
|
|
|
|
|
|
|
beta = broadcast_to(beta, sz)
|
|
|
|
|
|
|
|
TH = uniform.rvs(loc=-pi/2.0, scale=pi, size=sz,
|
|
|
|
|
|
|
|
random_state=self._random_state)
|
|
|
|
|
|
|
|
W = expon.rvs(size=sz, random_state=self._random_state)
|
|
|
|
|
|
|
|
aTH = alpha*TH
|
|
|
|
|
|
|
|
bTH = beta*TH
|
|
|
|
|
|
|
|
cosTH = cos(TH)
|
|
|
|
|
|
|
|
tanTH = tan(TH)
|
|
|
|
|
|
|
|
res = _lazywhere(alpha == 1, (alpha, beta, TH, aTH, bTH, cosTH, tanTH, W),
|
|
|
|
|
|
|
|
alpha1func, f2=alphanot1func)
|
|
|
|
|
|
|
|
return res
|
|
|
|
|
|
|
|
|
|
|
|
def _argcheck(self, alpha, beta):
|
|
|
|
def _argcheck(self, alpha, beta):
|
|
|
|
if beta == -1:
|
|
|
|
|
|
|
|
self.b = 0.0
|
|
|
|
|
|
|
|
elif beta == 1:
|
|
|
|
|
|
|
|
self.a = 0.0
|
|
|
|
|
|
|
|
return (alpha > 0) & (alpha <= 2) & (beta <= 1) & (beta >= -1)
|
|
|
|
return (alpha > 0) & (alpha <= 2) & (beta <= 1) & (beta >= -1)
|
|
|
|
|
|
|
|
|
|
|
|
def _pdf(self, x, alpha, beta):
|
|
|
|
def _pdf(self, x, alpha, beta):
|
|
|
@ -3087,10 +3145,13 @@ class logistic_gen(rv_continuous):
|
|
|
|
return special.expit(x)
|
|
|
|
return special.expit(x)
|
|
|
|
|
|
|
|
|
|
|
|
def _ppf(self, q):
|
|
|
|
def _ppf(self, q):
|
|
|
|
return -log1p(-q) + log(q)
|
|
|
|
return special.logit(q)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _sf(self, x):
|
|
|
|
|
|
|
|
return special.expit(-x)
|
|
|
|
|
|
|
|
|
|
|
|
def _isf(self, q):
|
|
|
|
def _isf(self, q):
|
|
|
|
return log1p(-q) - log(q)
|
|
|
|
return -special.logit(q)
|
|
|
|
|
|
|
|
|
|
|
|
def _stats(self):
|
|
|
|
def _stats(self):
|
|
|
|
return 0, pi*pi/3.0, 0, 6.0/5.0
|
|
|
|
return 0, pi*pi/3.0, 0, 6.0/5.0
|
|
|
@ -3222,6 +3283,8 @@ class lognorm_gen(rv_continuous):
|
|
|
|
%(example)s
|
|
|
|
%(example)s
|
|
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
|
|
|
|
_support_mask = rv_continuous._open_support_mask
|
|
|
|
|
|
|
|
|
|
|
|
def _rvs(self, s):
|
|
|
|
def _rvs(self, s):
|
|
|
|
return exp(s * self._random_state.standard_normal(self._size))
|
|
|
|
return exp(s * self._random_state.standard_normal(self._size))
|
|
|
|
|
|
|
|
|
|
|
@ -3285,6 +3348,8 @@ class gilbrat_gen(rv_continuous):
|
|
|
|
%(example)s
|
|
|
|
%(example)s
|
|
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
|
|
|
|
_support_mask = rv_continuous._open_support_mask
|
|
|
|
|
|
|
|
|
|
|
|
def _rvs(self):
|
|
|
|
def _rvs(self):
|
|
|
|
return exp(self._random_state.standard_normal(self._size))
|
|
|
|
return exp(self._random_state.standard_normal(self._size))
|
|
|
|
|
|
|
|
|
|
|
@ -3397,6 +3462,306 @@ class mielke_gen(rv_continuous):
|
|
|
|
mielke = mielke_gen(a=0.0, name='mielke')
|
|
|
|
mielke = mielke_gen(a=0.0, name='mielke')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class kappa4_gen(rv_continuous):
|
|
|
|
|
|
|
|
"""Kappa 4 parameter distribution.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
%(before_notes)s
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Notes
|
|
|
|
|
|
|
|
-----
|
|
|
|
|
|
|
|
The probability density function for kappa4 is::
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
kappa4.pdf(x, h, k) = (1.0 - k*x)**(1.0/k - 1.0)*
|
|
|
|
|
|
|
|
(1.0 - h*(1.0 - k*x)**(1.0/k))**(1.0/h-1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ``h`` and ``k`` are not equal to 0.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
If ``h`` or ``k`` are zero then the pdf can be simplified:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
h = 0 and k != 0::
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
kappa4.pdf(x, h, k) = (1.0 - k*x)**(1.0/k - 1.0)*
|
|
|
|
|
|
|
|
exp(-(1.0 - k*x)**(1.0/k))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
h != 0 and k = 0::
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
kappa4.pdf(x, h, k) = exp(-x)*(1.0 - h*exp(-x))**(1.0/h - 1.0)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
h = 0 and k = 0::
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
kappa4.pdf(x, h, k) = exp(-x)*exp(-exp(-x))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
kappa4 takes ``h`` and ``k`` as shape parameters.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
The kappa4 distribution returns other distributions when certain
|
|
|
|
|
|
|
|
``h`` and ``k`` values are used.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+------+-------------+----------------+------------------+
|
|
|
|
|
|
|
|
| h | k=0.0 | k=1.0 | -inf<=k<=inf |
|
|
|
|
|
|
|
|
+======+=============+================+==================+
|
|
|
|
|
|
|
|
| -1.0 | Logistic | | Generalized |
|
|
|
|
|
|
|
|
| | | | Logistic(1) |
|
|
|
|
|
|
|
|
| | | | |
|
|
|
|
|
|
|
|
| | logistic(x) | | |
|
|
|
|
|
|
|
|
+------+-------------+----------------+------------------+
|
|
|
|
|
|
|
|
| 0.0 | Gumbel | Reverse | Generalized |
|
|
|
|
|
|
|
|
| | | Exponential(2) | Extreme Value |
|
|
|
|
|
|
|
|
| | | | |
|
|
|
|
|
|
|
|
| | gumbel_r(x) | | genextreme(x, k) |
|
|
|
|
|
|
|
|
+------+-------------+----------------+------------------+
|
|
|
|
|
|
|
|
| 1.0 | Exponential | Uniform | Generalized |
|
|
|
|
|
|
|
|
| | | | Pareto |
|
|
|
|
|
|
|
|
| | | | |
|
|
|
|
|
|
|
|
| | expon(x) | uniform(x) | genpareto(x, -k) |
|
|
|
|
|
|
|
|
+------+-------------+----------------+------------------+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(1) There are at least five generalized logistic distributions.
|
|
|
|
|
|
|
|
Four are described here:
|
|
|
|
|
|
|
|
https://en.wikipedia.org/wiki/Generalized_logistic_distribution
|
|
|
|
|
|
|
|
The "fifth" one is the one kappa4 should match which currently
|
|
|
|
|
|
|
|
isn't implemented in scipy:
|
|
|
|
|
|
|
|
https://en.wikipedia.org/wiki/Talk:Generalized_logistic_distribution
|
|
|
|
|
|
|
|
http://www.mathwave.com/help/easyfit/html/analyses/distributions/gen_logistic.html
|
|
|
|
|
|
|
|
(2) This distribution is currently not in scipy.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
References
|
|
|
|
|
|
|
|
----------
|
|
|
|
|
|
|
|
J.C. Finney, "Optimization of a Skewed Logistic Distribution With Respect
|
|
|
|
|
|
|
|
to the Kolmogorov-Smirnov Test", A Dissertation Submitted to the Graduate
|
|
|
|
|
|
|
|
Faculty of the Louisiana State University and Agricultural and Mechanical
|
|
|
|
|
|
|
|
College, (August, 2004),
|
|
|
|
|
|
|
|
http://etd.lsu.edu/docs/available/etd-05182004-144851/unrestricted/Finney_dis.pdf
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
J.R.M. Hosking, "The four-parameter kappa distribution". IBM J. Res.
|
|
|
|
|
|
|
|
Develop. 38 (3), 25 1-258 (1994).
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
B. Kumphon, A. Kaew-Man, P. Seenoi, "A Rainfall Distribution for the Lampao
|
|
|
|
|
|
|
|
Site in the Chi River Basin, Thailand", Journal of Water Resource and
|
|
|
|
|
|
|
|
Protection, vol. 4, 866-869, (2012).
|
|
|
|
|
|
|
|
http://file.scirp.org/pdf/JWARP20121000009_14676002.pdf
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
C. Winchester, "On Estimation of the Four-Parameter Kappa Distribution", A
|
|
|
|
|
|
|
|
Thesis Submitted to Dalhousie University, Halifax, Nova Scotia, (March
|
|
|
|
|
|
|
|
2000).
|
|
|
|
|
|
|
|
http://www.nlc-bnc.ca/obj/s4/f2/dsk2/ftp01/MQ57336.pdf
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
%(after_notes)s
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
%(example)s
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
def _argcheck(self, h, k):
|
|
|
|
|
|
|
|
condlist = [np.logical_and(h > 0, k > 0),
|
|
|
|
|
|
|
|
np.logical_and(h > 0, k == 0),
|
|
|
|
|
|
|
|
np.logical_and(h > 0, k < 0),
|
|
|
|
|
|
|
|
np.logical_and(h <= 0, k > 0),
|
|
|
|
|
|
|
|
np.logical_and(h <= 0, k == 0),
|
|
|
|
|
|
|
|
np.logical_and(h <= 0, k < 0)]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def f0(h, k):
|
|
|
|
|
|
|
|
return (1.0 - h**(-k))/k
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def f1(h, k):
|
|
|
|
|
|
|
|
return log(h)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def f3(h, k):
|
|
|
|
|
|
|
|
a = np.empty(shape(h))
|
|
|
|
|
|
|
|
a[:] = -inf
|
|
|
|
|
|
|
|
return a
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def f5(h, k):
|
|
|
|
|
|
|
|
return 1.0/k
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.a = _lazyselect(condlist,
|
|
|
|
|
|
|
|
[f0, f1, f0, f3, f3, f5],
|
|
|
|
|
|
|
|
[h, k],
|
|
|
|
|
|
|
|
default=nan)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def f00(h, k):
|
|
|
|
|
|
|
|
return 1.0/k
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def f11(h, k):
|
|
|
|
|
|
|
|
a = np.empty(shape(h))
|
|
|
|
|
|
|
|
a[:] = inf
|
|
|
|
|
|
|
|
return a
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.b = _lazyselect(condlist,
|
|
|
|
|
|
|
|
[f00, f11, f11, f00, f11, f11],
|
|
|
|
|
|
|
|
[h, k],
|
|
|
|
|
|
|
|
default=nan)
|
|
|
|
|
|
|
|
return (h == h)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _pdf(self, x, h, k):
|
|
|
|
|
|
|
|
return exp(self._logpdf(x, h, k))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _logpdf(self, x, h, k):
|
|
|
|
|
|
|
|
condlist = [np.logical_and(h != 0, k != 0),
|
|
|
|
|
|
|
|
np.logical_and(h == 0, k != 0),
|
|
|
|
|
|
|
|
np.logical_and(h != 0, k == 0),
|
|
|
|
|
|
|
|
np.logical_and(h == 0, k == 0)]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def f0(x, h, k):
|
|
|
|
|
|
|
|
'''pdf = (1.0 - k*x)**(1.0/k - 1.0)*(
|
|
|
|
|
|
|
|
1.0 - h*(1.0 - k*x)**(1.0/k))**(1.0/h-1.0)
|
|
|
|
|
|
|
|
logpdf = ...
|
|
|
|
|
|
|
|
'''
|
|
|
|
|
|
|
|
return special.xlog1py(1.0/k-1.0,
|
|
|
|
|
|
|
|
-k*x
|
|
|
|
|
|
|
|
) + special.xlog1py(1.0/h-1.0,
|
|
|
|
|
|
|
|
-h*(1.0-k*x)**(1.0/k))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def f1(x, h, k):
|
|
|
|
|
|
|
|
'''pdf = (1.0 - k*x)**(1.0/k - 1.0)*exp(-(
|
|
|
|
|
|
|
|
1.0 - k*x)**(1.0/k))
|
|
|
|
|
|
|
|
logpdf = ...
|
|
|
|
|
|
|
|
'''
|
|
|
|
|
|
|
|
return special.xlog1py(1.0/k-1.0,-k*x)-(1.0-k*x)**(1.0/k)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def f2(x, h, k):
|
|
|
|
|
|
|
|
'''pdf = exp(-x)*(1.0 - h*exp(-x))**(1.0/h - 1.0)
|
|
|
|
|
|
|
|
logpdf = ...
|
|
|
|
|
|
|
|
'''
|
|
|
|
|
|
|
|
return -x + special.xlog1py(1.0/h-1.0, -h*exp(-x))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def f3(x, h, k):
|
|
|
|
|
|
|
|
'''pdf = exp(-x-exp(-x))
|
|
|
|
|
|
|
|
logpdf = ...
|
|
|
|
|
|
|
|
'''
|
|
|
|
|
|
|
|
return -x-exp(-x)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return _lazyselect(condlist,
|
|
|
|
|
|
|
|
[f0, f1, f2, f3],
|
|
|
|
|
|
|
|
[x, h, k],
|
|
|
|
|
|
|
|
default=nan)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _cdf(self, x, h, k):
|
|
|
|
|
|
|
|
return exp(self._logcdf(x, h, k))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _logcdf(self, x, h, k):
|
|
|
|
|
|
|
|
condlist = [np.logical_and(h != 0, k != 0),
|
|
|
|
|
|
|
|
np.logical_and(h == 0, k != 0),
|
|
|
|
|
|
|
|
np.logical_and(h != 0, k == 0),
|
|
|
|
|
|
|
|
np.logical_and(h == 0, k == 0)]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def f0(x, h, k):
|
|
|
|
|
|
|
|
'''cdf = (1.0 - h*(1.0 - k*x)**(1.0/k))**(1.0/h)
|
|
|
|
|
|
|
|
logcdf = ...
|
|
|
|
|
|
|
|
'''
|
|
|
|
|
|
|
|
return (1.0/h)*special.log1p(-h*(1.0-k*x)**(1.0/k))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def f1(x, h, k):
|
|
|
|
|
|
|
|
'''cdf = exp(-(1.0 - k*x)**(1.0/k))
|
|
|
|
|
|
|
|
logcdf = ...
|
|
|
|
|
|
|
|
'''
|
|
|
|
|
|
|
|
return -(1.0 - k*x)**(1.0/k)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def f2(x, h, k):
|
|
|
|
|
|
|
|
'''cdf = (1.0 - h*exp(-x))**(1.0/h)
|
|
|
|
|
|
|
|
logcdf = ...
|
|
|
|
|
|
|
|
'''
|
|
|
|
|
|
|
|
return (1.0/h)*special.log1p(-h*exp(-x))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def f3(x, h, k):
|
|
|
|
|
|
|
|
'''cdf = exp(-exp(-x))
|
|
|
|
|
|
|
|
logcdf = ...
|
|
|
|
|
|
|
|
'''
|
|
|
|
|
|
|
|
return -exp(-x)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return _lazyselect(condlist,
|
|
|
|
|
|
|
|
[f0, f1, f2, f3],
|
|
|
|
|
|
|
|
[x, h, k],
|
|
|
|
|
|
|
|
default=nan)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _ppf(self, q, h, k):
|
|
|
|
|
|
|
|
condlist = [np.logical_and(h != 0, k != 0),
|
|
|
|
|
|
|
|
np.logical_and(h == 0, k != 0),
|
|
|
|
|
|
|
|
np.logical_and(h != 0, k == 0),
|
|
|
|
|
|
|
|
np.logical_and(h == 0, k == 0)]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def f0(q, h, k):
|
|
|
|
|
|
|
|
return 1.0/k*(1.0 - ((1.0 - (q**h))/h)**k)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def f1(q, h, k):
|
|
|
|
|
|
|
|
return 1.0/k*(1.0 - (-log(q))**k)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def f2(q, h, k):
|
|
|
|
|
|
|
|
'''ppf = -log((1.0 - (q**h))/h)
|
|
|
|
|
|
|
|
'''
|
|
|
|
|
|
|
|
return -special.log1p(-(q**h)) + log(h)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def f3(q, h, k):
|
|
|
|
|
|
|
|
return -log(-log(q))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return _lazyselect(condlist,
|
|
|
|
|
|
|
|
[f0, f1, f2, f3],
|
|
|
|
|
|
|
|
[q, h, k],
|
|
|
|
|
|
|
|
default=nan)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _stats(self, h, k):
|
|
|
|
|
|
|
|
if h >= 0 and k >= 0:
|
|
|
|
|
|
|
|
maxr = 5
|
|
|
|
|
|
|
|
elif h < 0 and k >= 0:
|
|
|
|
|
|
|
|
maxr = int(-1.0/h*k)
|
|
|
|
|
|
|
|
elif k < 0:
|
|
|
|
|
|
|
|
maxr = int(-1.0/k)
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
maxr = 5
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
outputs = [None if r < maxr else nan for r in range(1, 5)]
|
|
|
|
|
|
|
|
return outputs[:]
|
|
|
|
|
|
|
|
kappa4 = kappa4_gen(name='kappa4')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class kappa3_gen(rv_continuous):
|
|
|
|
|
|
|
|
"""Kappa 3 parameter distribution.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
%(before_notes)s
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Notes
|
|
|
|
|
|
|
|
-----
|
|
|
|
|
|
|
|
The probability density function for `kappa` is::
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
kappa3.pdf(x, a) =
|
|
|
|
|
|
|
|
a*[a + x**a]**(-(a + 1)/a), for ``x > 0``
|
|
|
|
|
|
|
|
0.0, for ``x <= 0``
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
`kappa3` takes ``a`` as a shape parameter and ``a > 0``.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
References
|
|
|
|
|
|
|
|
----------
|
|
|
|
|
|
|
|
P.W. Mielke and E.S. Johnson, "Three-Parameter Kappa Distribution Maximum
|
|
|
|
|
|
|
|
Likelihood and Likelihood Ratio Tests", Methods in Weather Research,
|
|
|
|
|
|
|
|
701-707, (September, 1973),
|
|
|
|
|
|
|
|
http://docs.lib.noaa.gov/rescue/mwr/101/mwr-101-09-0701.pdf
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
B. Kumphon, "Maximum Entropy and Maximum Likelihood Estimation for the
|
|
|
|
|
|
|
|
Three-Parameter Kappa Distribution", Open Journal of Statistics, vol 2,
|
|
|
|
|
|
|
|
415-419 (2012)
|
|
|
|
|
|
|
|
http://file.scirp.org/pdf/OJS20120400011_95789012.pdf
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
%(after_notes)s
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
%(example)s
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
def _argcheck(self, a):
|
|
|
|
|
|
|
|
return a > 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _pdf(self, x, a):
|
|
|
|
|
|
|
|
return a*(a + x**a)**(-1.0/a-1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _cdf(self, x, a):
|
|
|
|
|
|
|
|
return x*(a + x**a)**(-1.0/a)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _ppf(self, q, a):
|
|
|
|
|
|
|
|
return (a/(q**-a - 1.0))**(1.0/a)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _stats(self, a):
|
|
|
|
|
|
|
|
outputs = [None if i < a else nan for i in range(1, 5)]
|
|
|
|
|
|
|
|
return outputs[:]
|
|
|
|
|
|
|
|
kappa3 = kappa3_gen(a=0.0, name='kappa3')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class nakagami_gen(rv_continuous):
|
|
|
|
class nakagami_gen(rv_continuous):
|
|
|
|
"""A Nakagami continuous random variable.
|
|
|
|
"""A Nakagami continuous random variable.
|
|
|
|
|
|
|
|
|
|
|
@ -3881,6 +4246,7 @@ class pearson3_gen(rv_continuous):
|
|
|
|
ans, x, skew = np.broadcast_arrays([1.0], x, skew)
|
|
|
|
ans, x, skew = np.broadcast_arrays([1.0], x, skew)
|
|
|
|
ans = ans.copy()
|
|
|
|
ans = ans.copy()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# mask is True where skew is small enough to use the normal approx.
|
|
|
|
mask = np.absolute(skew) < norm2pearson_transition
|
|
|
|
mask = np.absolute(skew) < norm2pearson_transition
|
|
|
|
invmask = ~mask
|
|
|
|
invmask = ~mask
|
|
|
|
|
|
|
|
|
|
|
@ -3940,13 +4306,18 @@ class pearson3_gen(rv_continuous):
|
|
|
|
return ans
|
|
|
|
return ans
|
|
|
|
|
|
|
|
|
|
|
|
def _rvs(self, skew):
|
|
|
|
def _rvs(self, skew):
|
|
|
|
|
|
|
|
skew = broadcast_to(skew, self._size)
|
|
|
|
ans, x, transx, skew, mask, invmask, beta, alpha, zeta = (
|
|
|
|
ans, x, transx, skew, mask, invmask, beta, alpha, zeta = (
|
|
|
|
self._preprocess([0], skew))
|
|
|
|
self._preprocess([0], skew))
|
|
|
|
if mask[0]:
|
|
|
|
|
|
|
|
return self._random_state.standard_normal(self._size)
|
|
|
|
nsmall = mask.sum()
|
|
|
|
ans = self._random_state.standard_gamma(alpha, self._size)/beta + zeta
|
|
|
|
nbig = mask.size - nsmall
|
|
|
|
if ans.size == 1:
|
|
|
|
ans[mask] = self._random_state.standard_normal(nsmall)
|
|
|
|
return ans[0]
|
|
|
|
ans[invmask] = (self._random_state.standard_gamma(alpha, nbig)/beta +
|
|
|
|
|
|
|
|
zeta)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if self._size == ():
|
|
|
|
|
|
|
|
ans = ans[0]
|
|
|
|
return ans
|
|
|
|
return ans
|
|
|
|
|
|
|
|
|
|
|
|
def _ppf(self, q, skew):
|
|
|
|
def _ppf(self, q, skew):
|
|
|
@ -4028,6 +4399,8 @@ class powerlognorm_gen(rv_continuous):
|
|
|
|
%(example)s
|
|
|
|
%(example)s
|
|
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
|
|
|
|
_support_mask = rv_continuous._open_support_mask
|
|
|
|
|
|
|
|
|
|
|
|
def _pdf(self, x, c, s):
|
|
|
|
def _pdf(self, x, c, s):
|
|
|
|
return (c/(x*s) * _norm_pdf(log(x)/s) *
|
|
|
|
return (c/(x*s) * _norm_pdf(log(x)/s) *
|
|
|
|
pow(_norm_cdf(-log(x)/s), c*1.0-1.0))
|
|
|
|
pow(_norm_cdf(-log(x)/s), c*1.0-1.0))
|
|
|
@ -4134,6 +4507,8 @@ class rayleigh_gen(rv_continuous):
|
|
|
|
%(example)s
|
|
|
|
%(example)s
|
|
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
|
|
|
|
_support_mask = rv_continuous._open_support_mask
|
|
|
|
|
|
|
|
|
|
|
|
def _rvs(self):
|
|
|
|
def _rvs(self):
|
|
|
|
return chi.rvs(2, size=self._size, random_state=self._random_state)
|
|
|
|
return chi.rvs(2, size=self._size, random_state=self._random_state)
|
|
|
|
|
|
|
|
|
|
|
@ -4141,9 +4516,7 @@ class rayleigh_gen(rv_continuous):
|
|
|
|
return exp(self._logpdf(r))
|
|
|
|
return exp(self._logpdf(r))
|
|
|
|
|
|
|
|
|
|
|
|
def _logpdf(self, r):
|
|
|
|
def _logpdf(self, r):
|
|
|
|
rr2 = r * r / 2.0
|
|
|
|
return log(r) - 0.5 * r * r
|
|
|
|
return _lazywhere(rr2 != inf, (r, rr2), lambda r, rr2: log(r) - rr2,
|
|
|
|
|
|
|
|
-rr2)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _cdf(self, r):
|
|
|
|
def _cdf(self, r):
|
|
|
|
return -special.expm1(-0.5 * r**2)
|
|
|
|
return -special.expm1(-0.5 * r**2)
|
|
|
@ -4152,10 +4525,10 @@ class rayleigh_gen(rv_continuous):
|
|
|
|
return sqrt(-2 * special.log1p(-q))
|
|
|
|
return sqrt(-2 * special.log1p(-q))
|
|
|
|
|
|
|
|
|
|
|
|
def _sf(self, r):
|
|
|
|
def _sf(self, r):
|
|
|
|
return exp(-0.5 * r**2)
|
|
|
|
return exp(self._logsf(r))
|
|
|
|
|
|
|
|
|
|
|
|
def _logsf(self, r):
|
|
|
|
def _logsf(self, r):
|
|
|
|
return -0.5 * r**2
|
|
|
|
return -0.5 * r * r
|
|
|
|
|
|
|
|
|
|
|
|
def _isf(self, q):
|
|
|
|
def _isf(self, q):
|
|
|
|
return sqrt(-2 * log(q))
|
|
|
|
return sqrt(-2 * log(q))
|
|
|
@ -4290,6 +4663,7 @@ class reciprocal_gen(rv_continuous):
|
|
|
|
return 0.5*log(a*b)+log(log(b/a))
|
|
|
|
return 0.5*log(a*b)+log(log(b/a))
|
|
|
|
reciprocal = reciprocal_gen(name="reciprocal")
|
|
|
|
reciprocal = reciprocal_gen(name="reciprocal")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class rice_gen(rv_continuous):
|
|
|
|
class rice_gen(rv_continuous):
|
|
|
|
"""A Rice continuous random variable.
|
|
|
|
"""A Rice continuous random variable.
|
|
|
|
|
|
|
|
|
|
|
@ -4321,8 +4695,8 @@ class rice_gen(rv_continuous):
|
|
|
|
|
|
|
|
|
|
|
|
def _rvs(self, b):
|
|
|
|
def _rvs(self, b):
|
|
|
|
# http://en.wikipedia.org/wiki/Rice_distribution
|
|
|
|
# http://en.wikipedia.org/wiki/Rice_distribution
|
|
|
|
sz = self._size if self._size else 1
|
|
|
|
t = b/np.sqrt(2) + self._random_state.standard_normal(size=(2,) +
|
|
|
|
t = b/np.sqrt(2) + self._random_state.standard_normal(size=(2, sz))
|
|
|
|
self._size)
|
|
|
|
return np.sqrt((t*t).sum(axis=0))
|
|
|
|
return np.sqrt((t*t).sum(axis=0))
|
|
|
|
|
|
|
|
|
|
|
|
def _cdf(self, x, b):
|
|
|
|
def _cdf(self, x, b):
|
|
|
@ -4653,10 +5027,9 @@ class truncnorm_gen(rv_continuous):
|
|
|
|
self._na = _norm_cdf(a)
|
|
|
|
self._na = _norm_cdf(a)
|
|
|
|
self._sb = _norm_sf(b)
|
|
|
|
self._sb = _norm_sf(b)
|
|
|
|
self._sa = _norm_sf(a)
|
|
|
|
self._sa = _norm_sf(a)
|
|
|
|
if self.a > 0:
|
|
|
|
self._delta = np.where(self.a > 0,
|
|
|
|
self._delta = -(self._sb - self._sa)
|
|
|
|
-(self._sb - self._sa),
|
|
|
|
else:
|
|
|
|
self._nb - self._na)
|
|
|
|
self._delta = self._nb - self._na
|
|
|
|
|
|
|
|
self._logdelta = log(self._delta)
|
|
|
|
self._logdelta = log(self._delta)
|
|
|
|
return (a != b)
|
|
|
|
return (a != b)
|
|
|
|
|
|
|
|
|
|
|
@ -4670,10 +5043,11 @@ class truncnorm_gen(rv_continuous):
|
|
|
|
return (_norm_cdf(x) - self._na) / self._delta
|
|
|
|
return (_norm_cdf(x) - self._na) / self._delta
|
|
|
|
|
|
|
|
|
|
|
|
def _ppf(self, q, a, b):
|
|
|
|
def _ppf(self, q, a, b):
|
|
|
|
if self.a > 0:
|
|
|
|
# XXX Use _lazywhere...
|
|
|
|
return _norm_isf(q*self._sb + self._sa*(1.0-q))
|
|
|
|
ppf = np.where(self.a > 0,
|
|
|
|
else:
|
|
|
|
_norm_isf(q*self._sb + self._sa*(1.0-q)),
|
|
|
|
return _norm_ppf(q*self._nb + self._na*(1.0-q))
|
|
|
|
_norm_ppf(q*self._nb + self._na*(1.0-q)))
|
|
|
|
|
|
|
|
return ppf
|
|
|
|
|
|
|
|
|
|
|
|
def _stats(self, a, b):
|
|
|
|
def _stats(self, a, b):
|
|
|
|
nA, nB = self._na, self._nb
|
|
|
|
nA, nB = self._na, self._nb
|
|
|
@ -4830,6 +5204,8 @@ class wald_gen(invgauss_gen):
|
|
|
|
|
|
|
|
|
|
|
|
%(example)s
|
|
|
|
%(example)s
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
|
|
|
|
_support_mask = rv_continuous._open_support_mask
|
|
|
|
|
|
|
|
|
|
|
|
def _rvs(self):
|
|
|
|
def _rvs(self):
|
|
|
|
return self._random_state.wald(1.0, 1.0, size=self._size)
|
|
|
|
return self._random_state.wald(1.0, 1.0, size=self._size)
|
|
|
|
|
|
|
|
|
|
|
|