uncertainty

Contents

uncertainty#

scarlet2.infer.uncertainty(scene, observations, pair_similarity=None, max_iter=100, return_hessian=False, key=None)[source]#

Estimate the per-parameter curvature (diagonal Hessian) of a fitted model.

Computes the diagonal of the Hessian \(H\) of the negative log-posterior loss at the current (assumed best-fit) parameter values of scene, which estimates the local marginal precision of each parameter. Under a Laplace approximation the “1-sigma” uncertainty of a parameter is \(1 / \sqrt{H}\) for the corresponding (positive) diagonal entry.

If return_hessian is True, the raw Hessian curvature is returned instead so the caller can handle non-positive entries (a direction not at a minimum) explicitly rather than receiving NaNs from the square root.

The Hessian diagonal is estimated stochastically with Hutchinson’s method (hvp_rad()) applied to the Hessian-vector product the loss function. Every non-fixed parameter of scene and observations is flattened into a single vector, so the estimate is taken jointly across all parameters.

If the loss contains priors (either per-parameter or pairwise), their curvature will be taken into account: This method provide the curvature as experienced by the optimizer, not necessarily limited to the log-likelihood.

The Hessian is evaluated in the unconstrained space and transformed via the exact change-of-variables \(H_\phi = H_\theta / (d \phi / d \theta)^2\) (valid at an extremum). Parameters without a constraint are returned unchanged.

Parameters:
  • scene (Scene) – The (fitted) model of the scene.

  • observations (Observation or list) – The observations the model was fit to.

  • pair_similarity (PairSimilarity, optional) – Same regularizer configuration as passed to fit(). Must match what was used during fitting so that the loss (and hence its Hessian) is identical. None (default) disables it.

  • max_iter (int, optional) – Maximum number of Rademacher probes to estimate the Hessian diagonal.

  • return_hessian (bool, optional) – If True, return the raw Hessian diagonal rather than the uncertainty (1/sqrt(H)).

  • key (jax.random.PRNGKey, optional) – A random key for generating Rademacher vectors. If None, a new key will be generated.

Returns:

Maps every non-fixed parameter name to the diagonal uncertainty of the same shape as the parameter, expressed in the natural (constrained) parameter space.

Return type:

dict