PCE METAMODELING: BOOTSTRAP PCE FOR LOCAL ERROR ESTIMATION¶
This example showcases the creation and use of a bootstrap polynomial chaos expansion (bPCE). The full computational model model is an analytical non-linear, non-monotonic function.
Package imports¶
from uqpylab import sessions, display_util
import matplotlib.pyplot as plt
import numpy as np
Initialize common plotting parameters¶
display_util.load_plt_defaults()
uq_colors = display_util.get_uq_color_order()
Start a remote UQCloud session¶
# Start the session
mySession = sessions.cloud()
# (Optional) Get a convenient handle to the command line interface
uq = mySession.cli
# Reset the session
mySession.reset()
Processing .
.
done! uqpylab.sessions :: INFO :: This is UQ[py]Lab, version 1.00, running on https://uqcloud.ethz.ch. UQ[py]Lab is free software, published under the open source BSD 3-clause license. To request special permissions, please contact: - Stefano Marelli (marelli@ibk.baug.ethz.ch). A new session (762aebd311024909a476fbcd402fd4c6) started.
uqpylab.sessions :: INFO :: Reset successful.
Set the random seed for reproducibility¶
uq.rng(100,'twister');
Computational model¶
The computational model is a simple analytical function defined by:
$$y(x) = x \sin(x), \; x \in [0, 15]$$
Specify this model using a string and create a MODEL object:
ModelOpts = {
'Type': 'Model',
'ModelFun': 'xsinx.model',
'isVectorized': 'true'
}
myModel = uq.createModel(ModelOpts)
Probabilistic input model¶
The probabilistic input model consists of a single uniform random variable:
$X \sim \mathcal{U}(0, 15)$
Specify its marginal distribution and create a INPUT object:
InputOpts = {
'Marginals': [
{
'Type': 'Uniform',
'Parameters': [0, 15]
}
]
}
myInput = uq.createInput(InputOpts)
Bootstrap-PCE (bPCE) metamodel¶
MetaOpts = {
"Type": "Metamodel",
"MetaType": "PCE",
"FullModel" : myModel["Name"]
}
Specify the expansion degree
MetaOpts["Degree"] = 11
Request an experimental design of size 15
MetaOpts["ExpDesign"] = {
"NSamples" : 15
}
And request 100 bootstrap replications:
MetaOpts["Bootstrap"] = {
"Replications" : 100
}
Create the PCE metamodel:
myPCE = uq.createModel(MetaOpts)
uqpylab.sessions :: INFO :: Received intermediate compute request, function: xsinx.model.
uqpylab.sessions :: INFO :: Carrying out local computation...
uqpylab.sessions :: INFO :: Local computation complete.
uqpylab.sessions :: INFO :: Starting transmission of intermediate compute results ((15, 1))...
uqpylab.sessions :: INFO :: Intermediate compute results sent.
Print out a report on the resulting PCE object:
uq.print(myPCE)
%------------ Polynomial chaos output ------------% Number of input variables: 1 Maximal degree: 11 q-norm: 1.00 Size of full basis: 12 Size of sparse basis: 11 Full model evaluations: 15 Leave-one-out error: 3.2730081e-03 Modified leave-one-out error: 8.7050061e-02 Mean value: 0.9001 Standard deviation: 6.4132 Coef. of variation: 712.533% %--------------------------------------------------%
Metamodels validation¶
Create a validation set of size $10^3$ over a regular grid:
Xval = uq.getSample(N=1e3, Method='grid')
Evaluate the true model responses for the validation set:
Yval = uq.evalModel(myModel, Xval)
Evaluate the PCE surrogate predictions on the validation set. In each case, both the mean and the variance of the PCE predictor are calculated:
[YPCE,YVarPCE,YBPCE] = uq.evalModel(myPCE, Xval, nargout=3)
YPCEq = np.transpose(np.quantile(YBPCE,[0.025,0.975],1))
np.shape(YPCEq)
(1000, 2)
# Extract quantile for plotting
YPCEq = np.transpose(np.quantile(YBPCE,[0.025,0.975],1))
# and also the final exp design of PCE
X = myPCE["ExpDesign"]["X"]
Y = myPCE["ExpDesign"]["Y"]
plt.plot(Xval, YPCE,'-')
plt.plot(Xval, YBPCE, '-',color=uq_colors[1],linewidth=0.2)
plt.plot(Xval, YPCEq, '--',color=uq_colors[0])
plt.plot(X, Y, 'ko',markersize=3)
plt.xlim([0, 15])
plt.ylim([-15, 20])
plt.xlabel('$\\mathrm{X}$')
plt.ylabel('$\\mathrm{Y}$')
plt.show()
Terminate the remote UQCloud session¶
mySession.quit()
uqpylab.sessions :: INFO :: Session 762aebd311024909a476fbcd402fd4c6 terminated.
True