.. 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
==============================
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.
.. 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)
Create a function R^n --> R^p
For example R^4 --> R
.. 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)])
Prepare the input/output samples
.. code-block:: default
sampleSize = 250
X = distribution.getSample(sampleSize)
Y = myModel(X)
dimension = X.getDimension()
build the orthogonal basis
.. code-block:: default
coll = [ot.StandardDistributionPolynomialFactory(distribution.getMarginal(i)) for i in range(dimension)]
enumerateFunction = ot.LinearEnumerateFunction(dimension)
productBasis = ot.OrthogonalProductPolynomialFactory(coll, enumerateFunction)
create the algorithm
.. 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()
get the metamodel function
.. code-block:: default
result = algo.getResult()
metamodel = result.getMetaModel()
Print residuals
.. code-block:: default
result.getResiduals()
.. raw:: html
[1.5987e-12]
.. rst-class:: sphx-glr-timing
**Total running time of the script:** ( 0 minutes 0.020 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 `_