.. 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 :ref:`Go to the end ` 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 7-8 In this example, we show how to perform the validation plot of a polynomial chaos for the :ref:`Ishigami function `. .. GENERATED FROM PYTHON SOURCE LINES 11-18 .. code-block:: Python from openturns.usecases import ishigami_function import openturns as ot import openturns.viewer as viewer from matplotlib import pylab as plt ot.Log.Show(ot.Log.NONE) .. GENERATED FROM PYTHON SOURCE LINES 19-21 Model description ----------------- .. GENERATED FROM PYTHON SOURCE LINES 23-24 We load the Ishigami test function from the usecases module : .. GENERATED FROM PYTHON SOURCE LINES 24-26 .. code-block:: Python im = ishigami_function.IshigamiModel() .. GENERATED FROM PYTHON SOURCE LINES 27-30 The model contains the input distribution :math:`X=(X_1, X_2, X_3)` in `im.inputDistribution` and the Ishigami function in `im.model`. We also have access to the input variable names with .. GENERATED FROM PYTHON SOURCE LINES 30-32 .. code-block:: Python input_names = im.inputDistribution.getDescription() .. GENERATED FROM PYTHON SOURCE LINES 33-37 .. code-block:: Python N = 100 inputTrain = im.inputDistribution.getSample(N) outputTrain = im.model(inputTrain) .. GENERATED FROM PYTHON SOURCE LINES 38-40 Create the chaos ---------------- .. GENERATED FROM PYTHON SOURCE LINES 42-43 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 45-47 .. code-block:: Python chaosalgo = ot.FunctionalChaosAlgorithm(inputTrain, outputTrain) .. GENERATED FROM PYTHON SOURCE LINES 48-51 Since the input distribution is known in our particular case, we instead create the multivariate basis from the distribution, that is three independent variables :math:`X_1` , :math:`X_2` and :math:`X_3` . .. GENERATED FROM PYTHON SOURCE LINES 53-59 .. code-block:: Python multivariateBasis = ot.OrthogonalProductPolynomialFactory([im.X1, im.X2, im.X3]) totalDegree = 8 enumfunc = multivariateBasis.getEnumerateFunction() basisSize = enumfunc.getBasisSizeFromTotalDegree(totalDegree) adaptiveStrategy = ot.FixedStrategy(multivariateBasis, basisSize) .. GENERATED FROM PYTHON SOURCE LINES 60-65 .. code-block:: Python selectionAlgorithm = ot.LeastSquaresMetaModelSelectionFactory() projectionStrategy = ot.LeastSquaresStrategy( inputTrain, outputTrain, selectionAlgorithm ) .. GENERATED FROM PYTHON SOURCE LINES 66-70 .. code-block:: Python chaosalgo = ot.FunctionalChaosAlgorithm( inputTrain, outputTrain, im.inputDistribution, adaptiveStrategy, projectionStrategy ) .. GENERATED FROM PYTHON SOURCE LINES 71-75 .. code-block:: Python chaosalgo.run() result = chaosalgo.getResult() metamodel = result.getMetaModel() .. GENERATED FROM PYTHON SOURCE LINES 76-78 Validation of the metamodel --------------------------- .. GENERATED FROM PYTHON SOURCE LINES 80-81 In order to validate the metamodel, we generate a test sample. .. GENERATED FROM PYTHON SOURCE LINES 83-91 .. code-block:: Python n_valid = 1000 inputTest = im.inputDistribution.getSample(n_valid) outputTest = im.model(inputTest) metamodelPredictions = metamodel(inputTest) val = ot.MetaModelValidation(outputTest, metamodelPredictions) r2Score = val.computeR2Score()[0] r2Score .. rst-class:: sphx-glr-script-out .. code-block:: none 0.9992294812153686 .. GENERATED FROM PYTHON SOURCE LINES 92-93 The :math:`R^2` is very close to 1: the metamodel seems very accurate. .. GENERATED FROM PYTHON SOURCE LINES 95-100 .. code-block:: Python graph = val.drawValidation() graph.setTitle("R2=%.2f%%" % (r2Score * 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: R2=99.92% :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 101-102 The metamodel has a good predictivity, since the points are almost on the first diagonal. .. _sphx_glr_download_auto_meta_modeling_polynomial_chaos_metamodel_plot_chaos_draw_validation.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_chaos_draw_validation.ipynb ` .. 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-zip :download:`Download zipped: plot_chaos_draw_validation.zip `