From f223b12cc2b260acecfc5936425370a78f151bd6 Mon Sep 17 00:00:00 2001 From: Fabian Joswig Date: Tue, 7 Dec 2021 08:27:24 +0000 Subject: [PATCH 1/2] fix: instances of plot.show changed to plot.draw in fit module --- .gitignore | 1 + pyerrors/fits.py | 6 +++--- tests/fits_test.py | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 77feb98c..fdaac56f 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ examples/B1k2_pcac_plateau.p examples/Untitled.* core.* *.swp +htmlcov diff --git a/pyerrors/fits.py b/pyerrors/fits.py index 85e28557..1651cd93 100644 --- a/pyerrors/fits.py +++ b/pyerrors/fits.py @@ -678,7 +678,7 @@ def qqplot(x, o_y, func, p): plt.xlabel('Theoretical quantiles') plt.ylabel('Ordered Values') plt.legend() - plt.show() + plt.draw() def residual_plot(x, y, func, fit_res): @@ -707,7 +707,7 @@ def residual_plot(x, y, func, fit_res): ax1.set_xlim([xstart, xstop]) ax1.set_ylabel('Residuals') plt.subplots_adjust(wspace=None, hspace=None) - plt.show() + plt.draw() def covariance_matrix(y): @@ -782,7 +782,7 @@ def ks_test(obs=None): loc_max_diff = np.argmax(np.abs(diffs)) loc = Xs[loc_max_diff] plt.annotate(s='', xy=(loc, loc), xytext=(loc, loc + diffs[loc_max_diff]), arrowprops=dict(arrowstyle='<->', shrinkA=0, shrinkB=0)) - plt.show() + plt.draw() print(scipy.stats.kstest(Qs, 'uniform')) diff --git a/tests/fits_test.py b/tests/fits_test.py index 5d7f1de3..53a23dc9 100644 --- a/tests/fits_test.py +++ b/tests/fits_test.py @@ -29,7 +29,7 @@ def test_least_squares(): y = a[0] * np.exp(-a[1] * x) return y - out = pe.least_squares(x, oy, func) + out = pe.least_squares(x, oy, func, expected_chisquare=True, resplot=True, qqplot=True) beta = out.fit_parameters for i in range(2): @@ -133,7 +133,7 @@ def test_total_least_squares(): odr.set_job(fit_type=0, deriv=1) output = odr.run() - out = pe.total_least_squares(ox, oy, func) + out = pe.total_least_squares(ox, oy, func, expected_chisquare=True) beta = out.fit_parameters for i in range(2): From 370cd34e0fc376a78c6b188412653aad7e4d2401 Mon Sep 17 00:00:00 2001 From: Fabian Joswig Date: Tue, 7 Dec 2021 08:31:24 +0000 Subject: [PATCH 2/2] refactor!: covariance3 removed --- pyerrors/obs.py | 64 ------------------------------------------------- 1 file changed, 64 deletions(-) diff --git a/pyerrors/obs.py b/pyerrors/obs.py index bc60a3a2..bea4f7e0 100644 --- a/pyerrors/obs.py +++ b/pyerrors/obs.py @@ -1546,70 +1546,6 @@ def covariance2(obs1, obs2, correlation=False, **kwargs): return dvalue -def covariance3(obs1, obs2, correlation=False, **kwargs): - """Another alternative implementation of the covariance of two observables. - - covariance2(obs, obs) is equal to obs.dvalue ** 2 - Currently only works if ensembles are identical. - The gamma method has to be applied first to both observables. - - If abs(covariance2(obs1, obs2)) > obs1.dvalue * obs2.dvalue, the covariance - is constrained to the maximum value in order to make sure that covariance - matrices are positive semidefinite. - - Keyword arguments - ----------------- - correlation -- if true the correlation instead of the covariance is - returned (default False) - plot -- if true, the integrated autocorrelation time for each ensemble is - plotted. - """ - - for name in sorted(set(obs1.names + obs2.names)): - if (obs1.shape.get(name) != obs2.shape.get(name)) and (obs1.shape.get(name) is not None) and (obs2.shape.get(name) is not None): - raise Exception('Shapes of ensemble', name, 'do not fit') - if (1 != len(set([len(idx) for idx in [obs1.idl[name], obs2.idl[name], _merge_idx([obs1.idl[name], obs2.idl[name]])]]))): - raise Exception('Shapes of ensemble', name, 'do not fit') - - if not hasattr(obs1, 'e_names') or not hasattr(obs2, 'e_names'): - raise Exception('The gamma method has to be applied to both Obs first.') - - tau_exp = [] - S = [] - for e_name in sorted(set(obs1.e_names + obs2.e_names)): - t_1 = obs1.tau_exp.get(e_name) - t_2 = obs2.tau_exp.get(e_name) - if t_1 is None: - t_1 = 0 - if t_2 is None: - t_2 = 0 - tau_exp.append(max(t_1, t_2)) - S_1 = obs1.S.get(e_name) - S_2 = obs2.S.get(e_name) - if S_1 is None: - S_1 = Obs.S_global - if S_2 is None: - S_2 = Obs.S_global - S.append(max(S_1, S_2)) - - check_obs = obs1 + obs2 - check_obs.gamma_method(tau_exp=tau_exp, S=S) - - if kwargs.get('plot'): - check_obs.plot_tauint() - check_obs.plot_rho() - - cov = (check_obs.dvalue ** 2 - obs1.dvalue ** 2 - obs2.dvalue ** 2) / 2 - - if np.abs(cov / obs1.dvalue / obs2.dvalue) > 1.0: - cov = np.sign(cov) * obs1.dvalue * obs2.dvalue - - if correlation: - cov = cov / obs1.dvalue / obs2.dvalue - - return cov - - def pseudo_Obs(value, dvalue, name, samples=1000): """Generate a pseudo Obs with given value, dvalue and name