File: plot_gaussian_process_fitter.py

package info (click to toggle)
openturns 1.26-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 67,708 kB
  • sloc: cpp: 261,605; python: 67,030; ansic: 4,378; javascript: 406; sh: 185; xml: 164; makefile: 101
file content (72 lines) | stat: -rw-r--r-- 2,001 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
"""
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 :class:`~openturns.experimental.GaussianProcessFitter` class, which estimates the parameters of the model.

# %%
import openturns as ot
import openturns.experimental as otexp
import openturns.viewer as otv


# %%
# 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 :class:`~openturns.experimental.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()

# %%
# The parameters of the covariance models also have been estimated.

# %%
result.getCovarianceModel()

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

# %%
responseSurface = result.getMetaModel()

# %%
# Plot the output of our model depending on :math:`x_2` with :math:`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 = otv.View(parametricModelGraph)

# %%
view.ShowAll()