statsmodels.tools.numdiff.approx_fprime

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

Gradient of function, or Jacobian if function f returns 1d array

Parameters:
xndarray

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. This is EPS**(1/2)*x for centered == False and EPS**(1/3)*x for centered == True.

argstuple

Tuple of additional arguments for function f.

kwargsdict

Dictionary of additional keyword arguments for function f.

centeredbool

Whether central difference should be returned. If not, does forward differencing.

Returns:
gradndarray

gradient or Jacobian

Notes

If f returns a 1d array, it returns a Jacobian. If a 2d array is returned by f (e.g., with a value for each observation), it returns a 3d array with the Jacobian of each observation with shape xk x nobs x xk. I.e., the Jacobian of the first observation would be [:, 0, :]


Last update: Nov 14, 2024