mirror of
https://github.com/fjosw/pyerrors.git
synced 2025-03-15 14:50:25 +01:00
fix: bug in estimation of chisquare for correlated fit fixed, tests
added.
This commit is contained in:
parent
ff5540d667
commit
e7f5961cd6
2 changed files with 9 additions and 1 deletions
|
@ -525,6 +525,10 @@ def _standard_fit(x, y, func, silent=False, **kwargs):
|
||||||
fit_result = scipy.optimize.least_squares(chisqfunc_residuals_corr, fit_result.x, method='lm', ftol=1e-15, gtol=1e-15, xtol=1e-15)
|
fit_result = scipy.optimize.least_squares(chisqfunc_residuals_corr, fit_result.x, method='lm', ftol=1e-15, gtol=1e-15, xtol=1e-15)
|
||||||
|
|
||||||
chisquare = np.sum(fit_result.fun ** 2)
|
chisquare = np.sum(fit_result.fun ** 2)
|
||||||
|
if kwargs.get('correlated_fit') is True:
|
||||||
|
assert np.isclose(chisquare, chisqfunc_corr(fit_result.x), atol=1e-14)
|
||||||
|
else:
|
||||||
|
assert np.isclose(chisquare, chisqfunc(fit_result.x), atol=1e-14)
|
||||||
|
|
||||||
output.iterations = fit_result.nfev
|
output.iterations = fit_result.nfev
|
||||||
|
|
||||||
|
@ -585,7 +589,7 @@ def _standard_fit(x, y, func, silent=False, **kwargs):
|
||||||
|
|
||||||
output.fit_parameters = result
|
output.fit_parameters = result
|
||||||
|
|
||||||
output.chisquare = chisqfunc(fit_result.x)
|
output.chisquare = chisquare
|
||||||
output.dof = x.shape[-1] - n_parms
|
output.dof = x.shape[-1] - n_parms
|
||||||
output.p_value = 1 - chi2.cdf(output.chisquare, output.dof)
|
output.p_value = 1 - chi2.cdf(output.chisquare, output.dof)
|
||||||
|
|
||||||
|
|
|
@ -149,8 +149,10 @@ def test_correlated_fit():
|
||||||
return p[1] * anp.exp(-p[0] * x)
|
return p[1] * anp.exp(-p[0] * x)
|
||||||
|
|
||||||
fitp = pe.least_squares(x, data, fitf, expected_chisquare=True)
|
fitp = pe.least_squares(x, data, fitf, expected_chisquare=True)
|
||||||
|
assert np.isclose(fitp.chisquare / fitp.dof, fitp.chisquare_by_dof, atol=1e-14)
|
||||||
|
|
||||||
fitpc = pe.least_squares(x, data, fitf, correlated_fit=True)
|
fitpc = pe.least_squares(x, data, fitf, correlated_fit=True)
|
||||||
|
assert np.isclose(fitpc.chisquare / fitpc.dof, fitpc.chisquare_by_dof, atol=1e-14)
|
||||||
for i in range(2):
|
for i in range(2):
|
||||||
diff = fitp[i] - fitpc[i]
|
diff = fitp[i] - fitpc[i]
|
||||||
diff.gamma_method()
|
diff.gamma_method()
|
||||||
|
@ -176,6 +178,8 @@ def test_fit_corr_independent():
|
||||||
out_corr = pe.least_squares(x, oy, func, correlated_fit=True, method=method)
|
out_corr = pe.least_squares(x, oy, func, correlated_fit=True, method=method)
|
||||||
|
|
||||||
assert np.isclose(out.chisquare, out_corr.chisquare)
|
assert np.isclose(out.chisquare, out_corr.chisquare)
|
||||||
|
assert np.isclose(out.dof, out_corr.dof)
|
||||||
|
assert np.isclose(out.chisquare_by_dof, out_corr.chisquare_by_dof)
|
||||||
assert (out[0] - out_corr[0]).is_zero(atol=1e-5)
|
assert (out[0] - out_corr[0]).is_zero(atol=1e-5)
|
||||||
assert (out[1] - out_corr[1]).is_zero(atol=1e-5)
|
assert (out[1] - out_corr[1]).is_zero(atol=1e-5)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue