pyrtid.utils.finite_differences.is_jacobian_correct#

pyrtid.utils.finite_differences.is_jacobian_correct(x: ndarray, fm: Callable, jac: Callable, fm_args: Optional[Union[Tuple[Any], List[Any]]] = None, fm_kwargs: Optional[Dict[str, Any]] = None, jac_args: Optional[Tuple[Any]] = None, jac_kwargs: Optional[Dict[str, Any]] = None, accuracy: int = 0, eps: Optional[float] = None, max_workers: int = 1) bool[source]#

Check by finite difference if the Jacobian matrix is correct.

Parameters
  • x (np.ndarray) – The input parameters vector.

  • fm (Callable) – Forward model.

  • jac (Callable) – Jacobian model.

  • fm_args (Tuple[Any]) – Positional arguments for the forward model.

  • fm_kwargs (Dict[Any, Any]) – Keyword arguments for the forward model.

  • grad_args (Tuple[Any]) – Positional arguments for the gradient model.

  • grad_kwargs (Dict[Any, Any]) – Keyword arguments for the gradient model.

  • accuracy (int, optional) – Number of points to use for the finite difference approximation. Possible values are 0 (2 points), 1 (4 points), 2 (6 points), 3 (8 points). The default is 0 which corresponds to the central difference scheme (2 points).

  • eps (float, optional) – The epsilon for the computation (h). The default value has been taken from the C++ implementation of [Wieschollek, 2016], and should correspond to the optimal h taking into account the roundoff errors due to the machine precision. The default is -2.2204e-6.

  • max_workers (int) – Number of workers used. If different from one, the calculation relies on multi-processing to decrease the computation time. The default is 1.

Returns

True if the Jacobian is correct, false otherwise.

Return type

bool