mirror of
https://github.com/fjosw/pyerrors.git
synced 2025-03-15 06:40:24 +01:00
refactor: deprecated e_tag and e_tag_global removed from modules and
tests
This commit is contained in:
parent
f1a45f4200
commit
ed6bb24607
3 changed files with 11 additions and 19 deletions
|
@ -88,8 +88,6 @@ def least_squares(x, y, func, priors=None, silent=False, **kwargs):
|
|||
priors has to be a list with an entry for every parameter in the fit. The entries can either be
|
||||
Obs (e.g. results from a previous fit) or strings containing a value and an error formatted like
|
||||
0.548(23), 500(40) or 0.5(0.4)
|
||||
It is important for the subsequent error estimation that the e_tag for the gamma method is large
|
||||
enough.
|
||||
silent : bool, optional
|
||||
If true all output to the console is omitted (default False).
|
||||
initial_guess : list
|
||||
|
@ -323,9 +321,6 @@ def _prior_fit(x, y, func, priors, silent=False, **kwargs):
|
|||
|
||||
output.fit_function = func
|
||||
|
||||
if Obs.e_tag_global < 4:
|
||||
warnings.warn("e_tag_global is smaller than 4, this can cause problems when calculating errors from fits with priors", RuntimeWarning)
|
||||
|
||||
x = np.asarray(x)
|
||||
|
||||
if not callable(func):
|
||||
|
|
|
@ -37,7 +37,6 @@ def test_least_squares():
|
|||
assert math.isclose(beta[i].value, popt[i], abs_tol=1e-5)
|
||||
assert math.isclose(pcov[i, i], beta[i].dvalue ** 2, abs_tol=1e-3)
|
||||
assert math.isclose(pe.covariance(beta[0], beta[1]), pcov[0, 1], abs_tol=1e-3)
|
||||
pe.Obs.e_tag_global = 0
|
||||
|
||||
chi2_pyerrors = np.sum(((f(x, *[o.value for o in beta]) - y) / yerr) ** 2) / (len(x) - 2)
|
||||
chi2_scipy = np.sum(((f(x, *popt) - y) / yerr) ** 2) / (len(x) - 2)
|
||||
|
@ -124,19 +123,17 @@ def test_total_least_squares():
|
|||
out = pe.total_least_squares(ox, oy, func)
|
||||
beta = out.fit_parameters
|
||||
|
||||
pe.Obs.e_tag_global = 5
|
||||
for i in range(2):
|
||||
beta[i].gamma_method(e_tag=5, S=1.0)
|
||||
beta[i].gamma_method(S=1.0)
|
||||
assert math.isclose(beta[i].value, output.beta[i], rel_tol=1e-5)
|
||||
assert math.isclose(output.cov_beta[i, i], beta[i].dvalue ** 2, rel_tol=2.5e-1), str(output.cov_beta[i, i]) + ' ' + str(beta[i].dvalue ** 2)
|
||||
assert math.isclose(pe.covariance(beta[0], beta[1]), output.cov_beta[0, 1], rel_tol=2.5e-1)
|
||||
|
||||
|
||||
out = pe.total_least_squares(ox, oy, func, const_par=[beta[1]])
|
||||
|
||||
diff = out.fit_parameters[0] - beta[0]
|
||||
assert(diff / beta[0] < 1e-3 * beta[0].dvalue)
|
||||
assert((out.fit_parameters[1] - beta[1]).is_zero())
|
||||
pe.Obs.e_tag_global = 0
|
||||
|
||||
|
||||
def test_odr_derivatives():
|
||||
|
|
|
@ -183,7 +183,7 @@ def test_covariance_is_variance():
|
|||
test_obs.gamma_method()
|
||||
assert np.abs(test_obs.dvalue ** 2 - pe.covariance(test_obs, test_obs)) <= 10 * np.finfo(np.float64).eps
|
||||
test_obs = test_obs + pe.pseudo_Obs(value, dvalue, 'q', 200)
|
||||
test_obs.gamma_method(e_tag=0)
|
||||
test_obs.gamma_method()
|
||||
assert np.abs(test_obs.dvalue ** 2 - pe.covariance(test_obs, test_obs)) <= 10 * np.finfo(np.float64).eps
|
||||
|
||||
|
||||
|
@ -221,7 +221,7 @@ def test_gamma_method():
|
|||
test_obs = pe.pseudo_Obs(value, dvalue, 't', int(1000 * (1 + np.random.rand())))
|
||||
|
||||
# Test if the error is processed correctly
|
||||
test_obs.gamma_method(e_tag=1)
|
||||
test_obs.gamma_method()
|
||||
assert np.abs(test_obs.value - value) < 1e-12
|
||||
assert abs(test_obs.dvalue - dvalue) < 1e-10 * dvalue
|
||||
|
||||
|
@ -241,7 +241,7 @@ def test_derived_observables():
|
|||
assert np.abs(d_Obs_ad.dvalue-d_Obs_fd.dvalue) < 1000 * np.finfo(np.float64).eps * d_Obs_ad.dvalue
|
||||
|
||||
i_am_one = pe.derived_observable(lambda x, **kwargs: x[0] / x[1], [d_Obs_ad, d_Obs_ad])
|
||||
i_am_one.gamma_method(e_tag=1)
|
||||
i_am_one.gamma_method()
|
||||
|
||||
assert i_am_one.value == 1.0
|
||||
assert i_am_one.dvalue < 2 * np.finfo(np.float64).eps
|
||||
|
@ -290,7 +290,7 @@ def test_overloaded_functions():
|
|||
for i, item in enumerate(funcs):
|
||||
ad_obs = item(test_obs)
|
||||
fd_obs = pe.derived_observable(lambda x, **kwargs: item(x[0]), [test_obs], num_grad=True)
|
||||
ad_obs.gamma_method(S=0.01, e_tag=1)
|
||||
ad_obs.gamma_method(S=0.01)
|
||||
assert np.max((ad_obs.deltas['t'] - fd_obs.deltas['t']) / ad_obs.deltas['t']) < 1e-8, item.__name__
|
||||
assert np.abs((ad_obs.value - item(val)) / ad_obs.value) < 1e-10, item.__name__
|
||||
assert np.abs(ad_obs.dvalue - dval * np.abs(deriv[i](val))) < 1e-6, item.__name__
|
||||
|
@ -447,8 +447,8 @@ def test_gamma_method_irregular():
|
|||
idx2 = [i + 1 for i in range(len(configs)) if configs[i] == 1]
|
||||
a = pe.Obs([zero_arr, zero_arr2], ['a1', 'a2'], idl=[idx, idx2])
|
||||
|
||||
afull.gamma_method(e_tag=1)
|
||||
a.gamma_method(e_tag=1)
|
||||
afull.gamma_method()
|
||||
a.gamma_method()
|
||||
|
||||
expe = (afull.dvalue * np.sqrt(N / np.sum(configs)))
|
||||
assert (a.dvalue - 5 * a.ddvalue < expe and expe < a.dvalue + 5 * a.ddvalue)
|
||||
|
@ -462,13 +462,13 @@ def test_gamma_method_irregular():
|
|||
arr = np.random.normal(1, .2, size=N)
|
||||
carr = gen_autocorrelated_array(arr, .346)
|
||||
a = pe.Obs([carr], ['a'])
|
||||
a.gamma_method(e_tag=1)
|
||||
a.gamma_method()
|
||||
|
||||
ae = pe.Obs([[carr[i] for i in range(len(carr)) if i % 2 == 0]], ['a'], idl=[[i for i in range(len(carr)) if i % 2 == 0]])
|
||||
ae.gamma_method(e_tag=1)
|
||||
ae.gamma_method()
|
||||
|
||||
ao = pe.Obs([[carr[i] for i in range(len(carr)) if i % 2 == 1]], ['a'], idl=[[i for i in range(len(carr)) if i % 2 == 1]])
|
||||
ao.gamma_method(e_tag=1)
|
||||
ao.gamma_method()
|
||||
|
||||
assert(ae.e_tauint['a'] < a.e_tauint['a'])
|
||||
assert((ae.e_tauint['a'] - 4 * ae.e_dtauint['a'] < ao.e_tauint['a']))
|
||||
|
|
Loading…
Add table
Reference in a new issue