def test_sparams_keyword(self): np.random.seed(123456) x = stats.norm.rvs(size=100) # Check that None, () and 0 (loc=0, for normal distribution) all work # and give the same results osm1, osr1 = stats.probplot(x, sparams=None, fit=False) osm2, osr2 = stats.probplot(x, sparams=0, fit=False) osm3, osr3 = stats.probplot(x, sparams=(), fit=False) assert_allclose(osm1, osm2) assert_allclose(osm1, osm3) assert_allclose(osr1, osr2) assert_allclose(osr1, osr3) # Check giving (loc, scale) params for normal distribution osm, osr = stats.probplot(x, sparams=(), fit=False)
def test_basic(self): np.random.seed(12345) x = stats.norm.rvs(size=20) osm, osr = stats.probplot(x, fit=False) osm_expected = [-1.8241636, -1.38768012, -1.11829229, -0.91222575, -0.73908135, -0.5857176, -0.44506467, -0.31273668, -0.18568928, -0.06158146, 0.06158146, 0.18568928, 0.31273668, 0.44506467, 0.5857176, 0.73908135, 0.91222575, 1.11829229, 1.38768012, 1.8241636] assert_allclose(osr, np.sort(x)) assert_allclose(osm, osm_expected) res, res_fit = stats.probplot(x, fit=True) res_fit_expected = [1.05361841, 0.31297795, 0.98741609] assert_allclose(res_fit, res_fit_expected)
def test_basic(self): np.random.seed(12345) x = stats.norm.rvs(size=20) osm, osr = stats.probplot(x, fit=False) osm_expected = [ -1.8241636, -1.38768012, -1.11829229, -0.91222575, -0.73908135, -0.5857176, -0.44506467, -0.31273668, -0.18568928, -0.06158146, 0.06158146, 0.18568928, 0.31273668, 0.44506467, 0.5857176, 0.73908135, 0.91222575, 1.11829229, 1.38768012, 1.8241636 ] assert_allclose(osr, np.sort(x)) assert_allclose(osm, osm_expected) res, res_fit = stats.probplot(x, fit=True) res_fit_expected = [1.05361841, 0.31297795, 0.98741609] assert_allclose(res_fit, res_fit_expected)
def test_dist_keyword(self): np.random.seed(12345) x = stats.norm.rvs(size=20) osm1, osr1 = stats.probplot(x, fit=False, dist='t', sparams=(3,)) osm2, osr2 = stats.probplot(x, fit=False, dist=stats.t, sparams=(3,)) assert_allclose(osm1, osm2) assert_allclose(osr1, osr2) assert_raises(ValueError, stats.probplot, x, dist='wrong-dist-name') assert_raises(AttributeError, stats.probplot, x, dist=[]) class custom_dist(object): """Some class that looks just enough like a distribution.""" def ppf(self, q): return stats.norm.ppf(q, loc=2) osm1, osr1 = stats.probplot(x, sparams=(2,), fit=False) osm2, osr2 = stats.probplot(x, dist=custom_dist(), fit=False) assert_allclose(osm1, osm2) assert_allclose(osr1, osr2)
def test_dist_keyword(self): np.random.seed(12345) x = stats.norm.rvs(size=20) osm1, osr1 = stats.probplot(x, fit=False, dist='t', sparams=(3, )) osm2, osr2 = stats.probplot(x, fit=False, dist=stats.t, sparams=(3, )) assert_allclose(osm1, osm2) assert_allclose(osr1, osr2) assert_raises(ValueError, stats.probplot, x, dist='wrong-dist-name') assert_raises(AttributeError, stats.probplot, x, dist=[]) class custom_dist(object): """Some class that looks just enough like a distribution.""" def ppf(self, q): return stats.norm.ppf(q, loc=2) osm1, osr1 = stats.probplot(x, sparams=(2, ), fit=False) osm2, osr2 = stats.probplot(x, dist=custom_dist(), fit=False) assert_allclose(osm1, osm2) assert_allclose(osr1, osr2)
def test_plot_kwarg(self): np.random.seed(7654321) fig = plt.figure() fig.add_subplot(111) x = stats.t.rvs(3, size=100) res1, fitres1 = stats.probplot(x, plot=plt) plt.close() res2, fitres2 = stats.probplot(x, plot=None) res3 = stats.probplot(x, fit=False, plot=plt) plt.close() res4 = stats.probplot(x, fit=False, plot=None) # Check that results are consistent between combinations of `fit` and # `plot` keywords. assert_(len(res1) == len(res2) == len(res3) == len(res4) == 2) assert_allclose(res1, res2) assert_allclose(res1, res3) assert_allclose(res1, res4) assert_allclose(fitres1, fitres2) # Check that a Matplotlib Axes object is accepted fig = plt.figure() ax = fig.add_subplot(111) stats.probplot(x, fit=False, plot=ax) plt.close()
import numpy as np import scipy.interpolate as si from wafo.plotbackend import plotbackend as plt import wafo.data as wd import wafo.objects as wo import wafo.stats as ws import wafo.kdetools as wk pstate = 'off' # Significant wave-height data on Weibull paper, fig = plt.figure() ax = fig.add_subplot(111) Hs = wd.atlantic() wei = ws.weibull_min.fit(Hs) tmp = ws.probplot(Hs, wei, ws.weibull_min, plot=ax) plt.show() #wafostamp([],'(ER)') #disp('Block = 1'),pause(pstate) ## # Significant wave-height data on Gumbel paper, plt.clf() ax = fig.add_subplot(111) gum = ws.gumbel_r.fit(Hs) tmp1 = ws.probplot(Hs, gum, ws.gumbel_r, plot=ax) #wafostamp([],'(ER)') plt.show() #disp('Block = 2'),pause(pstate) ##
##!#! Expected value (solid) compared to data removed #clf #plot(xx(inds1,1),xx(inds1,2),'+'), hold on #mu = tranproc(mu1o,fliplr(grec1)); #plot(y1(inds1,1), mu), hold off #disp('Block = 7'), pause(pstate) #! Crest height PDF #!------------------ #! Transform data so that kde works better plt.clf() wave_data = ts.wave_parameters() Ac = wave_data['Ac'] L2 = 0.6 ws.probplot(Ac**L2, dist='norm', plot=plt) plt.show() #!#! plt.clf()# fac = wk.TKDE(Ac,L2=L2)(np.linspace(0.01,3,200), output='plot') fac.plot() # wafostamp([],'(ER)') print(fac.integrate(a=0.01, b=3)) print(fac.integrate()) print('Block = 8'), # pause(pstate) #!#! Empirical crest height CDF plt.clf() Fac = fac.to_cdf()
clf() test0 = glc.dist2gauss() #! the following test takes time N = len(xx) test1 = S1.testgaussian(ns=N, cases=50, test0=test0) is_gaussian = sum(test1 > test0) > 5 print(is_gaussian) show() #! Normalplot of data xx #!------------------------ #! indicates that the underlying distribution has a "heavy" upper tail and a #! "light" lower tail. clf() import pylab ws.probplot(ts.data.ravel(), dist='norm', plot=pylab) show() #! Section 2.2.3 Spectral densities of sea data #!----------------------------------------------- #! Example 2: Different forms of spectra #! import wafo.spectrum.models as wsm clf() Hm0 = 7 Tp = 11 spec = wsm.Jonswap(Hm0=Hm0, Tp=Tp).tospecdata() spec.plot() show() #! Directional spectrum and Encountered directional spectrum #! Directional spectrum
##!#! Expected value (solid) compared to data removed #clf #plot(xx(inds1,1),xx(inds1,2),'+'), hold on #mu = tranproc(mu1o,fliplr(grec1)); #plot(y1(inds1,1), mu), hold off #disp('Block = 7'), pause(pstate) #! Crest height PDF #!------------------ #! Transform data so that kde works better plt.clf() wave_data = ts.wave_parameters() Ac = wave_data['Ac'] L2 = 0.6 ws.probplot(Ac**L2, dist='norm', plot=plt) plt.show() #!#! plt.clf() # fac = wk.TKDE(Ac, L2=L2)(np.linspace(0.01, 3, 200), output='plot') fac.plot() # wafostamp([],'(ER)') print(fac.integrate(a=0.01, b=3)) print(fac.integrate()) print('Block = 8'), # pause(pstate) #!#! Empirical crest height CDF plt.clf() Fac = fac.to_cdf()
clf() test0 = glc.dist2gauss() #! the following test takes time N = len(xx) test1 = S1.testgaussian(ns=N, cases=50, test0=test0) is_gaussian = sum(test1 > test0) > 5 print(is_gaussian) show() #! Normalplot of data xx #!------------------------ #! indicates that the underlying distribution has a "heavy" upper tail and a #! "light" lower tail. clf() import pylab ws.probplot(ts.data.ravel(), dist='norm', plot=pylab) show() #! Section 2.2.3 Spectral densities of sea data #!----------------------------------------------- #! Example 2: Different forms of spectra #! import wafo.spectrum.models as wsm clf() Hm0 = 7; Tp = 11; spec = wsm.Jonswap(Hm0=Hm0, Tp=Tp).tospecdata() spec.plot() show() #! Directional spectrum and Encountered directional spectrum #! Directional spectrum clf()