Skip to main content

numerical_gradient

Function numerical_gradient 

Source
pub fn numerical_gradient<T, F>(
    f: &F,
    x: &[T],
    h: T,
    mode: DifferenceMode,
) -> CoreResult<Array1<T>>
where T: Float + FromPrimitive + Debug, F: Fn(&[T]) -> T,
Expand description

Compute the numerical gradient of a scalar function at point x.

  • f – function from R^n -> R, taking a slice and returning a scalar.
  • x – the point at which to evaluate the gradient.
  • h – step size (e.g. 1e-5).
  • mode – finite difference mode.

Returns an Array1<T> of the same length as x.