Skip to main content

numerical_gradient_central_diff

Function numerical_gradient_central_diff 

Source
pub fn numerical_gradient_central_diff<F>(
    f: F,
    x: &Array1<f64>,
    eps: f64,
) -> Array1<f64>
where F: FnMut(&Array1<f64>) -> f64,
Expand description

Central finite-difference gradient of a scalar objective at x.

For each coordinate i, returns (f(x + eps·eᵢ) − f(x − eps·eᵢ)) / (2·eps). f is evaluated 2·len(x) times. The input slice is never mutated (each evaluation operates on a fresh clone), so f may borrow x’s surroundings freely.