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:
objectAbstract scalar functional of
x = [u, m, p].
- 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.
- class hippymfem.forward_uq.qoi.QuadraticStateQoi(W, comm=None)[source]
-
\(q = \tfrac12 u^{\!\top} W u\) for a symmetric
W.With
Wthe mass matrix restricted to a subdomain this is half the squared \(L^2\) norm of the state there.
- hippymfem.forward_uq.qoi.l2_norm_qoi(Vh, attributes=None, comm=None)[source]
q = 1/2 ||u||^2over the domain or over given element attributes.
- hippymfem.forward_uq.qoi.weighted_mean_qoi(Vh, w=None)[source]
q(u)= thew-weighted mean of the state,(w^T M u) / (w^T M 1).wis a field onVh(an indicator of a target region, say);Noneis the spatial mean. The functional is built bymass_functional(), so no matrix is formed; the normalizing volume is kept asq.volume.
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]
-
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, withFieldarguments.
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:
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:
ReducedMapThe reduced map
m -> q(u(m), m)with adjoint derivatives.A
ReducedMapwhose functional is the QoI: the same solves and blocks as the inverse problem’sModel, without a prior.- setLinearizationPoint(x, gauss_newton_approx=False)[source]
Fix the linearization point of the reduced Hessian.
matrix_freeis handed to the problem (seesetLinearizationPoint()): its second-derivative products are then computed from the element kernels rather than from assembled blocks.
- hessian(m=None, x=None)[source]
A
Parameter2QoiHessianatm(or at a givenx).
- class hippymfem.forward_uq.parameter2QoiMap.Parameter2QoiHessian(p2qoimap)[source]
Bases:
ReducedHessianMatrix-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 likeh.
- 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})\),
Both moments of that quadratic model are available in closed form from the eigenvalues \(d_i\) of the prior-preconditioned Hessian:
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:
objectFirst- and second-order Taylor model of a parameter-to-QoI map.
- Parameters:
p2qoimap (Parameter2QoiMap)
distribution (a prior, or a
GaussianLRPosterior) – The Gaussian the parameter is drawn from; the expansion point is its mean.
- 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.
Omegasupplies the randomized sketch;kdefaults to all of its columns.
- 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(), whicheval()with the full Hessian matches only when every eigenvalue that counts was kept; a control variate needs that. It costs one product withBinstead 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,
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.