.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_surrogate_modeling/gaussian_process_regression/plot_propagate_gpr_ishigami.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_surrogate_modeling_gaussian_process_regression_plot_propagate_gpr_ishigami.py: Gaussian Process Regression: propagate uncertainties ==================================================== In this example we propagate uncertainties through a GP metamodel of the :ref:`Ishigami model`. .. GENERATED FROM PYTHON SOURCE LINES 7-12 .. code-block:: Python import openturns as ot import openturns.viewer as otv .. GENERATED FROM PYTHON SOURCE LINES 13-17 We first build the metamodel and then compute its mean with a Monte-Carlo computation. We load the Ishigami model from the usecases module: .. GENERATED FROM PYTHON SOURCE LINES 17-22 .. code-block:: Python from openturns.usecases import ishigami_function im = ishigami_function.IshigamiModel() .. GENERATED FROM PYTHON SOURCE LINES 23-25 We build a design of experiments with a Latin Hypercube Sampling (LHS) for the three input variables supposed independent. .. GENERATED FROM PYTHON SOURCE LINES 25-28 .. code-block:: Python experiment = ot.LHSExperiment(im.distribution, 30, False, True) xdata = experiment.generate() .. GENERATED FROM PYTHON SOURCE LINES 29-31 We get the exact model and evaluate it at the input training data `xdata` to build the output data `ydata`. .. GENERATED FROM PYTHON SOURCE LINES 31-34 .. code-block:: Python model = im.model ydata = model(xdata) .. GENERATED FROM PYTHON SOURCE LINES 35-40 We define our GP process: - a constant basis in :math:`\mathbb{R}^3` ; - a squared exponential covariance function. .. GENERATED FROM PYTHON SOURCE LINES 40-50 .. code-block:: Python dimension = 3 basis = ot.ConstantBasisFactory(dimension).build() covarianceModel = ot.SquaredExponential([0.1] * dimension, [1.0]) fitter = ot.GaussianProcessFitter(xdata, ydata, covarianceModel, basis) fitter.run() fitter_result = fitter.getResult() algo = ot.GaussianProcessRegression(fitter_result) algo.run() result = algo.getResult() .. GENERATED FROM PYTHON SOURCE LINES 51-52 We finally get the metamodel to use with Monte-Carlo. .. GENERATED FROM PYTHON SOURCE LINES 52-54 .. code-block:: Python metamodel = result.getMetaModel() .. GENERATED FROM PYTHON SOURCE LINES 55-59 We want to estmate the mean of the Ishigami model with Monte-Carlo using the metamodel instead of the exact model. We first create a random vector following the input distribution : .. GENERATED FROM PYTHON SOURCE LINES 59-61 .. code-block:: Python X = ot.RandomVector(im.distribution) .. GENERATED FROM PYTHON SOURCE LINES 62-64 And then we create a random vector from the image of the input random vector by the metamodel : .. GENERATED FROM PYTHON SOURCE LINES 64-66 .. code-block:: Python Y = ot.CompositeRandomVector(metamodel, X) .. GENERATED FROM PYTHON SOURCE LINES 67-68 We now set our :class:`~openturns.ExpectationSimulationAlgorithm` object : .. GENERATED FROM PYTHON SOURCE LINES 68-73 .. code-block:: Python algo = ot.ExpectationSimulationAlgorithm(Y) algo.setMaximumOuterSampling(50000) algo.setBlockSize(1) algo.setCoefficientOfVariationCriterionType("NONE") .. GENERATED FROM PYTHON SOURCE LINES 74-75 We run it and store the results : .. GENERATED FROM PYTHON SOURCE LINES 75-78 .. code-block:: Python algo.run() result = algo.getResult() .. GENERATED FROM PYTHON SOURCE LINES 79-80 The expectation ( :math:`\mathbb{E}(Y)` mean ) is obtained with : .. GENERATED FROM PYTHON SOURCE LINES 80-82 .. code-block:: Python expectation = result.getExpectationEstimate() .. GENERATED FROM PYTHON SOURCE LINES 83-84 The mean estimate of the metamodel is .. GENERATED FROM PYTHON SOURCE LINES 84-86 .. code-block:: Python print("Mean of the Ishigami metamodel : %.3e" % expectation[0]) .. rst-class:: sphx-glr-script-out .. code-block:: none Mean of the Ishigami metamodel : 3.532e+00 .. GENERATED FROM PYTHON SOURCE LINES 87-88 We draw the convergence history. .. GENERATED FROM PYTHON SOURCE LINES 88-91 .. code-block:: Python graph = algo.drawExpectationConvergence() view = otv.View(graph) .. image-sg:: /auto_surrogate_modeling/gaussian_process_regression/images/sphx_glr_plot_propagate_gpr_ishigami_001.svg :alt: Expectation convergence graph at level 0.95 :srcset: /auto_surrogate_modeling/gaussian_process_regression/images/sphx_glr_plot_propagate_gpr_ishigami_001.svg :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 92-93 For reference, the exact mean of the Ishigami model is : .. GENERATED FROM PYTHON SOURCE LINES 93-95 .. code-block:: Python print("Mean of the Ishigami model : %.3e" % im.expectation) .. rst-class:: sphx-glr-script-out .. code-block:: none Mean of the Ishigami model : 3.500e+00 .. GENERATED FROM PYTHON SOURCE LINES 96-97 .. code-block:: Python otv.View.ShowAll() .. _sphx_glr_download_auto_surrogate_modeling_gaussian_process_regression_plot_propagate_gpr_ishigami.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_propagate_gpr_ishigami.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_propagate_gpr_ishigami.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_propagate_gpr_ishigami.zip `