fix: root module now also works with irregular monte carlo chains

This commit is contained in:
Fabian Joswig 2021-11-26 12:24:38 +00:00
parent f808c2243e
commit b2a249302a
2 changed files with 16 additions and 2 deletions

View file

@ -1,6 +1,6 @@
import scipy.optimize
from autograd import jacobian
from .obs import derived_observable, pseudo_Obs
from .obs import derived_observable
def find_root(d, func, guess=1.0, **kwargs):
@ -33,4 +33,6 @@ def find_root(d, func, guess=1.0, **kwargs):
da = jacobian(lambda u, v: func(v, u))(d.value, root[0])
deriv = - da / dx
return derived_observable(lambda x, **kwargs: x[0], [pseudo_Obs(root, 0.0, d.names[0], d.shape[d.names[0]]), d], man_grad=[0, deriv])
res = derived_observable(lambda x, **kwargs: x[0], [d], man_grad=[deriv])
res._value = root[0]
return res

View file

@ -17,3 +17,15 @@ def test_root_linear():
assert np.isclose(my_root.value, value)
difference = my_obs - my_root
assert difference.is_zero()
def test_root_linear_idl():
def root_function(x, d):
return x - d
my_obs = pe.Obs([np.random.rand(50)], ['t'], idl=[range(20, 120, 2)])
my_root = pe.roots.find_root(my_obs, root_function)
difference = my_obs - my_root
assert difference.is_zero()