.. 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.py: Create a random mixture of distributions ======================================== In this example we are going to build an affine combination of input random variables. .. math:: Y = 2 + 5 X_1 + X_2 where: - :math:`X1 \sim \mathcal{E}(\lambda=1.5)` - :math:`X2 \sim \mathcal{N}(\mu=4, \sigma=1)` This notion is different from the Mixture where the combination is made on the probability density functions and not on the univariate random variable. .. 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 distributions associated to the input random variables .. code-block:: default X1 = ot.Exponential(1.5) X2 = ot.Normal(4.0, 1.0) offset .. code-block:: default a0 = 2.0 Create the weights .. code-block:: default weight = [5.0, 1.0] create the affine combination .. code-block:: default distribution = ot.RandomMixture([X1, X2], weight, a0) distribution .. raw:: html

RandomMixture(Normal(mu = 6, sigma = 1) + Exponential(lambda = 0.3, gamma = 0))



ask its mean .. code-block:: default distribution.getMean() .. raw:: html

[9.33333]



ask its variance .. code-block:: default distribution.getCovariance()[0, 0] .. rst-class:: sphx-glr-script-out Out: .. code-block:: none 12.11111111111111 ask the 90% quantile .. code-block:: default distribution.computeQuantile(0.9) .. raw:: html

[13.8253]



ask its probability to exceeds 3 .. code-block:: default distribution.computeSurvivalFunction(3.0) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none 0.9998938620694351 draw PDF .. code-block:: default graph = distribution.drawPDF() view = viewer.View(graph) .. image:: /auto_probabilistic_modeling/distributions/images/sphx_glr_plot_random_mixture_distribution_001.png :alt: plot random mixture distribution :class: sphx-glr-single-img draw PDF .. code-block:: default graph = distribution.drawCDF() view = viewer.View(graph) plt.show() .. image:: /auto_probabilistic_modeling/distributions/images/sphx_glr_plot_random_mixture_distribution_002.png :alt: plot random mixture distribution :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.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.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_random_mixture_distribution.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_