diff --git a/pyerrors/obs.py b/pyerrors/obs.py index 168f7292..c29c1bd8 100644 --- a/pyerrors/obs.py +++ b/pyerrors/obs.py @@ -1358,7 +1358,7 @@ def covariance(obs1, obs2, correlation=False, **kwargs): 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'): + if not hasattr(obs1, 'e_dvalue') or not hasattr(obs2, 'e_dvalue'): raise Exception('The gamma method has to be applied to both Obs first.') dvalue = 0 @@ -1452,7 +1452,7 @@ def covariance2(obs1, obs2, correlation=False, **kwargs): if set(obs1.names).isdisjoint(set(obs2.names)): return 0. - if not hasattr(obs1, 'e_names') or not hasattr(obs2, 'e_names'): + if not hasattr(obs1, 'e_dvalue') or not hasattr(obs2, 'e_dvalue'): raise Exception('The gamma method has to be applied to both Obs first.') dvalue = 0 diff --git a/tests/covobs_test.py b/tests/covobs_test.py index 6f0e47f1..beedb54c 100644 --- a/tests/covobs_test.py +++ b/tests/covobs_test.py @@ -37,6 +37,7 @@ def test_covobs(): op.gamma_method() assert(np.isclose(oc.value, op.value, rtol=1e-14, atol=1e-14)) + [o.gamma_method() for o in cl] assert(pe.covariance(cl[0], cl[1]) == cov[0][1]) assert(pe.covariance2(cl[0], cl[1]) == cov[1][0]) diff --git a/tests/fits_test.py b/tests/fits_test.py index 54c15ef4..b37abc25 100644 --- a/tests/fits_test.py +++ b/tests/fits_test.py @@ -274,6 +274,41 @@ def test_r_value_persistence(): assert np.isclose(fitp[1].value, fitp[1].r_values['b']) +def test_prior_fit(): + def f(a, x): + return a[0] + a[1] * x + + a = pe.pseudo_Obs(0.0, 0.1, 'a') + b = pe.pseudo_Obs(1.0, 0.2, 'a') + + y = [a, b] + with pytest.raises(Exception): + fitp = pe.fits.least_squares([0, 1], 1 * np.array(y), f, priors=['0.0(8)', '1.0(8)']) + + [o.gamma_method() for o in y] + + fitp = pe.fits.least_squares([0, 1], y, f, priors=['0.0(8)', '1.0(8)']) + fitp = pe.fits.least_squares([0, 1], y, f, priors=y, resplot=True, qqplot=True) + + +def test_error_band(): + def f(a, x): + return a[0] + a[1] * x + + a = pe.pseudo_Obs(0.0, 0.1, 'a') + b = pe.pseudo_Obs(1.0, 0.2, 'a') + + x = [0, 1] + y = [a, b] + + fitp = pe.fits.least_squares(x, y, f) + + with pytest.raises(Exception): + pe.fits.error_band(x, f, fitp.fit_parameters) + fitp.gamma_method() + pe.fits.error_band(x, f, fitp.fit_parameters) + + def fit_general(x, y, func, silent=False, **kwargs): """Performs a non-linear fit to y = func(x) and returns a list of Obs corresponding to the fit parameters.