updated link functions.

master
pbrod 9 years ago
parent 3e08ffb25e
commit 9c0e598240

@ -36,6 +36,21 @@ arr = asarray
all = alltrue # @ReservedAssignment all = alltrue # @ReservedAssignment
def _burr_link(x, logSF, phat, ix):
c, d, loc, scale = phat
logp = log(-expm1(logSF))
xn = (x - loc) / scale
if ix == 1:
return -logp / log1p(xn**(-c))
if ix == 0:
return log1p(-exp(-logp / d)) / log(xn)
if ix == 2:
return x - scale * exp(log1p(-exp(-logp / d)) / c)
if ix == 3:
return (x - loc) / exp(log1p(-exp(-logp / d)) / c)
raise IndexError('Index to the fixed parameter is out of bounds')
def _expon_link(x, logSF, phat, ix): def _expon_link(x, logSF, phat, ix):
if ix == 1: if ix == 1:
return - (x - phat[0]) / logSF return - (x - phat[0]) / logSF
@ -104,20 +119,16 @@ def _genextreme_link(x, logSF, phat, ix):
if ix == 2: if ix == 2:
# link = -(x-loc)*c/expm1(c*log(-logP)) # link = -(x-loc)*c/expm1(c*log(-logP))
if c != 0.0: if c != 0.0:
phati = -(x - loc) * c / expm1(c * loglogP) return -(x - loc) * c / expm1(c * loglogP)
else: return -(x - loc) / loglogP
phati = -(x - loc) / loglogP if ix == 1:
elif ix == 1:
if c != 0: if c != 0:
phati = x + scale * expm1(c * loglogP) / c return x + scale * expm1(c * loglogP) / c
else: return x + scale * loglogP
phati = x + scale * loglogP if ix == 0:
elif ix == 0:
raise NotImplementedError( raise NotImplementedError(
'link(x,logSF,phat,i) where i=0 is not implemented!') 'link(x,logSF,phat,i) where i=0 is not implemented!')
else:
raise IndexError('Index to the fixed parameter is out of bounds') raise IndexError('Index to the fixed parameter is out of bounds')
return phati
def _genexpon_link(x, logSF, phat, ix): def _genexpon_link(x, logSF, phat, ix):
@ -125,14 +136,12 @@ def _genexpon_link(x, logSF, phat, ix):
xn = (x - loc) / scale xn = (x - loc) / scale
fact1 = (xn + expm1(-c * xn) / c) fact1 = (xn + expm1(-c * xn) / c)
if ix == 0: if ix == 0:
phati = b * fact1 + logSF return b * fact1 + logSF # a
elif ix == 1: if ix == 1:
phati = (a - logSF) / fact1 return (a - logSF) / fact1 # b
elif ix in [2, 3, 4]: if ix in [2, 3, 4]:
raise NotImplementedError('Only implemented for index in [0,1]!') raise NotImplementedError('Only implemented for index in [0,1]!')
else:
raise IndexError('Index to the fixed parameter is out of bounds') raise IndexError('Index to the fixed parameter is out of bounds')
return phati
def _rayleigh_link(x, logSF, phat, ix): def _rayleigh_link(x, logSF, phat, ix):
@ -163,7 +172,8 @@ LINKS = dict(expon=_expon_link,
rayleigh=_rayleigh_link, rayleigh=_rayleigh_link,
trunclayleigh=_trunclayleigh_link, trunclayleigh=_trunclayleigh_link,
genextreme=_genextreme_link, genextreme=_genextreme_link,
exponweib=_exponweib_link) exponweib=_exponweib_link,
burr=_burr_link)
def chi2isf(p, df): def chi2isf(p, df):

Loading…
Cancel
Save