Merge branch 'develop' into documentation

This commit is contained in:
fjosw 2022-06-24 11:51:32 +00:00
commit c6bee16919
5 changed files with 52 additions and 13 deletions

View file

@ -2,6 +2,15 @@
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
### Fixed
- Further bugs in connection with correlator objects which have arrays with None entries as content fixed.

View file

@ -177,13 +177,15 @@ def total_least_squares(x, y, func, silent=False, **kwargs):
if not callable(func):
raise TypeError('func has to be a function.')
for i in range(25):
for i in range(42):
try:
func(np.arange(i), x.T[0])
except Exception:
pass
continue
else:
break
else:
raise RuntimeError("Fit function is not valid.")
n_parms = i
if not silent:
@ -321,9 +323,11 @@ def _prior_fit(x, y, func, priors, silent=False, **kwargs):
try:
func(np.arange(i), 0)
except Exception:
pass
continue
else:
break
else:
raise RuntimeError("Fit function is not valid.")
n_parms = i
@ -442,13 +446,15 @@ def _standard_fit(x, y, func, silent=False, **kwargs):
if not callable(func):
raise TypeError('func has to be a function.')
for i in range(25):
for i in range(42):
try:
func(np.arange(i), x.T[0])
except Exception:
pass
continue
else:
break
else:
raise RuntimeError("Fit function is not valid.")
n_parms = i

View file

@ -249,9 +249,9 @@ def test_matrix_corr():
def test_corr_none_entries():
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]])
x = [l, n]
x = [la, n]
matr = pe.Corr(x)
matr.projected(np.asarray([1.0, 0.0]))

View file

@ -194,7 +194,7 @@ def test_linear_fit_guesses():
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];
[o.gamma_method() for o in yvals]
with pytest.raises(Exception):
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]):
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
fr = pe.least_squares(np.arange(1, 4), dat, func)
fr.gamma_method(S=0)
@ -448,8 +448,7 @@ def test_correlated_fit_vs_jackknife():
x_val = np.arange(1, 6, 2)
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)
[o.gamma_method(S=0) for o in dat];
dat
[o.gamma_method(S=0) for o in dat]
func = lambda a, x: a[0] * x + a[1] * x ** 2
fr = pe.least_squares(x_val, dat, func, correlated_fit=True, silent=True)
[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)
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():
obs1 = pe.pseudo_Obs(1.0, 0.1, 'test')
with pytest.raises(Exception):

View file

@ -258,8 +258,8 @@ def test_complex_matrix_inverse():
inverse_matrix = np.linalg.inv(matrix)
inverse_obs_matrix = pe.linalg.inv(obs_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].imag, inverse_obs_matrix[n, m].imag.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)
def test_matrix_functions():