From 60dbc2c6fe10ee4d537f6f8f269fe76dc376098f Mon Sep 17 00:00:00 2001 From: Fabian Joswig Date: Fri, 10 Jun 2022 08:56:41 +0100 Subject: [PATCH 1/5] build: minimal version numbers for dependencies updated. --- setup.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 31d810fc..9ce20d43 100644 --- a/setup.py +++ b/setup.py @@ -18,7 +18,7 @@ setup(name='pyerrors', license="MIT", packages=find_packages(), python_requires='>=3.6.0', - install_requires=['numpy>=1.16', 'autograd>=1.4', 'numdifftools', 'matplotlib>=3.3', 'scipy>=1', 'iminuit>=2', 'h5py', 'lxml', 'python-rapidjson'], + install_requires=['numpy>=1.16', 'autograd>=1.4', 'numdifftools', 'matplotlib>=3.3', 'scipy>=1', 'iminuit>=2', 'h5pyi>=3', 'lxml>=4', 'python-rapidjson>=1'], classifiers=[ 'Development Status :: 5 - Production/Stable', 'Intended Audience :: Science/Research', @@ -28,6 +28,6 @@ setup(name='pyerrors', 'Programming Language :: Python :: 3.8', 'Programming Language :: Python :: 3.9', 'Programming Language :: Python :: 3.10', - 'Topic :: Scientific/Engineering' + 'Topic :: Scientific/Engineering :: Physics' ], ) From 6aab72cf0e0befb611e9ad0e52946e4443828b94 Mon Sep 17 00:00:00 2001 From: Fabian Joswig Date: Fri, 10 Jun 2022 08:57:55 +0100 Subject: [PATCH 2/5] build: typo in setup.py corrected. --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 9ce20d43..9f3f5dfe 100644 --- a/setup.py +++ b/setup.py @@ -18,7 +18,7 @@ setup(name='pyerrors', license="MIT", packages=find_packages(), python_requires='>=3.6.0', - install_requires=['numpy>=1.16', 'autograd>=1.4', 'numdifftools', 'matplotlib>=3.3', 'scipy>=1', 'iminuit>=2', 'h5pyi>=3', 'lxml>=4', 'python-rapidjson>=1'], + install_requires=['numpy>=1.16', 'autograd>=1.4', 'numdifftools', 'matplotlib>=3.3', 'scipy>=1', 'iminuit>=2', 'h5py>=3', 'lxml>=4', 'python-rapidjson>=1'], classifiers=[ 'Development Status :: 5 - Production/Stable', 'Intended Audience :: Science/Research', From 5e550f432101c7b18a5481187f039acbd05e303d Mon Sep 17 00:00:00 2001 From: Fabian Joswig Date: Fri, 10 Jun 2022 09:29:04 +0100 Subject: [PATCH 3/5] tests: test for smooth_eigenvalues functionality added. --- tests/obs_test.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/obs_test.py b/tests/obs_test.py index 55a23abd..2a158c3e 100644 --- a/tests/obs_test.py +++ b/tests/obs_test.py @@ -736,6 +736,23 @@ def test_covariance_factorizing(): assert np.isclose(pe.covariance([mt0, tt[1]])[0, 1], -pe.covariance(tt)[0, 1]) +def test_covariance_smooth_eigenvalues(): + for c_coeff in range(0, 14, 2): + length = 14 + sm = 5 + t_fac = 1.5 + tt = pe.misc.gen_correlated_data(np.zeros(length), 1 - 0.1 ** c_coeff * np.ones((length, length)) + 0.1 ** c_coeff * np.diag(np.ones(length)), 'test', tau=0.5 + t_fac * np.random.rand(length), samples=200) + [o.gamma_method() for o in tt] + full_corr = pe.covariance(tt, correlation=True) + cov = pe.covariance(tt, smooth=sm, correlation=True) + + full_evals = np.linalg.eigh(full_corr)[0] + sm_length = np.where(full_evals < np.mean(full_evals[:-sm]))[0][-1] + + evals = np.linalg.eigh(cov)[0] + assert np.all(np.isclose(evals[:sm_length], evals[0], atol=1e-8)) + + def test_covariance_alternation(): length = 12 t_fac = 2.5 From f49562b895219e388fec0fb5e62db55bfd6c7077 Mon Sep 17 00:00:00 2001 From: Fabian Joswig Date: Fri, 10 Jun 2022 10:13:49 +0100 Subject: [PATCH 4/5] tests: additional test for least square fits added which probes different initial guess and exceptions. Tolerance in total least square tests relaxed. --- tests/fits_test.py | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/tests/fits_test.py b/tests/fits_test.py index bb3599e2..8dd6677d 100644 --- a/tests/fits_test.py +++ b/tests/fits_test.py @@ -184,6 +184,26 @@ def test_fit_corr_independent(): assert (out[1] - out_corr[1]).is_zero(atol=1e-5) +def test_linear_fit_guesses(): + for err in [10, 0.1, 0.001]: + xvals = [] + yvals = [] + for x in range(1, 8, 2): + xvals.append(x) + yvals.append(pe.pseudo_Obs(x + np.random.normal(0.0, err), err, 'test1') + pe.pseudo_Obs(0, err / 100, 'test2', samples=87)) + lin_func = lambda a, x: a[0] + a[1] * x + with pytest.raises(Exception): + pe.least_squares(xvals, yvals, lin_func) + [o.gamma_method() for o in yvals]; + with pytest.raises(Exception): + pe.least_squares(xvals, yvals, lin_func, initial_guess=[5]) + + bad_guess = pe.least_squares(xvals, yvals, lin_func, initial_guess=[999, 999]) + good_guess = pe.least_squares(xvals, yvals, lin_func, initial_guess=[0, 1]) + assert np.isclose(bad_guess.chisquare, good_guess.chisquare, atol=1e-8) + assert np.all([(go - ba).is_zero(atol=1e-6) for (go, ba) in zip(good_guess, bad_guess)]) + + def test_total_least_squares(): dim = 10 + int(30 * np.random.rand()) x = np.arange(dim) + np.random.normal(0.0, 0.15, dim) @@ -223,7 +243,7 @@ def test_total_least_squares(): beta[i].gamma_method(S=1.0) assert math.isclose(beta[i].value, output.beta[i], rel_tol=1e-5) assert math.isclose(output.cov_beta[i, i], beta[i].dvalue ** 2, rel_tol=2.5e-1), str(output.cov_beta[i, i]) + ' ' + str(beta[i].dvalue ** 2) - assert math.isclose(pe.covariance([beta[0], beta[1]])[0, 1], output.cov_beta[0, 1], rel_tol=2.5e-1) + assert math.isclose(pe.covariance([beta[0], beta[1]])[0, 1], output.cov_beta[0, 1], rel_tol=3.5e-1) out = pe.total_least_squares(ox, oy, func, const_par=[beta[1]]) @@ -246,7 +266,7 @@ def test_total_least_squares(): betac[i].gamma_method(S=1.0) assert math.isclose(betac[i].value, output.beta[i], rel_tol=1e-3) assert math.isclose(output.cov_beta[i, i], betac[i].dvalue ** 2, rel_tol=2.5e-1), str(output.cov_beta[i, i]) + ' ' + str(betac[i].dvalue ** 2) - assert math.isclose(pe.covariance([betac[0], betac[1]])[0, 1], output.cov_beta[0, 1], rel_tol=2.5e-1) + assert math.isclose(pe.covariance([betac[0], betac[1]])[0, 1], output.cov_beta[0, 1], rel_tol=3.5e-1) outc = pe.total_least_squares(oxc, oyc, func, const_par=[betac[1]]) @@ -261,7 +281,7 @@ def test_total_least_squares(): betac[i].gamma_method(S=1.0) assert math.isclose(betac[i].value, output.beta[i], rel_tol=1e-3) assert math.isclose(output.cov_beta[i, i], betac[i].dvalue ** 2, rel_tol=2.5e-1), str(output.cov_beta[i, i]) + ' ' + str(betac[i].dvalue ** 2) - assert math.isclose(pe.covariance([betac[0], betac[1]])[0, 1], output.cov_beta[0, 1], rel_tol=2.5e-1) + assert math.isclose(pe.covariance([betac[0], betac[1]])[0, 1], output.cov_beta[0, 1], rel_tol=3.5e-1) outc = pe.total_least_squares(oxc, oy, func, const_par=[betac[1]]) From efd6d97d0a318c3e0ba92c0b6b40564b780dfb7d Mon Sep 17 00:00:00 2001 From: Fabian Joswig Date: Fri, 10 Jun 2022 10:21:28 +0100 Subject: [PATCH 5/5] docs: CHANGELOG updated, version number bumped to 2.1.2 --- CHANGELOG.md | 6 +++++- pyerrors/version.py | 2 +- setup.py | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 457b4e6f..b052e0bf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,10 +2,14 @@ All notable changes to this project will be documented in this file. +## [2.1.2] - 2022-06-10 +### Fixed +- Bug in `Corr.matrix_symmetric` fixed which appeared when a time slice contained an array with `None` entries. + ## [2.1.1] - 2022-06-06 ### Fixed - Bug in error propagation of correlated least square fits fixed. -- Fit_result.gamma_method can now be called with kwargs +- `Fit_result.gamma_method` can now be called with kwargs ## [2.1.0] - 2022-05-31 ### Added diff --git a/pyerrors/version.py b/pyerrors/version.py index 0d8c75f0..4eabd0b3 100644 --- a/pyerrors/version.py +++ b/pyerrors/version.py @@ -1 +1 @@ -__version__ = "2.2.0+dev" +__version__ = "2.1.2" diff --git a/setup.py b/setup.py index 9f3f5dfe..2e5ba4be 100644 --- a/setup.py +++ b/setup.py @@ -4,7 +4,7 @@ this_directory = Path(__file__).parent long_description = (this_directory / "README.md").read_text() setup(name='pyerrors', - version='2.2.0+dev', + version='2.1.2', description='Error analysis for lattice QCD', long_description=long_description, long_description_content_type='text/markdown',