Create a Bayes distributionΒΆ

In this basic example we are going to build the distribution of the random vector

( \underline{X}|\underline{\Theta}, \underline{Y})

with X conditioned by the random variable Theta obtained with the random variable Y through a function f

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

In [1]:
from __future__ import print_function
import openturns as ot
In [2]:
# create the Y distribution
YDist = ot.Uniform(-1.0, 1.0)
In [3]:
# create Theta=f(y)
f = ot.SymbolicFunction(['y'], ['y', '1 + y'])
In [4]:
# create the X|Theta distribution
XgivenThetaDist = ot.Uniform()
In [5]:
# create the distribution
XDist = ot.BayesDistribution(XgivenThetaDist, YDist, f)
XDist.setDescription(['X|Theta=f(y)', 'y'])
XDist
Out[5]:

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

In [6]:
# Get a sample
XDist.getSample(5)
Out[6]:
X|Theta=f(y)y
01.14255833693481450.25975311321555417
1-0.6969445471579332-0.7294472983623179
20.663537103562033-0.30588591757295625
31.34439933816348360.8413591867141013
4-0.5808309532261675-0.8735878469738991
In [7]:
# draw PDF
XDist.drawPDF()
Out[7]:
../../_images/examples_probabilistic_modeling_bayes_distribution_8_0.svg