.. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_probabilistic_modeling_distributions_plot_random_mixture_distribution_discrete.py: 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. .. math:: Y = \sum_{i=1}^{20} X_i where :math:`X_i \sim U(1,2,3,4,5,6)` .. code-block:: default from __future__ import print_function import openturns as ot import openturns.viewer as viewer from matplotlib import pylab as plt ot.Log.Show(ot.Log.NONE) create the distribution associated to the dice roll .. code-block:: default X = ot.UserDefined([[i] for i in range(1,7)]) Roll the dice a few times .. code-block:: default X.getSample(10) .. raw:: html
v0
01
13
26
31
46
53
62
72
84
92


.. code-block:: default N = 20 Create the collection of identically distributed Xi .. code-block:: default coll = [X] * N Create the weights .. code-block:: default weight = [1.0] * N create the affine combination .. code-block:: default distribution = ot.RandomMixture(coll, weight) probability to exceed a sum of 100 after 20 dice rolls .. code-block:: default distribution.computeComplementaryCDF(100) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none 1.576207331110968e-05 draw PDF .. code-block:: default graph = distribution.drawPDF() view = viewer.View(graph) .. image:: /auto_probabilistic_modeling/distributions/images/sphx_glr_plot_random_mixture_distribution_discrete_001.png :alt: X0 PDF :class: sphx-glr-single-img draw CDF .. code-block:: default graph = distribution.drawCDF() view = viewer.View(graph) plt.show() .. image:: /auto_probabilistic_modeling/distributions/images/sphx_glr_plot_random_mixture_distribution_discrete_002.png :alt: X0 CDF :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.142 seconds) .. _sphx_glr_download_auto_probabilistic_modeling_distributions_plot_random_mixture_distribution_discrete.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_random_mixture_distribution_discrete.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_random_mixture_distribution_discrete.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_