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

DerivativeEstimator

Forward-difference derivative of a scalar function (SingleDimensionFunctionEvaluatorListener).

SymmetricDerivativeEstimator

Symmetric (central) difference derivative of a scalar function. Extends DerivativeEstimator.

SavitzkyGolayDerivativeEstimator

Derivative of a scalar function using a Savitzky-Golay style fit. Extends DerivativeEstimator.

GradientEstimator

Forward-difference gradient of a multivariate scalar function (MultiDimensionFunctionEvaluatorListener).

SymmetricGradientEstimator, SavitzkyGolayGradientEstimator

Symmetric and Savitzky-Golay variants of the gradient. Extend GradientEstimator.

JacobianEstimator

Jacobian matrix of a vector-valued function (MultiVariateFunctionEvaluatorListener).

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

relativeStep

EPS (1e-8)

Must be greater than 0, otherwise IllegalArgumentException.

minStep

0.0

Must be greater than or equal to 0 (NaN rejected), otherwise IllegalArgumentException.

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.