Create a general linear model metamodelΒΆ

In this example we create a global approximation of a model response using a general linear model. We show how to use the GaussianProcessFitter class, which estimates the parameters of the model.

import openturns as ot
import openturns.experimental as otexp
import openturns.viewer as viewer

We create a model and a sample from this model.

dimension = 2
input_names = ["x1", "x2"]
formulas = ["cos(0.1 * x1 + 0.2 * x2)"]
model = ot.SymbolicFunction(input_names, formulas)
distribution = ot.Normal(dimension)
x = distribution.getSample(100)
y = model(x)

We create a GaussianProcessFitter based on a quadratic basis. The run method estimates the coefficients of the trend and the hyperparameters of the covariance model.

basis = ot.QuadraticBasisFactory(dimension).build()
covarianceModel = ot.SquaredExponential([1] * dimension, [1.0])
algo = otexp.GaussianProcessFitter(x, y, covarianceModel, basis)
algo.run()
result = algo.getResult()

We see that the trend coefficients have been estimated.

result.getTrendCoefficients()
class=Point name=Unnamed dimension=6 values=[0.9893,-9.10261e-05,-7.8651e-05,-0.00443002,-0.0177721,-0.0178076]


The parameters of the covariance models also have been estimated.

result.getCovarianceModel()

SquaredExponential(scale=[3.42943,1.84012], amplitude=[0.00434356])



The getMetaModel method returns the metamodel where the parameters have been estimated.

responseSurface = result.getMetaModel()

Plot the output of our model depending on x_2 with x_1=0.5.

xmin = -5.0
xmax = 5.0
x1value = 0.5
parametricModelGraph = ot.ParametricFunction(model, [0], [x1value]).draw(xmin, xmax)
graphMetamodel = ot.ParametricFunction(responseSurface, [0], [x1value]).draw(xmin, xmax)
parametricModelGraph.add(graphMetamodel)
parametricModelGraph.setLegends(["Model", "Meta-Model"])
parametricModelGraph.setLegendPosition("upper right")
view = viewer.View(parametricModelGraph)
y0 as a function of x2
view.ShowAll()