diff --git a/pyerrors/obs.py b/pyerrors/obs.py index d211c541..42ae3b8c 100644 --- a/pyerrors/obs.py +++ b/pyerrors/obs.py @@ -426,6 +426,21 @@ class Obs: my_string_list.append(my_string) print('\n'.join(my_string_list)) + def reweight(self, rw): + """Reweight the obs with given rewighting factors. + + Parameters + ---------- + weight : Obs + Reweighting factor. An Observable that has to be defined on a superset of the + configurations in obs[i].idl for all i. + all_configs : bool + if True, the reweighted observables are normalized by the average of + the reweighting factor on all configurations in weight.idl and not + on the configurations in obs[i].idl. Default False. + """ + return reweight(rw, [self])[0] + def is_zero_within_error(self, sigma=1): """Checks whether the observable is zero within 'sigma' standard errors. @@ -1330,7 +1345,7 @@ def reweight(weight, obs, **kwargs): all_configs : bool if True, the reweighted observables are normalized by the average of the reweighting factor on all configurations in weight.idl and not - on the configurations in obs[i].idl. + on the configurations in obs[i].idl. Default False. """ result = [] for i in range(len(obs)): diff --git a/tests/obs_test.py b/tests/obs_test.py index 5b6a8509..1665ef62 100644 --- a/tests/obs_test.py +++ b/tests/obs_test.py @@ -858,7 +858,7 @@ def test_covariance_additional_non_overlapping_data(): assert np.isclose(corr1[0, 1], corr2[0, 1], atol=1e-14) -def test_coavariance_reorder_non_overlapping_data(): +def test_covariance_reorder_non_overlapping_data(): range1 = range(1, 20, 2) range2 = range(1, 41, 2) @@ -884,6 +884,12 @@ def test_empty_obs(): assert q == o +def test_reweight_method(): + obs1 = pe.pseudo_Obs(0.2, 0.01, 'test') + rw = pe.pseudo_Obs(0.999, 0.001, 'test') + assert obs1.reweight(rw) == pe.reweight(rw, [obs1])[0] + + def test_jackknife(): full_data = np.random.normal(1.1, 0.87, 5487)