UQ[PY]LAB USER MANUAL
BAYESIAN INFERENCE FOR MODEL
CALIBRATION AND INVERSE PROBLEMS
P.-R. Wagner, J. Nagel, S. Marelli, B. Sudret
CHAIR OF RISK, SAFETY AND UNCERTAINTY QUANTIFICATION
STEFANO-FRANSCINI-PLATZ 5
CH-8093 Z
¨
URICH
Risk, Safety &
Uncertainty Quantification
How to cite UQ[PY]LAB
C. Lataniotis, S. Marelli, B. Sudret, Uncertainty Quantification in the cloud with UQCloud, Proceedings of the 4th
International Conference on Uncertainty Quantification in Computational Sciences and Engineering (UNCECOMP
2021), Athens, Greece, June 27–30, 2021.
How to cite this manual
P.-R. Wagner, J. Nagel, S. Marelli, B. Sudret, UQ[py]Lab user manual Bayesian inference for model calibration
and inverse problems, Report UQ[py]Lab -V1.0-113, Chair of Risk, Safety and Uncertainty Quantification, ETH
Zurich, Switzerland, 2024
BIBT
E
X entry
@TechReport{UQdoc_10_113,
author = {Wagner, P.-R. and Nagel, J. and Marelli, S. and Sudret, B.},
title = {{UQ[py]Lab user manual -- Bayesian inversion for model calibration and
validation }},
institution = {Chair of Risk, Safety and Uncertainty Quantification, ETH Zurich,
Switzerland},
year = {2024},
note = {Report UQ[py]Lab - V1.0-113}
}
List of contributors:
Name Contribution
A. Hlobilov
´
a Translation from the UQLab manual
Document Data Sheet
Document Ref. UQ[PY]LAB-V1.0-113
Title: UQ[PY]LAB user manual Bayesian inference for model calibration
and inverse problems
Authors: P.-R. Wagner, J. Nagel, S. Marelli, B. Sudret
Chair of Risk, Safety and Uncertainty Quantification, ETH Zurich,
Switzerland
Date: 27/05/2024
Doc. Version Date Comments
V1.0 27/05/2024 Initial release
Abstract
Bayesian inference is a powerful tool for probabilistic model calibration and inversion. It
provides a comprehensive framework for combining information about parameters prior to
observations with information obtained from experiments. In Bayesian inference, this com-
bined information is expressed in a so-called posterior distribution of the parameters.
The UQ[PY]LAB Bayesian inference module offers an easy way to setup a Bayesian in-
verse problem and to compute its posterior distribution. It makes use of other available
UQ[PY]LAB modules (UQ[PY]LAB User Manual – the INPUT module, UQ[PY]LAB User Man-
ual the MODEL module) to define the forward model and the prior distribution. For the
computation of the posterior distribution, state-of-the-art algorithms are supplied. The man-
ual for the Bayesian inversion module is divided into three parts:
A brief introduction to the main ideas and theoretical foundations of Bayesian inver-
sion and discussions on Markov chain Monte Carlo, spectral likelihood expansion, and
stochastic spectral embedding algorithms;
An example-based guide with an explanation of the available options and methods;
A comprehensive reference list detailing all available functionalities of the Bayesian
inversion module.
Keywords: UQ[PY]LAB, Bayesian inversion, model calibration, inverse problems, Markov
chain Monte Carlo, spectral likelihood expansion, stochastic spectral embedding
Contents
1 Theory 1
1.1 Bayesian inference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2 Bayesian model calibration and inverse problems . . . . . . . . . . . . . . . . 4
1.2.1 A wide class of problems sharing the same methods . . . . . . . . . . . 4
1.2.2 Simple problems with known discrepancy parameters . . . . . . . . . 5
1.2.3 General case: discrepancy with unknown parameters . . . . . . . . . . 6
1.2.4 Multiple data groups . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
1.2.5 Inverse solution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
1.2.6 Model predictions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
1.3 Markov chain Monte Carlo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
1.3.1 Metropolis–Hastings algorithm . . . . . . . . . . . . . . . . . . . . . . 10
1.3.2 Adaptive Metropolis algorithm . . . . . . . . . . . . . . . . . . . . . . 11
1.3.3 Hamiltonian Monte Carlo algorithm . . . . . . . . . . . . . . . . . . . 12
1.3.4 Affine invariant ensemble algorithm . . . . . . . . . . . . . . . . . . . 13
1.3.5 Assessing convergence in MCMC simulations . . . . . . . . . . . . . . 14
1.4 Spectral likelihood expansion . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
1.5 Stochastic spectral likelihood embedding . . . . . . . . . . . . . . . . . . . . . 19
1.5.1 Sequential partitioning algorithm . . . . . . . . . . . . . . . . . . . . . 20
2 Usage 23
2.1 Reference problem: calibration of a simply supported beam model . . . . . . 23
2.2 Problem setup and solution . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
2.2.1 Initialize UQ[PY]LAB . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
2.2.2 Specify a prior distribution . . . . . . . . . . . . . . . . . . . . . . . . 25
2.2.3 Create a forward model . . . . . . . . . . . . . . . . . . . . . . . . . . 26
2.2.4 Provide measurements . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
2.2.5 Perform the Bayesian inverse analysis . . . . . . . . . . . . . . . . . . 26
2.2.6 Advanced options: discrepancy model . . . . . . . . . . . . . . . . . . 28
2.3 Multiple model outputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
2.3.1 Create a forward model . . . . . . . . . . . . . . . . . . . . . . . . . . 31
2.3.2 Provide measurements . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
2.3.3 Perform the inverse analysis . . . . . . . . . . . . . . . . . . . . . . . . 32
2.3.4 Advanced options: discrepancy model . . . . . . . . . . . . . . . . . . 33
2.4 Advanced options: solver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
2.4.1 MCMC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
2.4.2 Spectral likelihood expansion . . . . . . . . . . . . . . . . . . . . . . . 44
2.4.3 Stochastic spectral likelihood embedding . . . . . . . . . . . . . . . . . 45
2.4.4 No solver: posterior point by point evaluation . . . . . . . . . . . . . . 46
2.5 Advanced feature: multiple forward models . . . . . . . . . . . . . . . . . . . 47
2.5.1 Specify a prior distribution . . . . . . . . . . . . . . . . . . . . . . . . 48
2.5.2 Create a forward model . . . . . . . . . . . . . . . . . . . . . . . . . . 48
2.5.3 Provide measurements . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
2.5.4 Define a discrepancy model . . . . . . . . . . . . . . . . . . . . . . . . 50
2.5.5 Perform the inverse analysis . . . . . . . . . . . . . . . . . . . . . . . . 50
3 Reference List 55
3.1 Create a Bayesian inverse analysis . . . . . . . . . . . . . . . . . . . . . . . . . 58
3.1.1 Data dictionary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
3.1.2 Forward model dictionary . . . . . . . . . . . . . . . . . . . . . . . . . 59
3.1.3 Discrepancy model options . . . . . . . . . . . . . . . . . . . . . . . . 59
3.1.4 Solver options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
3.2 Accessing analysis results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
3.3 Post-processing results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
3.3.1 Markov chain Monte Carlo . . . . . . . . . . . . . . . . . . . . . . . . . 66
3.3.2 Spectral likelihood expansions . . . . . . . . . . . . . . . . . . . . . . 69
3.3.3 Stochastic spectral likelihood embedding . . . . . . . . . . . . . . . . . 70
3.4 Printing/Visualizing results . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
3.4.1 Printing the results: uq.print . . . . . . . . . . . . . . . . . . . . . . . 72
3.4.2 Graphically display the results: uq.display . . . . . . . . . . . . . . . . 72
Chapter 1
Theory
This section contains a short introduction to Bayesian methods (Gelman et al., 2014) with
a focus on inverse problems (Tarantola, 2005; Kaipio and Somersalo, 2005). An inverse
problem arises when unknown parameters that cannot be directly measured are estimated
based on experimental data that is only indirectly related to the parameters through a com-
putational model. The problem is called inverse, because instead of propagating information
about input parameters through a computational model (so-called forward approach), the
goal is to propagate information about the observations backwards to obtain insight on the
model inputs. This formulation encompasses a range of problems in the engineering and
natural sciences (Hadidi and Gucunski, 2008; Beck, 2010; Yuen and Kuok, 2011). This is a
very important extension to the Bayesia manual.
1.1 Bayesian inference
Statistics is generally described as the science that allows one to build models of com-
plex phenomena based on data. Statistical inference usually considers that this data X
def
=
{x
1
, . . . , x
N
} is made of independent realizations of an underlying random vector with an
associated probability density function (PDF) π(·), whose properties have to be established
from that data. Parametric statistical models make an assumption on the shape of this PDF
(e.g. Gaussian, Weibull, lognormal in the one-dimensional case), and the goal of inference is
to estimate the parameters θ of this PDF given the data or more formally:
Θ|X π(θ|X ) (1.1)
where Θ is the random vector associated with the parameters θ and the vertical line | is used
to denote a conditional dependence of the quantity on the left on the quantity on the right.
When a sufficient amount of data exists, classical estimators can be used: for instance, if a
Gaussian distribution X |θ N (x|µ, σ
2
) is to be fitted to a sufficiently large data set X , the
1
UQ[PY]LAB user manual
empirical mean and standard deviation of the sample may be used as estimators
b
θ of the
parameters θ
def
=
µ, σ
2
. Such a direct estimation is, however, not reliable when there is
only a handful of data points. In technical terms, the statistical uncertainty of the estimator
b
θ becomes too large in this case.
In this context, Bayesian statistics allows one to fit a statistical model by combining some prior
knowledge on the parameters with the (possibly few) observed data points, using Bayes’
theorem
1
. Before considering the data, in the Bayesian paradigm, the parameters of the
parametric distribution π(x|θ) are considered as a random vector denoted by Θ which is
assumed to follow the so-called prior distribution (with support D
Θ
):
Θ π(θ). (1.2)
This subjective choice should reflect the level of information existing on the parameters θ
before any measurement of X is carried out. From Bayes’ theorem, the posterior distribution
of the parameters, denoted as π(θ|x), is obtained by:
π(θ|x) =
π(x|θ) π(θ)
π(x)
. (1.3)
Consider now a data set of measured values X = {x
1
, . . . , x
N
}, whose points are viewed as
independent realizations of X |θ π(x|θ). With these measurements the likelihood function
L(θ; X ), a function of the parameters θ, can be defined:
L : θ 7→ L(θ; X )
def
=
N
Y
k=1
π(x
k
|θ). (1.4)
This implicitly assumes independence between individual measurements in X . Intuitively
the likelihood function for a given θ returns the relative likelihood of observing the data at
hand, under the assumption that it follows the prescribed parametric distribution π(x|θ).
Following Bayes’ theorem, the posterior distribution π(θ|X ) of the parameters θ given the
observations in X can now be written as:
π(θ|X ) =
L(θ; X ) π(θ)
Z
, (1.5)
where the normalizing factor Z, known as the evidence or marginal likelihood, shall ensure
that this distribution integrates to 1:
Z
def
=
Z
D
Θ
L(θ; X ) π(θ) dθ. (1.6)
The posterior distribution in Eq. (1.5) summarizes the information inferred about the param-
1
Bayes’ theorem is an elementary result of probability theory that reads as follows: for two events A and B
with non-zero probabilities, the following equation holds: P (B |A) =
P (A|B) P (B)
P (A)
, where P (A|B) denotes
the conditional probability of A given B.
UQ[PY]LAB-V1.0-113 - 2 -
Bayesian inference for model calibration and inverse problems
eters by combining the prior knowledge and the observed data. In this sense, the posterior
π(θ|X ) is an “update” of the prior distribution π(θ).
The practical computation of posterior distributions is not trivial. Particular analytical solu-
tions exist only for specific combinations of prior distributions on Θ and likelihood functions,
the so-called conjugate distributions (Gelman et al., 2014). In the general case though, sam-
pling methods shall be used such as Markov chain Monte Carlo simulation (see Section 1.3
for details).
In practical applications related to uncertainty quantification, the purpose of Bayesian infer-
ence may not just be to find the posterior distribution π(θ|X ), but also to propose “the best
distribution” for the parameters X |X given the information and data at hand. One possi-
bility is to select a point estimator
b
θ, i.e. a particular value from the posterior distribution of
π(θ|X ). Then the point posterior distribution of X |X simply reads:
π(x|X )
def
= π(x|
b
θ). (1.7)
Popular choices for
b
θ are the posterior mean, which is the mean value of the posterior dis-
tribution (1.5) and the posterior mode, a.k.a. maximum a posteriori (MAP), which is the
mode of this posterior distribution. Such choices disregard the estimation uncertainty in the
parameters θ.
In contrast, it is also possible to incorporate the uncertainty in θ into the prior and posterior
assessment of X and X |X respectively. This results in the so-called predictive distributions.
The prior predictive distribution of X is obtained by “averaging” the parametric distribution
π(x|θ) over the prior distribution π(θ):
2
π(x)
def
=
Z
D
Θ
π(x|θ) π(θ) dθ. (1.8)
The posterior predictive distribution π(x|X ) is obtained by “averaging” the parametric distri-
bution π(x|θ) over the posterior distribution π(θ|X ) in Eq. (1.5):
π(x|X )
def
=
Z
D
Θ
π(x|θ) π(θ|X ) dθ. (1.9)
2
It is noted here that for a single measurement X = x
1
, the prior predictive distribution at X equals the
normalization constant Z defined in Eq. (1.6).
UQ[PY]LAB-V1.0-113 - 3 -
UQ[PY]LAB user manual
1.2 Bayesian model calibration and inverse problems
1.2.1 A wide class of problems sharing the same methods
Let us consider a computational model M that allows the analyst to predict certain quantities
of interest gathered in a vector y R
N
out
as a function of input parameters x:
M : x D
X
R
M
7→ y = M(x) R
N
out
. (1.10)
Such models are commonly established based on first principles in engineering sciences (e.g.
mechanics, electromagnetism, fluid dynamics), but also natural sciences (e.g. geophysics,
wave propagation). Although analytical models with closed-form equations may be used,
the vast majority of computational models are black-box computer codes that solve the un-
derlying differential equations that govern the system of interest.
When input parameters {x
i
, i = 1, . . . , M} are not measurable directly, one resorts to mea-
suring the quantities of interest. Let us consider N independent measurement y
i
R
N
out
gathered in a data set Y
def
= {y
1
, . . . , y
N
}. In the context of computational modelling and
uncertainty quantification, two main classes of applications benefit from Bayesian inference,
namely model calibration and inverse problems. The two classes are very much related to each
other and they share the same problem statement and solution techniques, but they differ in
their final focus.
On the one hand, Bayesian inversion focuses on the identification of the values of the input
parameters x, rather than on the model used to infer them. For this reason, it is also known
as Bayesian inverse modelling: instead of predicting a model response from a set of input
parameters, the latter are inferred from a set of observed model responses Y. This is the
typical usage scenario in tomographic imaging applications, where the goal is to identify
the set of input parameters that caused a specific set of observations. The resulting inferred
input parameters can then be directly used to identify anomalies (e.g. position and length of
cracks in pressure vessels), or to identify properties of interest (e.g. location and volume of
subsurface oil reservoirs).
On the other hand, Bayesian model calibration focuses on identifying the input parameters of
a computational model to allow one to recover the observations in Y . A common scenario in
this respect is identifying unknown properties of key components of a complex system, based
on their observed response to controlled external loads in a laboratory experiment. Through
this procedure, known as calibration, the inferred values (and possibly the uncertainty of the
estimation) can then be used to predict the response of the same system to different external
loads, or even to design different systems sharing the same calibrated model component. This
approach is at the basis of the so-called verification and validation under uncertainty paradigm
(VVUQ) that is gaining momentum in the engineering practice worldwide (Oberkampf et al.,
2004; Oberkampf and Roy, 2010; Hu and Orient, 2016).
UQ[PY]LAB-V1.0-113 - 4 -
Bayesian inference for model calibration and inverse problems
1.2.2 Simple problems with known discrepancy parameters
Regardless of the specific context (model calibration or inversion), all Bayesian inverse prob-
lems share the same ingredients: a computational forward model M, a set of input parame-
ters x D
X
that need to be inferred, and a set of experimental data Y.
The forward model x 7→ M(x) is a mathematical representation of the system under con-
sideration. All models are always simplifications of the real world. Thus, to connect model
predictions to the observations Y, a discrepancy term shall be introduced. We consider the
following well-established format:
y = M(x) + ε, (1.11)
where ε R
N
out
is the term that describes the discrepancy between an experimental obser-
vation y and the model prediction. For the sake of simplicity, we consider it as an additive
Gaussian discrepancy
3
with zero mean value and given covariance matrix Σ in this introduc-
tion:
ε N (ε |0, Σ). (1.12)
This discrepancy term represents in practice the effects of measurement error (on y
i
Y)
and model inaccuracy. In the above equation, again for the sake of simplicity, this term is
supposed to have a zero mean, but it could more generally include a model bias term.
In the context of model inversion or calibration, the goal is to find the optimal values of the
input parameters x that allow one to fit the model predictions to the observations. In this
respect the epistemic uncertainty (lack of knowledge) on the input parameters is modelled by
considering the input parameters as a random vector X π(x), with given prior distribution
as in Eq. (1.2).
Note: In this section, the measurement data is denoted by Y, which plays the role of X
in Section 1.1. In contrast, the parameters to infer are the input parameters X of
the computational model M, which plays the role of parameters Θ in Section 1.1.
From Eqs. (1.11), (1.12) a particular measurement point y
i
Y is a realization of a Gaussian
distribution with mean value M(x) and covariance matrix Σ. This distribution is called the
error or discrepancy model π(y|x) given by:
π(y|x) = N (y|M(x), Σ). (1.13)
If N independent measurements y
i
are available and gathered in the data set Y = {y
1
, . . . , y
N
},
3
It is noted here that this simple Gaussian discrepancy assumption is only one out of many possible models. In
a more general setting, other distributions for the discrepancy are used as well (Schoups and Vrugt, 2010). Due
to the widespread use of the additive Gaussian models in engineering disciplines, the discussion is limited to this
discrepancy type.
UQ[PY]LAB-V1.0-113 - 5 -
UQ[PY]LAB user manual
the likelihood function can thus be written as
L(x; Y) =
N
Y
i=1
N (y
i
|M(x), Σ)
=
N
Y
i=1
1
p
(2π)
N
out
det(Σ)
exp
1
2
y
i
M(x)
Σ
1
y
i
M(x)
.
(1.14)
Combining the prior π(x) and the above likelihood L(x; Y), the posterior distribution in
Eq. (1.5) establishes the solution of the inverse problem:
π(x|Y) =
1
Z
π(x)
N
Y
i=1
N (y
i
|M(x), Σ). (1.15)
It summarizes the collected information about the unknowns x after conditioning on the
data. In this sense, the data are inverted through the forward model M.
1.2.3 General case: discrepancy with unknown parameters
In many practical situations, it is unrealistic to assume that the residual covariance matrix
Σ in Eq. (1.12) is perfectly known. However, by parametrizing the matrix as Σ(x
ε
), one
may treat its parameters x
ε
as additional unknowns that can be inferred jointly with the
input parameters of M. In this setting the parameter vector is defined by x = (x
M
, x
ε
),
i.e. a combined vector of forward model parameters x
M
and discrepancy parameters x
ε
.
For the sake of simplicity, consider a diagonal covariance matrix of the form Σ = σ
2
I
N
out
with unknown residual variances σ
2
= Var[ε
i
], i = 1, . . . , N
out
. This way, the discrepancy
parameter vector reduces to a single scalar, i.e. x
ε
σ
2
.
Assuming that one can elicit a prior distribution π(x
ε
) for the unknown variance σ
2
, and by
treating the uncertain model and the discrepancy parameters as being priorly independent,
one gets the joint prior distribution
π(x) = π(x
M
)π(σ
2
). (1.16)
The likelihood is then given as
L(x
M
, σ
2
; Y) =
N
Y
i=1
1
p
(2πσ
2
)
N
out
exp
1
2σ
2
y
i
M(x
M
)
y
i
M(x
M
)
. (1.17)
With the prior distribution in Eq. (1.16) and likelihood function in Eq. (1.17), the corre-
sponding posterior distribution can then again be computed as in Eq. (1.15):
π(x
M
, σ
2
|Y) =
1
Z
π(x
M
)π(σ
2
)L(x
M
, σ
2
; Y). (1.18)
This posterior distribution summarizes the updated information about the unknowns (x
M
, x
ε
UQ[PY]LAB-V1.0-113 - 6 -
Bayesian inference for model calibration and inverse problems
σ
2
) after conditioning on the data Y. One may then extract the marginals π(x
M,i
|Y) of indi-
vidual forward model inputs or the marginal π(x
ε
|Y) π(σ
2
|Y) of the residual variance.
More generally, any parametrization Σ(x
ε
) of the positive definite covariance matrix can
be incorporated into the Bayesian analysis. This just requires the specification of a prior
distribution π(x
ε
) and construction of a likelihood function of the more general form:
L(x
M
, x
ε
; Y) =
N
Y
i=1
1
p
(2π)
N
out
det(Σ(x
ε
))
exp
1
2
y
i
M(x
M
)
Σ
1
(x
ε
)
y
i
M(x
M
)
.
(1.19)
1.2.4 Multiple data groups
In practice, it occurs frequently that the measurements Y = {y
1
, . . . , y
N
} stem from various
measurement devices or experimental conditions with different discrepancy properties. In
these cases, it is necessary to arrange the elements of Y in disjoint data groups and define
different likelihood functions for each data group.
Denoting the g-th data group by G
(g)
= {y
i
}
iu
, where u {1, . . . , N}, the full data set can
be combined by
Y =
N
gr
[
g=1
G
(g)
. (1.20)
Each of the N
gr
data groups contains measurements collected with the same instruments un-
der similar measurement conditions. With this, it is clear that each data group requires a
different likelihood function L
(g)
describing the experimental conditions that led to measur-
ing G
(g)
. Possible choices for L
(g)
are presented in Section 1.2.2 and Section 1.2.3. Under the
assumption of independence between the N
gr
measurement conditions, the full likelihood
function can then be written as
L(x
M
, x
ε
; Y) =
N
gr
Y
g=1
L
(g)
(x
M
, x
(g)
ε
; G
(g)
), (1.21)
where x
(g)
ε
are the parameters of the g-th discrepancy group.
1.2.5 Inverse solution
The posterior distribution of the parameters computed by Eq. (1.15), is often characterized
through its first statistical moments. The posterior mean vector is given as
E [X |Y] =
Z
D
X
x π(x|Y) dx. (1.22)
UQ[PY]LAB-V1.0-113 - 7 -
UQ[PY]LAB user manual
It can be considered as a point estimate of the unknown parameter values. The estimation
uncertainty can be quantified through the posterior covariance matrix
Cov[X |Y] =
Z
D
X
(x E [X |Y])(x E [X |Y])
π(x|Y) dx. (1.23)
One may also be interested in the posterior marginals. The univariate posterior marginal of
a specific parameter x
i
with i {1, . . . , M} can be computed by integration over the other
components (sometimes called nuisance parameters):
π
i
(x
i
|Y) =
Z
D
X
i
π(x|Y) dx
i
, (1.24)
where x
i
refers to the parameter vector x excluding the i-th parameter x
i
.
More generally, it is also possible to define multivariate posterior marginals by integrating
the posterior over all but the parameters of interest. To this end, we split the random vector
X into two vectors X
u
with components {X
i
}
iu
D
X
u
and X
v
with components {X
i
}
iv
D
X
v
, where u and v are two non-empty disjoint index sets such that u v = {1, . . . , M}. The
multivariate posterior marginals then read:
π
u
(x
u
|Y) =
Z
D
X
v
π(x|Y) dx
v
. (1.25)
In practical inverse problems, the posterior distribution π(x|Y) can also be an intermediate
quantity that is further used for computing the conditional expectation of a certain quantity of
interest (QoI) h: D
X
R. This can be anything from a simple analytical function to complex
secondary models. This conditional expectation is simply the expectation of h(X |Y) and is
computed by the integral
E [h(X |Y)] =
Z
D
X
h(x) π(x|Y) dx. (1.26)
1.2.6 Model predictions
To assess the predictive capabilities of a computational model, the Bayesian inference frame-
work offers the possibility to compute predictive distributions, as seen in Section 1.1. Using
the previously defined discrepancy model, the prior predictive distribution from Eq. (1.8) can
be written as
π(y) =
Z
D
X
π(y|x)π(x) dx. (1.27)
UQ[PY]LAB-V1.0-113 - 8 -
Bayesian inference for model calibration and inverse problems
The posterior predictive distribution (see Eq. (1.9)) can be similarly written as
π(y|Y) =
Z
D
X
π(y|x)π(x|Y) dx. (1.28)
Owing to the considered additive Gaussian discrepancy model in Eq. (1.13), a sample from
those predictive distributions can be obtained by using samples from X and X |Y respec-
tively, propagating them through the model M and adding an independently sampled dis-
crepancy term ε.
1.3 Markov chain Monte Carlo
Posterior distribution as in Eq. (1.15) do not have a closed-form solution in practice. One
widespread option to solve inverse problems relies upon Markov chain Monte Carlo (MCMC)
simulations (Robert and Casella, 2004; Liu, 2004).
The basic idea of MCMC simulations is to construct a Markov chain (X
(1)
, X
(2)
, . . .) over
the prior support D
X
with an invariant distribution that equals the posterior distribution of
interest. Markov chains can be uniquely defined by their transition probability K(x
(t+1)
|x
(t)
)
from the step x
(t)
of the chain at iteration t to the step x
(t+1)
at the subsequent iteration t+1.
Then, the posterior is the invariant distribution of the Markov chain if the specified transition
probability fulfils the so-called detailed balance condition:
π(x
(t)
|Y) K(x
(t+1)
|x
(t)
) = π(x
(t+1)
|Y) K(x
(t)
|x
(t+1)
). (1.29)
This condition ensures that the Markov chain is reversible, i.e., that the probability to be at
x
(t)
and move to x
(t+1)
is equal the probability to be at x
(t+1)
and move to x
(t)
. By integrating
this condition over dx
(t)
, it can be shown that the invariant distribution of the Markov chain
is the posterior distribution:
π(x
(t+1)
|Y) =
Z
D
X
π(x
(t)
|Y) K(x
(t+1)
|x
(t)
) dx
(t)
. (1.30)
A Markov chain constructed this way can be used to approximate the expectation in Eq. (1.26)
as the iteration average of the T + 1 generated sample points x
(t)
E [h(X)|Y]
1
T
T
X
t=1
h(x
(t)
). (1.31)
A prototypical technique to ensure that this equation is fulfilled is the Metropolis–Hastings
(MH) algorithm (Metropolis et al., 1953; Hastings, 1970) that is based on proposing and
subsequently accepting or rejecting candidate points. In the following, the original MH al-
UQ[PY]LAB-V1.0-113 - 9 -
UQ[PY]LAB user manual
gorithm and three other popular MCMC algorithms are discussed as techniques to efficiently
sample from the posterior distribution.
1.3.1 Metropolis–Hastings algorithm
In the Metropolis–Hastings algorithm (MH), a chain is initialized at a certain seed point x
(0)
D
X
from the admissible domain. At iteration t from the current point x
(t)
, one then draws a
candidate point x
()
from a proposal distribution p(x
()
|x
(t)
). Subsequently, the candidate is
accepted (i.e., x
(t+1)
= x
()
) with probability:
α
x
()
, x
(t)
= min
(
1,
π(x
()
|Y) p(x
(t)
|x
()
)
π(x
(t)
|Y) p(x
()
|x
(t)
)
)
, (1.32)
and rejected otherwise (i.e., x
(t+1)
= x
(t)
). With this procedure, the transition probability
fulfills Eq. (1.30) and the chain of sample points eventually follows the posterior distribution.
These sample points can then, for example, be used to approximate expectations under the
posterior distribution as shown in Eq. (1.31).
It is advantageous that the model evidence cancels out from the acceptance probability in
Eq. (1.32). Hence, the MH algorithm only calls for pointwise evaluations of the unnormalized
posterior density π(x|Y) L(x; Y)π(x). This avoids the calculation of the often intractable
integral in Eq. (1.6).
The original Metropolis algorithm is based on a symmetrical proposal distribution with p(x
()
|x
(t)
) =
p(x
(t)
|x
()
). In this case, the acceptance probability in Eq. (1.32) reduces to:
α
x
()
, x
(t)
= min
(
1,
π(x
()
|Y)
π(x
(t)
|Y)
)
. (1.33)
A commonly used symmetric proposal is the Gaussian distribution p(x|x
(t)
) = N (x|x
(t)
, Σ
p
)
centered around the current step x
(t)
with a covariance matrix Σ
p
. This proposal corresponds
to the classical random walk Metropolis (RWM) sampler. Note that with a symmetric proposal
distribution, a candidate x
()
is always accepted if one has π(x
()
|Y) π(x
(t)
|Y), i.e., if it
is more likely to belong to the posterior distribution than x
(t)
. For π(x
()
|Y) < π(x
(t)
|Y),
however, the proposed candidate is not rejected, but accepted only with probability α =
π(x
()
|Y)(x
(t)
|Y).
In practice, in order to accept and reject the proposed candidates with the probability in
Eq. (1.32) or Eq. (1.33), one usually samples a random variate u [0, 1] according to a
standard uniform distribution U U(u|0, 1) and compares it to the ratio α from Eq. (1.32).
If α u, then the proposed candidate is accepted. Otherwise, in the event that α < u, the
proposed candidate is rejected.
UQ[PY]LAB-V1.0-113 - 10 -
Bayesian inference for model calibration and inverse problems
1.3.2 Adaptive Metropolis algorithm
A practical weak point of the standard Metropolis–Hastings algorithm is the need to choose a
proposal distribution p(x
()
|x
(t)
). Ideally, this distribution should be as similar to the poste-
rior distribution as possible. In most applications, however, the posterior shape is not known
a priori. Moreover, a badly chosen proposal distribution significantly affects the MCMC per-
formance up to the point where the MCMC algorithm fails because it does not accept any
proposed candidates. This typically occurs in high dimensions with strongly correlated pos-
terior distributions.
A workaround was proposed in Haario et al. (2001). In this approach known as adaptive
Metropolis algorithm (AM), the Gaussian proposal distribution of the classic Metropolis algo-
rithm (see Section 1.3.1) is tuned during the sampling procedure based on previously gen-
erated samples. The algorithm starts as a standard random walk Metropolis algorithm with
an initial proposal covariance C
0
. Following a starting period t
0
, the proposal distribution
covariance matrix is updated to:
C(t + 1) =
(
C
0
, t + 1 t
0
,
s
d
(M)
˜
C(t), t + 1 > t
0
,
(1.34)
where s
d
(M) =
2.38
2
M
is a tuning parameter that depends only on the dimension of the prob-
lem (Gelman et al., 1996). The empirical covariance
˜
C(t) is estimated based on available
sample points generated up to step t and can be computed through:
˜
C(t) =
1
t 1
t
X
i=1
(x
(i)
¯
x
(t)
)(x
(i)
¯
x
(t)
)
!
, where
¯
x
(t)
=
1
t
t
X
i=1
x
(i)
. (1.35)
In practical applications, an iterative approach can be used to compute the empirical covari-
ance matrices
˜
C(t) with a negligible computational burden (i.e., updated from one step t to
the next) (Haario et al., 2001). To avoid singularity of this estimated covariance matrix, a
small constant ϵ is added to the diagonal of its correlation matrix. This modified empirical
covariance matrix C
(t) is then used in the definition of the Gaussian proposal distribution
centered at the current step of the Markov chain:
p(x|x
(1)
, . . . , x
(t)
) = N (x|x
(t)
, C
(t)). (1.36)
After drawing a candidate point x
()
from the proposal distribution p(x|x
(1)
, . . . , x
(t)
), this
candidate is accepted with probability:
α
x
()
, x
(t)
= min
(
1,
π(x
()
|Y)
π(x
(t)
|Y)
)
, (1.37)
which is the acceptance probability already defined in Eq. (1.32) for symmetric proposal
UQ[PY]LAB-V1.0-113 - 11 -
UQ[PY]LAB user manual
distributions. As the transition probability K(x
(t+1)
|x
(0)
, . . . , x
(t)
) at each step t depends on
all previous steps through the proposal distribution, the generated chain is non-Markovian
and it does not fulfil the symmetry condition from Eq. (1.29). Nonetheless, it was shown in
Haario et al. (2001) that the generated sample points can be used to approximate posterior
properties by Eq. (1.31).
1.3.3 Hamiltonian Monte Carlo algorithm
Instead of purely relying on a random walk to sample from the posterior distribution, Hamil-
tonian Monte Carlo algorithms (HMC) exploit the gradient of the posterior distribution to
construct a Markov chain using Hamiltonian dynamics. The connection between Hamilto-
nian dynamics and MCMC algorithms was originally established in Duane et al. (1987) and
a more detailed description of the HMC algorithm can be found in Neal (2011); Nagel and
Sudret (2016a).
The core idea of the algorithm lies in randomly assigning a momentum to a particle and
letting it travel over a potential surface. This can be formalized by defining a potential U (x)
and a kinetic energy function K(p):
U(x) = log (π(x)L(x; Y)) , K(p) =
p
M
1
p
2
, (1.38)
where p = (p
1
, . . . , p
M
)
is the momentum vector and M is a mass matrix for the particle,
which is often assumed to be a diagonal or simply a scaled identity matrix. This mass property
can be considered a tuning parameter of the algorithm.
The Hamiltonian Monte Carlo algorithm then uses the energy functions from Eq. (1.38) to
define the Hamiltonian:
H(x, p) = U(x) + K(p). (1.39)
The Hamiltonian captures the total energy of a particle at position x with a given momentum
p. According to Hamiltonian dynamics, the movement of a particle in this system can be
calculated by (where the dot denotes the time derivative):
˙x
i
=
H(x, p)
p
i
, ˙p
i
=
H(x, p)
x
i
, for i = 1, . . . , M. (1.40)
These equations can be solved by the well-known leapfrog integration algorithm (Neal, 2011).
It starts out at the current position x(0) = x
(t)
of the particle and a given momentum p(0)
drawn from the distribution:
p(0) N (p|0, I
M
). (1.41)
The leapfrog algorithm then solves the Hamiltonian equations for a total duration τ , using a
UQ[PY]LAB-V1.0-113 - 12 -
Bayesian inference for model calibration and inverse problems
discrete timestep size of
τ
N
τ
. The result is the proposal position x(τ ) and momentum p(τ) of
the particle at time τ.
Given the new location and momentum of the particle, one again computes the Hamiltonian
and accepts the new candidate with probability:
α (x(τ), p(τ), x(0), p(0)) = min {1, exp (H(x(0), p(0)) H(x(τ ), p(τ)))} . (1.42)
If the new candidate is accepted, the next position of the Markov chain is set to x
(t+1)
= x(τ);
if it is rejected, it is set to x
(t+1)
= x
(t)
. It was shown in Neal (2011) that the invariant
distribution of the generated chain is the posterior distribution.
As the Hamiltonian is generally invariant between the initial point H(x(0), p(0)) and last
point H(x(τ ), p(τ)) of the dynamic simulation, the acceptance probability is theoretically
always one (i.e., no proposal points are rejected). Due to the numerical integration carried
out by the leapfrog method this is only true approximately. Nevertheless, the acceptance
probability of Hamiltonian Monte Carlo is typically close to one.
1.3.4 Affine invariant ensemble algorithm
Most MCMC algorithms perform poorly when the target (i.e., posterior) distribution shows
strong correlation between the parameters. The performance of these algorithms can typ-
ically only be improved by considerable amount of tuning. The affine invariant ensemble
algorithm (AIES) originally presented in Goodman and Weare (2010) alleviates this prob-
lem. It has the desirable property of being invariant to affine transformations of the target
distribution. This means that if there exists an affine transformation of the difficult-to-sample
(by standard MCMC methods) target distribution to an easier-to-sample target distribution,
AIES samples both distributions equally easily without explicitly requiring this affine trans-
formation.
The algorithm simultaneously runs an ensemble of C Markov chains {X
1
, . . . , X
C
}, where
each chain is called a walker. The Markov chain locations x
i
are updated walker by walker.
One such update consists of picking randomly a conjugate walker x
(t)
j
from the set of walkers
excluding the current i-th walker (j ̸= i).
The affine invariance property is achieved by generating proposals according to a so-called
stretch move. This refers to proposing a new candidate by:
x
()
i
= x
(t)
i
+ Z ·
x
(
˜
t)
j
x
(t)
i
, (1.43)
where
˜
t = t + 1 if j < i and
˜
t = t otherwise, i.e.it denotes the latest state of the j-th walker.
UQ[PY]LAB-V1.0-113 - 13 -
UQ[PY]LAB user manual
Z is randomly drawn from the PDF
p(z|a) =
1
z(2
a
2
a
)
if z [1/a, a] ,
0 otherwise,
(1.44)
The candidate x
()
i
is then accepted as the new location of the i-th walker with probability:
α
x
()
i
, x
(t)
i
, z
= min
(
1, z
M1
π(x
()
i
|Y)
π(x
(t)
i
|Y)
)
. (1.45)
This is repeated for all C walkers in the ensemble. The resulting chains fulfill the detailed
balance condition and the generated sample can thus be combined to estimate expectations
under the posterior distribution using Eq. (1.31). A practical advantage of the AIES algorithm
is that it only has a single scalar tuning parameter a, which is often set to a = 2 (Goodman
and Weare, 2010; Allison and Dunkley, 2013; Wicaksono, 2017). On the other hand, due to
its sequential nature, the algorithm cannot be parallelized which makes it comparably slow.
1.3.5 Assessing convergence in MCMC simulations
All MCMC algorithms produce chains of sample points that will eventually follow the pos-
terior distribution. In practice, however, one is forced to make decisions about convergence
based on a finite number of sample points. As MCMC algorithms lack a convergence crite-
rion, numerous heuristics have been developed to allow practitioners to assess the quality of
the produced Markov chains.
1.3.5.1 Acceptance rate
The acceptance rate r
a
gives a quantitative indication of how many proposed sample points
were accepted. It can be simply computed as the ratio between the number of accepted
points and the total number of iterations T + 1.
In MCMC algorithms, the acceptance rate depends mostly on their tuning parameters. For
the Metropolis algorithm with a Gaussian proposal, the optimal acceptance rate is shown
to approach r
a
= 0.23 as M (Roberts et al., 1997). For Hamiltonian Monte Carlo
algorithms, it was already mentioned that r
a
is typically close to one. It is difficult to assess
the quality of a generated MCMC chain purely based on the computed acceptance rate, but
it can serve as an indicator of a badly tuned algorithm.
In practical applications, acceptance rates close to one (except in the Hamiltonian Monte
Carlo algorithm) typically indicate that the proposal distribution does not sufficiently explore
the target distribution. Acceptance rates close to zero indicate instead that the proposed
UQ[PY]LAB-V1.0-113 - 14 -
Bayesian inference for model calibration and inverse problems
(a) After 500 steps
(b) After 10
5
steps
Figure 1: Trace plot and corresponding KDE at two different iterations of the chain.
candidate points are in low probability regions. The most common reasons for this are too
wide proposal distributions or proposal distributions that do not sufficiently resemble the
target distributions.
1.3.5.2 Trace and density plots
Trace plots show the evolution of a Markov chain. As chains are typically initialized at ran-
dom points, the evolution of an MCMC chain can give valuable insights about convergence.
Trace plots are typically assessed visually for each dimension individually.
A sample generated by the chain should eventually be distributed according to the posterior
distribution. A kernel density estimation (KDE) scheme (Wand and Jones, 1995) can thus be
employed to obtain an approximation of the posterior marginal. If the chain has reached its
steady state, this KDE of the posterior marginal should not change considerably with further
iterations.
An example of a trace plot with a corresponding KDE is displayed in Figure 1. It can be clearly
seen that the chain has not reached its steady state after 500 steps (Figure 1a) whereas it has
after 10
5
steps (Figure 1b).
UQ[PY]LAB-V1.0-113 - 15 -
UQ[PY]LAB user manual
1.3.5.3 Gelman-Rubin diagnostics
A quantitative approach to assess convergence was introduced by Gelman and Rubin (1992)
and later generalized by Brooks and Gelman (1998). The idea presented there is to compare
a set of C independent Markov chains that were initiated at different seed points. If the
chains are converged, the empirical second moments computed from the individual chains
should be the same as the empirical second moments computed from combining the samples
from all C chains.
Figure 2: Convergence of the MPSRF
ˆ
R
p
.
More formally, let {X
1
, . . . , X
C
} be the C chains run in parallel from different seed points
x
(0)
i
, where each chain X
i
= (x
(0)
i
, . . . , x
(T )
i
) contains T + 1 sample points with x
(t)
i
R
M
.
The Gelman-Rubin diagnostic requires the computation of two covariance matrices. The
covariance matrix of the i-th chain is estimated by:
W
i
=
1
T
T
X
t=0
x
(t)
i
¯
x
i
x
(t)
i
¯
x
i
,
¯
x
i
=
1
T + 1
T
X
t=0
x
(t)
i
. (1.46)
The matrices for all C chains are then averaged to obtain the within-sequence covariance
W R
M×M
:
W =
1
C
C
X
i=1
W
i
. (1.47)
The second matrix required is the so-called between-sequence variance B R
M×M
. It cap-
tures the covariance between the individual MCMC chains and is estimated as:
B =
1
C 1
C
X
i=1
(
¯
x
i
¯
¯
x) (
¯
x
i
¯
¯
x)
, where: (1.48)
¯
¯
x =
1
C(T + 1)
C
X
i=1
T
X
t=0
x
(t)
i
(1.49)
is the average of all (T + 1) states of the C chains. To estimate the difference between the
UQ[PY]LAB-V1.0-113 - 16 -
Bayesian inference for model calibration and inverse problems
within-sequence covariance estimate W and the between-sequence covariance estimate B, the
following multivariate potential scale reduction factor (MPSRF) is proposed in Brooks and
Gelman (1998):
ˆ
R
p
=
T
T + 1
+
C + 1
C
λ
1
, (1.50)
where λ
1
is the largest eigenvalue of the symmetric positive definite matrix W
1
B. This
ˆ
R
p
approaches 1 (from above) with increasing convergence of the MCMC algorithm. This
convergence is showcased for a sample MCMC chain in Figure 2. This method requires a set
of independent, parallel MCMC chains.
1.3.5.4 Burn-in
Once an MCMC chain has reached its steady state, the generated sample follows the posterior
distribution. When, however, a finite number of sample points is used to estimate posterior
properties (e.g. moments), the sample points generated prior to convergence can pollute the
estimation.
It is therefore common practice in practical MCMC applications to discard sample points that
were generated prior to convergence (Brooks et al., 2011). This discarded fraction is called
burn-in.
1.4 Spectral likelihood expansion
A different way to solving Bayesian inverse problem named spectral likelihood expansion
(SLE) was proposed in Nagel and Sudret (2016b). This sampling-free approach uses spectral
expansion techniques such as polynomial chaos expansion (PCE, UQ[PY]LAB User Manual
Polynomial Chaos Expansions) to approximate the likelihood function at the core of Bayesian
inverse problems.
Likelihood functions can be seen as scalar functions of the input random vector X π(x)
with finite output variance (Nagel and Sudret, 2016b). Assuming independent priors, i.e.
π(x) =
Q
M
i=1
π
i
(x
i
), their spectral expansion reads:
L(X) L
SLE
(X)
def
=
X
α∈A
a
α
Ψ
α
(X), (1.51)
where Ψ
α
are basis functions (polynomials in the case of PCE) that are orthogonal w.r.t. the
prior distribution π(x) and c
α
are the corresponding coefficients. Following this approxi-
mation, it becomes possible to exploit the orthogonality of the spectral basis functions to
post-process the expansion coefficients and extract the following important posterior quanti-
ties of interest:
UQ[PY]LAB-V1.0-113 - 17 -
UQ[PY]LAB user manual
Evidence The evidence emerges as the coefficient of the constant polynomial a
0
Z =
Z
D
X
L(x)π(x) dx E [L
SLE
(X)] = a
0
. (1.52)
Posterior Upon computing the evidence Z, the posterior can be evaluated directly through
π(x|Y)
L
SLE
(x)π(x)
Z
=
π(x)
a
0
X
α∈A
a
α
Ψ
α
(x). (1.53)
Posterior marginals An approximation of the univariate posterior marginals defined in Eq. (1.24)
can then also be derived analytically:
π
i
(x
i
|Y) =
Z
D
X
i
π(x|Y) dx
i
π
i
(x
i
)
a
0
X
α∈A
i=0
a
α
Ψ
α
(x
i
), (1.54)
where A
i=0
= {α A: α
j
= 0 j ̸= i}.
Similarly, an expression for the multivariate posterior marginal defined in Eq. (1.25)
can be derived. Denote by π
u
(x
u
)
def
=
Q
iu
π
i
(x
i
) and π
v
(x
v
)
def
=
Q
iv
π
i
(x
i
) the prior
marginal density functions of X
u
and X
v
respectively, the posterior marginal then
reads:
π
u
(x
u
|Y) =
Z
D
X
v
π(x|Y) dx
v
π
u
(x
u
)
a
0
X
α∈A
v=0
a
α
Ψ
α
(x
u
), (1.55)
where A
v=0
= {α A: α
i
= 0 i v}. The series in Eq. (1.54) is a subexpansion
that contains non-constant polynomials only along the dimensions i u.
Quantities of interest It is also possible to analytically compute posterior expectations of
functions that admit a polynomial chaos expansion on the same basis, of the form
h(X)
P
α∈A
b
α
Ψ
α
(X). Eq. (1.26) then reduces to the spectral product:
E [h(X)|Y] =
1
a
0
X
α∈A
a
α
b
α
. (1.56)
This expression can be used to compute posterior moments like mean, variance or
covariance.
The quality of these results depends only on the approximation error introduced in Eq. (1.51).
The latter, in turn, depends mainly on the chosen PCE truncation strategy (Nagel and Su-
dret, 2016b; L
¨
uthen et al., 2020) and the number of points used to compute the coefficients
(i.e. the experimental design). It is known that informative likelihood functions have quasi-
compact supports (i.e. L(X) 0 on a majority of D
X
). Such functions require a very high
polynomial degree to be approximated accurately, which in turn can lead to the need for
prohibitively large experimental designs.
UQ[PY]LAB-V1.0-113 - 18 -
Bayesian inference for model calibration and inverse problems
1.5 Stochastic spectral likelihood embedding
An extension of SLE (see Section 1.4), namely stochastic spectral likelihood embedding (SSLE),
was recently proposed in Wagner et al. (2021). This approach, similarly to SLE, directly ap-
proximates the likelihood function, but replaces the global spectral expansion in Eq. (1.51)
for an SSE metamodel ((Marelli et al., 2021), see also UQ[PY]LAB User Manual Stochas-
tic spectral embedding). Due to their local approximation strength, SSE metamodels are
more suitable for approximating functions with quasi-compact supports than purely global
approximation approaches.
Again, viewing the likelihood as a function of a random vector X with independent compo-
nents, we can write its SSLE representation as:
L(X) L
SSLE
(X)
def
=
X
k∈K
1
D
k
X
(X)
b
R
k
S
(X), (1.57)
where
b
R
k
S
(X) =
X
α∈A
k
a
k
α
Ψ
k
α
(X) (1.58)
are residual expansions.
The variable X is distributed according to the prior distribution π(x) and, consequently, the
local basis Ψ
k
α
is orthonormal w.r.t. that distribution.
Due to the local spectral properties of the residual expansions, the SSLE representation of
the likelihood function retains all of the post-processing properties of SLE (see Section 1.4):
Evidence The normalization constant Z emerges as the sum of the constant polynomial
coefficients weighted by the prior mass:
Z =
X
k∈K
X
α∈A
k
a
k
α
Z
D
k
X
Ψ
k
α
(x)π(x) dx =
X
k∈K
V
k
a
k
0
, where V
k
=
Z
D
k
X
π(x) dx.
(1.59)
Posterior This allows us to write the posterior density as
π(x|Y)
L
SSLE
(x)π(x)
Z
=
π(x)
P
k∈K
V
k
a
k
0
X
k∈K
1
D
k
X
(x)
b
R
k
S
(x). (1.60)
Posterior marginals Utilizing the disjoint sets u and v from Eq. (1.54) it is also possible to
analytically derive posterior marginal PDFs as
π
u
(x
u
|Y) =
Z
D
X
v
π(x|Y) dx
v
π
u
(x
u
)
P
k∈K
V
k
a
k
0
X
k∈K
1
D
k
X
u
(x
u
)
b
R
k
S,u
(x
u
)V
k
v
(1.61)
UQ[PY]LAB-V1.0-113 - 19 -
UQ[PY]LAB user manual
where
b
R
k
S,u
(x
u
) =
X
α∈A
k
v=0
a
k
α
Ψ
k
α
(x
u
) and V
k
v
=
Z
D
k
X
v
π
v
(x
v
) dx
v
. (1.62)
b
R
k
S,u
(x
u
) is a subexpansion of
b
R
k
S
(x) that contains only non-constant polynomials along
the dimensions i u. Note that, as we assumed that the prior distribution has inde-
pendent components, the constants V
k
and V
k
v
are obtained as products of univariate
integrals which are available analytically from the prior marginal cumulative distribu-
tion functions (CDFs).
Quantities of interest Posterior expectations of a function h(x) =
P
α∈A
k
b
k
α
Ψ
k
α
(x) for k
K can be approximated by:
E [h(X)|Y] =
Z
D
X
h(x)π(x|Y) dx
=
1
Z
X
k∈K
X
α∈A
k
a
k
α
Z
D
k
X
h(x
k
α
(x)π(x) dx
=
1
Z
X
k∈K
X
α∈A
k
a
k
α
b
k
α
,
(1.63)
where b
k
α
are the coefficients of the PCE of h in the card(K) bases {Ψ
k
α
}
α∈A
k
. The same
expression can also be used for computing posterior moments like mean, variance or
covariance.
These expressions can be seen as a generalization of the ones for SLE detailed in Section 1.4.
For a single-level global expansion (i.e. card(K) = 1) and consequently V
(0,1)
= 1, they are
identical.
1.5.1 Sequential partitioning algorithm
The algorithm to construct SSEs implemented in UQ[PY]LAB is called sequential partitioning
algorithm. It sequentially partitions selected refinement domains and constructs local expan-
sions of the residual to ultimately produce a likelihood approximation of the form shown in
Eq. (1.57). This algorithm is explained in detail in the UQ[PY]LAB User Manual – Stochastic
spectral embedding. In Wagner et al. (2021), modifications to this algorithm were proposed
that were shown to improve the SSE approximation accuracy for likelihood functions in SSLE.
These modifications pertain to the partitioning and sample enrichment strategies.
1.5.1.1 Partitioning strategy
The partitioning strategy determines how a selected refinement domain is split. For likelihood
functions, it was proposed in Wagner et al. (2021) to pick the split direction along which a
UQ[PY]LAB-V1.0-113 - 20 -
Bayesian inference for model calibration and inverse problems
(a) Refinement domain (b) Split along d = 1 (c) Split along d = 2 (d) Selected pair
Figure 3: Partitioning strategy for a 2D example visualized in the quantile space U . The
refinement domain D
ℓ,p
U
is split into two subdomains D
+1,s
1
U
and D
+1,s
2
U
.
split yields a maximum difference in the residual empirical variance between the two candi-
date subdomains created by the split. This can easily be visualized with an example given by
the M = 2 dimensional domain D
ℓ,p
X
in Figure 3a. Assume this subdomain was selected as
the refinement domain. To decide along which dimension to split, we construct the M candi-
date subdomain pairs {D
i,1
split
, D
i,2
split
}
i=1,...,M
and estimate the corresponding {E
i
split
}
i=1,...,M
in those subdomains defined by
E
i
split
def
=
Var
h
R
+1
(X
i,1
split
)
i
Var
h
R
+1
(X
i,2
split
)
i
. (1.64)
In this expression, X
i,1
split
and X
i,2
split
denote subsets of the experimental design X that lie within
the subdomains D
i,1
split
and D
i,2
split
respectively. The corresponding variances can be estimated
with the empirical variance of the residuals in the respective candidate subdomains.
After computing the residual variance differences, the split is carried out along dimension
d = arg max
i∈{1,...,M}
E
i
split
, (1.65)
i.e. to keep the subdomains D
d,1
split
and D
d,2
split
that introduce the largest difference in variance.
For d = 1, the resulting split can be seen in Figure 3d.
1.5.1.2 Sample enrichment
Likelihood functions are typically not equally informative at every point of the input space.
On the contrary, it is often the case that large input regions are close to zero, while only a
small subdomain of the input space yields likelihood responses that are multiple orders of
magnitude larger.
It was shown in Wagner et al. (2021) that it is therefore more efficient in terms of total
number of likelihood evaluations, to sequentially sample the experimental design in SSLE.
The rationale is to enrich the experimental design only in domains that have been selected
for refinement. Informative regions of the likelihood function (that are more difficult to ap-
UQ[PY]LAB-V1.0-113 - 21 -
UQ[PY]LAB user manual
proximate) will then receive a greater share of likelihood evaluations, because the refinement
domain selection in the sequential partitioning algorithm is based on the local approximation
error.
UQ[PY]LAB-V1.0-113 - 22 -
Chapter 2
Usage
In this chapter the implementation of Bayesian inversion as discussed in Chapter 1 is de-
scribed. A simple engineering inverse problem is solved with UQ[PY]LAB to exemplify the
usage of the Bayesian inversion module. This simple example is then extended to treat more
complex problems.
2.1 Reference problem: calibration of a simply supported beam
model
We consider a simply-supported beam such as the one shown in Figure 4. The beam has a
known rectangular cross-section of width b and height h and a known span of length L.
Figure 4: Simple beam bending test.
A set of N = 5 independent experiments are carried out with this beam, with the goal of
inferring the unknown material stiffness, i.e. its Young’s modulus E. In the experiments,
the beam is subject to a constant distributed load p and the mid-span deflection V
mid
is mea-
sured. The measurements are reported in Table 1. Due to measurement error, the measured
deflections vary across experiments.
Table 1: Beam deflection: measured deflections.
Experiment 1 2 3 4 5
V
mid
(mm) 12.84 13.12 12.13 12.19 12.67
23
UQ[PY]LAB user manual
The parameters (b, h, L, p) are considered known and their values are given in Table 2.
Table 2: Beam experiments: nominal values of the beam properties.
Variable Nominal Value
b (m) 0.15
h (m) 0.3
L (m) 5
p (N/m) 12 000
The analytical expression for the mid-span deflection V
mid
of the beam according to the stan-
dard beam theory is:
V
mid
=
5
32
pL
4
Ebh
3
. (2.1)
This simple equation serves as the forward model and relates the unknown Young’s modulus
to the measurable mid-span deflection.
Additionally, it is known from prior experiments that the Young’s modulus of the material
follows a lognormal distribution:
E LN (λ, ζ), with µ
E
= 30 (GPa) and σ
E
= 4.5 (GPa). (2.2)
In Bayesian inversion terms, the prior information on the model parameter x
M
E is E
LN (λ, ζ). Due to a lack of more information, an unknown additive Gaussian experimental
discrepancy model is assumed. As a weakly informative prior on the positive discrepancy
variance x
ε
σ
2
, a uniform distribution σ
2
U(0, µ
2
V
mid
) with µ
V
mid
equal to the empirical
mean of the observations given in Table 1.
2.2 Problem setup and solution
Solving an inverse problem with the Bayesian inverse module of UQ[PY]LAB typically re-
quires the specification of a prior distribution π(x), N independent observations Y = {y
1
, . . . , y
N
},
where y
i
R
N
out
and a forward model M. All these ingredients are briefly discussed in this
section.
2.2.1 Initialize UQ[PY]LAB
The first step is to initialize UQ[PY]LAB and fixing a random seed for reproducibility:
# Package imports
from uqpylab import sessions
import numpy as np
# Start the session
mySession = sessions.cloud()
UQ[PY]LAB-V1.0-113 - 24 -
Bayesian inference for model calibration and inverse problems
# (Optional) Get a convenient handle to the command line interface
uq = mySession.cli
# Reset the session
mySession.reset()
# Set the random seed for reproducibility
uq.rng(100, 'twister');
2.2.2 Specify a prior distribution
The prior distribution of the model parameters is defined as an INPUT object by:
PriorOpts = {
"Marginals": [
{
"Name": "b", # beam width
"Type": "Constant",
"Parameters": [0.15] # (m)
},
{
"Name": "h", # beam height
"Type": "Constant",
"Parameters": [0.3] # (m)
},
{
"Name": "L", # beam length
"Type": "Constant",
"Parameters": [5] # (m)
},
{
"Name": "E", # Young's modulus
"Type": "LogNormal",
"Moments": [30e9,4.5e9] # (N/mˆ2)
},
{
"Name": "p", # constant distributed load
"Type": "Constant",
"Parameters": [12000] # (N/m)
}
]
}
myPriorDist = uq.createInput(PriorOpts)
As the prior distribution is specified as an INPUT object, all the features of the UQ[PY]LAB
INPUT module (UQ[PY]LAB User Manual – the INPUT module) can be used, i.e., constant and
marginal distributions of any kind (including user-defined ones). Dependence may also be
specified using copulas.
Note: The known parameters from Table 2 are defined as Constant input marginals
and will not be considered during the calibration procedure, except when evalu-
ating the forward model.
UQ[PY]LAB-V1.0-113 - 25 -
UQ[PY]LAB user manual
2.2.3 Create a forward model
The computational model, given in Eq. (2.1), is defined as a Python file called
SimplySupportedBeam.py which you can download on https://uqpylab.uq-cloud.
io/examples. A UQ[PY]LAB MODEL is then created as:
ModelOpts = {
'Type': 'Model',
'Name': 'Forward model',
'ModelFun': 'SimplySupportedBeam.model'
}
myForwardModel = uq.createModel(ModelOpts)
For more details about the configuration options available for a MODEL object, please refer to
the UQ[PY]LAB User Manual – the MODEL module.
2.2.4 Provide measurements
The measurements Y are stored in an N × N
out
list of lists V_mid, where N
out
is the number
of model outputs:
V_mid = np.array([12.84, 13.12, 12.13, 12.19, 12.67])/1000 # (m)
myData = {
'y': V_mid.tolist(),
'Name': 'Beam mid-span deflection'
}
Note: In the present case where N
out
= 1, this list of lists reduces to a list.
2.2.5 Perform the Bayesian inverse analysis
The options are then gathered in a Python dictionary, here called BayesOpts:
BayesOpts = {
'Type': 'Inversion',
'Data': myData
}
The BayesOpts dictionary contains all information required to solve the inverse problem.
If not explicitly specified by the user, by default the Bayesian inversion module uses the last
created INPUT object (in this case myPriorDist) as a prior distribution and the last created
MODEL object (in this case myForwardModel) as the forward model. Therefore, to perform
the analysis, it is sufficient to create the corresponding ANALYSIS object:
myBayesianAnalysis = uq.createAnalysis(BayesOpts)
UQ[PY]LAB-V1.0-113 - 26 -
Bayesian inference for model calibration and inverse problems
Note: Without an explicitly-specified discrepancy model, UQ[PY]LAB assumes by de-
fault an unknown additive Gaussian discrepancy term, with a single unknown
residual parameter x
ε
σ
2
. The prior distribution of σ
2
is a weakly informative
uniform distribution σ
2
U(0, µ
2
Y
) with µ
Y
equal to the empirical mean of the
provided data Y.
Note: If not otherwise specified UQ[PY]LAB uses the affine invariant ensemble sampler
(Section 1.3.4) with C = 100 parallel chains and initial points drawn from the
prior distribution and performs T = 300 iterations.
The sample set generated by MCMC algorithms often needs to be post-processed before it
can be used as a true posterior sample (e.g., to remove burn-in, Section 1.3.5.4). By default
in UQ[PY]LAB the first half of the sample points generated by all chains are removed as
burn-in (see Section 1.3.5.4) and the empirical parameter mean E [X |Y] along with the
2.5th to 97.5th percentile based on the post-processed sample are estimated. Additionally,
samples from the prior distribution and from the posterior predictive distribution are drawn
(see Section 1.2.6) and stored in the myBayesianAnalysis object. For all available post-
processing options see Section 2.4.1.6 and Section 3.3.
A brief report of the analysis can then be generated by:
uq.print(myBayesianAnalysis)
which produces:
%----------------------- Inversion output -----------------------%
Number of calibrated model parameters: 1
Number of non-calibrated model parameters: 4
Number of calibrated discrepancy parameters: 1
%------------------- Data and Discrepancy
% Data-/Discrepancy group 1:
Number of independent observations: 5
Discrepancy:
Type: Gaussian
Discrepancy family: Scalar
Discrepancy parameters known: No
Associated outputs:
Model 1:
Output dimensions: 1
%------------------- Solver
Solution method: MCMC
Algorithm: AIES
Duration (HH:MM:SS): 00:00:55
Number of sample points: 3.00e+04
%------------------- Posterior Marginals
---------------------------------------------------------------------
UQ[PY]LAB-V1.0-113 - 27 -
UQ[PY]LAB user manual
| Parameter | Mean | Std | (0.025-0.975) Quant. | Type |
---------------------------------------------------------------------
| E | 2.4e+10 | 1.7e+09 | (2.2e+10 - 2.9e+10) | Model |
| Sigma2 | 3.7e-06 | 1.1e-05 | (1.1e-07 - 2.8e-05) | Discrepancy |
---------------------------------------------------------------------
%------------------- Point estimate
----------------------------------------
| Parameter | Mean | Parameter Type |
----------------------------------------
| E | 2.4e+10 | Model |
| Sigma2 | 3.7e-06 | Discrepancy |
----------------------------------------
The results can also be visualized by:
uq.display(myBayesianAnalysis)
which produces the images in Figure 5.
2.2.6 Advanced options: discrepancy model
The discrepancy model defines the connection between the supplied data and the forward
model. The Bayesian module of UQ[PY]LAB currently supports the option to specify a
Gaussian additive discrepancy as defined in Eq. (1.12).
In real applications, it is often beneficial to specify more accurately the discrepancy model.
The options are to either specify a known residual variance σ
2
(e.g. tabulated measurement
discrepancies from the instrument supplier) or an unknown x
ε
= σ
2
which can be inferred
together with the model parameters x
M
.
2.2.6.1 Known residual variance
If the variance is known a priori, as detailed in Section 1.2.2, it can be directly defined in an
DiscrepancyOpts dictionary (assuming that σ
2
= 10
7
(m
2
)):
DiscrepancyOpts = {
'Type': 'Gaussian',
'Parameters': 1e-7 # (mˆ2)
}
Which is then passed to BayesOpts by:
BayesOpts['Discrepancy'] = DiscrepancyOpts
UQ[PY]LAB-V1.0-113 - 28 -
Bayesian inference for model calibration and inverse problems
(a) Scatterplots of prior and posterior sample with the posterior mean point estimator from (1.31).
(b) Posterior predictive distribution from (1.28), data, and model at mean pre-
diction obtained by propagating the mean point estimator through the forward
model.
Figure 5: Visualize analysis: The results of the Bayesian inverse analysis on the input and the
model predictions.
UQ[PY]LAB-V1.0-113 - 29 -
UQ[PY]LAB user manual
2.2.6.2 Unknown residual variance
If σ
2
is not known a priori, as detailed in Section 1.2.3, the Bayesian framework can infer the
distribution of the discrepancy parameter x
ε
σ
2
. This requires the initial specification of a
prior distribution of the discrepancy parameter π(σ
2
) (see Eq. (1.2)).
The prior distribution of the parameter π(σ
2
) can be defined as a UQ[PY]LAB INPUT object
and then assigned to the DiscrepancyOpts dictionary’s Prior key:
DiscrepancyPriorOpts = {
'Name': 'Prior of discrepancy parameter',
'Marginals': {
'Name': 'Sigma2',
'Type': 'Uniform',
'Parameters': [0, np.mean(V_mid)
**
2]
}
}
myDiscrepancyPrior = uq.createInput(DiscrepancyPriorOpts)
DiscrepancyOpts = {
'Type': 'Gaussian',
'Prior': myDiscrepancyPrior['Name']
}
Which is then passed to BayesOpts by:
BayesOpts['Discrepancy'] = DiscrepancyOpts
If multiple UQ[PY]LAB INPUT objects are defined, the prior distribution must be specified by:
BayesOpts['Prior'] = myPriorDist['Name']
Note: Here a uniform prior on σ
2
with bounds U(0, µ
2
V
mid
) is implemented. This is the
default (see above Section 2.2.5) when no discrepancy options are provided.
Note: As the prior π(σ
2
) is defined for the variance σ
2
, only distributions with positive
support can be used here.
2.3 Multiple model outputs
Models with multiple outputs are often encountered in real calibration problems. These mul-
tiple outputs can be different measurable quantities (e.g., temperature and displacement),
quantities at different locations (e.g., deformations at different physical points), or at differ-
ent times (e.g., time series).
To show how such problems can be treated in UQ[PY]LAB, the reference problem from
UQ[PY]LAB-V1.0-113 - 30 -
Bayesian inference for model calibration and inverse problems
Section 2.1 is slightly extended. It is assumed that additionally to measurements of the
deflection at the beam mid-span at L/2, measurements are also available at L/4 as shown in
Figure 6.
Figure 6: Simple beam bending test.
The N = 5 measurements of the deflections V
mid
and V
L/4
are given in Table 3.
Table 3: Beam deflection: measured deflections.
Experiment 1 2 3 4 5
V
L/4
(mm) 8.98 8.66 8.85 9.19 8.64
V
mid
(mm) 12.84 13.12 12.13 12.19 12.67
Similarly to (2.1), the quarter deflection at L/4 can be computed analytically by the standard
beam theory:
V
L/4
=
57
512
pL
4
Ebh
3
. (2.3)
Again due to a lack of information on the discrepancy, two independent unknown experimen-
tal discrepancies ε
1
and ε
2
are assumed for the measured displacements V
mid
and V
L/4
, re-
spectively. As a weakly informative prior on the positive discrepancy variances x
ε
= (σ
2
1
, σ
2
2
),
two independent uniform distributions π(σ
2
i
) = U(0, µ
2
Y
i
) are chosen with µ
Y
i
equal to the
mean of the observations V
mid
and V
L/4
respectively (see Table 3).
2.3.1 Create a forward model
The equations for the beam mid-span (L/2) and quarter-span (L/4) deflection, given in
Eqs. (2.1) and (2.3), are implemented as a Python file called
SimplySupportedBeamTwo.py which you can download on https://uqpylab.uq-cloud.
io/examples. This function returns the two beam deflections for a single model parameter
realization x
M
in a row list of length N
out
= 2.
This is added to UQ[PY]LAB with the following commands:
ModelOpts = {
'Type': 'Model',
'Name': 'Forward model',
'ModelFun': 'SimplySupportedBeamTwo.model'
}
myForwardModel = uq.createModel(ModelOpts)
UQ[PY]LAB-V1.0-113 - 31 -
UQ[PY]LAB user manual
2.3.2 Provide measurements
The measurements are stored in an N × N
out
list of lists V and assigned to the BayesOpts
object:
V = np.array([[8.98, 8.66, 8.85, 9.19, 8.64], # L/4 (m)
[12.84, 13.12, 12.13, 12.19, 12.67]])/1000 # L/2 (m)
V = V.T # NxN_out array, where N_out is the number of model outputs
myData = {
'y': V.tolist(),
'Name': 'Beam quarter and midspan deflection',
}
Note: By default, UQ[PY]LAB assigns the i-th list of the list to the i-th output of the
forward model. For more advanced options, refer to Section 2.3.4.3.
Note: Without an explicitly-specified discrepancy model, the Bayesian inversion module
by default assumes unknown additive Gaussian discrepancies for all N
out
outputs
of the forward model, with the residual parameter vector x
ε
= (σ
2
1
, . . . , σ
2
N
out
).
The prior distribution is by default taken as independent uniform distributions
π(x
ε
) =
Q
N
out
i=1
π(σ
2
i
) where π(σ
2
i
) = U(0, µ
2
Y
i
) with µ
Y
i
equal to the empirical
mean of measurements available for the i-th output dimension.
2.3.3 Perform the inverse analysis
The analysis can be run with:
myBayesianAnalysis = uq.createAnalysis(BayesOpts)
To generate a prior predictive sample, call:
myBayesianAnalysis = uq.postProcessInversion(myBayesianAnalysis,
'priorPredictive',1000)
see Section 2.4.1.6 and Section 3.3 for all available post-processing options.
After the myBayesianAnalysis object is created, the results can be summarized with:
uq.print(myBayesianAnalysis)
which produces the report:
%----------------------- Inversion output -----------------------%
Number of calibrated model parameters: 1
Number of non-calibrated model parameters: 4
Number of calibrated discrepancy parameters: 2
%------------------- Data and Discrepancy
% Data-/Discrepancy group 1:
UQ[PY]LAB-V1.0-113 - 32 -
Bayesian inference for model calibration and inverse problems
Number of independent observations: 5
Discrepancy:
Type: Gaussian
Discrepancy family: Row
Discrepancy parameters known: No
Associated outputs:
Model 1:
Output dimensions: 1
2
%------------------- Solver
Solution method: MCMC
Algorithm: AIES
Duration (HH:MM:SS): 00:00:46
Number of sample points: 3.00e+04
%------------------- Posterior Marginals
---------------------------------------------------------------------
| Parameter | Mean | Std | (0.025-0.975) Quant. | Type |
---------------------------------------------------------------------
| E | 2.3e+10 | 6.6e+08 | (2.2e+10 - 2.5e+10) | Model |
| Sigma2 | 2e-06 | 6.3e-06 | (3.3e-08 - 1.8e-05) | Discrepancy |
| Sigma2 | 4.5e-06 | 1.2e-05 | (1.2e-07 - 3.6e-05) | Discrepancy |
---------------------------------------------------------------------
%------------------- Point estimate
----------------------------------------
| Parameter | Mean | Parameter Type |
----------------------------------------
| E | 2.3e+10 | Model |
| Sigma2 | 2e-06 | Discrepancy |
| Sigma2 | 4.5e-06 | Discrepancy |
----------------------------------------
%------------------- Correlation matrix (discrepancy parameters)
-------------------------------
| | Sigma2 Sigma2 |
-------------------------------
| Sigma2 | 1 -0.045 |
| Sigma2 | -0.045 1 |
-------------------------------
and visualized graphically with:
uq.display(myBayesianAnalysis)
which produces a set of plots similar to those in Figure 7.
2.3.4 Advanced options: discrepancy model
In the case of models with multiple outputs, the full covariance matrix Σ of the residual
discrepancy vector ε = (ε
i
, . . . , ε
N
out
) has to be defined for the likelihood function. In this
UQ[PY]LAB-V1.0-113 - 33 -
UQ[PY]LAB user manual
(a) Scatterplots of prior and posterior sample with the posterior mean point estimator from (1.31).
(b) Prior and posterior predictive distributions from (1.27) and (1.28), data,
and model at mean prediction obtained by propagating the mean point estima-
tor through the forward model.
Figure 7: Advanced discrepancy options: The results of the Bayesian inverse analysis on the
input and the model predictions.
UQ[PY]LAB-V1.0-113 - 34 -
Bayesian inference for model calibration and inverse problems
section, all options that are available in the UQ[PY]LAB Bayesian inversion module to define
this covariance matrix are presented:
1. Known residual variance: Section 2.3.4.1, see also Section 1.2.2
2. Unknown residual variance: Section 2.3.4.2, see also Section 1.2.3
3. Data and discrepancy groups: Section 2.3.4.3
2.3.4.1 Known residual variance
In special cases, the residual variance may be known. This can happen when the forward
model is supposed to perfectly represent the experimental setup, and when the discrepancy
term reduces to measurement error. If the variance of this error is provided by the instrument
supplier, it can be directly used to specify the covariance matrix Σ of the residual vector
ε = (ε
1
, . . . , ε
N
out
). This known covariance matrix can be specified in three different ways in
the Bayesian module of UQ[PY]LAB.
Independent and identically distributed ε
i
: In the case when all elements ε
i
of the resid-
ual vector ε independently follow the same distribution N (0, σ
2
) with a known variance σ
2
(e.g., σ
2
= 10
7
(m
2
)), this can specified by a DiscrepancyOpts dictionary like
DiscrepancyOpts = {
'Type': 'Gaussian',
'Parameters': 1e-7 # single scalar
}
This dictionary is then passed to BayesOpts as follows:
BayesOpts['Discrepancy'] = DiscrepancyOpts
Independent ε
i
: If each element of the residual vector ε
i
follows a Normal distribution
N (0, σ
2
i
) with a specific known residual variance σ
2
i
, but independence can still be assumed,
the DiscrepancyOpts dictionary can be defined as:
DiscrepancyOpts = {
'Type': 'Gaussian',
'Parameters': [[1e-7, 5e-7]] # row vector of length N_out
}
where the length of the Parameters list is equal to N
out
.
Dependent ε
i
: In the general case where a known Gaussian distribution can be assumed
for the discrepancy term, the covariance matrix can be passed to UQ[PY]LAB as follows:
UQ[PY]LAB-V1.0-113 - 35 -
UQ[PY]LAB user manual
DiscrepancyOpts = {
'Type': 'Gaussian',
'Parameters': [[1e-7, -5e-8],[-5e-8, 5e-7]] # N_out x N_out matrix
# passed as a nested list
}
This covariance matrix introduces negative correlation between the first and second discrep-
ancy parameter σ
2
1
and σ
2
2
. Any positive-definite matrix can be used as a covariance matrix.
2.3.4.2 Unknown residual variance
In most practical applications, the parameters σ
2
i
are not known a priori. As detailed in Sec-
tion 1.2.3, the Bayesian framework can infer the distribution of the discrepancy parameters
gathered in x
ε
. This requires the initial specification of a prior distribution of the discrep-
ancy parameters π(x
ε
) (see Eq. (1.2)). Similarly to the previous section, there are different
ways of specifying an unknown variance parameter σ
2
i
, depending on the distribution of the
residuals ε
i
.
Note: In contrast to the known residual variance case (see Section 2.3.4.1), the def-
inition of dependent unknown discrepancy terms ε
i
(see Section 2.3.4.1) is not
currently supported.
If an unknown residual variance is used, it becomes necessary to explicitly assign the INPUT
object defining the prior of the model parameters π(x
M
) to the BayesOpts dictionary. This
is necessary to avoid confusions between the model parameter INPUT and error parameter
INPUT objects. It can be assigned by:
BayesOpts['Prior'] = myPriorDist['Name']
Independent and identically distributed ε
i
: If the residuals of all observations are inde-
pendent and identically distributed, a single unknown variance parameter σ
2
can be used in
the distribution of all residuals ε
i
. The prior distribution of the parameter π(σ
2
) can be de-
fined as a UQ[PY]LAB INPUT object and then assigned to the DiscrepancyOpts dictionary:
DiscrepancyPriorOpts = {
'Name': 'Prior of discrepancy parameter',
'Marginals': {
'Name': 'Sigma2',
'Type': 'Uniform',
'Parameters': [0, 1e-4] # (mˆ2)
}
}
myDiscrepancyPrior = uq.createInput(DiscrepancyPriorOpts)
DiscrepancyOpts = {
'Type': 'Gaussian',
UQ[PY]LAB-V1.0-113 - 36 -
Bayesian inference for model calibration and inverse problems
'Prior': myDiscrepancyPrior['Name']
}
Here a uniform prior π(σ
2
) = U(0, 10
4
) (m
2
) is chosen.
Note: As the prior π(σ
2
) is defined for the variance σ
2
, only distributions with positive
support can be used here.
Independent ε
i
: If the residuals are independent but not identically distributed, the user
can specify a dedicated discrepancy distribution for each σ
2
i
. In the present case of N
out
= 2,
two independent prior distributions π(σ
2
i
) for the discrepancy parameters have to be speci-
fied. For the sake of illustration a lognormal prior is chosen for σ
2
1
and a uniform prior for σ
2
2
in the following code:
DiscrepancyPriorOpts = {
'Name': 'Prior of discrepancy parameter',
'Marginals': [
{
'Name': 'Sigma2_1',
'Type': 'Lognormal',
'Moments': [1e-5, 5e-6] # (mˆ2)
},
{
'Name': 'Sigma2_2',
'Type': 'Uniform',
'Parameters': [0, 1e-4] # (mˆ2)
}
]
}
myDiscrepancyPrior = uq.createInput(DiscrepancyPriorOpts)
DiscrepancyOpts = {
'Type': 'Gaussian',
'Prior': myDiscrepancyPrior['Name']
}
2.3.4.3 Data and discrepancy groups
It often occurs in inverse problems that different types or number of data are collected for in-
dividual model outputs. In this case, it is often also necessary to define dedicated discrepancy
options for individual outputs y
i
(see Section 1.2.4).
In UQ[PY]LAB this is achieved through so-called data- and discrepancy groups. The groups
are defined by specifying the DiscrepancyOpts and Data as list of dictionaries, rather than
simple dictionaries. All options that were discussed in the previous sections can then be
assigned to each dictionary in this array independently.
Consider the following case: for the first residual ε
1
the variance σ
2
is known to be σ
2
1
=
UQ[PY]LAB-V1.0-113 - 37 -
UQ[PY]LAB user manual
10
7
(m
2
), while for the second residual ε
2
the variance σ
2
2
is unknown and assigned a
uniform distribution σ
2
2
U(0, 10
4
) (m
2
). These discrepancy options can be passed to
UQ[PY]LAB by defining N
gr
= 2 dedicated DiscrepancyOpts and Data dictionaries in the
following way:
# group 1
V_quart = np.array([10.51, 9.60, 10.22, 8.16, 7.47])/1000 # L/4 (m)
Data = [
{
'y': V_quart.tolist(),
'Name': 'Deflection measurements at L/4',
'MOMap': [1] # Model Output Map
}
]
DiscrepancyOpts = [
{
'Type': 'Gaussian',
'Parameters': 1e-7 # (mˆ2)
}
]
# group 2
V_mid = np.array([12.59, 11.23, 15.28, 12.45, 13.21])/1000; # L/2 (m)
Data.append(
{
'y': V_mid.tolist(),
'Name': 'Deflection measurements at L/2',
'MOMap': [2] # Model Output Map
}
)
DiscrepancyPriorOpts = {
'Name': 'Prior of sigma',
'Marginals': {
'Name': 'Sigma2_2',
'Type': 'Uniform',
'Parameters': [0, 1e-4], # (mˆ2)
}
}
DiscrepancyPrior = uq.createInput(DiscrepancyPriorOpts)
DiscrepancyOpts.append(
{
'Type': 'Gaussian',
'Prior': DiscrepancyPrior['Name']
}
)
To link the defined group pairs with the model outputs, every Data dictionary requires a
MOMap List that maps the output indices i {1, . . . , N
out
} to the respective group.
Through the use of data and discrepancy groups, it also becomes possible to address problems
where the number of measurements is not the same for each model output.
A simple example on how to use the MOMap array is given in Example 4 of the Bayesian
inversion module (04-PredPrey.ipynb).
UQ[PY]LAB-V1.0-113 - 38 -
Bayesian inference for model calibration and inverse problems
Note: The output IDs specified in the MOMap list are not unique. By giving the same
index in the MOMap vectors of different data groups, it becomes possible to cali-
brate the same computational model using measurements gathered in different
experiments.
2.4 Advanced options: solver
In the previous sections, the solver was not explicitly specified. By default UQ[PY]LAB uses
an MCMC algorithm with the affine invariant ensemble sampler (see Section 1.3.4) with
a = 2.
The Bayesian module offers four different solvers that are described in more detail next:
MCMC: Section 2.4.1
SLE: Section 2.4.2
SSLE: Section 2.4.3
None: Section 2.4.4
2.4.1 MCMC
Currently, four MCMC samplers are shipped with the inversion module of UQ[PY]LAB:
Metropolis Hastings (MH), Adaptive-Metropolis (AM), Hamiltonian Monte Carlo (HMC) and
affine invariant ensemble sampler (AIES). Their theoretical foundations are detailed in Sec-
tion 1.3. An exhaustive list of all available options is given in Section 3.1.4.
To select an MCMC sampler, the following keys have to be specified:
Solver = {
'Type': 'MCMC',
'MCMC': {
'Sampler': 'MH', # AM, HMC, AIES
}
}
The number of iterations done by the sampler is given as a scalar in the Steps key:
Solver['MCMC']['Steps'] = 200
Note that the cost per iteration depends on the specific sampler (see Section 1.3). All MCMC
samplers require a set of initial seeds for the individual chains. These seeds are specified
through an M × C List of lists Seed, where C is the number of desired parallel chains:
Solver['MCMC']['Seed'] = Seed
UQ[PY]LAB-V1.0-113 - 39 -
UQ[PY]LAB user manual
Alternatively it is also possible to just pass the number of chains C to the solver by passing a
scalar value to the NChains key. For C = 20 this can be done by:
Solver['MCMC']['NChains'] = 20
The Bayesian module then automatically samples seeds from the prior distribution π(x).
The key Sampler specifies the sampling algorithm. The options are MH (Metropolis-Hastings,
Section 1.3.1), AM (adaptive Metropolis, Section 1.3.2), HMC (Hamiltonian Monte Carlo, Sec-
tion 1.3.3), and AIES (affine invariant ensemble sampler, Section 1.3.4). Depending on the
sampler, different options can be specified that are discussed in more detail next.
2.4.1.1 Metropolis-Hastings algorithm
The only parameter of the Metropolis-Hastings algorithm is the proposal distribution (see
Section 1.3.1 and Table 12), which can be specified by defining a myProposal dictionary
(see also Table 14).
If the algorithm is to use a Gaussian proposal distribution centered at the previous sample
(standard random walk algorithm), the myProposal dictionary should only contain one key
PriorScale that can, for instance, be set to:
myProposal = {'PriorScale': 0.1}
This PriorScale is then used to define a covariance matrix Σ
p
as a diagonal matrix propor-
tional to the M prior marginal variances. Alternatively this covariance matrix can also be
fully specified:
myProposal = {'Cov': Cov}
where Cov is an M × M positive-definite matrix.
Alternatively, if more advanced (e.g. non-Gaussian) proposal distributions are required, the
myProposal dictionary can also contain two keys:
myProposal = {
'Distribution': myProposalDistribution['Name'],
'Conditioning': 'Previous' # Other valid option: 'Global'
}
where myProposalDistribution is a UQ[PY]LAB INPUT object (UQ[PY]LAB User Manual
the INPUT module). The key Conditioning can either be set to 'Global' (default), to
draw proposals from the distribution specified by myProposalDistribution independently
of the previous sample point, or to 'Previous', which sets the mean value of the proposal
distribution to the previous sample point in every step.
UQ[PY]LAB-V1.0-113 - 40 -
Bayesian inference for model calibration and inverse problems
Note: A proposal distribution specified with the 'Previous' option can be very slow
compared to 'Global' proposals. Unless there is a justified reason to use this
option it is thus not recommended.
Finally, the proposal dictionary needs to be assigned to the Solver['MCMC']['Proposal']
key:
Solver['MCMC']['Proposal'] = myProposal
2.4.1.2 Adaptive Metropolis algorithm
The adaptive Metropolis algorithm takes the keys Proposal, T0, and Epsilon (see also
Table 13). They can be, for example, set to:
SolverMCMC = {
'Proposal': myProposal,
'MCMC': {
'T0': 1e2,
'Epsilon': 1e-4
}
}
where the myProposal dictionary can be specified as detailed in Section 2.4.1.1 and T0 is
the number of iterations t
0
during which the sampler uses the supplied proposal distribu-
tion myProposal before switching to the Gaussian distribution with the empirical covariance
matrix as detailed in Eq. (1.34). The small number Epsilon specifies the ϵ added to the
empirical correlation matrix to avoid singularity (see Section 1.3.2). If it is not specified, it is
automatically set to ϵ = 10
6
.
2.4.1.3 Hamiltonian Monte Carlo algorithm
The parameters of the Hamiltonian Monte Carlo algorithm are (see also Table 15):
SolverMCMC = {
'MCMC': {
'LeapfrogStep': 40,
'LeapfrogSize': 0.1,
'Mass': 1
}
}
with the number of leapfrog steps LeapfrogSteps (N
τ
), the leapfrog step size LeapfrogSize
(
τ
N
τ
), and the mass matrix M (see Section 1.3.3).
The mass matrix can be passed as a scalar value m, in which case the mass matrix takes the
form M = mI
M
or directly as an M × M matrix.
UQ[PY]LAB-V1.0-113 - 41 -
UQ[PY]LAB user manual
2.4.1.4 Affine invariant ensemble algorithm
The only parameter of the affine invariant ensemble algorithm is the scalar a (see also Ta-
ble 16). It can be set to any scalar parameter a > 1, for example for a = 3:
SolverMCMC = {'MCMC': {'a': 3}}
This defines the parameter used for the stretch move distribution in Eq. (1.43). If this param-
eter is not set, a value of a = 2 is assumed in accordance with Goodman and Weare (2010);
Allison and Dunkley (2013); Wicaksono (2017).
2.4.1.5 Visualization
UQ[PY]LAB currently does not offer the option to enable live trace plots during runtime.
However, it is possible to display trace plots to assess convergence after the analysis is per-
formed by using the following command:
uq.display(myBayesianAnalysis,trace='all')
This command displays all available traces. You can also specify desired traces using the
trace parameter. For instance, you can use trace=1 to display only the trace for the first
marginal or trace=[1,3] to display traces for the first and the third marginals. The resulting
plot will be similar to the one shown in Figure 8.
Figure 8: Trace plot and corresponding KDE after execution of the MCMC algorithm.
2.4.1.6 Post-processing
Following the analysis, the sample points generated by the MCMC algorithm are stored in
the Results key of the myBayesianAnalysis dictionary:
{
UQ[PY]LAB-V1.0-113 - 42 -
Bayesian inference for model calibration and inverse problems
'Sample': [[[...], [...]], [[...], [...]], ..., [[...], [...]]],
'Acceptance': [...],
'Time': ...,
'ForwardModel': {'evaluation': [[...], [...], ..., [...]]},
'LogLikeliEval': [[...], [...], ..., [...]],
'PostProc': {...}
}
The sample points are stored in the 3D list Sample with a regular shape T × M × C. The
associated forward model and log likelihood evaluations are stored in the ForwardModel
dictionary and LogLikeliEval list of lists with a regular shape T × C respectively.
Sample points generated by MCMC algorithms typically require post-processing before they
can be used as a true posterior sample. In the Bayesian module of UQ[PY]LAB this post-
processing is automatically done with the uq.postProcessInversionMCMC function that is
called for MCMC analyses by the wrapper function:
myBayesianAnalysis = uq.postProcessInversion(myBayesianAnalysis)
This function is called automatically after every analysis and performs a set of default post-
processing procedures: the first half of all sample points generated by the MCMC chains are
removed, the empirical parameter mean is estimated from these remaining sample points
along with the 2.5th and 97.5th percentiles, the covariance matrix is estimated, and samples
are drawn from the prior distribution and posterior predictive distribution.
These post-processing results are then stored in the PostProc dictionary inside the Results
dictionary. If uq.postProcessInversion is called with all possible options (see Sec-
tion 3.3), it contains the following keys of myBayesianAnalysis['Results']['PostProc']
dictionary
{
'PostSample': [[[...], [...]], [[...], [...]], ..., [[...], [...]]],
'PostLogLikeliEval': [[...], [...], ..., [...]],
'PostModel': {'evaluation': [[...], [...], ..., [...]]},
'PointEstimate': {'ForwardRun': {...}, 'X': [...], 'Type': ...},
'Dependence': {'Corr': [[...],[...]], 'Cov': [[...],[...]]},
'Percentiles': {'Values': [[...],[...]], 'Probabilities': [...],
'Mean': [...], 'Var': [...]},
'PriorSample': [[...], [...], ...,[...]],
'PostPredSample': {'ModelEvaluations': [...], 'Sample': [...],
'Discrepancy': [...]},
'ChainsQuality': {'BadChains': [...], 'GoodChains': [...]},
'MPSRF': ...,
'PriorPredSample': {'ModelEvaluations': ..., 'Sample': ...,
'Discrepancy': ...}
}
where the value of the PostSample key is a regular nested list of size T"xMxC" and type float,
where T" is the length of the MCMC chains without the burn in, C" is the number of chains
excluding the badChains and P is the number of drawn prior sample points. The value of
UQ[PY]LAB-V1.0-113 - 43 -
UQ[PY]LAB user manual
the PostLogLikeliEval key is a regular nested list of size T"xC" and type float.
For more control over the post-processing operations, it is recommended to adapt the post-
processing options to the problem at hand and recall the uq.postProcessInversion func-
tion after the analysis is complete. For example, to draw 1,000 sample points from the prior
predictive distribution, the function needs to be called with:
myBayesianAnalysis = uq.postProcessInversion(myBayesianAnalysis,
'priorPredictive', 1000)
uq.postProcessInversion always operates on the original Sample list and overwrites the
contents of the respective PostProc key when called repeatedly. As an example, after calling
myBayesianAnalysis = uq.postProcessInversion(myBayesianAnalysis,
'burnIn', 0.6)
T" will be 40% of the original T . After calling
myBayesianAnalysis = uq.postProcessInversion(myBayesianAnalysis,
'burnIn', 0.7)
T" will be 30% of the original T , independent of the previous call.
To maintain previously computed content of PostProc’s keys, uq.postProcessInversion
only overwrites values of the keys if the call produces new content or an output is explicitly
turned off by the user. This does not happen with the default options of uq.postProcessInversion
(see Section 3.3). In order to delete a previously computed post-processing result, it needs
to be removed explicitly e.g.:
myBayesianAnalysis = uq.postProcessInversion(myBayesianAnalysis,
'priorPredictive', 0)
removes a previously computed prior predictive sample while any other call would leave it
untouched.
An exhaustive list of available post-processing options can be found in Section 3.3.
2.4.2 Spectral likelihood expansion
To solve the Bayesian problem with the spectral likelihood expansion (SLE) technique (see
Section 1.4), the user should specify the Solver dictionary as follows:
Solver = {'Type': 'SLE'}
The Bayesian module of UQ[PY]LAB uses the polynomial chaos expansion module (PCE,
UQ[PY]LAB User Manual Polynomial Chaos Expansions) to construct the likelihood approx-
imation. Additional options for the PCE can be passed to UQ[PY]LAB through the following
syntax:
UQ[PY]LAB-V1.0-113 - 44 -
Bayesian inference for model calibration and inverse problems
Solver['SLE'] = {
'Degree': list(range(1,21)),
'ExpDesign': {
'NSamples': 1e4
}
}
which specifies a degree adaptive PCE to be computed based on an experimental design of
size 10
4
. In general, SLE accepts all options that can be passed to the MetaOpts dictionary in
UQ[PY]LAB User Manual Polynomial Chaos Expansions (e.g., TruncOptions). See Table 18
for more information.
To conduct an SLE-based inverse analysis, the following command should be executed (after
assigning the Solver dictionary to the BayesOpts['Solver'] key):
uq.createAnalysis(BayesOpts)
By default, the SLE-specific post-processing function uq.postProcessInversionSLE is
called after every SLE analysis by the wrapper function uq.postProcessInversion: it
computes the Bayesian evidence (see Eq. (1.52)) and the posterior mean (see Eq. (1.56)).
These values are stored in the myBayesianAnalysis['Results']['PostProc'] key that
reads
{
'Evidence': ...,
'Posterior': '...',
'Mean': [..., ...],
'PointEstimate': {'X': [..., ...], 'Type': '...'}
}
To additionally compute the posterior covariance and correlation matrices, the post-processing
function can be called again with the following arguments:
myBayesianAnalysis = uq.postProcessInversion(myBayesianAnalysis,
'dependence', True)
The results of the analysis can be inspected with the uq.print function.
2.4.3 Stochastic spectral likelihood embedding
To solve the Bayesian problem with the stochastic spectral likelihood embedding (SSLE)
technique (see Section 1.5), the user should specify the Solver dictionary as follows:
Solver = {'Type': 'SSLE'}
The Bayesian module of UQ[PY]LAB uses the stochastic spectral embedding module (SSE,
UQ[PY]LAB User Manual Stochastic spectral embedding) to construct the likelihood ap-
proximation. Additional options for the SSE can be passed to UQ[PY]LAB through the
UQ[PY]LAB-V1.0-113 - 45 -
UQ[PY]LAB user manual
following syntax:
Solver['SSLE'] = {
# Expansion options
'ExpOptions': {
'Degree': list(range(1,5))
},
# Experimental design options
'ExpDesign': {
'NSamples': 1000,
'NEnrich': 100
}
}
which specifies degree adaptive PCE for the residual expansions with an experimental design
of size 1000. By default, the experimental design is added sequentially (see Section 1.5.1.2),
where we now specified an enrichment rate of 100 sample points per refinement step.
By default, SSLE uses a partitioning strategy based on the residual variance difference (see
Section 1.5.1.1)
uq.createAnalysis(BayesOpts)
By default, the SSLE-specific post-processing function uq.postProcessInversionSSLE is
called after every SLE analysis by the wrapper function uq.postProcessInversion: it
computes the Bayesian evidence (see Eq. (1.59)) and the posterior mean (see Eq. (1.63)).
These values are stored in the myBayesianAnalysis['Results']['PostProc'] key:
{
'Evidence': ...,
'Mean': [..., ...],
'PointEstimate': {'X': [..., ...], 'Type': '...'},
'Posterior': '...',
}
To additionally compute the posterior covariance and correlation matrices, the post-processing
function can be called again with the following arguments:
myBayesianAnalysis = uq.postProcessInversion(myBayesianAnalysis,
'dependence', True).
The results of the analysis can be inspected with the uq.print function.
2.4.4 No solver: posterior point by point evaluation
Sometimes it is not required to solve the inverse problem, but only to evaluate the prior/-
posterior PDFs, or the likelihood function for specific parameter points x
0
(e.g., maximum a
posteriori estimation). In this case, the solver type has to be set to 'None':
Solver['Type'] = 'None'
UQ[PY]LAB-V1.0-113 - 46 -
Bayesian inference for model calibration and inverse problems
After the analysis creation with uq.createAnalysis(), the analysis object contains the
following:
{
'results_idx': 2,
'Options': {'Data': {...}, 'Solver': {...}, 'Type': 'Inversion'},
'Results': 0,
'Internal': {'customLikeli': 0, ...},
'Name': 'Analysis 1',
'Type': 'uq_inversion',
'core_component': 'analysis',
'displayFun': 'None',
'printFun': 'None',
'Discrepancy': {'Type': 'Gaussian', ...},
'Data': {'Name': 'Beam mid-span deflection', 'y': [...], 'MOMap': [...]},
'PriorDist': 'Input 2',
'ForwardModel': {'Model': 'Model 1', 'PMap': [...]},
'LogPrior': '@(x)uq_evalLogPDF(x,Internal.FullPrior)',
'UnnormPosterior': '...',
'UnnormLogPosterior': '...',
'Class': 'uq_analysis',
'Prior': '@(x)uq_evalPDF(x,Internal.FullPrior)',
'Likelihood': "@(x)uq_inversion_likelihood(x,Internal,'Likelihood')",
'LogLikelihood': "@(x)uq_inversion_likelihood(x,Internal,'LogLikelihood')"
}
If the solver type is set to 'None', no results are generated. Instead the analysis generates
function handles to the prior distribution, the likelihood function and the unnormalized pos-
terior distribution. The handle to the unnormalized posterior distribution can be used to find
the maximum a posteriori (MAP) parameter value as shown in the supplied Example 7 of
Bayesian inversion module (07-MAP.ipynb).
2.5 Advanced feature: multiple forward models
When data from multiple data sources are available (e.g., stresses and temperatures), dif-
ferent computational models may be needed. In the Bayesian module of UQ[PY]LAB, it is
possible to perform an inversion on multiple models with different output and discrepancy
options that depend on the same set, or subsets, of the parameters x
M
. This can be achieved
by specifying dictionaries for the ForwardModel key.
To show how such a problem is set up in UQ[PY]LAB, it is assumed now that additional
longitudinal tensile tests are carried out on a beam as shown in Figure 9.
The nominal value of the load P is 50 kN. In total N = 3 tensile tests are carried out,
resulting in the deformations given in Table 4.
Table 4: Beam elongation: measured deformations.
Experiment 1 2 3
U (mm) 0.235 0.236 0.229
UQ[PY]LAB-V1.0-113 - 47 -
UQ[PY]LAB user manual
Figure 9: Tensile test.
The elongation U of the specimen under a load P can be computed with (Sudret, 2018):
U =
P L
Ebh
. (2.4)
In this case, the measurements were carried out with a measuring device that has a known
measurement error distribution of ε N (0, 2 · 10
11
) (m).
2.5.1 Specify a prior distribution
The model prior object from Section 2.2.2 can be extended to contain the point load P :
PriorOpts['Marginals'].append(
{
'Name': 'P',
'Type': 'Constant',
'Parameters': [50000] # (N)
}
)
myPriorDist = uq.createInput(PriorOpts)
2.5.2 Create a forward model
Each forward model has to be set up as a dedicated UQ[PY]LAB MODEL. To do this, Eq. (2.4)
is translated to a string UQ[PY]LAB MODEL and assigned together with the
uq.SimplySupportedBeam model:
# Forward model 1
ModelOpts1 = {
'Type' : 'Model',
'Name': 'Beam bending deflection',
'ModelFun':'SimplySupportedBeam.model',
}
myModel1 = uq.createModel(ModelOpts1)
# Forward model 2
ModelOpts2 = {
'Type' : 'Model',
'Name': 'Beam elongation',
'mString': 'X(:,5).
*
X(:,3)./(X(:,1).
*
X(:,2).
*
X(:,4))',
UQ[PY]LAB-V1.0-113 - 48 -
Bayesian inference for model calibration and inverse problems
}
myModel2 = uq.createModel(ModelOpts2)
# Forward models
ForwardModels = [
{
'Model': myModel1['Name'],
'PMap': [1,2,3,4,5]
},
{
'Model': myModel2['Name'],
'PMap': [1,2,3,4,6]
}
]
The parameter map PMap defines which parameters from the model parameter vector x
M
are used for the respective model. The tensile test in ForwardModels[1] takes the 6-th
parameter from the model prior distribution as a 5-th input ('X(:,5)' in the equation string
takes the 6-th parameter from the model prior distribution as a 5-th input ('X(:,5)' in the
equation string; note that mString follows the Matlab syntax).
Note: By default, the PMap list is set to address each parameter in the model parameter
list x
M
. However, in most realistic usage scenarios, it should be updated to list
the desired parameters properly.
2.5.3 Provide measurements
The results of the tensile test are stored in a list U and are assigned to the second data group
myData[1]:
U = np.array([0.235, 0.236, 0.229])/1000
myData = [
# Data group 1
{
'y': V_mid.tolist(),
'Name': 'Beam mid-span deflection',
'MOMap': [1, # Model ID
1] # Output ID
},
# Data group 2
{
'y': U.tolist(),
'Name': 'Beam elongation',
'MOMap': [2, # Model ID
1] # Output ID
}
]
UQ[PY]LAB-V1.0-113 - 49 -
UQ[PY]LAB user manual
Note: In the case of multiple models, the MOMap is mandatory and has to be defined as
a list if each model has only one output or a nested list in case of several outputs
per model. In the second case scenario, each inner list contains an index of the
corresponding model and an index of the corresponding model output.
2.5.4 Define a discrepancy model
The discrepancy can then be specified separately for the first model M
1
(x
M
), where the
variance of the discrepancy term is inferred from data, and the second model M
2
(x
M
),
where the measurement error variance is known, as follows:
# Prior options for Discrepancy group 1
DiscrepancyPriorOpts1 = {
'Name': 'Prior of sigma_1ˆ2',
'Marginals': {
'Name': 'Sigma2',
'Type': 'Uniform',
'Parameters': [0, 1e-4], #(mˆ2)
}
}
myDiscrepancyPrior1 = uq.createInput(DiscrepancyPriorOpts1)
DiscrepancyOpts = [
# Discrepancy group 1
{
'Type': 'Gaussian',
'Prior': myDiscrepancyPrior1['Name']
},
# Discrepancy group 2
{
'Type': 'Gaussian',
'Parameters': [2e-11], # (mˆ2) known discr. variance
}
]
2.5.5 Perform the inverse analysis
As in the previous case, all the options are then gathered in a single dictionary that contains
all the information to perform the Bayesian inversion:
BayesOpts = {
'Type': 'Inversion',
'Name': 'Bayesian multiple models',
'Prior': myPriorDist['Name'],
'ForwardModel': ForwardModels,
'Data': myData,
'Discrepancy': DiscrepancyOpts,
}
In this case, PriorDist has to be explicitly assigned to the BayesOpt dictionaries to avoid
confusion with the INPUT object in the discrepancy model. It is also necessary to explicitly
UQ[PY]LAB-V1.0-113 - 50 -
Bayesian inference for model calibration and inverse problems
assign the ForwardModels list of dictionaries, as there are multiple forward models now.
The inverse problem can then be solved by running the analysis:
myBayesianAnalysis = uq.createAnalysis(BayesOpts)
Run post-processing with non-default options by removing 30%, instead of the default 50%,
of the initially generated sample points:
myBayesianAnalysis = uq.postProcessInversion(myBayesianAnalysis,
'burnIn', 0.3)
The results of this analysis can be assessed with a brief report generated by:
uq.print(myBayesianAnalysis)
which returns:
%----------------------- Inversion output -----------------------%
Number of calibrated model parameters: 1
Number of non-calibrated model parameters: 5
Number of calibrated discrepancy parameters: 1
%------------------- Data and Discrepancy
% Data-/Discrepancy group 1:
Number of independent observations: 5
Discrepancy:
Type: Gaussian
Discrepancy family: Scalar
Discrepancy parameters known: No
Associated outputs:
Model 1:
Output dimensions: 1
% Data-/Discrepancy group 2:
Number of independent observations: 3
Discrepancy:
Type: Gaussian
Discrepancy family: Scalar
Discrepancy parameters known: Yes
Associated outputs:
Model 2:
Output dimensions: 1
%------------------- Solver
Solution method: MCMC
Algorithm: AIES
Duration (HH:MM:SS): 00:00:53
Number of sample points: 3.00e+04
%------------------- Posterior Marginals
---------------------------------------------------------------------
UQ[PY]LAB-V1.0-113 - 51 -
UQ[PY]LAB user manual
| Parameter | Mean | Std | (0.025-0.975) Quant. | Type |
---------------------------------------------------------------------
| E | 2.4e+10 | 2.6e+08 | (2.3e+10 - 2.4e+10) | Model |
| Sigma2 | 2e-06 | 4.9e-06 | (1.4e-07 - 1.4e-05) | Discrepancy |
---------------------------------------------------------------------
%------------------- Point estimate
----------------------------------------
| Parameter | Mean | Parameter Type |
----------------------------------------
| E | 2.4e+10 | Model |
| Sigma2 | 2e-06 | Discrepancy |
----------------------------------------
A visualization of the analysis can be produced by:
uq.display(myBayesianAnalysis)
which produces the images shown in Figure 10.
A simple example on how to use the multiple forward model feature is given in Example 5 of
the Bayesian inversion module 05-MultipleModels.ipynb.
UQ[PY]LAB-V1.0-113 - 52 -
Bayesian inference for model calibration and inverse problems
(a) Scatterplots of prior and posterior sample with the posterior mean point estimator from (1.31).
(b) Posterior predictive distribution from (1.28), data, and model at mean prediction obtained by propa-
gating the mean point estimator through the forward model for both data groups.
Figure 10: Multiple forward models: The results of the Bayesian inverse analysis on the input
and the model predictions.
UQ[PY]LAB-V1.0-113 - 53 -
Chapter 3
Reference List
How to read the reference list
Python dictionaries play an important role throughout the UQ[PY]LAB syntax. They offer
a natural way to semantically group configuration options and output quantities. Due to
the complexity of the algorithms implemented, it is not uncommon to employ nested dictio-
naries to fine-tune the inputs and outputs. Throughout this reference guide, a table-based
description of the configuration dictionaries is adopted.
The simplest case is given when a value of a dictionary key is a simple value or a list:
Table X: Input
Name String A description of the field is put here
which corresponds to the following syntax:
Input = {
'Name' : 'My Input'
}
The columns, from left to right, correspond to the name, the data type and a brief description
of each key-value pair. At the beginning of each row a symbol is given to inform as to whether
the corresponding key is mandatory, optional, mutually exclusive, etc. The comprehensive
list of symbols is given in the following table:
Mandatory
Optional
55
UQ[PY]LAB user manual
Mandatory, mutually exclusive (only one of
the keys can be set)
Optional, mutually exclusive (one of them
can be set, if at least one of the group is set,
otherwise none is necessary)
When the value of one of the keys of a dictionary is a dictionary itself, a link to a table that
describes the structure of that nested dictionary is provided, as in the case of the Options
key in the following example:
Table X: Input
Name String Description
Options Table Y Description of the Options
dictionary
Table Y: Input['Options']
Key1 String Description of Key1
Key2 Double Description of Key2
In some cases, an option value gives the possibility to define further options related to that
value. The general syntax would be:
Input = {
'Option1' : 'VALUE1',
'VALUE1' : {
'Val1Opt1' : ... ,
'Val1Opt2' : ...
}
}
This is illustrated as follows:
Table X: Input
Option1 String Short description
'VALUE1' Description of 'VALUE1'
'VALUE2' Description of 'VALUE2'
VALUE1 Table Y Options for 'VALUE1'
VALUE2 Table Z Options for 'VALUE2'
Table Y: Input['VALUE1']
Val1Opt1 String Description
Val1Opt2 Float Description
UQ[PY]LAB-V1.0-113 - 56 -
Bayesian inference for model calibration and inverse problems
Table Z: Input['VALUE2']
Val2Opt1 String Description
Val2Opt2 Float Description
UQ[PY]LAB-V1.0-113 - 57 -
UQ[PY]LAB user manual
3.1 Create a Bayesian inverse analysis
Syntax
myBayesianAnalysis = uq.createAnalysis(BayesOpts)
Input
The dictionary BayesOpts contains the information for a Bayesian inverse analysis. N
mod
is
the number of computational forward models and N
gr
is the number of data- and discrepancy
groups.
Table 5: BayesOpts
Type 'Inversion' Inverse modelling
Data Table 6 The data used for inversion.
See also Section 2.2.4,
Section 2.3.4.3 and Section 2.5.3.
Prior String Name of UQ[PY]LAB INPUT
containing the prior distribution of
the parameters.
If not specified and no INPUT object
is used in the Discrepancy or the
Solver key, the currently selected
INPUT object is used
See also UQ[PY]LAB User Manual –
the INPUT module.
ForwardModel String or Table 7 String containing name of the
UQ[PY]LAB forward MODEL used for
inversion.
If not specified, the currently
selected MODEL object will be used
Discrepancy Table 8 The discrepancy model.
Solver Table 9 Solver used for the inverse analysis.
See also Section 2.4.
Name String Name of the module. If not set by
the user, a unique string is
automatically assigned to it.
3.1.1 Data dictionary
The Data key-pair value contains a list of dictionaries of size N
gr
. The g-th dictionary in this
list defines the g-th data group G
(g)
used in solving the inverse problem. N
out
,g
is the number
of model outputs related to the current data group (Section 2.3.4.3):
UQ[PY]LAB-V1.0-113 - 58 -
Bayesian inference for model calibration and inverse problems
Table 6: BayesOpts['Data']
y List of N lists of type
Floats and length N
out
,g
The observations G
(g)
.
MOMap Integers Model output map relating the g-th
data group to specific model outputs.
See also Section 2.3.4.3.
Nested list of 1 list of
length N
out
,g
and type
integers
default: consecutive
numbering [[1, . . . , N
out
]]
Vector of model output indices
related to the g-th data group.
If N
mod
> 1 the definition below has
to be used.
Nested list of N
out
,g
lists
of length 2 and type
integers
Each sublist contains a pair of the
model index and the model output
index.
Name String Name of the data group.
Note: The data and discrepancy groups are closely related. There always have to be
as many data groups as discrepancy groups. See also Section 1.2.4 and Sec-
tion 2.3.4.3.
3.1.2 Forward model dictionary
The ForwardModel key-value pair contains a list of dictionaries of length N
mod
. The i-th
dictionary in this list contains the i-th computational forward model (Section 2.5.2):
Table 7: BayesOpts['ForwardModel']
Model String i-th UQ[PY]LAB forward MODEL
used in the inverse analysis.
PMap List with M entries
default: [1,...,M]
Parameter map of the i-th forward
model. Defines which parameters
from Prior are used for the
evaluation of this forward model.
See also Section 2.5.2.
3.1.3 Discrepancy model options
The Discrepancy key-value pair contains a list of dictionaries of length N
gr
. The g-th dictio-
nary in this list defines the g-th discrepancy group used in solving the inverse problem. N
out
,g
is the number of model outputs related to the current discrepancy group (Section 2.3.4):
Table 8: BayesOpts['Discrepancy']
UQ[PY]LAB-V1.0-113 - 59 -
UQ[PY]LAB user manual
Parameters Floats Parameters for a known discrepancy
model.
See also Section 2.3.4.1.
Float scalar Independent discrepancies with
same variance
Nested list of 1 list of type
Float and length N
out
,g
Independent discrepancies with
individual variances
Nested list of N
out
,g
lists
of type Float and length
N
out
,g
Full covariance matrix
Prior String Name of UQ[PY]LAB INPUT. Prior
distribution for an unknown
variance.
See also Section 2.3.4.2.
Type String
default: 'Gaussian'
Type of the discrepancy distribution
'Gaussian' Only Gaussian discrepancies are
currently supported
Note: The data and discrepancy groups are closely related. There always have to be as
many data as discrepancy groups. See also Section 1.2.4 and Section 2.3.4.3.
3.1.4 Solver options
The solver used in analyzing the inverse problem can be specified with the following struc-
ture:
Table 9: BayesOpts['Solver']
Type String
default: 'MCMC'
Solution method of analysis.
'MCMC' Markov chain Monte Carlo.
See also Section 2.4.1.
'SLE' Spectral likelihood expansion.
See also Section 2.4.2.
'SSLE' Stochastic spectral likelihood
embedding.
See also Section 2.4.3.
'None' Only initialize and provide handles.
See also Section 2.4.4.
MCMC Table 10 Parameters of the MCMC algorithm.
UQ[PY]LAB-V1.0-113 - 60 -
Bayesian inference for model calibration and inverse problems
SLE Table 18 Options for the PCE used in SLE. See
UQ[PY]LAB User Manual –
Polynomial Chaos Expansions.
3.1.4.1 Markov chain Monte Carlo
If the solver type is 'MCMC', the key BayesOpts['Solver']['MCMC'] accepts the additional
options listed in Table 10.
Table 10: BayesOpts['Solver']['MCMC']
Sampler String
default: 'AIES'
MCMC algorithm
'MH' Metropolis-Hastings algorithm.
See also Table 12 and
Section 2.4.1.1.
'AM' Adaptive Metropolis algorithm.
See also Table 13 and
Section 2.4.1.2.
'HMC' Hamiltonian Monte Carlo algorithm.
See also Table 15 and
Section 2.4.1.3.
'AIES' Affine invariant ensemble sampler
algorithm.
See also Table 16 and
Section 2.4.1.4.
Steps Integer scalar
default:
MH, AM: 3,000
HMC, AIES: 300
Number of MCMC iterations T per
chain
Visualize Table 17 MCMC runtime visualization.
See also Section 2.4.1.5
NChains Integer scalar
default:
MH, AM, HMC: 10
AIES: 100
Number of parallel chains C. Initial
points are randomly drawn from
π(x)
Seed List of M lists of length C
and type Float or List of 1
list of M lists of length C
and type Float
Initial points of the MCMC algorithm
Table 11: BayesOpts['Solver']['MCMC']['Visualize']
Parameters Integer Which parameter should be
visualized
Interval Integer scalar Plot interval
UQ[PY]LAB-V1.0-113 - 61 -
UQ[PY]LAB user manual
Depending on the chosen Sampler, different additional options can be specified:
Metropolis-Hastings algorithm - Table 12
Adaptive Metropolis algorithm - Table 13
Hamiltonian Monte Carlo algorithm - Table 15
Affine invariant ensemble sampler algorithm - Table 16
Table 12: BayesOpts['Solver']['MCMC'] (Metropolis-Hastings)
Proposal Table 14 Proposal distribution p(x|x
(t)
)
Table 13: BayesOpts['Solver']['MCMC'] (Adaptive Metropolis)
Proposal Table 14 Proposal distribution p(x|x
(t)
) until
T0
T0 Integer scalar
default: 300
Number of iterations t
0
until the
adaptive proposal distribution is
used.
Epsilon Float scalar
default: 1e-6
Correction ϵ added to adaptive
correlation diagonal to avoid
singularity.
Table 14: BayesOpts['Solver']['MCMC']['Proposal']
PriorScale Floats
default: 0.1
Uses the scaled prior marginal
variances as the covariance matrix
Σ
p
for Gaussian proposal centered at
x
(t)
.
Cov List of M lists of length
M and type Float
Full covariance matrix Σ
p
Distribution String Name of UQ[PY]LAB INPUT object.
Custom proposal distribution.
Requires also Conditioning key
Conditioning String Type of conditioning of proposal
distribution
'Previous' Proposal distribution mean is set to
x
(t)
'Global' Samples are not conditioned on x
(t)
but are directly drawn from supplied
Distribution.
UQ[PY]LAB-V1.0-113 - 62 -
Bayesian inference for model calibration and inverse problems
Table 15: BayesOpts['Solver']['MCMC'] (Hamiltonian Monte Carlo)
LeapfrogSteps Integer scalar
default: 10
Number of leapfrog integration steps
N
τ
LeapfrogSize Float scalar
default: 0.01
Size of leapfrog integration steps
τ
N
τ
Mass Floats
default: 1
Mass matrix M .
Float scalar Scale factor for identity matrix used
as M .
List of M lists of length
M and type Float
Full M .
Table 16: BayesOpts['Solver']['MCMC'] (Affine invariant ensemble sampler)
a Float scalar > 1
default: 2
Parameter a for stretch move
proposal.
Table 17: BayesOpts['Solver']['MCMC']['Visualize']
Parameters Integer Which parameter should be
visualized
Interval Integer scalar Plot interval
3.1.4.2 Spectral likelihood expansions
If the solver type is 'SLE', the key BayesOpts['Solver']['SLE'] accepts the additional
options listed in Table 18. These options pertain to the properties of the PCE used in SLE and
the table lists only the options that are set by default. Additional options can be found in the
UQ[PY]LAB User Manual – Polynomial Chaos Expansions.
Table 18: BayesOpts['Solver']['SLE']
MetaType String
default: 'PCE'
Type of the expansion. Currently
only 'PCE' is supported.
Method String
default: 'LARS'
PCE calculation strategy. See the
UQ[PY]LAB User Manual –
Polynomial Chaos Expansions for
available options.
Degree Integer array
default:
[0,1,2,...,15]
Adaptively selected degree of the
PCE.
UQ[PY]LAB-V1.0-113 - 63 -
UQ[PY]LAB user manual
ExpDesign Dictionary Properties of the experimental design
according to Table 11 of the
UQ[PY]LAB User Manual –
Polynomial Chaos Expansions.
[...] Additional options can be selected
according to Table 3 of the
UQ[PY]LAB User Manual –
Polynomial Chaos Expansions.
3.1.4.3 Stochastic spectral likelihood embedding
Momentarily, no specific options are available for the SSLE solver. They will be made avail-
able at a later release.
3.2 Accessing analysis results
Syntax
myBayesianAnalysis = uq.createAnalysis(BayesOpts)
Output
After the analysis, the object myBayesianAnalysis contains the following important key-
value pairs:
Table 19: myBayesianAnalysis
LogPrior String MATLAB Function handle of Log Prior
probability density function log π(x).
Prior String MATLAB Function handle of Prior probability
density function π(x).
LogLikelihood String MATLAB Function handle of Log-likelihood
function log L(x; y).
Likelihood String MATLAB Function handle of Likelihood
function.
Results Table 20 Results of the specified Solver. If the 'None'
option was specified, this key contains 0.
Note: During the analysis all constant parameters from the input distribution are re-
moved. The above handles expect parameters x without constants.
If the solver Type was set to 'MCMC' the result key contains:
UQ[PY]LAB-V1.0-113 - 64 -
Bayesian inference for model calibration and inverse problems
Table 20: myBayesianAnalysis['Results'] (MCMC)
Sample List of T lists of
M lists of
length C and
type Float
Sample generated by the MCMC algorithm.
ForwardModel Dictionary The forward model evaluations associated with
the sample stored in the Sample key.
Acceptance List of length C
and type Float
Acceptance rate of each chain.
Time Float scalar Time required for simulation.
PostProc Table 24 The post processed MCMC results as generated
by uq.postProcessInversion (see
Section 3.3.1).
If the solver Type was set to 'SLE' the result key contains:
Table 21: myBayesianAnalysis['Results'] (SLE)
SLE 'SLE' Name of SLE uq_model of the likelihood
function.
PostProc Table 27 The results obtained from post-processing the
SLE with uq.postProcessInversion (see
Section 3.3.2).
Note: The key SLE contains a string with a UQ[PY]LAB name of the metamodel. To
retrieve the metamodel, one can write:
parentName = myBayesianAnalysis['Name']
objPath = 'Results.SLE'
myModel = uq.extractFromAnalysis(parentName=parentName,
objPath=objPath)
If the solver Type was set to 'SSLE' the result key contains:
Table 22: myBayesianAnalysis['Results'] (SSLE)
SSLE 'SSLE' Name of SSE uq_model of the likelihood
function.
PostProc Table 29 The results obtained from post-processing the
SSLE with uq.postProcessInversion (see
Section 3.3.3).
UQ[PY]LAB-V1.0-113 - 65 -
UQ[PY]LAB user manual
Note: The key SSLE contains a string with a UQ[PY]LAB name of the metamodel. To
retrieve the metamodel, one can write:
parentName = myBayesianAnalysis['Name']
objPath = 'Results.SSLE'
myModel = uq.extractFromAnalysis(parentName=parentName,
objPath=objPath)
3.3 Post-processing results
Syntax
uq.postProcessInversion(myBayesianAnalysis[, Name, Value])
Depending on the solver type, different post-processing functions are called, when the anal-
ysis is passed to uq.postProcessInversion:
Markov chain Monte Carlo - Section 3.3.1
Spectral likelihood expansions - Section 3.3.2
Stochastic spectral likelihood embedding - Section 3.3.3
3.3.1 Markov chain Monte Carlo
Description
uq.postProcessInversion(myBayesianAnalysis) post-processes the results stored in
myBayesianAnalysis['Results']['Sample']. By default the first half of the sample
points generated is discarded and the empirical posterior mean is estimated along with
the 5th and 95th percentile from this reduced sample. Additionally, 1,000 sample points
from the prior distribution and from the posterior predictive distribution are drawn.
uq.postProcessInversion(myBayesianAnalysis, Name, Value) post-processes the re-
sults stored in myBayesianAnalysis['Results']['Sample'] using additional op-
tions specified by Name, Value pairs given in any order. These options are summarized
in Table 23.
For a comprehensive discussion of the function logic, see also Section 2.4.1.6.
Note: If prior predictive samples are drawn, additional forward model evaluations are
computed.
UQ[PY]LAB-V1.0-113 - 66 -
Bayesian inference for model calibration and inverse problems
Table 23: uq.postProcessInversion(..., Name, Value) (MCMC)
'burnIn' Integer or Float
scalar
default: 0.5
The burn-in for the MCMC sample (see
Section 1.3.5.4).
Float between 0
and 0.99
Specifies the fraction of sample points that are
discarded as burn-in.
Integer
between 1 and
T
Specifies the number of sample points that are
discarded as burn-in.
'percentiles' List of Floats
default:
[0.025; 0.975]
Computes the specified percentiles using the
supplied sample.
'dependence' Logical
default: True
if True the posterior covariance and
correlation matrices are computed.
'badChains' List of integers
default: []
Removes the specified chains from the sample.
'prior' Integer
default: 1,000
Draws a specified number of sample points
from the prior distribution.
'priorPredictive' Integer
default: 0
Draws a specified number of sample points
from the prior predictive distribution, see also
Eq. (1.27).
'posteriorPredictive'
Integer
default:
min(1,000, T C)
Draws a specified number of sample points
from the posterior predictive distribution, see
also Eq. (1.28).
'pointEstimate' String or List of
Floats or Nested
list of Floats
default:
'Mean'
Computes a point estimate.
'Mean' Computes the empirical mean from the
supplied sample.
'MAP' Returns the point with the maximum posterior
probability from the supplied sample.
'None' Removes possibly existing point estimate.
Nested list of
Floats
Adds P custom estimators passed as List of P
lists of length M and type Float .
Nested list Any combination of the above, except 'None',
passed inside a nested list.
'gelmanRubin' Logical
default: False
if True the multivariate potential scale
reduction factor
ˆ
R
p
is computed (see
Section 1.3.5.3).
Examples:
UQ[PY]LAB-V1.0-113 - 67 -
UQ[PY]LAB user manual
The command:
uq.postProcessInversion(myBayesianAnalysis, 'badChains', [1, 5],
'pointEstimate', 'MAP')
removes the sample points generated by the first and fifth chain from the sample and com-
putes the maximum a posterior (MAP) point taken as the maximum unnormalized posterior
evaluation from the available sample.
All post-processing results generated by the uq.postProcessInversion function are stored
in the myBayesianAnalysis['Results']['PostProc'] dictionary. The keys of this
dictionary are listed in Table 24.
Table 24: myBayesianAnalysis['Results']['PostProc']
ChainsQuality Dictionary Information about good and bad chains of the
MCMC sample specified with the
'badChains' argument of
uq.postProcessInversion.
PostSample List of T lists of
M lists of
length C and
type Float
Posterior sample after post-processing with
uq.postProcessInversion after removing
bad chains and burn-in.
PriorSample List of N
prior
lists of length
M and type
Float
Prior sample of length N
prior
.
PriorPredSample Table 25 Prior predictive sample for each discrepancy
group.
PostPredSample Table 25 Posterior predictive sample for each
discrepancy group.
PostLogLikeliEval List of T lists of
length C and
type Float
Log likelihood evaluations at PostSample.
PostModel Dictionary or
List of N
gr
dictionaries
Forward model evaluations at PostModel.
PointEstimate Dictionary Information related to the point estimate
computed with
uq.postProcessInversion.
Dependence Dictionary Posterior dependence estimates like the
covariance or correlation matrices.
Percentiles Dictionary Percentiles of the posterior marginals.
MPSRF Float Multivariate potential scale reduction factor
defined in Section 1.3.5.3.
The PriorPredSample and PostPredSample key contains list of dictionaries of size N
gr
.
UQ[PY]LAB-V1.0-113 - 68 -
Bayesian inference for model calibration and inverse problems
The g-th dictionary in this list contains the predictive sample for the g-th discrepancy group.
N
pred
is the number of predictive samples:
Table 25: myBayesianAnalysis['Results']['PostProc']['{Prior,Post}PredSample']
Sample N
pred
× N
out
,g
Predictive sample for g-th discrepancy group.
ModelEvaluations N
pred
× N
out
,g
Model evaluations corresponding to the
predictive sample.
Discrepancy N
pred
× N
out
,g
The discrepancy value corresponding to the
predictive sample.
3.3.2 Spectral likelihood expansions
Description
uq.postProcessInversion(myBayesianAnalysis) post-processes the results stored in
myBayesianAnalysis['Results']['SLE']. By default the evidence and the poste-
rior mean are computed.
uq.postProcessInversion(myBayesianAnalysis, Name, Value) post-processes the re-
sults stored in myBayesianAnalysis['Results']['SLE'] using additional options
specified by Name, Value pairs given in any order. These options are summarized in
Table 28.
Table 26: uq.postProcessInversion(..., Name, Value) (SLE)
'evidence' Boolean
default: True
Switch to compute the Bayesian evidence.
'pointEstimate' String or (Mul-
tidimensional)
Nested list
default:
'Mean'
Computes a point estimate.
'Mean' Computes the mean from the SLE.
'None' Removes possibly existing point estimate.
Nested list Adds P custom estimators passed as a list of P
lists of length M and type Float.
Multidimen-
sional nested
list
Any combination of the above, except 'None',
passed inside a multidimensional nested list.
'dependence' Boolean
default: False
if True the posterior covariance and
correlation matrices are computed.
'parameters' List of Integers
default:
[1,...,M]
Parameters to consider.
UQ[PY]LAB-V1.0-113 - 69 -
UQ[PY]LAB user manual
Examples:
The command:
uq.postProcessInversion(myBayesianAnalysis,
'dependence', True, 'parameters', [1, 3])
computes the posterior covariance for the input parameters x
1
and x
3
.
All post-processing results generated by the uq.postProcessInversion function are stored
in the myBayesianAnalysis['Results']['PostProc'] dictionary. The keys of this dic-
tionary are listed in Table 27.
Table 27: myBayesianAnalysis['Results']['PostProc']
Evidence Float The Bayesian evidence Z.
PointEstimate Dictionary Information related to the point estimate
computed with
uq.postProcessInversion.
Dependence Dictionary Posterior dependence estimates like the
covariance or correlation matrices.
3.3.3 Stochastic spectral likelihood embedding
Description
uq.postProcessInversion(myBayesianAnalysis) post-processes the results stored in
myBayesianAnalysis['Results']['SSLE']. By default the evidence and the poste-
rior mean are computed.
uq.postProcessInversion(myBayesianAnalysis, Name, Value) post-processes the re-
sults stored in myBayesianAnalysis['Results']['SSLE'] using additional options
specified by Name, Value pairs given in any order. These options are summarized in
Table 28.
Table 28: uq.postProcessInversion(..., Name, Value) (SSLE)
'evidence' Boolean
default: True
Switch to compute the Bayesian evidence.
'pointEstimate' String or (Mul-
tidimensional)
Nested list
default:
'Mean'
Computes a point estimate.
UQ[PY]LAB-V1.0-113 - 70 -
Bayesian inference for model calibration and inverse problems
'Mean' Computes the mean from the SSLE.
'None' Removes possibly existing point estimate.
Nested list Adds P custom estimators passed as a list of P
lists of length M and type Float .
Multidimen-
sional nested
list
Any combination of the above, except 'None',
passed inside a multidimensional nested list.
'dependence' Boolean
default: False
if True the posterior covariance and
correlation matrices are computed.
'parameters' List of integers
default:
[1,...,M]
Parameters to consider.
Examples:
The command:
uq.postProcessInversion(myBayesianAnalysis,
'dependence', True, 'parameters', [1, 3])
computes the posterior covariance for the input parameters x
1
and x
3
.
All post-processing results generated by the uq.postProcessInversion function are stored
in the myBayesianAnalysis['Results']['PostProc'] dictionary. The keys of this dic-
tionary are listed in Table 29.
Table 29: myBayesianAnalysis['Results']['PostProc']
Evidence Float The Bayesian evidence Z.
PointEstimate Dictionary Information related to the point estimate
computed with
uq.postProcessInversion.
Dependence Dictionary Posterior dependence estimates like the
covariance or correlation matrices.
3.4 Printing/Visualizing results
UQ[PY]LAB offers two commands to conveniently print reports containing contextually rele-
vant information for a given object. If the post-processing was carried out with the
uq.postProcessInversion function, the post-processed sample is used.
UQ[PY]LAB-V1.0-113 - 71 -
UQ[PY]LAB user manual
3.4.1 Printing the results: uq.print
Syntax
uq.print(myBayesianAnalysis)
Description
uq.print(myBayesianAnalysis) print a report on the results of the Bayesian analysis in
object myBayesianAnalysis.
3.4.2 Graphically display the results: uq.display
Syntax
uq.display(myBayesianAnalysis[, Name, Value])
Depending on the solver type, different display functions are called, when the analysis is
passed to uq.display, which is a wrapper function for displaying the all types outputs:
Markov chain Monte Carlo - Section 3.4.2.1
Spectral likelihood expansions - Section 3.4.2.2
Stochastic spectral likelihood embedding - Section 3.4.2.3
3.4.2.1 Markov chain Monte Carlo
Description
uq.display(myBayesianAnalysis) create a visualization of the Bayesian analysis in ob-
ject myBayesianAnalysis. By default a scatterplot of the posterior sample and, if
available, the prior and posterior predictive distributions are plotted.
uq.display(myBayesianAnalysis, Name, Value) create a visualization of the Bayesian
analysis in object myBayesianAnalysis using only options specified by Name, Value
pairs given in any order. These options are summarized in Table 30.
Table 30: uq.display(..., Name, Value)
'scatterplot' String or Inte-
ger
default: 'all'
Scatterplots of the posterior and (if available)
prior sample.
UQ[PY]LAB-V1.0-113 - 72 -
Bayesian inference for model calibration and inverse problems
'all' Plots M dimensional scatterplots of the
generated samples.
List of integers Plots the scatterplot with the specified
parameters.
'predDist' Boolean Requires initial call to
uq.postProcessInversion to draw prior
and/or posterior predictive sample points (see
Eq. (1.27) and Eq. (1.28)).
if N
out
= 1 displays histogram plots based on
the sample points generated by
uq.postProcessInversion and
scatterplots of Y
if N
out
> 1 displays violin plots based on the
sample points generated by
uq.postProcessInversion and
scatterplots of Y
'trace' String or Inte-
ger
default:
'none'
Trace plot of MCMC chains.
'all' Displays trace plot of all M parameters
List of integers Displays trace plot of the parameters specified
by the passed List of integers
'meanConvergence' String or Inte-
ger
default:
'none'
Convergence plot of the empirical mean
averaged over all chains.
'all' Displays convergence of mean estimate of all
M parameters.
List of integers Displays convergence of mean estimate of
parameters specified by the list of Integers
'acceptance' Boolean If True a plot of the acceptance ratio for all
chains is displayed
Examples:
The command:
uq.display(myBayesianAnalysis, 'scatterplot', [1, 3])
displays scatterplots of the first and third parameter x
1
and x
3
.
3.4.2.2 Spectral likelihood expansions
UQ[PY]LABcurrently does not support visualizing data from spectral likelihood expansions.
UQ[PY]LAB-V1.0-113 - 73 -
UQ[PY]LAB user manual
3.4.2.3 Stochastic spectral likelihood embedding
UQ[PY]LABcurrently does not support visualizing data from stochastic spectral likelihood
embedding.
UQ[PY]LAB-V1.0-113 - 74 -
References
Allison, R. and J. Dunkley (2013). Comparison of sampling techniques for Bayesian param-
eter estimation. Monthly Notices of the Royal Astronomical Society 437(4), 3918–3928. 14,
42
Beck, J. L. (2010). Bayesian system identification based on probability logic. Structural
Control & Health Monitoring 17(7), 825–847. 1
Brooks, S., A. Gelman, G. L. Jones, and X.-L. Meng (Eds.) (2011). Handbook of Markov Chain
Monte Carlo. Handbooks of Modern Statistical Methods. Chapman & Hall/CRC. 17
Brooks, S. P. and A. Gelman (1998). General methods for monitoring convergence of iterative
simulations. Journal of Computational and Graphical Statistics 7(4), 434–455. 16, 17
Duane, S., A. D. Kennedy, B. J. Pendleton, and D. Roweth (1987). Hybrid Monte Carlo.
Physics Letters B 195(2), 216–222. 12
Gelman, A., J. B. Carlin, H. S. Stern, D. B. Dunson, A. Vehtari, and D. B. Rubin (2014).
Bayesian Data Analysis (3 ed.). Texts in Statistical Science. Boca Raton, Florida, USA: CRC
Press. 1, 3
Gelman, A., G. O. Roberts, and W. R. Gilks (1996). Efficient Metropolis jumping rules. In
J. M. Bernardo, J. O. Berger, A. P. Dawid, and A. F. M. Smith (Eds.), Bayesian Statistics 5,
Proceedings of the 5th Valencia International Meeting, June 5-9, 1994, pp. 599–607. Oxford
University Press. 11
Gelman, A. and D. B. Rubin (1992). Inference from iterative simulation using multiple se-
quences. Statistical Science 7(4), 457–472. 16
Goodman, J. and J. Weare (2010). Ensemble samplers with affine invariance. Communica-
tions in Applied Mathematics and Computational Science 5(1), 65–80. 13, 14, 42
Haario, H., E. Saksman, and J. Tamminen (2001). An adaptive Metropolis algorithm.
Bernoulli 7(2), 223–242. 11, 12
Hadidi, R. and N. Gucunski (2008). Probabilistic approach to the solution of inverse problems
in civil engineering. Journal of Computing in Civil Engineering 22(6), 338–347. 1
75
UQ[PY]LAB user manual
Hastings, W. K. (1970). Monte Carlo sampling methods using Markov chains and their ap-
plications. Biometrika 57(1), 97–109. 9
Hu, K. T. and G. Orient (2016). The 2014 Sandia verification and validation challenge:
problem statement. Journal of Verification, Validation and Uncertainty Quantification 1(1),
1–10. 4
Kaipio, J. and E. Somersalo (2005). Statistical and Computational Inverse Problems. Number
160 in Applied Mathematical Sciences. New York: Springer. 1
Liu, J. S. (2004). Monte Carlo Strategies in Scientific Computing. Springer Series in Statistics.
New York: Springer. 9
L
¨
uthen, N., S. Marelli, and B. Sudret (2020, September). Automatic selection of basis-
adaptive sparse polynomial chaos expansions for engineering applications. 18
Marelli, S., P.-R. Wagner, C. Lataniotis, and B. Sudret (2021). Stochastic spectral embedding.
11(2), 25–47. 19
Metropolis, N., A. W. Rosenbluth, M. N. Rosenbluth, A. H. Teller, and E. Teller (1953). Equa-
tion of state calculations by fast computing machines. Journal of Chemical Physics 21(6),
1087–1092. 9
Nagel, J. B. and B. Sudret (2016a). Hamiltonian Monte Carlo and borrowing strength in
hierarchical inverse problems. ASCE-ASME Journal of Risk and Uncertainty in Engineering
Systems, Part A: Civil Engineering 2(3), 1–12. 12
Nagel, J. B. and B. Sudret (2016b). Spectral likelihood expansions for Bayesian inference.
309, 267–294. 17, 18
Neal, R. M. (2011). MCMC using Hamiltonian dynamics. In S. Brooks, A. Gelman, G. L.
Jones, and X.-L. Meng (Eds.), Handbook of Markov Chain Monte Carlo, Handbooks of Mod-
ern Statistical Methods, Chapter 5, pp. 113–162. Boca Raton, Florida, USA: Chapman &
Hall/CRC. 12, 13
Oberkampf, W. and C. Roy (2010). Verification and Validation in Scientific Computing. Cam-
bridge University Press. 4
Oberkampf, W., T. Trucano, and C. Hirsch (2004). Verification, validation, and predictive
capability in computational engineering and physics. Applied Mechanics Reviews 57(5),
345–384. 4
Robert, C. P. and G. Casella (2004). Monte Carlo Statistical Methods (2 ed.). Springer Series
in Statistics. New York: Springer. 9
Roberts, G. O., A. Gelman, and W. R. Gilks (1997). Weak convergence and optimal scaling of
random walk Metropolis algorithms. The Annals of Applied Probability 7(1), 110–120. 14
UQ[PY]LAB-V1.0-113 - 76 -
Bayesian inference for model calibration and inverse problems
Schoups, G. and J. A. Vrugt (2010). A formal likelihood function for parameter and predictive
inference of hydrologic models with correlated, heteroscedastic, and non-Gaussian errors.
Water Resources Research 46(10), W10531. 5
Sudret, B. (2018). Einf
¨
uhrung in die Baustatik. ETH Z
¨
urich. 48
Tarantola, A. (2005). Inverse Problem Theory and Methods for Model Parameter Estimation.
Philadelphia, Pennsylvania, USA: Society for Industrial and Applied Mathematics (SIAM).
1
Wagner, P.-R., S. Marelli, and B. Sudret (2021). Bayesian model inversion using stochastic
spectral embedding. 436, 110141. 19, 20, 21
Wand, M. and M. C. Jones (1995). Kernel smoothing. Chapman and Hall, Boca Raton. 15
Wicaksono, D. C. (2017). Bayesian uncertainty quantification of physical models in thermal-
hydraulics system codes. Ph. D. thesis, Swiss Federal Institute of Technology, Lausanne,
Switzerland. 14, 42
Yuen, K.-V. and S.-C. Kuok (2011). Bayesian methods for updating dynamic models. Applied
Mechanics Reviews 64(1), 1–18. 1
UQ[PY]LAB-V1.0-113 - 77 -