Forward UQ

Quantities of interest, the parameter-to-QoI map, Taylor approximations.

hippymfem.forward_uq.qoi

Quantities of interest: scalar functionals of the state and parameter.

A QoI plays the role the misfit plays in the inverse problem: it supplies a value, its first derivatives, and the action of its second derivatives. The forward-UQ machinery then treats \(m \mapsto q(u(m), m)\) as a parameter-to-QoI map and propagates uncertainty through it.

class hippymfem.forward_uq.qoi.Qoi[source]

Bases: object

Abstract scalar functional of x = [u, m, p].

eval(x)[source]
grad(i, x, g)[source]
setLinearizationPoint(x)[source]
apply_ij(i, j, dir, out)[source]
class hippymfem.forward_uq.qoi.NullQoi[source]

Bases: Qoi

Always zero; useful as a placeholder.

eval(x)[source]
grad(i, x, g)[source]
setLinearizationPoint(x)[source]
apply_ij(i, j, dir, out)[source]
class hippymfem.forward_uq.qoi.LinearStateQoi(ell)[source]

Bases: Qoi

\(q = \ell^{\!\top} u\) for a fixed dual vector \(\ell\).

Covers pointwise and averaged observations of the state: with \(\ell = B^{\!\top}e_k\) it is the value at target k, and with \(\ell = M\mathbf{1}/|\Omega|\) the spatial average.

eval(x)[source]
grad(i, x, g)[source]
setLinearizationPoint(x)[source]
apply_ij(i, j, dir, out)[source]
class hippymfem.forward_uq.qoi.QuadraticStateQoi(W, comm=None)[source]

Bases: Qoi, KeepAlive

\(q = \tfrac12 u^{\!\top} W u\) for a symmetric W.

With W the mass matrix restricted to a subdomain this is half the squared \(L^2\) norm of the state there.

eval(x)[source]
grad(i, x, g)[source]
setLinearizationPoint(x)[source]
apply_ij(i, j, dir, out)[source]
hippymfem.forward_uq.qoi.l2_norm_qoi(Vh, attributes=None, comm=None)[source]

q = 1/2 ||u||^2 over the domain or over given element attributes.

hippymfem.forward_uq.qoi.weighted_mean_qoi(Vh, w=None)[source]

q(u) = the w-weighted mean of the state, (w^T M u) / (w^T M 1).

w is a field on Vh (an indicator of a target region, say); None is the spatial mean. The functional is built by mass_functional(), so no matrix is formed; the normalizing volume is kept as q.volume.

hippymfem.forward_uq.qoi.mean_state_qoi(Vh)[source]

q = the spatial average of the state, (1^T M u) / (1^T M 1).

hippymfem.forward_uq.variationalQoi

Quantities of interest defined by a pointwise density.

The same machinery as the forward problem: the user writes q(u, m, x) -> scalar at one quadrature point, and the value, first and second derivatives all come from differentiating it. Use this when the QoI is an integral such as \(\int_\Omega e^{m}|\nabla u|^2\), which no fixed matrix represents.

class hippymfem.forward_uq.variationalQoi.VariationalQoi(Vh, qoi_varf, quadrature_degree=None)[source]

Bases: Qoi, KeepAlive

QoI from a pointwise density q(u, m, x).

Parameters:
  • Vh (sequence of 3 spaces) – [STATE, PARAMETER, ADJOINT].

  • qoi_varf (callable) – qoi_varf(u, m, x) -> scalar, JAX-traceable, with Field arguments.

eval(x)[source]
grad(i, x, g)[source]
setLinearizationPoint(x)[source]
apply_ij(i, j, dir, out)[source]

hippymfem.forward_uq.parameter2QoiMap

The parameter-to-QoI map and its derivatives.

For a QoI \(q(u, m)\) constrained by the forward PDE, the reduced map is \(\mathcal{Q}(m) = q(u(m), m)\). Its gradient comes from the same adjoint machinery as the inverse problem’s, and its Hessian from the same incremental solves:

\[\nabla\mathcal{Q} = \partial_m q + C^{\!\top}p, \qquad \mathcal{H} = \text{(the reduced Hessian of }q).\]

The sign convention differs from the inverse problem’s in one place: the adjoint source is \(-\partial_u q\) rather than \(-\partial_u\Phi\), and there is no regularization term.

class hippymfem.forward_uq.parameter2QoiMap.Parameter2QoiMap(problem, qoi)[source]

Bases: ReducedMap

The reduced map m -> q(u(m), m) with adjoint derivatives.

A ReducedMap whose functional is the QoI: the same solves and blocks as the inverse problem’s Model, without a prior.

