feat: Obs.reweight method added.

This commit is contained in:
Fabian Joswig 2022-06-23 13:50:24 +01:00
parent b047f12c12
commit d922b72f3b
2 changed files with 23 additions and 2 deletions

View file

@ -426,6 +426,21 @@ class Obs:
my_string_list.append(my_string) my_string_list.append(my_string)
print('\n'.join(my_string_list)) 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): def is_zero_within_error(self, sigma=1):
"""Checks whether the observable is zero within 'sigma' standard errors. """Checks whether the observable is zero within 'sigma' standard errors.
@ -1330,7 +1345,7 @@ def reweight(weight, obs, **kwargs):
all_configs : bool all_configs : bool
if True, the reweighted observables are normalized by the average of if True, the reweighted observables are normalized by the average of
the reweighting factor on all configurations in weight.idl and not 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 = [] result = []
for i in range(len(obs)): for i in range(len(obs)):

View file

@ -858,7 +858,7 @@ def test_covariance_additional_non_overlapping_data():
assert np.isclose(corr1[0, 1], corr2[0, 1], atol=1e-14) 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) range1 = range(1, 20, 2)
range2 = range(1, 41, 2) range2 = range(1, 41, 2)
@ -884,6 +884,12 @@ def test_empty_obs():
assert q == o 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(): def test_jackknife():
full_data = np.random.normal(1.1, 0.87, 5487) full_data = np.random.normal(1.1, 0.87, 5487)