Added more work to LevelCrossings.extrapolate (not finished yet)

master
Per.Andreas.Brodtkorb 14 years ago
parent 0a9293fc27
commit 2110de71e6

@ -183,9 +183,9 @@ class LevelCrossings(WafoData):
u_min = self.args[i.min()] u_min = self.args[i.min()]
if u_max is None: if u_max is None:
u_max = self.args[i.max()] u_max = self.args[i.max()]
lcf, lcx = self.data, self.args
# # Extrapolate LC for high levels # Extrapolate LC for high levels
# [lcEst.High,Est.High] = self._extrapolate(lc,u_max,u_max-lc_max,method, dist); [lcEst.High,Est.High] = self._extrapolate(lcx,lcf,u_max,u_max-lc_max,method, dist);
# #
# # Extrapolate LC for low levels # # Extrapolate LC for low levels
# #
@ -199,137 +199,120 @@ class LevelCrossings(WafoData):
# semilogx(lc(:,2),lc(:,1),lcEst.High(:,2),lcEst.High(:,1),lcEst.Low(:,2),lcEst.Low(:,1)) # semilogx(lc(:,2),lc(:,1),lcEst.High(:,2),lcEst.High(:,1),lcEst.Low(:,2),lcEst.Low(:,1))
# end # end
# #
### ##
# def _extrapolate(self, lcx,lcf,u,offset,method,dist) def _extrapolate(self, lcx,lcf,u,offset,method,dist):
# # Extrapolate the level crossing spectra for high levels # Extrapolate the level crossing spectra for high levels
#
# method = method.lower() method = method.lower()
# dist = dist.lower() dist = dist.lower()
#
# # Excedences over level u # Excedences over level u
# Iu = lcx>u; Iu = lcx>u;
# lcx1, lcf1 = lcx[Iu], lcf[Iu] lcx1, lcf1 = lcx[Iu], lcf[Iu]
# lcf3,lcx3 = _make_increasing(lcf1[::-1],lcx1[::-1]) lcf2,lcx2 = _make_increasing(lcf1[::-1],lcx1[::-1])
#
# # Corrected by PJ 17-Feb-2004 nim1 = 0
# lc3=[0 0; lc3]; x=[]
# x=[]; for k, ni in enumerate(lcf2.tolist()):
# for k=2:length(lc3(:,1)) nk = ni - nim1
# nk = lc3(k,2)-lc3(k-1,2); x.append(ones(nk)*lcx2[k])
# x = [x; ones(nk,1)*lc3(k,1)]; #end
# #end
# x = x-u; x = np.hstack(x)-u
#
# # Estimate tail # Estimate tail
#
# if dist=='genpareto': if dist=='genpareto':
# genpareto = distributions.genpareto genpareto = distributions.genpareto
# phat = genpareto.fit2(x, floc=0, method=method) phat = genpareto.fit2(x, floc=0, method=method)
#
## Est.k = phat.params(1); df = 0.01
## Est.s = phat.params(2); xF = np.arange(0.0,4+df/2,df)
## if isnan(phat.fixpar(3)) F = phat.cdf(xF)
## Est.cov = phat.covariance; lcu = np.interp(u,lcx,lcf)+1
## else covar = phat.par_cov[::2,::2]
## Est.cov = phat.covariance(1:2,1:2); # Calculate 90 # confidence region, an ellipse, for (k,s)
## end B, D = np.linalg.eig(covar);
## if Est.k>0, b = phat.par[::2]
## Est.UpperLimit = u+Est.s/Est.k; if b[0]>0:
## end upperlimit = u + b[1]/b[0]
# df = 0.01
# xF = np.arange(0.0,4+df/2,df) r = sqrt(-2*log(1-90/100)); # 90 # confidence sphere
# F = phat.cdf(xF) Nc = 16+1;
# Est.lcu = interp1(lcx,lcf,u)+1 ang = linspace(0,2*pi,Nc);
# c0 = np.vstack((r*sqrt(D[0,0])*sin(ang), r*sqrt(D[1,1])*cos(ang))) # 90# Circle
# # Calculate 90 # confidence region, an ellipse, for (k,s) # plot(c0(1,:),c0(2,:))
# [B,D] = eig(Est.cov);
# b = [Est.k; Est.s]; c1 = B*c0+b*ones((1,len(c0))); # Transform to ellipse for (k,s)
# # plot(c1(1,:),c1(2,:)), hold on
# r = sqrt(-2*log(1-90/100)); # 90 # confidence sphere
# Nc = 16+1; # Calculate conf.int for lcu
# ang = linspace(0,2*pi,Nc); # Assumtion: lcu is Poisson distributed
# c0 = [r*sqrt(D(1,1))*sin(ang); r*sqrt(D(2,2))*cos(ang)]; # 90# Circle # Poissin distr. approximated by normal when calculating conf. int.
# # plot(c0(1,:),c0(2,:)) dXX = 1.64*sqrt(lcu); # 90 # quantile for lcu
#
# c1 = B*c0+b*ones(1,length(c0)); # Transform to ellipse for (k,s) lcEstCu = zeros((len(xF),Nc));
# # plot(c1(1,:),c1(2,:)), hold on lcEstCl = lcEstCu;
# for i in range(Nc):
# # Calculate conf.int for lcu k=c1[0,i]
# # Assumtion: lcu is Poisson distributed s=c1[2,i]
# # Poissin distr. approximated by normal when calculating conf. int. F2 = genpareto.cdf(xF,k,scale=s)
# dXX = 1.64*sqrt(Est.lcu); # 90 # quantile for lcu lcEstCu[:,i] = (lcu+dXX)*(1-F2);
# lcEstCl[:,i] = (lcu-dXX)*(1-F2);
# lcEstCu = zeros(length(xF),Nc); #end
# lcEstCl = lcEstCu;
# for i=1:Nc lcEstCI = [min(lcEstCl), max(lcEstCu)]
# k=c1(1,i);
# s=c1(2,i); lcEst = [xF+u, lcu*(1-F), lcEstCI];
# F2 = cdfgenpar(xF,k,s);
# lcEstCu(:,i) = (Est.lcu+dXX)*(1-F2); elif dist=='expon':
# lcEstCl(:,i) = (Est.lcu-dXX)*(1-F2); n = len(x)
# end s = mean(x);
# cov = s/n;
# lcEstCI = [min(lcEstCl')' max(lcEstCu')']; Est.s = s;
# Est.cov = cov;
# lcEst = [xF+u Est.lcu*(1-F) lcEstCI];
# xF = np.arange(0.0,4+df/2,df) #xF = (0.0:0.01:4)';
# case 'exp' F = -expm1(-xF/s)
# lcu = np.interp(u,lcx,lcf)+1
# n = length(x);
# s = mean(x); lcEst = [xF+u, Est.lcu*(1-F)]
# cov = s/n;
# Est.s = s; elif dist== 'ray':
# Est.cov = cov;
# n = len(x)
# xF = (0.0:0.01:4)'; Sx = sum((x+offset)**2-offset**2)
# F = 1-exp(-xF/s); s = sqrt(Sx/n); # Shape parameter
# Est.lcu = interp1(lc(:,1),lc(:,2),u)+1;
# cov = NaN;
# lcEst = [xF+u Est.lcu*(1-F)];
# xF = np.arange(0.0,4+df/2,df) #xF = (0.0:0.01:4)';
# case 'ray' F = -expm1(-((xF+offset)**2-offset**2)/s**2);
# lcu = np.interp(u,lcx,lcf,u)+1
# n = length(x);
# Sx = sum((x+offset).^2-offset^2); lcEst = [xF+u, Est.lcu*(1-F)];
# s=sqrt(Sx/n); # Shape parameter
# else:
# Est.s = s; raise ValueError()
# Est.cov = NaN;
#
# xF = (0.0:0.01:4)'; ## End extrapolate
# F = 1 - exp(-((xF+offset).^2-offset^2)/s^2);
# Est.lcu = interp1(lc(:,1),lc(:,2),u)+1; def _make_increasing(f, t=None):
# # Makes the signal f strictly increasing.
# lcEst = [xF+u Est.lcu*(1-F)];
# n = len(f)
# otherwise if t is None:
# t = np.arange(n)
# error(['Unknown method: ' method]); ff = [f[0],]
# tt = [t[0],]
# end
# for i in xrange(1,n):
# if f[i]>ff[-1]:
# ## End extrapolate ff.append(f[i])
# tt.append(t[i])
# def _make_increasing(f, t=None):
# # Makes the signal x strictly increasing. return np.asarray(ff), np.asarray(tt)
# #
# # x = two column matrix with times in first column and values in the second.
#
# n = len(f)
# if t is None:
# t = np.arange(n)
# ff = []
# tt = []
# ff.append(f[0])
# tt.append(t[0])
#
# for i in xrange(1,n):
# if f[i]>ff[-1]
# ff.append(f[i])
# tt.append(t[i])
#
# return np.asarray(ff), np.asarray(tt)
def sim(self, ns, alpha): def sim(self, ns, alpha):
""" """

