statsmodels.tools.numdiff.approx_fprime_cs

statsmodels.tools.numdiff.approx_fprime_cs(x, f, epsilon=None, args=(), kwargs={})[source]

Calculate gradient or Jacobian with complex step derivative approximation

Parameters
xarray

parameters at which the derivative is evaluated

ffunction

f(*((x,)+args), **kwargs) returning either one value or 1d array

epsilonfloat, optional

Stepsize, if None, optimal stepsize is used. Optimal step-size is EPS*x. See note.

argstuple

Tuple of additional arguments for function f.

kwargsdict

Dictionary of additional keyword arguments for function f.

Returns
partialsndarray

array of partial derivatives, Gradient or Jacobian

Notes

The complex-step derivative has truncation error O(epsilon**2), so truncation error can be eliminated by choosing epsilon to be very small. The complex-step derivative avoids the problem of round-off error with small epsilon because there is no subtraction.