Create a polynomial chaos metamodelΒΆ

In this basic example we are going to create a global approximation of a model response using functional chaos.

Here

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

In [9]:
from __future__ import print_function
import openturns as ot
In [10]:
# prepare some X/Y data
ot.RandomGenerator.SetSeed(0)
dimension = 2
input_names = ['x1', 'x2']
formulas = ['cos(x1 + x2)', '(x2 + 1) * exp(x1 - 2 * x2)']
model = ot.SymbolicFunction(input_names, formulas)
distribution = ot.Normal(dimension)
x  = distribution.getSample(30)
y = model(x)
In [11]:
# create a functional chaos model
algo = ot.FunctionalChaosAlgorithm(x, y)
algo.run()
result = algo.getResult()
responseSurface = result.getMetaModel()
In [12]:
# 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[12]:
../../_images/examples_meta_modeling_functional_chaos_5_0.svg
In [13]:
# draw Sobol' indices
sensitivityAnalysis = ot.FunctionalChaosRandomVector(result)
first_order = list(map(lambda i: sensitivityAnalysis.getSobolIndex(i), range(dimension)))
ot.SaltelliSensitivityAlgorithm.DrawImportanceFactors(first_order, input_names, '1st order Sobol\' indices')
Out[13]:
../../_images/examples_meta_modeling_functional_chaos_6_0.svg