.. 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 :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_build_distribution.py: Fit a distribution from an input sample ======================================= .. GENERATED FROM PYTHON SOURCE LINES 6-11 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 14-18 .. code-block:: Python import openturns as ot ot.Log.Show(ot.Log.NONE) .. GENERATED FROM PYTHON SOURCE LINES 19-20 We first create the function `model`. .. GENERATED FROM PYTHON SOURCE LINES 22-28 .. code-block:: Python 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 29-30 Then we create a sample `x` and compute the corresponding output sample `y`. .. GENERATED FROM PYTHON SOURCE LINES 32-37 .. code-block:: Python distribution = ot.Normal(dimension) samplesize = 1000 inputSample = distribution.getSample(samplesize) outputSample = model(inputSample) .. GENERATED FROM PYTHON SOURCE LINES 38-40 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 42-44 .. code-block:: Python ot.ResourceMap.SetAsUnsignedInteger("FittingTest-LillieforsMaximumSamplingSize", 100) .. GENERATED FROM PYTHON SOURCE LINES 45-47 .. code-block:: Python distribution = ot.FunctionalChaosAlgorithm.BuildDistribution(inputSample) .. GENERATED FROM PYTHON SOURCE LINES 48-54 .. code-block:: Python 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 .. 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-60 .. code-block:: Python algo = ot.FunctionalChaosAlgorithm(inputSample, outputSample) .. GENERATED FROM PYTHON SOURCE LINES 61-62 Reset default settings .. GENERATED FROM PYTHON SOURCE LINES 62-63 .. code-block:: Python ot.ResourceMap.Reload() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 2.266 seconds) .. _sphx_glr_download_auto_meta_modeling_polynomial_chaos_metamodel_plot_chaos_build_distribution.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_build_distribution.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_chaos_build_distribution.py `