Create a linear least squares modelΒΆ

In this basic example we are going to create a global approximation of a model response using a linear function:

\underline{y} \, \approx \, \widehat{h}(\underline{x}) \,
                     = \, \sum_{j=0}^{n_X} \; a_j \; \psi_j(\underline{x})

Here

h(x) = [cos(x_1 + x_2), (x2 + 1)* e^{x_1 - 2* x_2}]

In [2]:
from __future__ import print_function
import openturns as ot

# prepare some data
formulas = ['cos(x1 + x2)', '(x2 + 1) * exp(x1 - 2 * x2)']
model = ot.SymbolicFunction(['x1', 'x2'], formulas)
x  = [[0.5,0.5], [-0.5,-0.5], [-0.5,0.5], [0.5,-0.5]]
x += [[0.25,0.25], [-0.25,-0.25], [-0.25,0.25], [0.25,-0.25]]
y = model(x)
In [3]:
# create a linear least squares model
algo = ot.LinearLeastSquares(x, y)
algo.run()
responseSurface = algo.getResponseSurface()
In [4]:
# plot 2nd output of our model with x1=0.5
graph = ot.ParametricFunction(responseSurface, [0], [0.5]).getMarginal(1).draw(-0.5, 0.5)
curve = ot.ParametricFunction(model, [0], [0.5]).getMarginal(1).draw(-0.5, 0.5).getDrawable(0)
curve.setColor('red')
graph.add(curve)
graph
Out[4]:
../../_images/examples_meta_modeling_create_linear_least_squares_model_4_0.svg