mirror of
https://github.com/fjosw/pyerrors.git
synced 2025-03-16 23:30:24 +01:00
Merge branch 'develop' into documentation
This commit is contained in:
commit
aac77b5e74
2 changed files with 28 additions and 0 deletions
|
@ -1564,6 +1564,25 @@ def load_object(path):
|
||||||
return pickle.load(file)
|
return pickle.load(file)
|
||||||
|
|
||||||
|
|
||||||
|
def import_jackknife(jacks, name):
|
||||||
|
"""Imports jackknife samples and returns an Obs
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
jacks : numpy.ndarray
|
||||||
|
numpy array containing the mean value as zeroth entry and
|
||||||
|
the N jackknife samples as first to Nth entry.
|
||||||
|
name : str
|
||||||
|
name of the ensemble the samples are defined on.
|
||||||
|
"""
|
||||||
|
length = len(jacks) - 1
|
||||||
|
prj = (np.ones((length, length)) - (length - 1) * np.identity(length))
|
||||||
|
samples = jacks[1:] @ prj
|
||||||
|
new_obs = Obs([samples], [name])
|
||||||
|
new_obs._value = jacks[0]
|
||||||
|
return new_obs
|
||||||
|
|
||||||
|
|
||||||
def merge_obs(list_of_obs):
|
def merge_obs(list_of_obs):
|
||||||
"""Combine all observables in list_of_obs into one new observable
|
"""Combine all observables in list_of_obs into one new observable
|
||||||
|
|
||||||
|
|
|
@ -534,3 +534,12 @@ def test_jackknife():
|
||||||
my_new_obs = my_obs + pe.Obs([full_data], ['test2'])
|
my_new_obs = my_obs + pe.Obs([full_data], ['test2'])
|
||||||
with pytest.raises(Exception):
|
with pytest.raises(Exception):
|
||||||
my_new_obs.export_jackknife()
|
my_new_obs.export_jackknife()
|
||||||
|
|
||||||
|
|
||||||
|
def test_import_jackknife():
|
||||||
|
full_data = np.random.normal(1.105, 0.021, 754)
|
||||||
|
my_obs = pe.Obs([full_data], ['test'])
|
||||||
|
my_jacks = my_obs.export_jackknife()
|
||||||
|
reconstructed_obs = pe.import_jackknife(my_jacks, 'test')
|
||||||
|
assert my_obs == reconstructed_obs
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue