Fixed a failing doctest. Reorganized _penalized_nnlf

master
Per A Brodtkorb 9 years ago
parent b88a141d54
commit 89b37b64dd

@ -1429,7 +1429,9 @@ class SpecData1D(PlotData):
>>> f = S.to_t_pdf(pdef='Tc', paramt=(0, 10, 51), speed=7) >>> f = S.to_t_pdf(pdef='Tc', paramt=(0, 10, 51), speed=7)
>>> Hm0 = 7 >>> Hm0 = 7
>>> Tp = 11 >>> Tp = 11
>>> S = sm.Jonswap(4*pi/Tp,[Hm0 Tp]) >>> S = sm.Jonswap(4*pi/Tp,[Hm0, Tp])
Sk = spec2spec(S,'k1d') Sk = spec2spec(S,'k1d')
L0 = spec2mom(S,1) L0 = spec2mom(S,1)
paramu = [sqrt(L0)*[-4 4] 41] paramu = [sqrt(L0)*[-4 4] 41]

@ -342,19 +342,19 @@ def _penalized_nnlf(self, theta, x):
if not self._argcheck(*args) or scale <= 0: if not self._argcheck(*args) or scale <= 0:
return inf return inf
x = asarray((x-loc) / scale) x = asarray((x-loc) / scale)
N = len(x)
loginf = log(_XMAX)
if np.isneginf(self.a).all() and np.isinf(self.b).all():
Nbad = 0
else:
cond0 = (x < self.a) | (self.b < x) cond0 = (x < self.a) | (self.b < x)
Nbad = sum(cond0) Nbad = sum(cond0)
if Nbad > 0: if Nbad > 0:
x = argsreduce(~cond0, x)[0] x = argsreduce(~cond0, x)[0]
logpdf = self._logpdf(x, *args)
N = len(x) finite_logpdf = np.isfinite(logpdf)
return self._nnlf(x, *args) + N*log(scale) + Nbad * 100.0 * loginf Nbad += np.sum(~finite_logpdf, axis=0)
logscale = N * log(scale)
if Nbad > 0:
penalty = Nbad * log(_XMAX) * 100
return -np.sum(logpdf[finite_logpdf], axis=0) + penalty + logscale
return -np.sum(logpdf, axis=0) + logscale
def _reduce_func(self, args, options): def _reduce_func(self, args, options):

Loading…
Cancel
Save