hessian

Function hessian 

Source
pub fn hessian<G, T: DualNum<F>, F: DualNumFloat, D: Dim, O: Mappable<Dual2Vec<T, F, D>>>(
    g: G,
    x: &OVector<T, D>,
) -> O::Output<(T, OVector<T, D>, OMatrix<T, D, D>)>
where G: Fn(OVector<Dual2Vec<T, F, D>, D>) -> O, DefaultAllocator: Allocator<D> + Allocator<U1, D> + Allocator<D, D>,
Expand description

Calculate the Hessian of a scalar function.

let v = SVector::from([4.0, 3.0]);
let fun = |v: SVector<Dual2SVec64<2>, 2>| (v[0].powi(2) + v[1].powi(2)).sqrt();
let (f, g, h) = hessian(fun, &v);
assert_eq!(f, 5.0);
assert_relative_eq!(g[0], 0.8);
assert_relative_eq!(g[1], 0.6);
assert_relative_eq!(h[(0,0)], 0.072);
assert_relative_eq!(h[(0,1)], -0.096);
assert_relative_eq!(h[(1,0)], -0.096);
assert_relative_eq!(h[(1,1)], 0.128);