Numerical Derivatives, Gradients and Jacobians
| This documentation was generated with the assistance of AI. Please report any inaccuracies. |
Many algorithms in the library (Levenberg-Marquardt fitting, conjugate-gradient and quasi-Newton optimization)
need derivatives of functions that are only available as black boxes. The estimators described here
approximate them numerically with finite differences. They live in the com.irurueta.numerical package.
Estimators
| Class | Purpose |
|---|---|
|
Forward-difference derivative of a scalar function ( |
|
Symmetric (central) difference derivative of a scalar function. Extends |
|
Derivative of a scalar function using a Savitzky-Golay style fit. Extends |
|
Forward-difference gradient of a multivariate scalar function ( |
|
Symmetric and Savitzky-Golay variants of the gradient. Extend |
|
Jacobian matrix of a vector-valued function ( |
Step rule
Each parameter is perturbed by a step computed from two settings:
The step is then corrected to the value that was actually applied in floating point (h = (x + h) - x), which
reduces finite-precision error.
| Setting | Default | Constraint |
|---|---|---|
|
|
Must be greater than |
|
|
Must be greater than or equal to |
With the defaults the behavior is identical to previous versions: h = EPS * |x|, falling back to EPS when
is exactly zero.
Usage
var estimator = new SymmetricDerivativeEstimator(x -> Math.exp(x));
// or set the step settings when constructing
var jacobianEstimator = new JacobianEstimator(listener, 1e-7, 1e-7);
// or afterwards
var gradientEstimator = new GradientEstimator(point -> point[0] * point[1]);
gradientEstimator.setRelativeStep(1e-7);
gradientEstimator.setMinStep(1e-7);
var gradient = gradientEstimator.gradient(new double[]{1e-9, 2.0});
All estimators expose getRelativeStep(), setRelativeStep(double), getMinStep() and
setMinStep(double), and a constructor taking (listener, relativeStep, minStep).
When to set a minimum step
With the default minStep = 0.0, the step is proportional to . For parameters that are small but not
zero (for example 1e-5 to 1e-10) the step collapses (e.g. 1e-18) and the difference quotient loses
precision; the step is also discontinuous at zero. Setting a minimum step avoids this. For instance
relativeStep = minStep = 1e-7 yields .
An absolute minimum step assumes the parameters are scaled to order 1. If parameters have very
different magnitudes, rescale them rather than using a large minStep.
|