pysdic.workflows.compute_uncertainty#

compute_uncertainty(correlation, parameters=None, *, image_noise_std=None, vertices=None, batch_size=256)[source]#

Estimate the covariance of the unknowns of a correlation term (displacements and parameters of transformations) from its Jacobian at convergence and from the noise of the gray levels.

Near the solution, the Gauss-Newton step is linear in the residuals, \(\delta\vec{p} = -H^{-1} J^T \vec{r}\) with \(H = J^T J\). The term weights the residuals by \(\sqrt{w_p}\): with a noise of variance \(s^2\) on the raw residuals \(g_2 - g_1\), the covariance of the weighted residuals is \(s^2 W\) with \(W = \text{diag}(w_p)\), and

\[\text{Cov}(\vec{p}) \approx s^2 \, H^{-1} (J^T W J) H^{-1}\]

(equal to \(s^2 w H^{-1}\) for equal weights \(w\)). The variance \(s^2\) is:

  • by default, estimated a posteriori from the raw residuals at parameters, \(s^2 = \sum r^2 / (m - n)\): it includes the noise of the images and the errors of the model (interpolation, gray level changes, …);

  • with image_noise_std \(\sigma\), the noise of the two images of a pairing, \(s^2 = 2 \sigma^2\): only valid for the raw gray levels (term without gray level correction, the correction rescales the noise).

Only the unknowns constrained by the term are kept (non-zero column of the Jacobian, e.g. not the vertices without integration points); a direction not observable by the term (e.g. the tangential displacement with stereo pairings only) gives a huge or infinite variance. The covariance does not include the other terms of a problem (e.g. a temporal regularization), which reduce the uncertainty.

Note

The covariance of a vertex needs two sparse solves per unknown of the vertex: give vertices to compute only some of them on a large mesh.

Parameters:
  • correlation (pysdic.SDICCorrelationTerm) – The term, in mode "rJ".

  • parameters (Optional[ArrayLike], optional) – The complete vector of unknowns at convergence (with a parametrization, parametrization.p_func(result.parameters)). By default, the current state of the analysis (pysdic.SDICCorrelationTerm.pack()).

  • image_noise_std (Optional[Real], optional) – The standard deviation of the noise of the images (gray levels). By default, the variance is estimated from the residuals.

  • vertices (Optional[ArrayLike], optional) – The vertices whose covariance is computed (indices). By default, all the vertices.

  • batch_size (Integral, optional (default: 256)) – The number of columns solved at once (memory \(n \times\) batch_size).

Returns:

The covariances of the displacements and of the transformations.

Return type:

UncertaintyResult

Raises:

ValueError – If the term is not in mode "rJ", image_noise_std is used with a gray level correction, there are not more residuals than unknowns, or the Hessian is singular.

Examples

from pysdic.workflows import compute_uncertainty

analysis.apply_unknowns(unknowns, result.parameters)  # Measure done
uncertainty = compute_uncertainty(correlation)  # At the current state of the analysis
std = uncertainty.standard_deviations[1]  # (N_v, 3), frame 1
print(f"Median uncertainty: {numpy.nanmedian(std, axis=0)} mm")