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¶

In [1]:
from uqpylab import sessions
import numpy as np
import matplotlib.pyplot as plt

Start a remote UQCloud session¶

In [2]:
# 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¶

In [3]:
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:

In [4]:
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:

In [5]:
InputOpts = {
    'Marginals': {
        'Type': 'Uniform', 
        'Parameters': [0, 15]
    }
}

Create an INPUT object based on the specified marginals:

In [6]:
myInput = uq.createInput(InputOpts)

Experimental design¶

To compare different PC-Kriging metamodeling techniques, create an experimental design of size $10$ using the Sobol' sequences:

In [7]:
X = uq.getSample(myInput, 10, 'Sobol')

Evaluate the computational model at the experimental design points:

In [8]:
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:

In [9]:
SeqPCKOpts = {
    "Type": "Metamodel",
    "MetaType": "PCK",
    "Mode": "Sequential"
}

Assign the experimental design to the metamodel specification:

In [10]:
SeqPCKOpts["ExpDesign"] = {
    "X": X.tolist(),
    "Y": Y.tolist(),
}

Specify the range for the selection of the maximum polynomial degree of the trend:

In [11]:
SeqPCKOpts["PCE"] = {
    "Degree": np.arange(1,11).tolist()
}

Create the Sequential PC-Kriging metamodel:

In [12]:
mySeqPCK = uq.createModel(SeqPCKOpts)
Processing . done!

Print a summary of the resulting metamodel:

In [13]:
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:

In [14]:
uq.display(mySeqPCK);

The metamodel can predict at any new point in the input domain. For example, at $x = 3$:

In [15]:
[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:

In [16]:
OptPCKOpts = SeqPCKOpts
OptPCKOpts['Mode'] = 'Optimal'

Create the Optimal PC-Kriging metamodel:

In [17]:
myOptPCK = uq.createModel(OptPCKOpts)

Display a visual representation of the resulting Optimal PC-Kriging metamodel:

In [18]:
uq.display(myOptPCK);

Terminate the remote UQCloud session¶

In [19]:
mySession.quit()
 uqpylab.sessions :: INFO     :: Session a815349599ac4d23894b067446e46003 terminated.
Out[19]:
True