Create a random mixture of discrete distributionsΒΆ

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)

In [13]:
from __future__ import print_function
import openturns as ot
In [14]:
# create the distribution associated to the value obtained after a dice roll
dice_values = list(map(lambda x: [x], range(1,7)))
X = ot.UserDefined(dice_values)
In [23]:
# Roll the dice a few times
X.getSample(10)
Out[23]:
v0
06.0
16.0
22.0
33.0
46.0
55.0
65.0
74.0
85.0
92.0
In [16]:
N = 20
In [17]:
# Create the collection of identically distributed Xi
coll = [X] * N
In [18]:
# Create the weights
weight = [1.0] * N
In [19]:
# create the affine combination
distribution = ot.RandomMixture(coll, weight)
In [20]:
# probability to exceed a sum of 100 after 20 dice rolls
distribution.computeComplementaryCDF(100)
Out[20]:
1.576207331110968e-05
In [21]:
# draw PDF
distribution.drawPDF()
Out[21]:
../../_images/examples_probabilistic_modeling_random_mixture_distribution_discrete_10_0.svg
In [22]:
# draw CDF
distribution.drawCDF()
Out[22]:
../../_images/examples_probabilistic_modeling_random_mixture_distribution_discrete_11_0.svg