# Create a conditional distribution¶

In this basic example we are going to build the distribution of the random vector X conditioned by the random variable Theta

with Theta obtained with the random variable Y through a function f

In [6]:

from __future__ import print_function
import openturns as ot

In [7]:

# create the Y distribution
YDist = ot.Uniform(-1.0, 1.0)

In [8]:

# create Theta=f(y)
f = ot.SymbolicFunction(['y'], ['y', '1+y^2'])

In [9]:

# create the X|Theta distribution

In [10]:

# create the distribution
XDist.setDescription(['X|Theta=f(y)'])
XDist

Out[10]:


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

In [11]:

# Get a sample
XDist.getSample(5)

Out[11]:

 X|Theta=f(y) 0 0.9728112831135585 1 -0.6559410049696013 2 1.0507751769138765 3 1.2772566044528357 4 -0.1016629888293733
In [12]:

# draw PDF
XDist.drawPDF()

Out[12]: