Skip to main content

finite_diff_gradient

Function finite_diff_gradient 

Source
pub fn finite_diff_gradient<S: Scalar>(
    f: &dyn Fn(&[S]) -> S,
    x: &[S],
    g: &mut [S],
)
Expand description

Compute a finite-difference gradient using the canonical central FD step cbrt(S::EPSILON) * (1 + |x|), which scales with |x| to remain valid for large-magnitude parameters. The additive scaling prevents silent zero-gradient failures that occur when an unscaled step falls below the precision floor of x + h == x (manifesting for |x| > ~5e7 at f64 precision).