Skip to content

Laplace Approximation of the Posterior

laplace

Wrapper for the Gaussian low-rank posterior object in Hippylib.

This module provides the functionality for the so-called Laplace approximation of the posterior, a method of variational inference. The Laplace approximation is based on the linearization of the forward map that governs the inverse problem, typically about the MAP point. In combination with a Gaussian prior and likelihood, the Laplace approximation results in a Gaussian posterior, defined by a mean function (the MAP estimate), and the local Hessian at that point.

The Laplace-approximation implemented in SPINrelies on the GaussianLRPosterior object in Hippylib, which takes a low-rank approximation of the Hessian as input. This low-rank approximation is computed in SPIN using the compute_low_rank_hessian function. The MAP can be found using the Newton-CG solver in Hippylib, which is wrapped in the NewtonCGSolver class for SPIN applications.

Classes:

Name Description
LowRankLaplaceApproximationSettings

Input for the low-rank Laplace approximation object.

LowRankLaplaceApproximation

Wrapper for the low-rank Laplace approximation object.

spin.hippylib.laplace.LowRankLaplaceApproximationSettings dataclass

Input for the low-rank Laplace approximation object.

Attributes:

Name Type Description
inference_model hl.Model

Hippylib inference model object.

mean npt.NDArray[np.floating]

Mean function (usually the MAP).

low_rank_hessian_eigenvalues npt.NDArray[np.floating]

Eigenvalues for low-rank approximation of the negative log-posterior Hessian (at the MAP).

low_rank_hessian_eigenvectors Iterable[npt.NDArray[np.floating]]

Eigenvectors for low-rank approximation of the negative log-posterior Hessian (at the MAP).

spin.hippylib.laplace.LowRankLaplaceApproximation

Low-rank Laplace approximation of the posterior distribution.

This class provides a wrapper for the GaussianLRPosterior object in Hippylib with a more modern and user-friendly interface.

Attributes:

Name Type Description
hippylib_gaussian_posterior hl.GaussianLRPosterior

Underlying Hippylib object

Methods:

Name Description
compute_pointwise_variance

Compute the pointwise variance for the Laplace approximation.

hippylib_gaussian_posterior property

hippylib_gaussian_posterior: hl.GaussianLRPosterior

Return the underlying GaussianLRPosterior Hippylib object.

__init__

__init__(settings: LowRankLaplaceApproximationSettings) -> None

Initialize the underlying hippylib object.

Parameters:

Name Type Description Default
settings LowRankLaplaceApproximationSettings

Input data for the approximation.

required

compute_pointwise_variance

compute_pointwise_variance(method: Annotated[str, Is[lambda x: x in Exact, Randomized]], num_eigenvalues_randomized: Annotated[int, Is[lambda x: x > 0]] | None = None) -> npt.NDArray[np.floating]

Compute the pointwise variance field of the Laplace approximation.

For a detailed description of the different methods, we refer to the documentation of the GaussianLRPosterior object in Hippylib.

Parameters:

Name Type Description Default
method str

Algorithm for computation of the variance, options are "Exact", and "Randomized".

required
num_eigenvalues_randomized int

Number of dominant eigenvalues for the randomized algorithm. Defaults to None.

None

Raises:

Type Description
ValueError

Checks that num_eigenvalues_randomized is provided for the 'Randomized' algorithm

Returns:

Type Description
npt.NDArray[np.floating]

npt.NDArray[np.floating]: Pointwise variance field.