smmargins.utils._central_jacobian¶
- smmargins.utils._central_jacobian(func: Callable[[ndarray], ndarray], x: ndarray, rel_step: float | None = None) ndarray¶
Jacobian of
funcatxvia central differences.This is a numerical-analysis primitive used throughout the module whenever an analytic derivative is unavailable.
- Parameters:
func (callable) – Maps a length-
pvector to a scalar or length-mvector.x (ndarray of shape (p,)) – Point at which to evaluate the Jacobian.
rel_step (float, optional) – Relative step size. Default is \(\epsilon^{1/3}\), the truncation-vs-rounding sweet spot for central differences.
- Returns:
The Jacobian matrix \(J_{ij} = \partial f_i / \partial x_j\).
- Return type:
ndarray of shape (m, p)
Notes
Uses the central-difference formula
\[\frac{\partial f}{\partial x_j} \approx \frac{f(x + h e_j) - f(x - h e_j)}{2 h_j},\]where \(h_j = \text{rel\_step} \cdot \max(|x_j|, 1)\) and \(e_j\) is the j-th unit vector. The truncation error is \(O(h^2)\) and the round-off error is \(O(\epsilon / h)\); choosing \(h \sim \epsilon^{1/3}\) balances the two.
References
Nocedal, J. and Wright, S. J. (2006). Numerical Optimization, 2nd ed., Springer. Chapter 8 (Calculating Derivatives).