eval(x)[source]
evalGradientParameter(x, mg)[source]

mg = \(\partial_m q + C^{\!\top}p\).

setLinearizationPoint(x, gauss_newton_approx=False)[source]

Fix the linearization point of the reduced Hessian.

matrix_free is handed to the problem (see setLinearizationPoint()): its second-derivative products are then computed from the element kernels rather than from assembled blocks.

reduced_eval(m)[source]

Q(m): solve forward, then evaluate.

reduced_gradient(m, g=None)[source]

grad Q(m); returns (value, gradient).

hessian(m=None, x=None)[source]

A Parameter2QoiHessian at m (or at a given x).

class hippymfem.forward_uq.parameter2QoiMap.Parameter2QoiHessian(p2qoimap)[source]

Bases: ReducedHessian

Matrix-free Hessian of the parameter-to-QoI map: the reduced Hessian of the map’s functional, with no prior term.

hippymfem.forward_uq.parameter2QoiMap.parameter2QoiMapVerify(p2qoimap, m0, eps=None, verbose=True)[source]

Finite-difference check of the reduced gradient and Hessian.

Returns (eps, err_grad, err_H), each of which should fall like h.

hippymfem.forward_uq.parameter2QoiMap.qoiVerify(p2qoimap, m0, eps=None, verbose=True)

hIPPYlib’s name for the verification helper

hippymfem.forward_uq.taylorApproximationQoi

Taylor approximations of the parameter-to-QoI map, and their moments.

Around the mean \(\bar m\) of a Gaussian \(m \sim N(\bar m, R^{-1})\),

\[\mathcal{Q}(m) \approx \bar q + g^{\!\top}\delta m + \tfrac12 \delta m^{\!\top}\mathcal{H}\,\delta m .\]

Both moments of that quadratic model are available in closed form from the eigenvalues \(d_i\) of the prior-preconditioned Hessian:

\[\mathbb{E}[\mathcal{Q}] \approx \bar q + \tfrac12\sum_i d_i, \qquad \mathrm{Var}[\mathcal{Q}] \approx g^{\!\top}R^{-1}g + \tfrac12\sum_i d_i^2 .\]

That is the point of the construction: a handful of Hessian eigenpairs replaces a Monte Carlo sum, and the same quadratic model then serves as a control variate for a small sample (see varianceReductionMC).

class hippymfem.forward_uq.taylorApproximationQoi.TaylorApproximationQoi(p2qoimap, distribution)[source]

Bases: object

First- and second-order Taylor model of a parameter-to-QoI map.

Parameters:
computeLowRankFactorization(Omega, k=None, s=1, check=False)[source]

Solve at the mean and factor the prior-preconditioned Hessian.

Must be called before the moment methods. Omega supplies the randomized sketch; k defaults to all of its columns.

expectedValue(order=2)[source]

Expected value of the Taylor model (analytic).

variance(order=2)[source]

Variance of the Taylor model (analytic).

eval(m, order=2)[source]

Evaluate the Taylor model at a realization m, with the full Hessian.

eval_lowrank(m, order=2)[source]

The Taylor model with the low-rank Hessian of the factorization, \(\bar q + \bar g^{\top}\delta m + \tfrac12\sum_i d_i (u_i^{\top} B\,\delta m)^2\).

Its mean under the distribution is exactly expectedValue(), which eval() with the full Hessian matches only when every eigenvalue that counts was kept; a control variate needs that. It costs one product with B instead of the two PDE solves of a Hessian action.

hippymfem.forward_uq.varianceReductionMC

Monte Carlo with a Taylor-model control variate.

Plain Monte Carlo estimates \(\mathbb{E}[\mathcal{Q}]\) with an error falling like \(\sigma/\sqrt{N}\), and each sample costs a PDE solve. Using the quadratic Taylor model \(\mathcal{Q}_2\) as a control variate,

\[\mathbb{E}[\mathcal{Q}] \approx \mathbb{E}[\mathcal{Q}_2] + \frac{1}{N}\sum_i \left(\mathcal{Q}(m_i) - \mathcal{Q}_2(m_i)\right),\]

the sampled quantity is the difference, whose variance is small whenever the map is nearly quadratic. \(\mathbb{E}[\mathcal{Q}_2]\) is known analytically, so nothing is lost and the sample variance is what shrinks.

hippymfem.forward_uq.varianceReductionMC.varianceReductionMC(prior, p2qoimap, taylor_qoi, nsamples, order=2, rng=None, verbose=False, comm=None)[source]

Estimate the mean of the QoI with and without the Taylor control variate.

Returns a dict with the plain Monte Carlo estimate, the corrected estimate, the two sample standard deviations, and the observed variance reduction factor.