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

\underline{X}|\underline{\Theta}

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

\underline{\Theta}=f(\underline{Y})

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
XgivenThetaDist = ot.Uniform()
In [10]:
# create the distribution
XDist = ot.ConditionalDistribution(XgivenThetaDist, YDist, f)
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)
00.9728112831135585
1-0.6559410049696013
21.0507751769138765
31.2772566044528357
4-0.1016629888293733
In [12]:
# draw PDF
XDist.drawPDF()
Out[12]:
../../_images/examples_probabilistic_modeling_conditional_distribution_8_0.svg