KRIGING METAMODELING: TRUSS DATA SET¶

This example showcases how to perform 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_util
import numpy as np
import matplotlib.pyplot as plt
import scipy.io

# Initialize common plotting parameters
display_util.load_plt_defaults()
uq_colors = display_util.get_uq_color_order()

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()
 uqpylab.sessions :: INFO     :: A new session (aa0a56fe1d0e43ff8f0faa014783c7e3) started.
 uqpylab.sessions :: INFO     :: Reset successful.

Set random seed for reproducibility¶

In [3]:
uq.rng(0,'twister');

Retrieve data sets¶

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

In [4]:
# Read the binary files (stored in .mat format)
mat = scipy.io.loadmat('Truss_Experimental_Design.mat')
X = mat['X']
Y = mat['Y']

# Also read the validation basis data set file and store the contents in matrices:
mat = scipy.io.loadmat('Truss_Validation_Basis.mat')
X_val = mat['Xval']
Y_val = mat['Yval']

Kriging metamodel¶

Select Kriging as the metamodeling tool:

In [5]:
MetaOpts = {
    'Type': 'Metamodel',
    'MetaType': 'Kriging'
}

Use experimental design loaded from the data files:

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

Use maximum-likelihood to estimate the hyperparameters:

In [7]:
MetaOpts['EstimMethod'] = 'ML'

Use the built-in covariance-matrix adaptation evolution strategy optimization algorithm (CMAES) for estimating the hyperparameters:

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

Provide the validation data set to get the validation error:

In [9]:
MetaOpts['ValidationSet'] = {
    'X': X_val.tolist(),
    'Y': Y_val.tolist()
}

Create the Kriging metamodel:

In [10]:
myKriging = uq.createModel(MetaOpts)

Print a summary of the resulting Kriging metamodel:

In [11]:
uq.print(myKriging)
%---------------- Kriging metamodel ----------------%
    Object Name:            Model 1      
    Input Dimension:        10           
    Output Dimension:       1            

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

    Trend                  
       Type:                ordinary     
       Degree:              0            
       Beta:                [-0.09712	]  

    Gaussian Process (GP)  
       Corr. type:          ellipsoidal  
       Corr. isotropy:      anisotropic  
       Corr. family:        matern-5_2   
       sigma^2:             1.82059e-04  
       Estimation method:   Maximum-likelihood (ML)

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

    GP Regression          
       Mode:                interpolation

    Error estimates        
       Leave-one-out:       5.82005e-03  
       Validation:          2.09772e-03  
%---------------------------------------------------%

Validation¶

Evaluate the Kriging metamodel at the validation set:

In [12]:
Y_Krg = uq.evalModel(myKriging, X_val)

Plot histograms of the true output and the Kriging prediction:

In [16]:
plt.hist(Y_val, color=uq_colors[0], alpha = 0.8)
plt.hist(Y_Krg, color=uq_colors[1], alpha = 0.8)
legend_text = ['True model response', 'Kriging prediction']
plt.legend(legend_text, loc="best")
plt.xlabel('$\mathrm{Y}$')
plt.ylabel('Counts');
plt.show()

Plot the true vs. predicted values:

In [14]:
plt.scatter(Y_val, Y_Krg, marker='o', s=3)
plt.plot([np.min(Y_val), np.max(Y_val)], [np.min(Y_val), np.max(Y_val)], 'k')
plt.axis([np.min(Y_val), np.max(Y_val), np.min(Y_val), np.max(Y_val)])
plt.grid(True)
plt.xlabel('$\mathrm{Y_{true}}$')
plt.ylabel('$\mathrm{Y_{Krg}}$');
plt.show()

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

In [15]:
print('Kriging metamodel validation error: {:5.4e}'.format(myKriging['Error']['Val']))
print('Kriging metamodel LOO error:        {:5.4e}'.format(myKriging['Error']['LOO']))
Kriging metamodel validation error: 2.0977e-03
Kriging metamodel LOO error:        5.8200e-03

Terminate the remote UQCloud session¶

In [ ]:
mySession.quit()