mirror of
https://github.com/fjosw/pyerrors.git
synced 2025-05-15 20:13:41 +02:00
Merge branch 'develop' into documentation
This commit is contained in:
commit
75cc221421
5 changed files with 49 additions and 8 deletions
|
@ -2,10 +2,14 @@
|
||||||
|
|
||||||
All notable changes to this project will be documented in this file.
|
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
|
## [2.1.1] - 2022-06-06
|
||||||
### Fixed
|
### Fixed
|
||||||
- Bug in error propagation of correlated least square fits 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
|
## [2.1.0] - 2022-05-31
|
||||||
### Added
|
### Added
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
__version__ = "2.2.0+dev"
|
__version__ = "2.1.2"
|
||||||
|
|
6
setup.py
6
setup.py
|
@ -4,7 +4,7 @@ this_directory = Path(__file__).parent
|
||||||
long_description = (this_directory / "README.md").read_text()
|
long_description = (this_directory / "README.md").read_text()
|
||||||
|
|
||||||
setup(name='pyerrors',
|
setup(name='pyerrors',
|
||||||
version='2.2.0+dev',
|
version='2.1.2',
|
||||||
description='Error analysis for lattice QCD',
|
description='Error analysis for lattice QCD',
|
||||||
long_description=long_description,
|
long_description=long_description,
|
||||||
long_description_content_type='text/markdown',
|
long_description_content_type='text/markdown',
|
||||||
|
@ -18,7 +18,7 @@ setup(name='pyerrors',
|
||||||
license="MIT",
|
license="MIT",
|
||||||
packages=find_packages(),
|
packages=find_packages(),
|
||||||
python_requires='>=3.6.0',
|
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', 'h5py>=3', 'lxml>=4', 'python-rapidjson>=1'],
|
||||||
classifiers=[
|
classifiers=[
|
||||||
'Development Status :: 5 - Production/Stable',
|
'Development Status :: 5 - Production/Stable',
|
||||||
'Intended Audience :: Science/Research',
|
'Intended Audience :: Science/Research',
|
||||||
|
@ -28,6 +28,6 @@ setup(name='pyerrors',
|
||||||
'Programming Language :: Python :: 3.8',
|
'Programming Language :: Python :: 3.8',
|
||||||
'Programming Language :: Python :: 3.9',
|
'Programming Language :: Python :: 3.9',
|
||||||
'Programming Language :: Python :: 3.10',
|
'Programming Language :: Python :: 3.10',
|
||||||
'Topic :: Scientific/Engineering'
|
'Topic :: Scientific/Engineering :: Physics'
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
|
@ -184,6 +184,26 @@ def test_fit_corr_independent():
|
||||||
assert (out[1] - out_corr[1]).is_zero(atol=1e-5)
|
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():
|
def test_total_least_squares():
|
||||||
dim = 10 + int(30 * np.random.rand())
|
dim = 10 + int(30 * np.random.rand())
|
||||||
x = np.arange(dim) + np.random.normal(0.0, 0.15, dim)
|
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)
|
beta[i].gamma_method(S=1.0)
|
||||||
assert math.isclose(beta[i].value, output.beta[i], rel_tol=1e-5)
|
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(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]])
|
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)
|
betac[i].gamma_method(S=1.0)
|
||||||
assert math.isclose(betac[i].value, output.beta[i], rel_tol=1e-3)
|
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(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]])
|
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)
|
betac[i].gamma_method(S=1.0)
|
||||||
assert math.isclose(betac[i].value, output.beta[i], rel_tol=1e-3)
|
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(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]])
|
outc = pe.total_least_squares(oxc, oy, func, const_par=[betac[1]])
|
||||||
|
|
||||||
|
|
|
@ -736,6 +736,23 @@ def test_covariance_factorizing():
|
||||||
assert np.isclose(pe.covariance([mt0, tt[1]])[0, 1], -pe.covariance(tt)[0, 1])
|
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():
|
def test_covariance_alternation():
|
||||||
length = 12
|
length = 12
|
||||||
t_fac = 2.5
|
t_fac = 2.5
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue