Small updates

master
per.andreas.brodtkorb 14 years ago
parent 4d8ba7aefc
commit 51387dcb5d

@ -1,7 +1,7 @@
Metadata-Version: 1.0 Metadata-Version: 1.0
Name: wafo Name: wafo
Version: 0.1.2 Version: 0.1.2
Summary: UNKNOWN Summary: Statistical analysis and simulation of random waves and random loads
Home-page: http://code.google.com/p/pywafo/ Home-page: http://code.google.com/p/pywafo/
Author: WAFO-group Author: WAFO-group
Author-email: wafo@maths.lth.se Author-email: wafo@maths.lth.se

@ -262,14 +262,11 @@ src/wafo/spectrum/models.py
src/wafo/stats/__init__.py src/wafo/stats/__init__.py
src/wafo/stats/core.py src/wafo/stats/core.py
src/wafo/stats/distributions.py src/wafo/stats/distributions.py
src/wafo/stats/distributions_juli2010.py
src/wafo/stats/estimation.py src/wafo/stats/estimation.py
src/wafo/stats/misc.py src/wafo/stats/misc.py
src/wafo/stats/twolumps.py
src/wafo/test/__init__.py src/wafo/test/__init__.py
src/wafo/test/test_gaussian.py src/wafo/test/test_gaussian.py
src/wafo/test/test_misc.py src/wafo/test/test_misc.py
src/wafo/test/test_objects.py
src/wafo/transform/__init__.py src/wafo/transform/__init__.py
src/wafo/transform/core.py src/wafo/transform/core.py
src/wafo/transform/models.py src/wafo/transform/models.py

@ -981,7 +981,17 @@ def accum(accmap, a, func=None, size=None, fill_value=0, dtype=None):
out[s] = func(vals[s]) out[s] = func(vals[s])
return out return out
def bitget(int_type, offset):
'''
Returns the value of the bit at the offset position in int_type.
Example
-------
>>> bitget(5, np.r_[0:4])
array([1, 0, 1, 0])
'''
mask = (1 << offset)
return (int_type & mask) != 0
def gridcount(data, X): def gridcount(data, X):
''' '''
GRIDCOUNT D-dimensional histogram using linear binning. GRIDCOUNT D-dimensional histogram using linear binning.
@ -1016,11 +1026,13 @@ def gridcount(data, X):
>>> import numpy as np >>> import numpy as np
>>> import wafo.kdetools as wk >>> import wafo.kdetools as wk
>>> import pylab as plb >>> import pylab as plb
>>> N = 500; >>> N = 20;
>>> data = np.random.rayleigh(1,N) >>> data = np.random.rayleigh(1,N)
>>> x = np.linspace(0,max(data)+1,50) >>> x = np.linspace(0,max(data)+1,50)
>>> dx = x[1]-x[0] >>> dx = x[1]-x[0]
>>> c = wk.gridcount(data,x) >>> c = wk.gridcount(data,x)
>>> h = plb.plot(x,c,'.') # 1D histogram >>> h = plb.plot(x,c,'.') # 1D histogram
>>> h1 = plb.plot(x,c/dx/N) # 1D probability density plot >>> h1 = plb.plot(x,c/dx/N) # 1D probability density plot
>>> np.trapz(x,c/dx/N) >>> np.trapz(x,c/dx/N)
@ -1043,7 +1055,6 @@ def gridcount(data, X):
if d != d1: if d != d1:
raise ValueError('Dimension 0 of data and X do not match.') raise ValueError('Dimension 0 of data and X do not match.')
dx = np.diff(x[:, :2], axis=1) dx = np.diff(x[:, :2], axis=1)
xlo = x[:, 0] xlo = x[:, 0]
xup = x[:, -1] xup = x[:, -1]
@ -1061,47 +1072,46 @@ def gridcount(data, X):
abs = np.abs abs = np.abs
if d == 1: if d == 1:
x.shape = (-1,) x.shape = (-1,)
c = (accum(binx, (x[binx + 1] - data), size=[inc, ]) + c = (accum(binx, (x[binx + 1] - dat), size=[inc, ]) +
accum(binx, (data - x[binx]), size=[inc, ])) / w accum(binx, (dat - x[binx]), size=[inc, ])) / w
elif d == 2: elif d == 2:
b2 = binx[1] b2 = binx[1]
b1 = binx[0] b1 = binx[0]
c_ = np.c_ c_ = np.c_
stk = np.vstack stk = np.vstack
c = (accum(c_[b1, b2] , abs(np.prod(stk([X[0, b1 + 1], X[1, b2 + 1]]) - data, axis=0)), size=[inc, inc]) + c = (accum(c_[b1, b2] , abs(np.prod(stk([X[0, b1 + 1], X[1, b2 + 1]]) - dat, axis=0)), size=[inc, inc]) +
accum(c_[b1 + 1, b2] , abs(np.prod(stk([X[0, b1], X[1, b2 + 1]]) - data, axis=0)), size=[inc, inc]) + accum(c_[b1 + 1, b2] , abs(np.prod(stk([X[0, b1], X[1, b2 + 1]]) - dat, axis=0)), size=[inc, inc]) +
accum(c_[b1 , b2 + 1], abs(np.prod(stk([X[0, b1 + 1], X[1, b2]]) - data, axis=0)), size=[inc, inc]) + accum(c_[b1 , b2 + 1], abs(np.prod(stk([X[0, b1 + 1], X[1, b2]]) - dat, axis=0)), size=[inc, inc]) +
accum(c_[b1 + 1, b2 + 1], abs(np.prod(stk([X[0, b1], X[1, b2]]) - data, axis=0)), size=[inc, inc])) / w accum(c_[b1 + 1, b2 + 1], abs(np.prod(stk([X[0, b1], X[1, b2]]) - dat, axis=0)), size=[inc, inc])) / w
else: # % d>2 else: # % d>2
raise ValueError('Not implemented for d>2')
Nc = csiz.prod() Nc = csiz.prod()
c = np.zeros((Nc, 1)) c = np.zeros((Nc,))
fact2 = inc * np.arange(d) fact2 = np.asarray(np.reshape(inc * np.arange(d), (d, -1)), dtype=int)
fact1 = csiz.cumprod() / inc fact1 = np.asarray(np.reshape(csiz.cumprod() / inc, (d, -1)), dtype=int)
#fact1 = fact1(ones(n,1),:); #fact1 = fact1(ones(n,1),:);
# for ir in xrange(2**(d-1)): bt0 = [0, 0]
# bt0[:,:,1] = bitget(ir,1:d) X1 = X.ravel()
# bt0[:,:,2] = 1-bt0[:,:,1] for ir in xrange(2 ** (d - 1)):
# for ix in range(2): bt0[0] = np.reshape(bitget(ir, np.arange(d)), (d, -1))
# one = mod(ix,2)+1; bt0[1] = 1 - bt0[0]
# two = mod(ix+1,2)+1; for ix in xrange(2):
# # Convert to linear index (faster than sub2ind) one = np.mod(ix, 2)
# b1 = sum((binx + bt0(ones(n,1),:,one)-1).*fact1,2)+1; #%linear index to c two = np.mod(ix + 1, 2)
# bt2 = bt0(:,:,two) + fact2; # Convert to linear index
# b2 = binx + bt2(ones(n,1),:); #% linear index to X b1 = np.sum((binx + bt0[one]) * fact1, axis=0) #linear index to c
# bt2 = bt0[two] + fact2
# c = c + accum(b1,abs(prod(X(b2)-data,2)),[Nc,1]); b2 = binx + bt2 # linear index to X
# #c = c + accum([b1,ones(n,1)],abs(prod(X(b2)-data,2)),[Nc,1]); c += accum(b1, abs(np.prod(X1[b2] - dat, axis=0)), size=(Nc,))
# #[len,bin,val] = bincount(b1,abs(prod(X(b2)-data,2)));
# #c(bin) = c(bin)+val; c = np.reshape(c / w, csiz)
# # TODO: check that the flipping of axis is correct
# #end T = range(d); T[-2],T[-1] = T[-1], T[-2]
# #end c = c.transpose(*T)
# c = reshape(c/w,csiz);
#end if d == 2: # make sure c is stored in the same way as meshgrid
if d == 2: #% make sure c is stored in the same way as meshgrid
c = c.T c = c.T
elif d == 3: elif d == 3:
c = c.transpose(1, 0, 2) c = c.transpose(1, 0, 2)
@ -1130,6 +1140,7 @@ def test_gridcount():
data = np.random.rayleigh(1, size=(2, N)) data = np.random.rayleigh(1, size=(2, N))
x = np.linspace(0, max(data.ravel()) + 1, 10) x = np.linspace(0, max(data.ravel()) + 1, 10)
X = np.vstack((x, x)) X = np.vstack((x, x))
dx = x[1] - x[0] dx = x[1] - x[0]
c = wk.gridcount(data, X) c = wk.gridcount(data, X)
h = plb.contourf(x, x, c) h = plb.contourf(x, x, c)

