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.

Y = \sum_{i=1}^{20} X_i

where

X_i \tilde{} U(1,2,3,4,5,6)

[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
06.0
16.0
22.0
33.0
46.0
55.0
65.0
74.0
85.0
92.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]:
../../_images/examples_probabilistic_modeling_random_mixture_distribution_discrete_10_0.svg
[22]:
# draw CDF
distribution.drawCDF()
[22]:
../../_images/examples_probabilistic_modeling_random_mixture_distribution_discrete_11_0.svg