KRIGING METAMODELING: ONE-DIMENSIONAL EXAMPLE¶
This example showcases how to perform Kriging metamodeling on a simple one-dimensional function using various types of correlation families.
Package imports¶
from uqpylab import sessions
import matplotlib.pyplot as plt
import numpy as np
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 (4f84b445542b42aaacc69ab0d3caa7df) 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)
Experimental design and model responses¶
Generate an experimental design $X$ of size $8$ using the latin hypercube sampling (LHS):
X = uq.getSample(N=8, Method='LHS')
Y = uq.evalModel(myModel, X)
Kriging metamodels¶
Three different correlation functions of the underlying Gaussian process to create Kriging metamodels are considered.
Matérn 5/2 correlation¶
Select the metamodeling tool and the Kriging module:
MetaOpts = {
"Type": "Metamodel",
"MetaType": "Kriging"
}
Use the experimental design and corresponding model responses generated earlier:
MetaOpts["ExpDesign"] = {
"X": X.tolist(),
"Y": Y.tolist()
}
Create the Kriging metamodel:
myKrigingMat = uq.createModel(MetaOpts)
Processing . done!
Note that the various options that have not been explicitly specified have been automatically assigned to their default values. This includes the correlation family which is set to Matérn 5/2 by default.
Print out a report on the resulting Kriging object:
uq.print(myKrigingMat)
%---------------- Kriging metamodel ----------------% Object Name: Model 2 Input Dimension: 1 Output Dimension: 1 Experimental Design X size: [8x1] Y size: [8x1] Sampling: User Trend Type: ordinary Degree: 0 Beta: [ 2.64467 ] Gaussian Process (GP) Corr. type: ellipsoidal Corr. isotropy: anisotropic Corr. family: matern-5_2 sigma^2: 4.59087e+02 Estimation method: Cross-validation (CV) Hyperparameters theta: [ 0.85210 ] Optim. method: Hybrid Genetic Alg. GP Regression Mode: interpolation Error estimates Leave-one-out: 5.40328e-01 %---------------------------------------------------%
Plot a representation of the mean and the 95% confidence bounds of the Kriging predictor:
uq.display(myKrigingMat);
Linear correlation¶
Create another Kriging metamodel with the same configuration options but use a linear correlation family instead:
MetaOpts['Corr'] = {
"Family": "Linear"
}
myKrigingLin = uq.createModel(MetaOpts)
Exponential correlation¶
Finally, create a Kriging metamodel using the exponential correlation family:
MetaOpts['Corr']['Family'] = 'Exponential'
myKrigingExp = uq.createModel(MetaOpts)
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 Kriging surrogate predictions on the validation set. In each case, both the mean and the variance of the Kriging predictor are calculated:
[YMeanMat,YVarMat] = uq.evalModel(myKrigingMat, Xval, nargout=2)
[YMeanLin,YVarLin] = uq.evalModel(myKrigingLin, Xval, nargout=2)
[YMeanExp,YVarExp] = uq.evalModel(myKrigingExp, Xval, nargout=2)
plt.plot(Xval, YMeanMat,'-')
plt.plot(Xval, YMeanLin,'-')
plt.plot(Xval, YMeanExp, '--')
plt.plot(Xval, Yval, '-k')
plt.plot(X, Y, 'ko',markersize=2)
plt.xlim([0, 15])
plt.ylim([-15, 20])
plt.legend(['Kriging, R: Matern 5/2',
'Kriging, R: Linear',
'Kriging, R: Exponential',
'True model', 'Observations'],
loc='upper left')
plt.xlabel('X')
plt.ylabel('Y')
plt.show()
Finally, compare the variance that is predicted by each Kriging metamodel:
plt.plot(Xval, YVarMat,'-')
plt.plot(Xval, YVarLin,'-')
plt.plot(Xval, YVarExp, '--')
plt.plot(X, np.zeros(Y.shape), 'ko',markersize=3)
plt.xlim([0, 15])
plt.ylim([0, 60])
plt.legend(['Kriging, R: Matern 5/2',
'Kriging, R: Linear',
'Kriging, R: Exponential',
'Observations'],
loc='upper left')
plt.xlabel('X')
plt.ylabel('Y')
plt.show()
Terminate the remote UQCloud session¶
mySession.quit()
uqpylab.sessions :: INFO :: Session 4f84b445542b42aaacc69ab0d3caa7df terminated.
True