From a45e20b51c9f06319acbf0400f91a338ea65d24c Mon Sep 17 00:00:00 2001 From: Fabian Joswig Date: Tue, 10 Jan 2023 10:28:12 +0000 Subject: [PATCH] feat: multi parameter root feature added. --- pyerrors/roots.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/pyerrors/roots.py b/pyerrors/roots.py index 5f6134b5..334157a7 100644 --- a/pyerrors/roots.py +++ b/pyerrors/roots.py @@ -27,15 +27,17 @@ def find_root(d, func, guess=1.0, **kwargs): Obs `Obs` valued root of the function. ''' - root = scipy.optimize.fsolve(func, guess, d.value) + d_val = np.vectorize(lambda x: x.value)(np.array(d)) + + root = scipy.optimize.fsolve(func, guess, d_val) # Error propagation as detailed in arXiv:1809.01289 - dx = jacobian(func)(root[0], d.value) + dx = jacobian(func)(root[0], d_val) try: - da = jacobian(lambda u, v: func(v, u))(d.value, root[0]) + da = jacobian(lambda u, v: func(v, u))(d_val, root[0]) except TypeError: raise Exception("It is required to use autograd.numpy instead of numpy within root functions, see the documentation for details.") from None deriv = - da / dx - - res = derived_observable(lambda x, **kwargs: (x[0] + np.finfo(np.float64).eps) / (d.value + np.finfo(np.float64).eps) * root[0], [d], man_grad=[deriv]) + res = derived_observable(lambda x, **kwargs: (x[0] + np.finfo(np.float64).eps) / (np.array(d).reshape(-1)[0].value + np.finfo(np.float64).eps) * root[0], + np.array(d).reshape(-1), man_grad=np.array(deriv).reshape(-1)) return res