@ -872,7 +872,6 @@ class FitDistribution(rv_frozen):
SF = (arange(n, 0, -1)) / n SF = (arange(n, 0, -1)) / n
plotbackend.semilogy(self.data, SF, 'b.', self.data, self.sf(self.data), 'r-') plotbackend.semilogy(self.data, SF, 'b.', self.data, self.sf(self.data), 'r-')
#plotbackend.plot(self.data,SF,'b.',self.data,self.sf(self.data),'r-') #plotbackend.plot(self.data,SF,'b.',self.data,self.sf(self.data),'r-')
plotbackend.xlabel('x'); plotbackend.xlabel('x');
plotbackend.ylabel('F(x) (%s)' % self.dist.name) plotbackend.ylabel('F(x) (%s)' % self.dist.name)
plotbackend.title('Empirical SF plot') plotbackend.title('Empirical SF plot')
@ -888,8 +887,6 @@ class FitDistribution(rv_frozen):
n = len(self.data) n = len(self.data)
F = (arange(1, n + 1)) / n F = (arange(1, n + 1)) / n
plotbackend.plot(self.data, F, 'b.', self.data, self.cdf(self.data), 'r-') plotbackend.plot(self.data, F, 'b.', self.data, self.cdf(self.data), 'r-')
plotbackend.xlabel('x'); plotbackend.xlabel('x');
plotbackend.ylabel('F(x) (%s)' % self.dist.name) plotbackend.ylabel('F(x) (%s)' % self.dist.name)
plotbackend.title('Empirical CDF plot') plotbackend.title('Empirical CDF plot')
@ -934,7 +931,6 @@ class FitDistribution(rv_frozen):
#plotbackend.hist(self.data,normed=True,fill=False) #plotbackend.hist(self.data,normed=True,fill=False)
plotbackend.plot(self.data, self.pdf(self.data), 'r-', xx, yy, 'b-') plotbackend.plot(self.data, self.pdf(self.data), 'r-', xx, yy, 'b-')
plotbackend.xlabel('x'); plotbackend.xlabel('x');
plotbackend.ylabel('f(x) (%s)' % self.dist.name) plotbackend.ylabel('f(x) (%s)' % self.dist.name)
plotbackend.title('Density plot') plotbackend.title('Density plot')
@ -953,7 +949,6 @@ class FitDistribution(rv_frozen):
y = self.ppf(eprob) y = self.ppf(eprob)
y1 = self.data[[0, -1]] y1 = self.data[[0, -1]]
plotbackend.plot(self.data, y, 'b.', y1, y1, 'r-') plotbackend.plot(self.data, y, 'b.', y1, y1, 'r-')
plotbackend.xlabel('Empirical') plotbackend.xlabel('Empirical')
plotbackend.ylabel('Model (%s)' % self.dist.name) plotbackend.ylabel('Model (%s)' % self.dist.name)
plotbackend.title('Residual Quantile Plot'); plotbackend.title('Residual Quantile Plot');
@ -974,14 +969,11 @@ class FitDistribution(rv_frozen):
mcdf = self.cdf(self.data) mcdf = self.cdf(self.data)
p1 = [0, 1] p1 = [0, 1]
plotbackend.plot(ecdf, mcdf, 'b.', p1, p1, 'r-') plotbackend.plot(ecdf, mcdf, 'b.', p1, p1, 'r-')
plotbackend.xlabel('Empirical') plotbackend.xlabel('Empirical')
plotbackend.ylabel('Model (%s)' % self.dist.name) plotbackend.ylabel('Model (%s)' % self.dist.name)
plotbackend.title('Residual Probability Plot'); plotbackend.title('Residual Probability Plot');
plotbackend.axis([0, 1, 0, 1])
plotbackend.axis('equal') plotbackend.axis('equal')
plotbackend.axis([0, 1, 0, 1])
def _pvalue(self, theta, x, unknown_numpar=None): def _pvalue(self, theta, x, unknown_numpar=None):

Loading…
Cancel
Save