Create a discrete random mixtureΒΆ
In this example we are going to build the distribution of the value of the sum of 20 dice rolls.
where
[13]:
from __future__ import print_function
import openturns as ot
[14]:
# create the distribution associated to the dice roll
X = ot.UserDefined([[i] for i in range(1,7)])
[23]:
# Roll the dice a few times
X.getSample(10)
[23]:
v0 | |
---|---|
0 | 6.0 |
1 | 6.0 |
2 | 2.0 |
3 | 3.0 |
4 | 6.0 |
5 | 5.0 |
6 | 5.0 |
7 | 4.0 |
8 | 5.0 |
9 | 2.0 |
[16]:
N = 20
[17]:
# Create the collection of identically distributed Xi
coll = [X] * N
[18]:
# Create the weights
weight = [1.0] * N
[19]:
# create the affine combination
distribution = ot.RandomMixture(coll, weight)
[20]:
# probability to exceed a sum of 100 after 20 dice rolls
distribution.computeComplementaryCDF(100)
[20]:
1.576207331110968e-05
[21]:
# draw PDF
distribution.drawPDF()
[21]:
[22]:
# draw CDF
distribution.drawCDF()
[22]: