.. 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_build_distribution.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_build_distribution.py: Fit a distribution from an input sample ======================================= .. GENERATED FROM PYTHON SOURCE LINES 6-8 In this example we show how to use the `BuildDistribution` function to fit a distribution to an input sample. This function is used by the `FunctionalChaosAlgorithm` class when we want to create a polynomial chaos metamodel and we have a design of experiments which have been computed beforehand. In this case, we have to identify the distributions which best fit to the input sample in order to define the input probabilistic model. This is, in turn, used by in the polynomial chaos to create the orthogonal basis. .. GENERATED FROM PYTHON SOURCE LINES 11-17 .. 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 18-19 We first create the function `model`. .. GENERATED FROM PYTHON SOURCE LINES 21-27 .. code-block:: default ot.RandomGenerator.SetSeed(0) dimension = 2 input_names = ['x1', 'x2'] formulas = ['cos(x1 + x2)', '(x2 + 1) * exp(x1)'] model = ot.SymbolicFunction(input_names, formulas) .. GENERATED FROM PYTHON SOURCE LINES 28-29 Then we create a sample `x` and compute the corresponding output sample `y`. .. GENERATED FROM PYTHON SOURCE LINES 31-36 .. code-block:: default distribution = ot.Normal(dimension) samplesize = 1000 inputSample = distribution.getSample(samplesize) outputSample = model(inputSample) .. GENERATED FROM PYTHON SOURCE LINES 37-39 Create a functional chaos model. First, we need to fit a distribution on the input sample. We can do this automatically with the Lilliefors test. .. GENERATED FROM PYTHON SOURCE LINES 41-44 .. code-block:: default ot.ResourceMap.SetAsUnsignedInteger( "FittingTest-LillieforsMaximumSamplingSize", 100) .. GENERATED FROM PYTHON SOURCE LINES 45-47 .. code-block:: default distribution = ot.FunctionalChaosAlgorithm.BuildDistribution(inputSample) .. GENERATED FROM PYTHON SOURCE LINES 48-54 .. code-block:: default for i in range(dimension): marginal = distribution.getMarginal(i) marginalname = marginal.getImplementation().getClassName() print("Marginal #", i, ":", marginalname) distribution.getCopula() .. rst-class:: sphx-glr-script-out Out: .. code-block:: none Marginal # 0 : Normal Marginal # 1 : Normal .. raw:: html

IndependentCopula(dimension = 2)



.. GENERATED FROM PYTHON SOURCE LINES 55-56 The previous call to `BuildDistribution` is what is done internally by the following constructor of `FunctionalChaosAlgorithm`. .. GENERATED FROM PYTHON SOURCE LINES 58-59 .. code-block:: default algo = ot.FunctionalChaosAlgorithm(inputSample, outputSample) .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 3.261 seconds) .. _sphx_glr_download_auto_meta_modeling_polynomial_chaos_metamodel_plot_chaos_build_distribution.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_build_distribution.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_chaos_build_distribution.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_