.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_meta_modeling/kriging_metamodel/plot_propagate_kriging_ishigami.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_meta_modeling_kriging_metamodel_plot_propagate_kriging_ishigami.py: Kriging : propagate uncertainties ================================= .. GENERATED FROM PYTHON SOURCE LINES 5-10 .. code-block:: default import openturns as ot import numpy as np from matplotlib import pylab as plt import openturns.viewer as otv .. GENERATED FROM PYTHON SOURCE LINES 11-16 In this example we propagate uncertainties through a kriging metamodel of the :ref:`Ishigami model`. We first build the metamodel and then compute its mean with a MonteCarlo computation. .. GENERATED FROM PYTHON SOURCE LINES 18-19 We first load the Ishigami model from the usecases module : .. GENERATED FROM PYTHON SOURCE LINES 19-22 .. code-block:: default from openturns.usecases import ishigami_function as ishigami_function im = ishigami_function.IshigamiModel() .. GENERATED FROM PYTHON SOURCE LINES 23-25 We build a design of experiments with a LHS for the three input variables supposed independent. .. GENERATED FROM PYTHON SOURCE LINES 25-28 .. code-block:: default experiment = ot.LHSExperiment(im.distributionX, 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:: default model = im.model ydata = model(xdata) .. GENERATED FROM PYTHON SOURCE LINES 35-40 We define our kriging strategy : - a constant basis in :math:`\mathbb{R}^3` ; - a squared exponential covariance function. .. GENERATED FROM PYTHON SOURCE LINES 40-47 .. code-block:: default dimension = 3 basis = ot.ConstantBasisFactory(dimension).build() covarianceModel = ot.SquaredExponential([0.1]*dimension, [1.0]) algo = ot.KrigingAlgorithm(xdata, ydata, covarianceModel, basis) algo.run() result = algo.getResult() .. GENERATED FROM PYTHON SOURCE LINES 48-49 We finally get the metamodel to use with MonteCarlo. .. GENERATED FROM PYTHON SOURCE LINES 49-51 .. code-block:: default metamodel = result.getMetaModel() .. GENERATED FROM PYTHON SOURCE LINES 52-56 We want to estmate the mean of the Ishigami model with MonteCarlo using the metamodel instead of the exact model. We first create a random vector following the input distribution : .. GENERATED FROM PYTHON SOURCE LINES 56-58 .. code-block:: default X = ot.RandomVector(im.distributionX) .. GENERATED FROM PYTHON SOURCE LINES 59-61 And then we create a random vector from the image of the input random vector by the metamodel : .. GENERATED FROM PYTHON SOURCE LINES 61-63 .. code-block:: default Y = ot.CompositeRandomVector(metamodel, X) .. GENERATED FROM PYTHON SOURCE LINES 64-65 We now set our :class:`~openturns.ExpectationSimulationAlgorithm` object : .. GENERATED FROM PYTHON SOURCE LINES 65-70 .. code-block:: default algo = ot.ExpectationSimulationAlgorithm(Y) algo.setMaximumOuterSampling(50000) algo.setBlockSize(1) algo.setCoefficientOfVariationCriterionType('NONE') .. GENERATED FROM PYTHON SOURCE LINES 71-72 We run it and store the result : .. GENERATED FROM PYTHON SOURCE LINES 72-75 .. code-block:: default algo.run() result = algo.getResult() .. GENERATED FROM PYTHON SOURCE LINES 76-77 The expectation ( :math:`\mathbb{E}(Y)` mean ) is obtained with : .. GENERATED FROM PYTHON SOURCE LINES 77-79 .. code-block:: default expectation = result.getExpectationEstimate() .. GENERATED FROM PYTHON SOURCE LINES 80-81 The mean estimate of the metamodel is .. GENERATED FROM PYTHON SOURCE LINES 81-83 .. code-block:: default print("Mean of the Ishigami metamodel : %.3e" % expectation[0]) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none Mean of the Ishigami metamodel : 3.694e+00 .. GENERATED FROM PYTHON SOURCE LINES 84-85 We draw the convergence history. .. GENERATED FROM PYTHON SOURCE LINES 85-88 .. code-block:: default graph = algo.drawExpectationConvergence() view = otv.View(graph) .. image-sg:: /auto_meta_modeling/kriging_metamodel/images/sphx_glr_plot_propagate_kriging_ishigami_001.png :alt: Expectation convergence graph at level 0.95 :srcset: /auto_meta_modeling/kriging_metamodel/images/sphx_glr_plot_propagate_kriging_ishigami_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 89-90 For reference, the exact mean of the Ishigami model is : .. GENERATED FROM PYTHON SOURCE LINES 90-93 .. code-block:: default print("Mean of the Ishigami model : %.3e" % im.expectation) plt.show() .. rst-class:: sphx-glr-script-out Out: .. code-block:: none Mean of the Ishigami model : 3.500e+00 .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.553 seconds) .. _sphx_glr_download_auto_meta_modeling_kriging_metamodel_plot_propagate_kriging_ishigami.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_propagate_kriging_ishigami.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_propagate_kriging_ishigami.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_