/usr/lib/python3/dist-packages/astroML/tests/test_resample.py is in python3-astroml 0.3-6.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | from __future__ import print_function, division
import numpy as np
from numpy.testing import assert_allclose, run_module_suite
from astroML.resample import bootstrap, jackknife
from astroML.stats import mean_sigma
def test_jackknife_results():
np.random.seed(0)
x = np.random.normal(0, 1, 100)
mu1, sig1 = jackknife(x, np.mean, kwargs=dict(axis=1))
mu2, sig2 = jackknife(x, np.std, kwargs=dict(axis=1))
assert_allclose([mu1, sig1, mu2, sig2],
[0.0598080155345, 0.100288031685,
1.01510470168, 0.0649020337599])
def test_jackknife_multiple():
np.random.seed(0)
x = np.random.normal(0, 1, 100)
mu1, sig1 = jackknife(x, np.mean, kwargs=dict(axis=1))
mu2, sig2 = jackknife(x, np.std, kwargs=dict(axis=1))
res = jackknife(x, mean_sigma, kwargs=dict(axis=1))
assert_allclose(res[0], (mu1, sig1))
assert_allclose(res[1], (mu2, sig2))
def test_bootstrap_results():
np.random.seed(0)
x = np.random.normal(0, 1, 100)
distribution = bootstrap(x, 100, np.mean, kwargs=dict(axis=1),
random_state=0)
mu, sigma = mean_sigma(distribution)
assert_allclose([mu, sigma], [0.08139846, 0.10465327])
def test_bootstrap_multiple():
np.random.seed(0)
x = np.random.normal(0, 1, 100)
dist_mean = bootstrap(x, 100, np.mean, kwargs=dict(axis=1),
random_state=0)
dist_std = bootstrap(x, 100, np.std, kwargs=dict(axis=1),
random_state=0)
res = bootstrap(x, 100, mean_sigma, kwargs=dict(axis=1),
random_state=0)
assert_allclose(res[0], dist_mean)
assert_allclose(res[1], dist_std)
def test_bootstrap_pass_indices():
np.random.seed(0)
x = np.random.normal(0, 1, 100)
dist1 = bootstrap(x, 100, np.mean,
kwargs=dict(axis=1), random_state=0)
dist2 = bootstrap(x, 100, lambda i: np.mean(x[i], axis=1),
pass_indices=True, random_state=0)
assert_allclose(dist1, dist2)
def test_jackknife_pass_indices():
np.random.seed(0)
x = np.random.normal(0, 1, 100)
res1 = jackknife(x, np.mean,
kwargs=dict(axis=1))
res2 = jackknife(x, lambda i: np.mean(x[i], axis=1),
pass_indices=True)
assert_allclose(res1, res2)
if __name__ == '__main__':
run_module_suite()
|