PC-KRIGING METAMODELING: DEMONSTRATION OF BASIC USAGE¶
This example illustrates different options of constructing polynomial chaos-Kriging (PC-Kriging) metamodels of a simple one-dimensional analytical function.
Package imports¶
from uqpylab import sessions
import numpy as np
import matplotlib.pyplot as plt
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 (a815349599ac4d23894b067446e46003) started.
uqpylab.sessions :: INFO :: Reset successful.
Set the random seed for reproducibility¶
uq.rng(101,'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 in UQCloud using a string:
ModelOpts = {
'Type': 'Model',
'ModelFun': 'xsinx.model'
}
myModel = uq.createModel(ModelOpts)
Probabilistic input model¶
The probabilistic input model consists of one uniform random variable:
$X \sim \mathcal{U}(0, 15)$
Specify the marginal and create an INPUT object:
InputOpts = {
'Marginals': {
'Type': 'Uniform',
'Parameters': [0, 15]
}
}
Create an INPUT object based on the specified marginals:
myInput = uq.createInput(InputOpts)
Experimental design¶
To compare different PC-Kriging metamodeling techniques, create an experimental design of size $10$ using the Sobol' sequences:
X = uq.getSample(myInput, 10, 'Sobol')
Evaluate the computational model at the experimental design points:
Y = uq.evalModel(myModel, X)
PC-KRIGING METAMODELS¶
Two different modes of PC-Kriging metamodel are considered below: Sequential mode and Optimal mode.
Sequential PC-Kriging metamodel¶
Select PCK
as the metamodeling tool in UQLab and sequential
as its mode:
SeqPCKOpts = {
"Type": "Metamodel",
"MetaType": "PCK",
"Mode": "Sequential"
}
Assign the experimental design to the metamodel specification:
SeqPCKOpts["ExpDesign"] = {
"X": X.tolist(),
"Y": Y.tolist(),
}
Specify the range for the selection of the maximum polynomial degree of the trend:
SeqPCKOpts["PCE"] = {
"Degree": np.arange(1,11).tolist()
}
Create the Sequential PC-Kriging metamodel:
mySeqPCK = uq.createModel(SeqPCKOpts)
Processing . done!
Print a summary of the resulting metamodel:
uq.print(mySeqPCK)
%--------------- PC-Kriging metamodel ---------------% Object Name: Model 2 Input Dimension: 1 Experimental Design Sampling: User X size: [10x1] Y size: [10x1] Combination Mode: Sequential Trend Type: orthogonal polynomials No. polys: 4 Gaussian Process Corr. Handle: uq_eval_Kernel Hyperparameters theta: [ 0.09651 ] Optim. method: Hybrid Genetic Algorithm Leave-one-out error: 7.0028372e-02 %--------------------------------------------------%
Display a visual representation of the resulting Sequential PC-Kriging metamodel:
uq.display(mySeqPCK);
The metamodel can predict at any new point in the input domain. For example, at $x = 3$:
[ySPCK,ySPCKs2] = uq.evalModel(mySeqPCK, 3, nargout=2)
print("Prediction mean value: {:.4e}".format(np.squeeze(ySPCK)[()]))
print("Prediction variance: {:.4e}".format(np.squeeze(ySPCKs2)[()]))
Prediction mean value: 1.1038e-01 Prediction variance: 1.0577e+00
Optimal PC-Kriging metamodel¶
Optimal PC-Kriging metamodels differ from the Sequential PC-Kriging metamodels only in the construction of the trend function. Hence, the same options as before can be used with a slight adjustment, now with optimal
as the mode:
OptPCKOpts = SeqPCKOpts
OptPCKOpts['Mode'] = 'Optimal'
Create the Optimal PC-Kriging metamodel:
myOptPCK = uq.createModel(OptPCKOpts)
Display a visual representation of the resulting Optimal PC-Kriging metamodel:
uq.display(myOptPCK);
Terminate the remote UQCloud session¶
mySession.quit()
uqpylab.sessions :: INFO :: Session a815349599ac4d23894b067446e46003 terminated.
True