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:¶
- x : ndarray¶
parameters at which the derivative is evaluated
- f : function¶
f(*((x,)+args), **kwargs) returning either one value or 1d array
- epsilon : float, 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.
- args : tuple¶
Tuple of additional arguments for function f.
- kwargs : dict¶
Dictionary of additional keyword arguments for function f.
- centered : bool¶
Whether central difference should be returned. If not, does forward differencing.
- Returns:¶
grad – gradient or Jacobian
- Return type:¶
ndarray
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, :]