diff --git a/pyerrors/fits.py b/pyerrors/fits.py index 1ea2f827..16fb5405 100644 --- a/pyerrors/fits.py +++ b/pyerrors/fits.py @@ -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) 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 @@ -585,7 +589,7 @@ def _standard_fit(x, y, func, silent=False, **kwargs): output.fit_parameters = result - output.chisquare = chisqfunc(fit_result.x) + output.chisquare = chisquare output.dof = x.shape[-1] - n_parms output.p_value = 1 - chi2.cdf(output.chisquare, output.dof) diff --git a/tests/fits_test.py b/tests/fits_test.py index 88b8438a..a288f547 100644 --- a/tests/fits_test.py +++ b/tests/fits_test.py @@ -149,8 +149,10 @@ def test_correlated_fit(): return p[1] * anp.exp(-p[0] * x) 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) + assert np.isclose(fitpc.chisquare / fitpc.dof, fitpc.chisquare_by_dof, atol=1e-14) for i in range(2): diff = fitp[i] - fitpc[i] 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) 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[1] - out_corr[1]).is_zero(atol=1e-5)