.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_probabilistic_modeling/distributions/plot_compound_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_probabilistic_modeling_distributions_plot_compound_distribution.py: Create a compound distribution =================================== .. GENERATED FROM PYTHON SOURCE LINES 7-35 In this example we are going to build the distribution of the random vector :math:`\inputRV` defined by the conditional distribution of: .. math:: \inputRV|\vect{\Theta} where :math:`\vect{\Theta}` is the output of the random variable :math:`\vect{Y}` through the link function :math:`f`: .. math:: \vect{\Theta} & = f(\vect{Y})\\ \vect{Y} & \sim \cL_{\vect{Y}} This example creates a :class:`~openturns.CompoundDistribution` which offers all the methods attached to the distributions. We consider the case where :math:`X` is of dimension 1 and follows a uniform distribution defined by: =============== ========================================================= =============================== Variable Distribution Parameter =============== ========================================================= =============================== :math:`X` :class:`~openturns.Uniform` (:math:`a, b`) :math:`(a,b) = (Y, 1+Y^2)` :math:`Y` :class:`~openturns.Uniform` (:math:`c, d`) :math:`(c,d) = (-1, 1)` =============== ========================================================= =============================== .. GENERATED FROM PYTHON SOURCE LINES 37-40 .. code-block:: Python import openturns as ot import openturns.viewer as otv .. GENERATED FROM PYTHON SOURCE LINES 41-42 Create the :math:`Y` distribution. .. GENERATED FROM PYTHON SOURCE LINES 42-44 .. code-block:: Python YDist = ot.Uniform(-1.0, 1.0) .. GENERATED FROM PYTHON SOURCE LINES 45-46 Create the link function :math:`f: y \rightarrow (y, 1+y^2)`. .. GENERATED FROM PYTHON SOURCE LINES 46-48 .. code-block:: Python f = ot.SymbolicFunction(["y"], ["y", "1+y^2"]) .. GENERATED FROM PYTHON SOURCE LINES 49-51 Create the conditional distribution of :math:`\vect{X}|\vect{\Theta}`: as the parameters have no importance, we use the default distribution. .. GENERATED FROM PYTHON SOURCE LINES 51-53 .. code-block:: Python XgivenThetaDist = ot.Uniform() .. GENERATED FROM PYTHON SOURCE LINES 54-58 In this example, the range of :math:`\vect{X}` depends on its parameters which are random. Thus, the model is not regular. We advice to change the discretization method that performs the integration. By default, this method is the quadrature method *GaussProduct*. We prefer to use the *QMC*. We use the :class:`~openturns.ResourceMap`. .. GENERATED FROM PYTHON SOURCE LINES 58-60 .. code-block:: Python ot.ResourceMap.SetAsString('CompoundDistribution-ContinuousDiscretizationMethod', 'QMC') .. GENERATED FROM PYTHON SOURCE LINES 61-62 Create the compound distribution of :math:`X`. .. GENERATED FROM PYTHON SOURCE LINES 62-66 .. code-block:: Python XDist = ot.CompoundDistribution(XgivenThetaDist, YDist, f) XDist.setDescription([r"$X|\mathbf{\boldsymbol{\Theta}} = f(Y)$"]) XDist .. raw:: html
CompoundDistribution


.. GENERATED FROM PYTHON SOURCE LINES 67-68 Get a sample: .. GENERATED FROM PYTHON SOURCE LINES 68-70 .. code-block:: Python XDist.getSample(5) .. raw:: html
$X|\mathbf{\boldsymbol{\Theta}} = f(Y)$
00.9728113
1-0.655941
21.050775
31.277257
4-0.101663


.. GENERATED FROM PYTHON SOURCE LINES 71-72 Draw the PDF. .. GENERATED FROM PYTHON SOURCE LINES 72-76 .. code-block:: Python graph = XDist.drawPDF() view = otv.View(graph) .. image-sg:: /auto_probabilistic_modeling/distributions/images/sphx_glr_plot_compound_distribution_001.svg :alt: plot compound distribution :srcset: /auto_probabilistic_modeling/distributions/images/sphx_glr_plot_compound_distribution_001.svg :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 77-78 .. code-block:: Python view.ShowAll() .. _sphx_glr_download_auto_probabilistic_modeling_distributions_plot_compound_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_compound_distribution.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_compound_distribution.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_compound_distribution.zip `