From 331d7cb4716ec2dc4601b50d4aaf24634831d6dc Mon Sep 17 00:00:00 2001 From: Fabian Joswig Date: Mon, 15 Nov 2021 14:18:26 +0000 Subject: [PATCH] test_jackknife added --- pyerrors/obs.py | 2 +- tests/obs_test.py | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/pyerrors/obs.py b/pyerrors/obs.py index d73f92e3..2204a429 100644 --- a/pyerrors/obs.py +++ b/pyerrors/obs.py @@ -562,7 +562,7 @@ class Obs: Returns ------- - np.ndarray + numpy.ndarray Returns a numpy array of length N + 1 where N is the number of samples for the given ensemble and replicum. The zeroth entry of the array contains the mean value of the Obs, entries 1 to N contain the N jackknife samples diff --git a/tests/obs_test.py b/tests/obs_test.py index f0c63ac7..7ce035ab 100644 --- a/tests/obs_test.py +++ b/tests/obs_test.py @@ -504,3 +504,18 @@ def test_covariance2_symmetry(): cov_ba = pe.covariance2(a, test_obs1) assert np.abs(cov_ab - cov_ba) <= 10 * np.finfo(np.float64).eps assert np.abs(cov_ab) < test_obs1.dvalue * test_obs2.dvalue * (1 + 10 * np.finfo(np.float64).eps) + + +def test_jackknife(): + full_data = np.random.normal(1.1, 0.87, 5487) + + my_obs = pe.Obs([full_data], ['test']) + + n = full_data.size + mean = np.mean(full_data) + tmp_jacks = np.zeros(n + 1) + tmp_jacks[0] = mean + for i in range(n): + tmp_jacks[i + 1] = (n * mean - full_data[i]) / (n - 1) + + assert np.allclose(tmp_jacks, my_obs.export_jackknife())