PC-KRIGING METAMODELING: TRUSS DATA SET¶

This example showcases how to perform polynomial chaos-Kriging (PC-Kriging) metamodeling using existing data sets. The data sets come from a finite element model of a truss structure and are retrieved from different MAT-files. The files consist of an experimental design of size $200$ and a validation set of size $10^4$.

Package imports¶

In [1]:
from uqpylab import sessions, display_general, display_util
import numpy as np
import matplotlib.pyplot as plt
import scipy.io

Parameters¶

In [2]:
UQColors = display_util.get_uq_color_order(2)
UQBlue = UQColors[0]
UQOrange = UQColors[1]

Start a remote UQCloud session¶

In [3]:
# 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 (c04a8cf3642440ec880e02fc0b5c6f03) started.
 uqpylab.sessions :: INFO     :: Reset successful.

Retrieve data sets¶

The experimental design and the validation basis are stored in two separate files in the following location:

In [4]:
file_location = './Truss_Matlab_FEM'

Read the experimental design data set file and store the content in matrices:

In [5]:
mat = scipy.io.loadmat('{}/{}'.format(file_location,'Truss_Experimental_Design.mat'))
X = mat['X']
Y = mat['Y']

Read the validation basis data set file and store the contents in matrices:

In [6]:
mat = scipy.io.loadmat('{}/{}'.format(file_location,'Truss_Validation_Basis.mat'))
Xval = mat['Xval']
Yval = mat['Yval']

Probabilistic input model¶

Due to the use of polynomial chaos as trend, a probabilistic input model has to be specified for the PC-Kriging metamodel. Specify the marginals of the probabilistic input model:

In [7]:
# Young's modulus of cross-sections
InputOpts = {
    'Marginals': [{'Name': 'E{:d}'.format(i), 'Type': 'Lognormal', 'Moments': [2.1e11, 2.1e10]} for i in range(1,3)]
}

# Cross-section of horizontal elements
InputOpts['Marginals'].append({'Name': 'A1', 'Type': 'Lognormal', 'Moments': [2.0e-3, 2.0e-4]})

# Cross-section of diagonal elements
InputOpts['Marginals'].append({'Name': 'A2', 'Type': 'Lognormal', 'Moments': [1.0e-3, 1.0e-4]})

# Loads on the node of top chord
InputOpts['Marginals'].extend([{'Name': 'P{:d}'.format(i), 'Type': 'Gumbel', 'Moments': [5.0e4, 7.5e3]} for i in range(1,7)])

Create an INPUT object based on the specified marginals:

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

PC-Kriging metamodel¶

Select PCK as the metamodeling tool and sequential as its mode:

In [9]:
MetaOpts = {
    'Type': 'Metamodel',
    'MetaType': 'PCK',
    'Mode': 'sequential'
}

Use experimental design loaded from the data files:

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

Use the covariance matrix adaptation-evolution strategy (CMA-ES) optimization algorithm (built in UQLab) for the hyperparameters estimation of the Kriging part of the PC-Kriging metamodel:

In [11]:
MetaOpts['Kriging'] = {
    'Optim': {
        'Method': 'CMAES'
    }
}

Set the maximum polynomial degree of the polynomial chaos expansion (PCE) trend to $5$:

In [12]:
MetaOpts['PCE'] = {
    'Degree': np.arange(1,6).tolist()
}

Provide the validation data set to get the validation error:

In [13]:
MetaOpts['ValidationSet'] = {
    'X': Xval.tolist(),
    'Y': Yval.tolist()
}

Create the PC-Kriging metamodel:

In [14]:
myPCK = uq.createModel(MetaOpts)
Processing .
 done!

Print a summary of the resulting PC-Kriging metamodel:

In [15]:
uq.print(myPCK)
%--------------- PC-Kriging metamodel ---------------%
	Object Name:		Model 1
	Input Dimension:	10

	Experimental Design
		Sampling:	User
		X size:		[200x10]
		Y size:		[200x1]

	Combination
		Mode:			sequential

	Trend
		Type:		orthogonal polynomials
		No. polys:	88

	Gaussian Process
		Corr. Handle:	uq_eval_Kernel

	Hyperparameters
		theta:		[ 5.00050	 5.00050	 5.00050	 5.00050	 5.00050	 5.00050	 5.00050	 5.00050	 5.00050	 5.00050	]
	Optim. method:		CMAES

	Leave-one-out error:	2.0613877e-05

	Validation error:		5.7079071e-05

%--------------------------------------------------%

Validation¶

Evaluate the PC-Kriging metamodel at the validation set points:

In [16]:
YPCK = uq.evalModel(myPCK,Xval)

Plot histograms of the true output and the PC-Kriging prediction:

In [17]:
nBins1 = display_general.BinWidth_ScottsRule(Yval)
nBins2 = display_general.BinWidth_ScottsRule(YPCK)

plt.hist(Yval, facecolor=UQBlue, bins=nBins1)   
plt.hist(YPCK, facecolor=UQOrange, bins=nBins2)  
legend_text = ['True model response', 'PCK prediction']
plt.legend(legend_text, fontsize=14, frameon=False, loc="best")
plt.xlabel('$Y$')
plt.ylabel('Counts')
plt.grid(True)
No description has been provided for this image

Plot the true vs. predicted values:

In [18]:
plt.scatter(Yval, YPCK, marker = '+', color=UQBlue)
plt.plot([np.min(Yval), np.max(Yval)], [np.min(Yval), np.max(Yval)], color="black")

plt.xlabel('$Y_{true}$')
plt.ylabel('$Y_{PCK}$')
plt.grid(True)
No description has been provided for this image

Print the validation and leave-one-out (LOO) cross-validation errors:

In [19]:
print('PCK metamodel validation error: {:5.4e}'.format(myPCK['Error']['Val']))
print('PCK metamodel LOO error:        {:5.4e}'.format(myPCK['Error']['LOO']))
PCK metamodel validation error: 5.7079e-05
PCK metamodel LOO error:        2.0614e-05

Terminate the remote UQCloud session¶

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