def create_derivatives(func1, params): num_hessian_diag = numerical_hessian(func1, params=params, hessian='diag') num_hessian = numerical_hessian(func1, params=params) tf_hessian_diag = autodiff_hessian(func1, params=params, hessian='diag') tf_hessian = autodiff_hessian(func1, params=params) return num_hessian, num_hessian_diag, tf_hessian, tf_hessian_diag
def test_numerical_hessian(): param1 = zfit.Parameter('param1', 4.) param2 = zfit.Parameter('param2', 5.) param3 = zfit.Parameter('param3', 2.) def func1(): return param1 * param2 ** 2 + param3 ** param1 num_hessian = numerical_hessian(func1, params=[param1, param2, param3]) tf_hessian = autodiff_hessian(func1, params=[param1, param2, param3]) np.testing.assert_allclose(num_hessian, tf_hessian, rtol=1e-5, atol=1e-10)