.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_probabilistic_modeling/distributions/plot_bayes_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_bayes_distribution.py: Create a Joint by Conditioning distribution ============================================ .. GENERATED FROM PYTHON SOURCE LINES 7-17 In this example we are going to build the distribution of the random vector: .. math:: (Y, \vect{X}|\vect{\Theta}) with :math:`\vect{X}` conditioned by the random vector :math:`\vect{\Theta}` obtained with the random variable :math:`Y` through a function :math:`f`: .. math:: \vect{\Theta} = f(\vect{Y}) .. GENERATED FROM PYTHON SOURCE LINES 19-23 .. code-block:: Python import openturns as ot import openturns.viewer as viewer .. GENERATED FROM PYTHON SOURCE LINES 24-28 We consider the following case: :math:`X|\vect{\Theta} \sim \cN(\vect{\Theta})` with :math:`\vect{\Theta} = (Y, 0.1 + Y^2)` and :math:`Y \sim \cN(0,1)`. We first create the :math:`Y` distribution: .. GENERATED FROM PYTHON SOURCE LINES 28-30 .. code-block:: Python YDist = ot.Normal(0.0, 1.0) .. GENERATED FROM PYTHON SOURCE LINES 31-32 Then we create the link function :math:`f: y \rightarrow (y, 0.1+y^2)`: .. GENERATED FROM PYTHON SOURCE LINES 32-34 .. code-block:: Python f = ot.SymbolicFunction(["y"], ["y", "0.1 + y^2"]) .. GENERATED FROM PYTHON SOURCE LINES 35-36 Then, we create the :math:`\vect{X}|\vect{\Theta}` distribution: .. GENERATED FROM PYTHON SOURCE LINES 36-38 .. code-block:: Python XgivenThetaDist = ot.Normal() .. GENERATED FROM PYTHON SOURCE LINES 39-40 At last, we create the distribution of :math:`(Y,X)`: .. GENERATED FROM PYTHON SOURCE LINES 40-44 .. code-block:: Python XDist = ot.JointByConditioningDistribution(XgivenThetaDist, YDist, f) XDist.setDescription(["Y", r"$X|\mathbf{\boldsymbol{\Theta}} = f(Y)$"]) XDist .. raw:: html
JointByConditioningDistribution


.. GENERATED FROM PYTHON SOURCE LINES 45-46 Get a sample: .. GENERATED FROM PYTHON SOURCE LINES 46-48 .. code-block:: Python sample = XDist.getSample(100) .. GENERATED FROM PYTHON SOURCE LINES 49-50 Draw the PDF: .. GENERATED FROM PYTHON SOURCE LINES 50-59 .. code-block:: Python ot.ResourceMap.SetAsString("Contour-DefaultColorMapNorm", "rank") graph = XDist.drawPDF(sample.getMin(), sample.getMax(), [256] * 2) graph.setTitle(r"$(Y,X)$ iso-PDF") cloud = ot.Cloud(sample) cloud.setColor("red") cloud.setLegend("sample") graph.add(cloud) view = viewer.View(graph) .. image-sg:: /auto_probabilistic_modeling/distributions/images/sphx_glr_plot_bayes_distribution_001.svg :alt: $(Y,X)$ iso-PDF :srcset: /auto_probabilistic_modeling/distributions/images/sphx_glr_plot_bayes_distribution_001.svg :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 60-61 .. code-block:: Python view.ShowAll() .. _sphx_glr_download_auto_probabilistic_modeling_distributions_plot_bayes_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_bayes_distribution.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_bayes_distribution.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_bayes_distribution.zip `