Skip to content

Prior Object

prior

Prior distribution interface.

Class

Prior: Prior distribution class.

ls_prior.prior.Prior

Prior distribution class.

This class implements functionality of a Gaussian prior measure that is typically required in the context of Bayesian inference. In the spirit of separation of concerns, the prior component is rather stupid. It simply utilizes objects for the (representation of) a covariance operator \(\mathcal{C}\), its factorization \(\widehat{\mathcal{C}}\), and a precision operator \(\mathcal{C}^{-1}\). These components have to adhere to the interface prescribed by the InterfaceComponent class. The necessary objects can be manually assembled and be handed to the Prior class for maximum flexibility. On the other hand, the builder module provides a convenient alternative for the setup of a preconfigured prior object.

Methods:

Name Description
evaluate_cost

Evaluate the cost/negative log-probability for a given parameter vector.

evaluate_gradient

Evaluate the gradient of the cost functional with respect to a given parameter vector.

evaluate_hessian_vector_product

Evaluate the Hessian-vector product of the cost functional in the given direction.

sample

Generate a sample from the prior distribution.

__init__

__init__(
    mean_vector: np.ndarray[tuple[int], np.dtype[np.float64]],
    precision_operator: components.InterfaceComponent,
    covariance_operator: components.InterfaceComponent,
    covariance_factorization: components.InterfaceComponent,
    fem_converter: fem.FEMConverter,
    seed: int,
) -> None

Initialize Prior distribution object.

Parameters:

Name Type Description Default
mean_vector np.ndarray[tuple[int], np.dtype[np.float64]]

Mean vector \(\overline{m}\) of the prior measure.

required
precision_operator components.InterfaceComponent

Representation of the precision operator \(\mathcal{C}^{-1}\).

required
covariance_operator components.InterfaceComponent

Representation of the covariance operator \(\mathcal{C}\).

required
covariance_factorization components.InterfaceComponent

Representation of a factorization \(\widehat{\mathcal{C}}\) of the covariance operator for sampling.

required
fem_converter fem.FEMConverter

Converter object to switch between vertex- and DoF-based representation of vectors.

required
seed int

Random seed for the internal random number generator.

required

Raises:

Type Description
ValueError

Checks that precision operator has the correct shape.

ValueError

Checks that covariance operator has the correct shape.

ValueError

Checks that covariance factor has the correct shape.

evaluate_cost

evaluate_cost(parameter_vector: np.ndarray[tuple[int], np.dtype[np.float64]]) -> float

Evaluate the cost functional, i.e. the negative log probability for given input.

Computes \(\frac{1}{2} (m-\overline{m})^T \mathcal{C}^{-1} (m-\overline{m})\).

Parameters:

Name Type Description Default
parameter_vector np.ndarray[tuple[int], np.dtype[np.float64]]

Parameter candidate for which to evaluate the cost/negative log probability, given on mesh vertices.

required

Returns:

Name Type Description
float float

cost/negative log probability

evaluate_gradient

evaluate_gradient(
    parameter_vector: np.ndarray[tuple[int], np.dtype[np.float64]],
) -> np.ndarray[tuple[int], np.dtype[np.float64]]

Evaluate the gradient of the cost/negative log-probability w.r.t. the parameter vector.

Computes \(\mathcal{C}^{-1} (m - \overline{m})\).

Parameters:

Name Type Description Default
parameter_vector np.ndarray[tuple[int], np.dtype[np.float64]]

Parameter candidate for which to evaluate the gradient, given on mesh vertices.

required

Returns:

Type Description
np.ndarray[tuple[int], np.dtype[np.float64]]

np.ndarray[tuple[int], np.dtype[np.float64]]: Gradient of the cost/negative log-probability, given on mesh vertices.

evaluate_hessian_vector_product

evaluate_hessian_vector_product(
    direction_vector: np.ndarray[tuple[int], np.dtype[np.float64]],
) -> np.ndarray[tuple[int], np.dtype[np.float64]]

Evaluate the application of the Hessian of the cost functional on a given direction.

Computes \(\mathcal{C}^{-1} m_{\text{dir}}\).

Parameters:

Name Type Description Default
direction_vector np.ndarray[tuple[int], np.dtype[np.float64]]

Direction for which to evaluate the Hessian-vector product, given on mesh vertices.

required

Returns:

Type Description
np.ndarray[tuple[int], np.dtype[np.float64]]

np.ndarray[tuple[int], np.dtype[np.float64]]: Hessian-vector product, given on mesh vertices.

generate_sample

generate_sample() -> np.ndarray[tuple[int], np.dtype[np.float64]]

Generate a sample from the prior measure.

Computes sample in two-step procedure:

  1. Generate i.i.d. normal vector \(\xi\) matching input dimension of \(\widehat{\mathcal{C}}\).
  2. Multiply with covariance factorization \(\widehat{\mathcal{C}}\) and add mean

Returns:

Type Description
np.ndarray[tuple[int], np.dtype[np.float64]]

np.ndarray[tuple[int], np.dtype[np.float64]]: Sample vector, given on mesh vertices.

_check_input_dimension

_check_input_dimension(vector: np.ndarray) -> None

Checks dimension of input vectors, applied in all interface methods.

_check_output_dimension

_check_output_dimension(vector: np.ndarray) -> None

Checks dimension of result vectors, applied in all interface methods.