[][src]Function levenberg_marquardt::differentiate_holomorphic_numerically

pub fn differentiate_holomorphic_numerically<F, N, M, O>(
    problem: &mut O
) -> Option<MatrixMN<F, M, N>> where
    F: RealField,
    N: Dim,
    M: Dim,
    O: LeastSquaresProblem<Complex<F>, M, N>,
    DefaultAllocator: Allocator<Complex<F>, N, Buffer = O::ParameterStorage> + Allocator<F, N> + Allocator<F, M, N>, 

Compute a numerical approximation of the Jacobian for holomorphic residuals.

This method is much more precise than differentiate_numerically but it requires that your residuals are holomorphic on a neighborhood of the real line. You also must provide an implementation of LeastSquaresProblem for complex numbers.

This method is mainly intended for testing your derivative implementation.

Panics

The function panics if the parameters which are set when the function is called are not real.

Example

use nalgebra::{ComplexField, convert};

struct ExampleProblem<F: ComplexField> {
    params: Vector2<F>,
}

// Implement LeastSquaresProblem to be usable with complex numbers
impl<F: ComplexField> LeastSquaresProblem<F, U2, U2> for ExampleProblem<F> {
    // ... omitted ...
}

// parameters for which you want to test your derivative
let x = Vector2::new(0.03877264483558185, -0.7734472300384164);

// instantiate f64 variant to compute the derivative we want to check
let jacobian_from_trait = (ExampleProblem::<f64> { params: x }).jacobian().unwrap();

// then use Complex<f64> and compute the numerical derivative
let jacobian_numerically = {
    let mut problem = ExampleProblem::<Complex<f64>> {
        params: convert(x),
    };
    differentiate_holomorphic_numerically(&mut problem).unwrap()
};

assert_relative_eq!(jacobian_from_trait, jacobian_numerically, epsilon = 1e-15);