@ -216,6 +216,22 @@ Check accuracy of cdf and ppf
Random number generation Random number generation
>>> R = %(name)s.rvs(%(shapes)s, size=100) >>> R = %(name)s.rvs(%(shapes)s, size=100)
Compare ML and MPS method
>>> phat = %(name)s.fit2(R, method='ml');
>>> phat.plotfitsummary(); plt.figure(plt.gcf().number+1)
>>> phat2 = %(name)s.fit2(R, method='mps')
>>> phat2.plotfitsummary(); plt.figure(plt.gcf().number+1)
Fix loc=0 and estimate shapes and scale
>>> phat3 = %(name)s.fit2(R, scale=1, floc=0, method='mps')
>>> phat3.plotfitsummary(); plt.figure(plt.gcf().number+1)
Accurate confidence interval with profile loglikelihood
>>> lp = phat3.profile()
>>> lp.plot()
>>> pci = lp.get_bounds()
""" """
_doc_default = ''.join([_doc_default_longsummary, _doc_default = ''.join([_doc_default_longsummary,

@ -713,7 +713,7 @@ class FitDistribution(rv_frozen):
'''Compute covariance '''Compute covariance
''' '''
somefixed = (self.par_fix != None) and any(isfinite(self.par_fix)) somefixed = (self.par_fix != None) and any(isfinite(self.par_fix))
H1 = numpy.asmatrix(self.dist.hessian_nnlf(self.par, self.data)) #H1 = numpy.asmatrix(self.dist.hessian_nnlf(self.par, self.data))
H = numpy.asmatrix(self.dist.hessian_nlogps(self.par, self.data)) H = numpy.asmatrix(self.dist.hessian_nlogps(self.par, self.data))
self.H = H self.H = H
try: try:

@ -7,7 +7,7 @@ Created on 19. nov. 2010
import wafo.stats as ws import wafo.stats as ws
from wafo.stats.estimation import Profile, FitDistribution from wafo.stats.estimation import Profile, FitDistribution
from numpy import log, array from numpy import log, array
def test_profile(): def test_fit_and_profile():
''' '''
# MLE # MLE
import wafo.stats as ws import wafo.stats as ws

Loading…
Cancel
Save