test_jackknife added

This commit is contained in:
Fabian Joswig 2021-11-15 14:18:26 +00:00
parent 69d786c155
commit 331d7cb471
2 changed files with 16 additions and 1 deletions

View file

@ -562,7 +562,7 @@ class Obs:
Returns Returns
------- -------
np.ndarray numpy.ndarray
Returns a numpy array of length N + 1 where N is the number of samples 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 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 the mean value of the Obs, entries 1 to N contain the N jackknife samples

View file

@ -504,3 +504,18 @@ def test_covariance2_symmetry():
cov_ba = pe.covariance2(a, test_obs1) 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 - 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) 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())