Create a Joint by Conditioning 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(\vect{Y})

import openturns as ot
import openturns.viewer as viewer

We consider the following case: X|\vect{\Theta} \sim \cN(\vect{\Theta}) with \vect{\Theta} = (Y, 0.1 + Y^2) and Y \sim \cN(0,1).

We first create the Y distribution:

YDist = ot.Normal(0.0, 1.0)

Then we create the link function f: y \rightarrow (y, 0.1+y^2):

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

Then, we create the \vect{X}|\vect{\Theta} distribution:

XgivenThetaDist = ot.Normal()

At last, we create the distribution of (Y,X):

XDist = ot.JointByConditioningDistribution(XgivenThetaDist, YDist, f)
XDist.setDescription(["Y", r"$X|\mathbf{\boldsymbol{\Theta}} = f(Y)$"])
XDist
JointByConditioningDistribution
  • name=JointByConditioningDistribution
  • dimension=2
  • weight=1
  • range=]-inf (-7.65063), (7.65063) +inf[ ]-inf (-396.355), (396.355) +inf[
  • description=[Y,$X|\mathbf{\boldsymbol{\Theta}} = f(Y)$]
  • isParallel=false
  • isCopula=false


Get a sample:

sample = XDist.getSample(100)

Draw the PDF:

ot.ResourceMap.SetAsString("Contour-DefaultColorMapNorm", "rank")
graph = XDist.drawPDF(sample.getMin(), sample.getMax(), [256] * 2)
graph.setTitle(r"$(Y,X)$ iso-PDF")
cloud = ot.Cloud(sample)
cloud.setColor("red")
cloud.setLegend("sample")
graph.add(cloud)
view = viewer.View(graph)
$(Y,X)$ iso-PDF
view.ShowAll()