.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_probabilistic_modeling/distributions/plot_mixture_distribution.py" .. LINE NUMBERS ARE GIVEN BELOW. .. 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_mixture_distribution.py: Create a mixture of PDFs ======================== .. GENERATED FROM PYTHON SOURCE LINES 6-14 In this example we are going to build a distribution whose PDF is defined by a linear combination of probability density functions: .. math:: f(x) = \sum_{i=1}^N \alpha_i p_i(x), \quad \alpha_i \geq 0, \quad \sum_i \alpha_i = 1 The weigths are automatically normalized. It is also possible to create a mixture of copulas. .. GENERATED FROM PYTHON SOURCE LINES 16-21 .. code-block:: default import openturns as ot import openturns.viewer as viewer from matplotlib import pylab as plt ot.Log.Show(ot.Log.NONE) .. GENERATED FROM PYTHON SOURCE LINES 22-23 create a collection of distribution and the associated weights .. GENERATED FROM PYTHON SOURCE LINES 23-27 .. code-block:: default distributions = [ot.Triangular(1.0, 2.0, 4.0), ot.Normal(-1.0, 1.0), ot.Uniform(5.0, 6.0)] weights = [0.4, 1.0, 0.2] .. GENERATED FROM PYTHON SOURCE LINES 28-29 create the mixture .. GENERATED FROM PYTHON SOURCE LINES 29-32 .. code-block:: default distribution = ot.Mixture(distributions, weights) print(distribution) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none Mixture((w = 0.25, d = Triangular(a = 1, m = 2, b = 4)), (w = 0.625, d = Normal(mu = -1, sigma = 1)), (w = 0.125, d = Uniform(a = 5, b = 6))) .. GENERATED FROM PYTHON SOURCE LINES 33-34 draw PDF .. GENERATED FROM PYTHON SOURCE LINES 34-37 .. code-block:: default graph = distribution.drawPDF() view = viewer.View(graph) .. image-sg:: /auto_probabilistic_modeling/distributions/images/sphx_glr_plot_mixture_distribution_001.png :alt: plot mixture distribution :srcset: /auto_probabilistic_modeling/distributions/images/sphx_glr_plot_mixture_distribution_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 38-39 define a list of copulas and the associated weights .. GENERATED FROM PYTHON SOURCE LINES 39-42 .. code-block:: default copulas = [ot.GumbelCopula(4.5), ot.ClaytonCopula(2.3)] weights = [0.2, 0.8] .. GENERATED FROM PYTHON SOURCE LINES 43-44 create a mixture of copulas .. GENERATED FROM PYTHON SOURCE LINES 44-47 .. code-block:: default distribution = ot.Mixture(copulas, weights) print(distribution) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none Mixture((w = 0.2, d = GumbelCopula(theta = 4.5)), (w = 0.8, d = ClaytonCopula(theta = 2.3))) .. GENERATED FROM PYTHON SOURCE LINES 48-49 draw PDF .. GENERATED FROM PYTHON SOURCE LINES 49-52 .. code-block:: default graph = distribution.drawPDF() view = viewer.View(graph) plt.show() .. image-sg:: /auto_probabilistic_modeling/distributions/images/sphx_glr_plot_mixture_distribution_002.png :alt: [X0,X1] iso-PDF :srcset: /auto_probabilistic_modeling/distributions/images/sphx_glr_plot_mixture_distribution_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.195 seconds) .. _sphx_glr_download_auto_probabilistic_modeling_distributions_plot_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_mixture_distribution.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_mixture_distribution.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_