.. 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_probabilistic_modeling_distributions_plot_conditional_distribution.py: Create a conditional distribution ================================= In this example we are going to build the distribution of the random vector X conditioned by the random variable Theta .. math:: \underline{X}|\underline{\Theta} with Theta obtained with the random variable Y through a function f .. math:: \underline{\Theta}=f(\underline{Y}) .. code-block:: default from __future__ import print_function import openturns as ot import openturns.viewer as viewer from matplotlib import pylab as plt create the Y distribution .. code-block:: default YDist = ot.Uniform(-1.0, 1.0) create Theta=f(y) .. code-block:: default f = ot.SymbolicFunction(['y'], ['y', '1+y^2']) create the X|Theta distribution .. code-block:: default XgivenThetaDist = ot.Uniform() create the distribution .. code-block:: default XDist = ot.ConditionalDistribution(XgivenThetaDist, YDist, f) XDist.setDescription(['X|Theta=f(y)']) XDist .. raw:: html

ConditionalDistribution(X with X|Theta~Uniform(Theta), Theta=f(Y), f=[y]->[y,1+y^2], Y~Uniform(a = -1, b = 1))



Get a sample .. code-block:: default XDist.getSample(5) .. raw:: html
X|Theta=f(y)
00.635176
10.4034392
20.3888339
30.9779865
40.4113054


draw PDF .. code-block:: default graph = XDist.drawPDF() view = viewer.View(graph) plt.show() .. image:: /auto_probabilistic_modeling/distributions/images/sphx_glr_plot_conditional_distribution_001.png :alt: plot conditional distribution :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.102 seconds) .. _sphx_glr_download_auto_probabilistic_modeling_distributions_plot_conditional_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_conditional_distribution.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_conditional_distribution.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_