approx_derivative#
- cuqi.utilities.approx_derivative(func, wrt, direction=None, epsilon=1.4901161193847656e-08)#
Approximates the derivative of callable (possibly vector-valued) function func evaluated at point wrt. If direction is provided, the direction-Jacobian product will be computed and returned, otherwise, the Jacobian matrix (or the gradient in case of a scalar function func) will be returned. The approximation is done using forward differences.
- Parameters:
func (function handler) – A vector-valued function of the form func(x).
wrt (ndarray) – The point at which the derivative to be evaluated.
direction (ndarray) – The direction used to compute direction-Jacobian product. If None, the Jacobian matrix is returned.
epsilon (float) – The spacing in the finite difference approximation.
- Returns:
The approximate Jacobian matrix.
- Return type:
ndarray