Skip to content

Commit

Permalink
update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
sofianehaddad committed Apr 8, 2024
1 parent a2e3bc7 commit 513648e
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 3 deletions.
24 changes: 24 additions & 0 deletions python/doc/pyplots/GaussianProcessFitter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import openturns as ot
from openturns.experimental import GaussianProcessFitter
from openturns.viewer import View

f = ot.SymbolicFunction(["x"], ["x * sin(x)"])
sampleX = [[1.0], [2.0], [3.0], [4.0], [5.0], [6.0], [7.0], [8.0]]
sampleY = f(sampleX)
basis = ot.Basis(
[ot.SymbolicFunction(["x"], ["x"]), ot.SymbolicFunction(["x"], ["x^2"])]
)
covarianceModel = ot.SquaredExponential([1.0])
covarianceModel.setActiveParameter([])
algo = GaussianProcessFitter(sampleX, sampleY, covarianceModel, basis)
algo.run()
result = algo.getResult()

graph = f.draw(0.0, 10.0)
graph.add(result.getMetaModel().draw(0.0, 10.0))
graph.add(ot.Cloud(sampleX, sampleY))
graph.setColors(["blue", "red", "black"])
graph.setLegends(["model", "meta model", "sample"])
graph.setLegendPosition("upper left")
graph.setTitle("y(x)=x * sin(x)")
View(graph, figure_kw={"figsize": (8, 4)})
26 changes: 26 additions & 0 deletions python/doc/pyplots/GaussianProcessRegression.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import openturns as ot
from openturns.experimental import GaussianProcessFitter, GaussianProcessRegression
from openturns.viewer import View

f = ot.SymbolicFunction(["x"], ["x * sin(x)"])
sampleX = [[1.0], [2.0], [3.0], [4.0], [5.0], [6.0], [7.0], [8.0]]
sampleY = f(sampleX)
basis = ot.Basis(
[ot.SymbolicFunction(["x"], ["x"]), ot.SymbolicFunction(["x"], ["x^2"])]
)
covarianceModel = ot.SquaredExponential([1.0])
covarianceModel.setActiveParameter([])
fitter_algo = GaussianProcessFitter(sampleX, sampleY, covarianceModel, basis)
fitter_algo.run()
algo = GaussianProcessRegression(fitter_algo.getResult())
algo.run()
result = algo.getResult()

graph = f.draw(0.0, 10.0)
graph.add(result.getMetaModel().draw(0.0, 10.0))
graph.add(ot.Cloud(sampleX, sampleY))
graph.setColors(["blue", "red", "black"])
graph.setLegends(["model", "meta model", "sample"])
graph.setLegendPosition("upper left")
graph.setTitle("y(x)=x * sin(x)")
View(graph, figure_kw={"figsize": (8, 4)})
6 changes: 3 additions & 3 deletions python/doc/user_manual/response_surface/kriging.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ Gaussian Process Regression

.. autosummary::
:toctree: _generated/
:template: class.rst_t
:template: classWithPlot.rst_t

GaussianProcessRegression
GaussianProcessFitter

:template: class.rst_t
GaussianProcessRegressionResult
GaussianProcessFitterResult
experimental.GaussianProcessRegressionResult
experimental.GaussianProcessFitterResult


Construction of the regression basis
Expand Down

0 comments on commit 513648e

Please sign in to comment.