|
|
@ -2188,11 +2188,11 @@ class rv_continuous(rv_generic):
|
|
|
|
return inf
|
|
|
|
return inf
|
|
|
|
x = arr((x - loc) / scale)
|
|
|
|
x = arr((x - loc) / scale)
|
|
|
|
cond0 = (x <= self.a) | (x >= self.b)
|
|
|
|
cond0 = (x <= self.a) | (x >= self.b)
|
|
|
|
if (any(cond0)):
|
|
|
|
Nbad = sum(cond0)
|
|
|
|
return inf
|
|
|
|
if Nbad>0:
|
|
|
|
else:
|
|
|
|
x = argsreduce(1 - cond0, *((x,)))[0]
|
|
|
|
#linfo = numpy.finfo(float)
|
|
|
|
#return inf
|
|
|
|
realmax = floatinfo.machar.xmax
|
|
|
|
#else:
|
|
|
|
|
|
|
|
|
|
|
|
lowertail = True
|
|
|
|
lowertail = True
|
|
|
|
if lowertail:
|
|
|
|
if lowertail:
|
|
|
@ -2214,16 +2214,16 @@ class rv_continuous(rv_generic):
|
|
|
|
# logDj = log((yU-yL)/(r-1)) for j = i+1,i+2,...i+r-1
|
|
|
|
# logDj = log((yU-yL)/(r-1)) for j = i+1,i+2,...i+r-1
|
|
|
|
|
|
|
|
|
|
|
|
# The following is OK when only minimization of T is wanted
|
|
|
|
# The following is OK when only minimization of T is wanted
|
|
|
|
|
|
|
|
|
|
|
|
i_tie = nonzero(tie)
|
|
|
|
i_tie = nonzero(tie)
|
|
|
|
tiedata = x[i_tie]
|
|
|
|
tiedata = x[i_tie]
|
|
|
|
|
|
|
|
|
|
|
|
logD[i_tie + 1] = log(self._pdf(tiedata, *args)) - log(scale)
|
|
|
|
logD[i_tie + 1] = log(self._pdf(tiedata, *args)) - log(scale)
|
|
|
|
|
|
|
|
|
|
|
|
finiteD = numpy.isfinite(logD)
|
|
|
|
finiteD = numpy.isfinite(logD)
|
|
|
|
nonfiniteD = 1 - finiteD
|
|
|
|
nonfiniteD = 1 - finiteD
|
|
|
|
if any(nonfiniteD):
|
|
|
|
Nbad += sum(nonfiniteD, axis=0)
|
|
|
|
T = -sum(logD[finiteD], axis=0) + 100.0 * log(realmax) * sum(nonfiniteD, axis=0);
|
|
|
|
if Nbad>0:
|
|
|
|
|
|
|
|
realmax = floatinfo.machar.xmax
|
|
|
|
|
|
|
|
T = -sum(logD[finiteD], axis=0) + 100.0 * log(realmax) * Nbad;
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
T = -sum(logD, axis=0) #%Moran's negative log product spacing statistic
|
|
|
|
T = -sum(logD, axis=0) #%Moran's negative log product spacing statistic
|
|
|
|
return T
|
|
|
|
return T
|
|
|
@ -2237,8 +2237,7 @@ class rv_continuous(rv_generic):
|
|
|
|
return None
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
|
|
def _nnlf(self, x, *args):
|
|
|
|
def _nnlf(self, x, *args):
|
|
|
|
xmin = floatinfo.machar.xmin
|
|
|
|
return -sum(self._logpdf(x, *args),axis=0)
|
|
|
|
return -sum(np.maximum(self._logpdf(x, *args),100*log(xmin)),axis=0)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def nnlf(self, theta, x):
|
|
|
|
def nnlf(self, theta, x):
|
|
|
|
''' Return negative loglikelihood function, i.e., - sum (log pdf(x, theta),axis=0)
|
|
|
|
''' Return negative loglikelihood function, i.e., - sum (log pdf(x, theta),axis=0)
|
|
|
@ -2254,16 +2253,14 @@ class rv_continuous(rv_generic):
|
|
|
|
return inf
|
|
|
|
return inf
|
|
|
|
x = arr((x-loc) / scale)
|
|
|
|
x = arr((x-loc) / scale)
|
|
|
|
cond0 = (x <= self.a) | (self.b <= x)
|
|
|
|
cond0 = (x <= self.a) | (self.b <= x)
|
|
|
|
newCall = True
|
|
|
|
if (any(cond0)):
|
|
|
|
if newCall:
|
|
|
|
# old call: return inf
|
|
|
|
goodargs = argsreduce(1 - cond0, *((x,)))
|
|
|
|
goodargs = argsreduce(1 - cond0, *((x,)))
|
|
|
|
goodargs = tuple(goodargs + list(args))
|
|
|
|
goodargs = tuple(goodargs + list(args))
|
|
|
|
N = len(x)
|
|
|
|
N = len(x)
|
|
|
|
Nbad = sum(cond0)
|
|
|
|
Nbad = sum(cond0)
|
|
|
|
xmin = floatinfo.machar.xmin
|
|
|
|
xmax = floatinfo.machar.xmax
|
|
|
|
return self._nnlf(*goodargs) + N * log(scale) + Nbad * 100.0 * log(xmin)
|
|
|
|
return self._nnlf(*goodargs) + N * (log(scale) + Nbad * 100.0 * log(xmax))
|
|
|
|
elif (any(cond0)):
|
|
|
|
|
|
|
|
return inf
|
|
|
|
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
N = len(x)
|
|
|
|
N = len(x)
|
|
|
|
return self._nnlf(x, *args) + N*log(scale)
|
|
|
|
return self._nnlf(x, *args) + N*log(scale)
|
|
|
@ -2399,7 +2396,7 @@ class rv_continuous(rv_generic):
|
|
|
|
index = range(Nargs)
|
|
|
|
index = range(Nargs)
|
|
|
|
names = ['f%d' % n for n in range(Nargs - 2)] + ['floc', 'fscale']
|
|
|
|
names = ['f%d' % n for n in range(Nargs - 2)] + ['floc', 'fscale']
|
|
|
|
x0 = args[:]
|
|
|
|
x0 = args[:]
|
|
|
|
for n, key in zip(index, names):
|
|
|
|
for n, key in zip(index[::-1], names[::-1]):
|
|
|
|
if kwds.has_key(key):
|
|
|
|
if kwds.has_key(key):
|
|
|
|
fixedn.append(n)
|
|
|
|
fixedn.append(n)
|
|
|
|
args[n] = kwds[key]
|
|
|
|
args[n] = kwds[key]
|
|
|
@ -8092,10 +8089,18 @@ def main():
|
|
|
|
lp = pht.profile()
|
|
|
|
lp = pht.profile()
|
|
|
|
|
|
|
|
|
|
|
|
def test_genpareto():
|
|
|
|
def test_genpareto():
|
|
|
|
genextreme.pdf(np.inf,0)
|
|
|
|
|
|
|
|
|
|
|
|
numargs = genpareto.numargs
|
|
|
|
|
|
|
|
[ c ] = [0.9,] * numargs
|
|
|
|
|
|
|
|
rv = genpareto(c)
|
|
|
|
|
|
|
|
R = genpareto.rvs(c, size=100)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
phat = genpareto.fit2(R, floc=0, fscale=1,method='mps')
|
|
|
|
|
|
|
|
print(phat.par)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
if __name__ == '__main__':
|
|
|
|
#main()
|
|
|
|
#main()
|
|
|
|
test_genpareto()
|
|
|
|
test_genpareto()
|
|
|
|
#test_truncrayleigh()
|
|
|
|
#test_truncrayleigh()
|
|
|
|
#test_lognorm()
|
|
|
|
#test_lognorm()
|
|
|
|
|
|
|
|
|
|
|
|