WallGo.helpers.hessian

hessian(f, x, order=4, epsilon=1e-16, scale=1.0, dx=None, xAxis=None, yAxis=None, args=None)[source]

Computes the hessian of a callable function. Uses the epsilon and scale parameters to estimate the optimal value of dx, if the latter is not provided.

Parameters:
  • f (function) – Function to differentiate. Should take an array as argument and return an array.

  • x (array-like) – The position at which to evaluate the derivative. The size of the last axis must correspond to the number of variables on which f depends.

  • order (int, optional) – The accuracy order of the scheme. Errors are of order \(\mathcal{O}({\rm d}x^{\text{order}/(\text{order}+2)})\). Can be 2 or 4. The default is 4.

  • epsilon (float, optional) – Fractional accuracy at which f can be evaluated. If f is a simple function, should be close to the machine precision. Default is 1e-16.

  • scale (float, optional) – Typical scale at which f(x) change by order 1. Default is 1.

  • dx (float or None, optional) – The magnitude of finite differences. If None, use epsilon and scale to estimate the optimal dx. Default is None.

  • xAxis (list, int or None, optional) – Lines of the hessian matrix to return. If None, returns all the lines. Default is None.

  • yAxis (list, int or None, optional) – Columns of the hessian matrix to return. If None, returns all the columns. Default is None.

  • args (list, optional) – List of other fixed arguments passed to the function \(f\).

Returns:

res – The value of the hessian of f evaluated at x.

Return type:

float