1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
"""
Create a conditional distribution
=================================
"""
# %%
# %%
# In this example we are going to build the distribution of the random vector :math:`\vect{X}` conditioned by the random vector :math:`\vect{\Theta}`
#
# .. math::
# \vect{X}|\vect{\Theta}
#
# with :math:`\vect{\Theta}` obtained with the random variable :math:`Y` through a function :math:`f`
#
# .. math::
# \vect{\Theta}=f(Y)
#
# %%
import openturns as ot
import openturns.viewer as viewer
from matplotlib import pylab as plt
# %%
# Create the :math:`Y` distribution
YDist = ot.Uniform(-1.0, 1.0)
# %%
# Create :math:`\vect{\Theta}=f(Y)`
f = ot.SymbolicFunction(["y"], ["y", "1+y^2"])
# %%
# Create the :math:`\vect{X}|\vect{\Theta}` distribution
XgivenThetaDist = ot.Uniform()
# %%
# create the distribution
XDist = ot.DeconditionedDistribution(XgivenThetaDist, YDist, f)
XDist.setDescription(["X|Theta=f(y)"])
XDist
# %%
# Get a sample
XDist.getSample(5)
# %%
# Draw PDF
graph = XDist.drawPDF()
view = viewer.View(graph)
plt.show()
|