.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_meta_modeling/polynomial_chaos_metamodel/plot_chaos_draw_validation.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_polynomial_chaos_metamodel_plot_chaos_draw_validation.py: Validate a polynomial chaos =========================== .. GENERATED FROM PYTHON SOURCE LINES 6-7 In this example, we show how to perform the draw validation of a polynomial chaos for the :ref:`Ishigami function `. .. GENERATED FROM PYTHON SOURCE LINES 10-17 .. code-block:: default from openturns.usecases import ishigami_function as ishigami_function import openturns as ot import openturns.viewer as viewer from matplotlib import pylab as plt from math import pi ot.Log.Show(ot.Log.NONE) .. GENERATED FROM PYTHON SOURCE LINES 18-20 Model description ----------------- .. GENERATED FROM PYTHON SOURCE LINES 22-23 We load the Ishigami test function from the usecases module : .. GENERATED FROM PYTHON SOURCE LINES 23-25 .. code-block:: default im = ishigami_function.IshigamiModel() .. GENERATED FROM PYTHON SOURCE LINES 26-28 The `IshigamiModel` data class contains the input distribution :math:`X=(X_1, X_2, X_3)` in `im.distributionX` and the Ishigami function in `im.model`. We also have access to the input variable names with .. GENERATED FROM PYTHON SOURCE LINES 28-30 .. code-block:: default input_names = im.distributionX.getDescription() .. GENERATED FROM PYTHON SOURCE LINES 31-35 .. code-block:: default N = 100 inputTrain = im.distributionX.getSample(N) outputTrain = im.model(inputTrain) .. GENERATED FROM PYTHON SOURCE LINES 36-38 Create the chaos ---------------- .. GENERATED FROM PYTHON SOURCE LINES 40-41 We could use only the input and output training samples: in this case, the distribution of the input sample is computed by selecting the best distribution that fits the data. .. GENERATED FROM PYTHON SOURCE LINES 43-45 .. code-block:: default chaosalgo = ot.FunctionalChaosAlgorithm(inputTrain, outputTrain) .. GENERATED FROM PYTHON SOURCE LINES 46-47 Since the input distribution is known in our particular case, we instead create the multivariate basis from the distribution, that is three independent variables X1, X2 and X3. .. GENERATED FROM PYTHON SOURCE LINES 49-56 .. code-block:: default multivariateBasis = ot.OrthogonalProductPolynomialFactory( [im.X1, im.X2, im.X3]) totalDegree = 8 enumfunc = multivariateBasis.getEnumerateFunction() P = enumfunc.getStrataCumulatedCardinal(totalDegree) adaptiveStrategy = ot.FixedStrategy(multivariateBasis, P) .. GENERATED FROM PYTHON SOURCE LINES 57-61 .. code-block:: default selectionAlgorithm = ot.LeastSquaresMetaModelSelectionFactory() projectionStrategy = ot.LeastSquaresStrategy( inputTrain, outputTrain, selectionAlgorithm) .. GENERATED FROM PYTHON SOURCE LINES 62-65 .. code-block:: default chaosalgo = ot.FunctionalChaosAlgorithm( inputTrain, outputTrain, im.distributionX, adaptiveStrategy, projectionStrategy) .. GENERATED FROM PYTHON SOURCE LINES 66-70 .. code-block:: default chaosalgo.run() result = chaosalgo.getResult() metamodel = result.getMetaModel() .. GENERATED FROM PYTHON SOURCE LINES 71-73 Validation of the metamodel --------------------------- .. GENERATED FROM PYTHON SOURCE LINES 75-76 In order to validate the metamodel, we generate a test sample. .. GENERATED FROM PYTHON SOURCE LINES 78-85 .. code-block:: default n_valid = 1000 inputTest = im.distributionX.getSample(n_valid) outputTest = im.model(inputTest) val = ot.MetaModelValidation(inputTest, outputTest, metamodel) Q2 = val.computePredictivityFactor()[0] Q2 .. rst-class:: sphx-glr-script-out Out: .. code-block:: none 0.9972078325177286 .. GENERATED FROM PYTHON SOURCE LINES 86-87 The Q2 is very close to 1: the metamodel is excellent. .. GENERATED FROM PYTHON SOURCE LINES 89-94 .. code-block:: default graph = val.drawValidation() graph.setTitle("Q2=%.2f%%" % (Q2*100)) view = viewer.View(graph) plt.show() .. image-sg:: /auto_meta_modeling/polynomial_chaos_metamodel/images/sphx_glr_plot_chaos_draw_validation_001.png :alt: Q2=99.72% :srcset: /auto_meta_modeling/polynomial_chaos_metamodel/images/sphx_glr_plot_chaos_draw_validation_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 95-96 The metamodel has a good predictivity, since the points are almost on the first diagonal. .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.196 seconds) .. _sphx_glr_download_auto_meta_modeling_polynomial_chaos_metamodel_plot_chaos_draw_validation.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_chaos_draw_validation.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_chaos_draw_validation.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_