mirror of
https://github.com/fjosw/pyerrors.git
synced 2025-05-16 20:43:41 +02:00
Merge branch 'develop' into documentation
This commit is contained in:
commit
c6bee16919
5 changed files with 52 additions and 13 deletions
|
@ -2,6 +2,15 @@
|
||||||
|
|
||||||
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.x.x] - 2022-xx-xx
|
||||||
|
### Added
|
||||||
|
- `Obs.reweight` method added in analogy to `Corr.reweight` which allows for a more convenient reweighting of individual observables.
|
||||||
|
- `Corr.show` now has the additional argument `title` which allows to add a title to the figure. Figures are now saved with `bbox_inches='tight'`.
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- `Corr.m_eff` can now deal with correlator entries which are exactly zero.
|
||||||
|
- Minor bugs in `input.dobs` fixed.
|
||||||
|
|
||||||
## [2.1.3] - 2022-06-13
|
## [2.1.3] - 2022-06-13
|
||||||
### Fixed
|
### Fixed
|
||||||
- Further bugs in connection with correlator objects which have arrays with None entries as content fixed.
|
- Further bugs in connection with correlator objects which have arrays with None entries as content fixed.
|
||||||
|
|
|
@ -177,13 +177,15 @@ def total_least_squares(x, y, func, silent=False, **kwargs):
|
||||||
if not callable(func):
|
if not callable(func):
|
||||||
raise TypeError('func has to be a function.')
|
raise TypeError('func has to be a function.')
|
||||||
|
|
||||||
for i in range(25):
|
for i in range(42):
|
||||||
try:
|
try:
|
||||||
func(np.arange(i), x.T[0])
|
func(np.arange(i), x.T[0])
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
continue
|
||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
|
else:
|
||||||
|
raise RuntimeError("Fit function is not valid.")
|
||||||
|
|
||||||
n_parms = i
|
n_parms = i
|
||||||
if not silent:
|
if not silent:
|
||||||
|
@ -321,9 +323,11 @@ def _prior_fit(x, y, func, priors, silent=False, **kwargs):
|
||||||
try:
|
try:
|
||||||
func(np.arange(i), 0)
|
func(np.arange(i), 0)
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
continue
|
||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
|
else:
|
||||||
|
raise RuntimeError("Fit function is not valid.")
|
||||||
|
|
||||||
n_parms = i
|
n_parms = i
|
||||||
|
|
||||||
|
@ -442,13 +446,15 @@ def _standard_fit(x, y, func, silent=False, **kwargs):
|
||||||
if not callable(func):
|
if not callable(func):
|
||||||
raise TypeError('func has to be a function.')
|
raise TypeError('func has to be a function.')
|
||||||
|
|
||||||
for i in range(25):
|
for i in range(42):
|
||||||
try:
|
try:
|
||||||
func(np.arange(i), x.T[0])
|
func(np.arange(i), x.T[0])
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
continue
|
||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
|
else:
|
||||||
|
raise RuntimeError("Fit function is not valid.")
|
||||||
|
|
||||||
n_parms = i
|
n_parms = i
|
||||||
|
|
||||||
|
|
|
@ -249,9 +249,9 @@ def test_matrix_corr():
|
||||||
|
|
||||||
def test_corr_none_entries():
|
def test_corr_none_entries():
|
||||||
a = pe.pseudo_Obs(1.0, 0.1, 'a')
|
a = pe.pseudo_Obs(1.0, 0.1, 'a')
|
||||||
l = np.asarray([[a, a], [a, a]])
|
la = np.asarray([[a, a], [a, a]])
|
||||||
n = np.asarray([[None, None], [None, None]])
|
n = np.asarray([[None, None], [None, None]])
|
||||||
x = [l, n]
|
x = [la, n]
|
||||||
matr = pe.Corr(x)
|
matr = pe.Corr(x)
|
||||||
matr.projected(np.asarray([1.0, 0.0]))
|
matr.projected(np.asarray([1.0, 0.0]))
|
||||||
|
|
||||||
|
|
|
@ -194,7 +194,7 @@ def test_linear_fit_guesses():
|
||||||
lin_func = lambda a, x: a[0] + a[1] * x
|
lin_func = lambda a, x: a[0] + a[1] * x
|
||||||
with pytest.raises(Exception):
|
with pytest.raises(Exception):
|
||||||
pe.least_squares(xvals, yvals, lin_func)
|
pe.least_squares(xvals, yvals, lin_func)
|
||||||
[o.gamma_method() for o in yvals];
|
[o.gamma_method() for o in yvals]
|
||||||
with pytest.raises(Exception):
|
with pytest.raises(Exception):
|
||||||
pe.least_squares(xvals, yvals, lin_func, initial_guess=[5])
|
pe.least_squares(xvals, yvals, lin_func, initial_guess=[5])
|
||||||
|
|
||||||
|
@ -414,7 +414,7 @@ def test_fit_vs_jackknife():
|
||||||
|
|
||||||
for i, cov in enumerate([cov1, cov2, cov3]):
|
for i, cov in enumerate([cov1, cov2, cov3]):
|
||||||
dat = pe.misc.gen_correlated_data(np.arange(1, 4), cov, 'test', 0.5, samples=samples)
|
dat = pe.misc.gen_correlated_data(np.arange(1, 4), cov, 'test', 0.5, samples=samples)
|
||||||
[o.gamma_method(S=0) for o in dat];
|
[o.gamma_method(S=0) for o in dat]
|
||||||
func = lambda a, x: a[0] + a[1] * x
|
func = lambda a, x: a[0] + a[1] * x
|
||||||
fr = pe.least_squares(np.arange(1, 4), dat, func)
|
fr = pe.least_squares(np.arange(1, 4), dat, func)
|
||||||
fr.gamma_method(S=0)
|
fr.gamma_method(S=0)
|
||||||
|
@ -448,8 +448,7 @@ def test_correlated_fit_vs_jackknife():
|
||||||
x_val = np.arange(1, 6, 2)
|
x_val = np.arange(1, 6, 2)
|
||||||
for i, cov in enumerate([cov1, cov2, cov3]):
|
for i, cov in enumerate([cov1, cov2, cov3]):
|
||||||
dat = pe.misc.gen_correlated_data(x_val + x_val ** 2 + np.random.normal(0.0, 0.1, 3), cov, 'test', 0.5, samples=samples)
|
dat = pe.misc.gen_correlated_data(x_val + x_val ** 2 + np.random.normal(0.0, 0.1, 3), cov, 'test', 0.5, samples=samples)
|
||||||
[o.gamma_method(S=0) for o in dat];
|
[o.gamma_method(S=0) for o in dat]
|
||||||
dat
|
|
||||||
func = lambda a, x: a[0] * x + a[1] * x ** 2
|
func = lambda a, x: a[0] * x + a[1] * x ** 2
|
||||||
fr = pe.least_squares(x_val, dat, func, correlated_fit=True, silent=True)
|
fr = pe.least_squares(x_val, dat, func, correlated_fit=True, silent=True)
|
||||||
[o.gamma_method(S=0) for o in fr]
|
[o.gamma_method(S=0) for o in fr]
|
||||||
|
@ -496,6 +495,31 @@ def test_fit_no_autograd():
|
||||||
pe.total_least_squares(oy, oy, func)
|
pe.total_least_squares(oy, oy, func)
|
||||||
|
|
||||||
|
|
||||||
|
def test_invalid_fit_function():
|
||||||
|
def func1(a, x):
|
||||||
|
return a[0] + a[1] * x + a[2] * anp.sinh(x) + a[199]
|
||||||
|
|
||||||
|
def func2(a, x, y):
|
||||||
|
return a[0] + a[1] * x
|
||||||
|
|
||||||
|
def func3(x):
|
||||||
|
return x
|
||||||
|
|
||||||
|
xvals =[]
|
||||||
|
yvals =[]
|
||||||
|
err = 0.1
|
||||||
|
|
||||||
|
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))
|
||||||
|
[o.gamma_method() for o in yvals]
|
||||||
|
for func in [func1, func2, func3]:
|
||||||
|
with pytest.raises(Exception):
|
||||||
|
pe.least_squares(xvals, yvals, func)
|
||||||
|
with pytest.raises(Exception):
|
||||||
|
pe.total_least_squares(yvals, yvals, func)
|
||||||
|
|
||||||
|
|
||||||
def test_singular_correlated_fit():
|
def test_singular_correlated_fit():
|
||||||
obs1 = pe.pseudo_Obs(1.0, 0.1, 'test')
|
obs1 = pe.pseudo_Obs(1.0, 0.1, 'test')
|
||||||
with pytest.raises(Exception):
|
with pytest.raises(Exception):
|
||||||
|
|
|
@ -258,8 +258,8 @@ def test_complex_matrix_inverse():
|
||||||
inverse_matrix = np.linalg.inv(matrix)
|
inverse_matrix = np.linalg.inv(matrix)
|
||||||
inverse_obs_matrix = pe.linalg.inv(obs_matrix)
|
inverse_obs_matrix = pe.linalg.inv(obs_matrix)
|
||||||
for (n, m), entry in np.ndenumerate(inverse_matrix):
|
for (n, m), entry in np.ndenumerate(inverse_matrix):
|
||||||
assert np.isclose(inverse_matrix[n, m].real, inverse_obs_matrix[n, m].real.value)
|
assert np.isclose(inverse_matrix[n, m].real, inverse_obs_matrix[n, m].real.value)
|
||||||
assert np.isclose(inverse_matrix[n, m].imag, inverse_obs_matrix[n, m].imag.value)
|
assert np.isclose(inverse_matrix[n, m].imag, inverse_obs_matrix[n, m].imag.value)
|
||||||
|
|
||||||
|
|
||||||
def test_matrix_functions():
|
def test_matrix_functions():
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue