Create a Bayes distributionΒΆ

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

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

with \vect{X} conditioned by the random vector \vect{\Theta} obtained with the random variable Y through a function f

\vect{\Theta}=f(Y)

import openturns as ot
import openturns.viewer as viewer
from matplotlib import pylab as plt

ot.Log.Show(ot.Log.NONE)

Create the Y distribution

YDist = ot.Normal(0.0, 1.0)

Create \vect{\Theta}=f(Y)

f = ot.SymbolicFunction(["y"], ["y", "0.1 + y^2"])

Create the \vect{X}|\vect{\Theta} distribution

XgivenThetaDist = ot.Normal()

create the distribution

XDist = ot.JointByConditioningDistribution(XgivenThetaDist, YDist, f)
XDist.setDescription(["X|Theta=f(y)", "y"])
XDist
JointByConditioningDistribution
  • name=JointByConditioningDistribution
  • dimension=2
  • weight=1
  • range=]-inf (-7.65063), (7.65063) +inf[ ]-inf (-412.759), (412.759) +inf[
  • description=[X|Theta=f(y),y]
  • isParallel=false
  • isCopula=false


Get a sample

sample = XDist.getSample(100)

Draw PDF

graph = XDist.drawPDF()
cloud = ot.Cloud(sample)
cloud.setColor("red")
cloud.setLegend("sample")
graph.add(cloud)
view = viewer.View(graph)
plt.show()
X|Theta=f(y) iso-PDF