.. 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 =========================== In this example, we show how to perform the draw validation of a polynomial chaos for the :ref:`Ishigami function `. .. code-block:: default 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) Model description ----------------- We load the Ishigami test function from the usecases module : .. code-block:: default from openturns.usecases import ishigami_function as ishigami_function im = ishigami_function.IshigamiModel() 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 .. code-block:: default input_names = im.distributionX.getDescription() .. code-block:: default N = 100 inputTrain = im.distributionX.getSample(N) outputTrain = im.model(inputTrain) Create the chaos ---------------- 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. .. code-block:: default chaosalgo = ot.FunctionalChaosAlgorithm(inputTrain, outputTrain) 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. .. 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) .. code-block:: default selectionAlgorithm = ot.LeastSquaresMetaModelSelectionFactory() projectionStrategy = ot.LeastSquaresStrategy(inputTrain, outputTrain, selectionAlgorithm) .. code-block:: default chaosalgo = ot.FunctionalChaosAlgorithm(inputTrain, outputTrain, im.distributionX, adaptiveStrategy, projectionStrategy) .. code-block:: default chaosalgo.run() result = chaosalgo.getResult() metamodel = result.getMetaModel() Validation of the metamodel --------------------------- In order to validate the metamodel, we generate a test sample. .. 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 The Q2 is very close to 1: the metamodel is excellent. .. code-block:: default graph = val.drawValidation() graph.setTitle("Q2=%.2f%%" % (Q2*100)) view = viewer.View(graph) plt.show() .. image:: /auto_meta_modeling/polynomial_chaos_metamodel/images/sphx_glr_plot_chaos_draw_validation_001.png :alt: Q2=99.72% :class: sphx-glr-single-img 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.192 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 `_