Skip to main content

check_gradient

Function check_gradient 

Source
pub fn check_gradient<T, F>(
    f: &F,
    analytical_grad: &ArrayView1<'_, T>,
    x: &[T],
    h: T,
    tolerance: T,
) -> CoreResult<GradientCheckResult<T>>
where T: Float + FromPrimitive + Debug + Display, F: Fn(&[T]) -> T,
Expand description

Check an analytical gradient against a numerical gradient.

  • f – scalar function R^n -> R.
  • analytical_grad – the gradient your code computes at x.
  • x – the point at which the gradient was computed.
  • h – finite difference step size (e.g. 1e-5).
  • tolerance – maximum allowed relative error per component.

Returns a GradientCheckResult with element-wise details.