compute_l2_error

pyapprox.approximate.compute_l2_error(f, g, variable, nsamples, rel=False)[source]

Compute the \(\ell^2\) error of the output of two functions f and g, i.e.

\[\lVert f(z)-g(z)\rVert\approx \sum_{m=1}^M f(z^{(m)})\]

from a set of random draws \(\mathcal{Z}=\{z^{(m)}\}_{m=1}^M\) from the PDF of \(z\).

Parameters
fcallable

Function with signature

g(z) -> np.ndarray

where z is a 2D np.ndarray with shape (nvars,nsamples) and the output is a 2D np.ndarray with shaoe (nsamples,nqoi)

gcallable

Function with signature

f(z) -> np.ndarray

where z is a 2D np.ndarray with shape (nvars,nsamples) and the output is a 2D np.ndarray with shaoe (nsamples,nqoi)

variablepya.IndependentMultivariateRandomVariable

Object containing information of the joint density of the inputs z. This is used to generate random samples from this join density

nsamplesinteger

The number of samples used to compute the \(\ell^2\) error

relboolean

True - compute relative error False - compute absolute error

Returns
errornp.ndarray (nqoi)