diff --git a/pyerrors/fits.py b/pyerrors/fits.py index 8e57f696..13b70f7f 100644 --- a/pyerrors/fits.py +++ b/pyerrors/fits.py @@ -18,8 +18,6 @@ from odrpack import odr_fit from .obs import Obs, cov_Obs, covariance, derived_observable, invert_corr_cov_cholesky -_rng = np.random.default_rng() - class Fit_result(Sequence): """Represents fit results. @@ -948,6 +946,6 @@ def _construct_prior_obs(i_prior, i_n): return i_prior elif isinstance(i_prior, str): loc_val, loc_dval = _extract_val_and_dval(i_prior) - return cov_Obs(loc_val, loc_dval ** 2, '#prior' + str(i_n) + f"_{_rng.integers(2147483647):010d}") + return cov_Obs(loc_val, loc_dval ** 2, '#prior' + str(i_n) + f"_{np.random.randint(2147483647):010d}") else: raise TypeError("Prior entries need to be 'Obs' or 'str'.") diff --git a/pyerrors/misc.py b/pyerrors/misc.py index 5ab1b84c..99481faf 100644 --- a/pyerrors/misc.py +++ b/pyerrors/misc.py @@ -10,8 +10,6 @@ import scipy from .obs import Obs from .version import __version__ -_rng = np.random.default_rng() - def print_config(): """Print information about version of python, pyerrors and dependencies.""" @@ -122,7 +120,7 @@ def pseudo_Obs(value, dvalue, name, samples=1000): return Obs([np.zeros(samples) + value], [name]) else: for _ in range(100): - deltas = [_rng.normal(0.0, dvalue * np.sqrt(samples), samples)] + deltas = [np.random.normal(0.0, dvalue * np.sqrt(samples), samples)] deltas -= np.mean(deltas) deltas *= dvalue / np.sqrt(np.var(deltas) / samples) / np.sqrt(1 + 3 / samples) deltas += value @@ -165,7 +163,7 @@ def gen_correlated_data(means, cov, name, tau=0.5, samples=1000): raise Exception('All integrated autocorrelations have to be >= 0.5.') a = (2 * tau - 1) / (2 * tau + 1) - rand = _rng.multivariate_normal(np.zeros_like(means), cov * samples, samples) + rand = np.random.multivariate_normal(np.zeros_like(means), cov * samples, samples) # Normalize samples such that sample variance matches input norm = np.array([np.var(o, ddof=1) / samples for o in rand.T]) diff --git a/tests/misc_test.py b/tests/misc_test.py index 028ea6da..99bb5056 100644 --- a/tests/misc_test.py +++ b/tests/misc_test.py @@ -22,18 +22,3 @@ def test_obs_errorbar(): def test_print_config(): pe.print_config() - - -def test_pseudo_Obs_seed_independence(): - # pseudo_Obs now uses a module-local np.random.default_rng() generator, - # so np.random.seed() no longer controls its output. The per-sample - # deltas therefore differ between successive calls even with a re-seed, - # though the normalized value / dvalue still match the requested inputs. - np.random.seed(0) - a = pe.pseudo_Obs(1.0, 0.1, "e") - np.random.seed(0) - b = pe.pseudo_Obs(1.0, 0.1, "e") - - assert not np.allclose(a.deltas["e"], b.deltas["e"]) - assert np.isclose(a.value, b.value) - assert np.isclose(a.dvalue, b.dvalue)