KrigingSurrogate#

The KrigingSurrogate implements a simple Kriging interpolation method based on Gaussian Processes for Machine Learning (GPML) by Rasmussen and Williams. In the default configuration, the surrogate computes the mean of the predicted value. KrigingSurrogate also has an option “eval_rmse”, which can be set to True to also compute the RMSE (root mean squared error).

Here is a simple example where a Kriging model is used to approximate the output of a sinusoidal component.

import numpy as np

import openmdao.api as om

prob = om.Problem()

sin_mm = om.MetaModelUnStructuredComp()
sin_mm.add_input('x', 2.1)
sin_mm.add_output('f_x', 0., surrogate=om.KrigingSurrogate())

prob.model.add_subsystem('sin_mm', sin_mm)

prob.setup()

# train the surrogate and check predicted value
sin_mm.options['train_x'] = np.linspace(0,10,20)
sin_mm.options['train_f_x'] = .5*np.sin(sin_mm.options['train_x'])

prob.set_val('sin_mm.x', 2.1)

prob.run_model()

print(prob.get_val('sin_mm.f_x'))
[0.4316104]

KrigingSurrogate Options#

All options can be passed in as arguments or set later by accessing the options dictionary.

OptionDefaultAcceptable ValuesAcceptable TypesDescription
eval_rmseFalse[True, False]['bool']Flag indicating whether the Root Mean Squared Error (RMSE) should be computed. Set to False by default.
lapack_drivergesvdN/A['str']Which lapack driver should be used for scipy's linalg.svd.Options are 'gesdd' which is faster but not as robust,or 'gesvd' which is slower but more reliable.'gesvd' is the default.
nugget2.220446049250313e-15N/AN/ANugget smoothing parameter for smoothing noisy data. Represents the variance of the input values. If nugget is an ndarray, it must be of the same length as the number of training points. Default: 10. * Machine Epsilon
training_cacheN/AN/A['str']Cache the trained model to avoid repeating training and write it to the given file. If the specified file exists, it will be used to load the weights

KrigingSurrogate Constructor#

The call signature for the KrigingSurrogate constructor is:

KrigingSurrogate.__init__(**kwargs)[source]

Initialize all attributes.

Parameters:
**kwargsdict

options dictionary.

KrigingSurrogate Option Examples#

eval_rmse

By default, KrigingSurrogate only returns the mean of the predicted outputs. You can compute both the mean and the root mean square prediction error by setting the “eval_rmse” option to True. The most recent calculation of error is stored in the component’s metadata, and accessed as follows.

import numpy as np

import openmdao.api as om

prob = om.Problem()

sin_mm = om.MetaModelUnStructuredComp()
sin_mm.add_input('x', 2.1)
sin_mm.add_output('f_x', 0., surrogate=om.KrigingSurrogate(eval_rmse=True))

prob.model.add_subsystem('sin_mm', sin_mm)

prob.setup()

# train the surrogate and check predicted value
sin_mm.options['train_x'] = np.linspace(0,10,20)
sin_mm.options['train_f_x'] = .5*np.sin(sin_mm.options['train_x'])

prob.set_val('sin_mm.x', 2.1)

prob.run_model()

print("mean")
print(prob.get_val('sin_mm.f_x'))
print("std")
print(sin_mm._metadata('f_x')['rmse'][0, 0])
mean
[0.4316104]
std
2.1138841680290568e-05