fix: fits and root now work when the value of the zeroth input is

exactly zero. Tests extended.
This commit is contained in:
Fabian Joswig 2021-12-07 18:40:36 +00:00
parent 968cdf3181
commit 9ddadaf6b3
3 changed files with 33 additions and 4 deletions

View file

@ -1,3 +1,4 @@
import numpy as np
import scipy.optimize
from autograd import jacobian
from .obs import derived_observable
@ -33,5 +34,5 @@ def find_root(d, func, guess=1.0, **kwargs):
da = jacobian(lambda u, v: func(v, u))(d.value, root[0])
deriv = - da / dx
res = derived_observable(lambda x, **kwargs: x[0] / d.value * root[0], [d], man_grad=[deriv])
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])
return res