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})

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

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

[6]:
# Get a sample
sample = XDist.getSample(100)
[9]:
# draw PDF
graph = XDist.drawPDF()
cloud = ot.Cloud(sample)
cloud.setColor('red')
cloud.setLegend('sample')
graph.add(cloud)
graph
/home/schueller/.local/lib/python3.5/site-packages/matplotlib/contour.py:1180: UserWarning: No contour levels were found within the data range.
  warnings.warn("No contour levels were found"
[9]:
../../_images/examples_probabilistic_modeling_bayes_distribution_8_1.svg