.. 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_functional_chaos_database.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_functional_chaos_database.py: Polynomial chaos over database ============================== .. GENERATED FROM PYTHON SOURCE LINES 6-10 In this example we are going to create a global approximation of a model response using functional chaos over a design of experiment. You will need to specify the distribution of the input parameters. If not known, statistical inference can be used to select a possible candidate, and fitting tests can validate such an hypothesis. .. GENERATED FROM PYTHON SOURCE LINES 12-18 .. code-block:: default from __future__ import print_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 Create a function R^n --> R^p For example R^4 --> R .. GENERATED FROM PYTHON SOURCE LINES 21-29 .. code-block:: default myModel = ot.SymbolicFunction(['x1', 'x2', 'x3', 'x4'], [ '1+x1*x2 + 2*x3^2+x4^4']) # Create a distribution of dimension n # for example n=3 with indpendent components distribution = ot.ComposedDistribution( [ot.Normal(), ot.Uniform(), ot.Gamma(2.75, 1.0), ot.Beta(2.5, 1.0, -1.0, 2.0)]) .. GENERATED FROM PYTHON SOURCE LINES 30-31 Prepare the input/output samples .. GENERATED FROM PYTHON SOURCE LINES 31-36 .. code-block:: default sampleSize = 250 X = distribution.getSample(sampleSize) Y = myModel(X) dimension = X.getDimension() .. GENERATED FROM PYTHON SOURCE LINES 37-38 build the orthogonal basis .. GENERATED FROM PYTHON SOURCE LINES 38-43 .. code-block:: default coll = [ot.StandardDistributionPolynomialFactory( distribution.getMarginal(i)) for i in range(dimension)] enumerateFunction = ot.LinearEnumerateFunction(dimension) productBasis = ot.OrthogonalProductPolynomialFactory(coll, enumerateFunction) .. GENERATED FROM PYTHON SOURCE LINES 44-45 create the algorithm .. GENERATED FROM PYTHON SOURCE LINES 45-53 .. code-block:: default degree = 6 adaptiveStrategy = ot.FixedStrategy( productBasis, enumerateFunction.getStrataCumulatedCardinal(degree)) projectionStrategy = ot.LeastSquaresStrategy() algo = ot.FunctionalChaosAlgorithm( X, Y, distribution, adaptiveStrategy, projectionStrategy) algo.run() .. GENERATED FROM PYTHON SOURCE LINES 54-55 get the metamodel function .. GENERATED FROM PYTHON SOURCE LINES 55-58 .. code-block:: default result = algo.getResult() metamodel = result.getMetaModel() .. GENERATED FROM PYTHON SOURCE LINES 59-60 Print residuals .. GENERATED FROM PYTHON SOURCE LINES 60-61 .. code-block:: default result.getResiduals() .. raw:: html

[2.64115e-15]



.. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.040 seconds) .. _sphx_glr_download_auto_meta_modeling_polynomial_chaos_metamodel_plot_functional_chaos_database.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_functional_chaos_database.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_functional_chaos_database.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_