From e4d18fc8c8af09e40c510a30a024a4d011566ae3 Mon Sep 17 00:00:00 2001 From: Fabian Joswig Date: Thu, 6 Oct 2022 18:09:37 +0100 Subject: [PATCH] tests: num_grad test for total least squares added. --- tests/fits_test.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/tests/fits_test.py b/tests/fits_test.py index 698acd26..4018abb8 100644 --- a/tests/fits_test.py +++ b/tests/fits_test.py @@ -83,7 +83,7 @@ def test_least_squares(): assert math.isclose(pcov[i, i], betac[i].dvalue ** 2, abs_tol=1e-3) -def test_fit_num_grad(): +def test_least_squares_num_grad(): x = [] y = [] for i in range(2, 5): @@ -97,6 +97,20 @@ def test_fit_num_grad(): assert(num[1] == auto[1]) +def test_total_least_squares_num_grad(): + x = [] + y = [] + for i in range(2, 5): + x.append(pe.pseudo_Obs(i * 0.01, 0.0001, "ens")) + y.append(pe.pseudo_Obs(i * 0.01, 0.0001, "ens")) + + num = pe.fits.total_least_squares(x, y, lambda a, x: np.exp(a[0] * x) + a[1], num_grad=True) + auto = pe.fits.total_least_squares(x, y, lambda a, x: anp.exp(a[0] * x) + a[1], num_grad=False) + + assert(num[0] == auto[0]) + assert(num[1] == auto[1]) + + def test_alternative_solvers(): dim = 92 x = np.arange(dim)