File: plot_conditional_distribution.py

package info (click to toggle)
openturns 1.24-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 66,204 kB
  • sloc: cpp: 256,662; python: 63,381; ansic: 4,414; javascript: 406; sh: 180; xml: 164; yacc: 123; makefile: 98; lex: 55
file content (51 lines) | stat: -rw-r--r-- 1,037 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
"""
Create a conditional distribution
=================================
"""

# %%

# %%
# In this example we are going to build the distribution of the random vector :math:`\vect{X}` conditioned by the random vector :math:`\vect{\Theta}`
#
# .. math::
#    \vect{X}|\vect{\Theta}
#
# with :math:`\vect{\Theta}` obtained with the random variable :math:`Y` through a function :math:`f`
#
# .. math::
#    \vect{\Theta}=f(Y)
#

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

# %%
# Create the :math:`Y` distribution
YDist = ot.Uniform(-1.0, 1.0)

# %%
# Create :math:`\vect{\Theta}=f(Y)`
f = ot.SymbolicFunction(["y"], ["y", "1+y^2"])

# %%
# Create the :math:`\vect{X}|\vect{\Theta}` distribution
XgivenThetaDist = ot.Uniform()

# %%
# create the distribution
XDist = ot.DeconditionedDistribution(XgivenThetaDist, YDist, f)
XDist.setDescription(["X|Theta=f(y)"])
XDist

# %%
# Get a sample
XDist.getSample(5)

# %%
# Draw PDF
graph = XDist.drawPDF()
view = viewer.View(graph)
plt.show()