.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "api/gallery/probability/continuous/plot_01_gamma_generalizes_exponential.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_api_gallery_probability_continuous_plot_01_gamma_generalizes_exponential.py: The gamma distribution generalizes the exponential ========================================================== A Gamma(shape=1, rate) distribution is exactly an Exponential(rate); increasing the shape parameter builds up a sum of exponentials. .. GENERATED FROM PYTHON SOURCE LINES 10-15 .. code-block:: Python import numpy as np from mathematicskit.probability import Exponential, Gamma, Normal from mathematicskit.probability.visualizers.plots import plot_distribution .. GENERATED FROM PYTHON SOURCE LINES 16-18 Gamma(1, rate) matches Exponential(rate) exactly ------------------------------------------------------------------ .. GENERATED FROM PYTHON SOURCE LINES 18-27 .. code-block:: Python rate = 2.0 gamma = Gamma(shape=1.0, rate=rate) exponential = Exponential(rate=rate) xs = np.linspace(0.01, 3.0, 50) print("max |gamma(1,r) - exponential(r)| pdf difference:", np.max(np.abs(gamma.pdf(xs) - exponential.pdf(xs)))) plot_distribution(Gamma(shape=5.0, rate=2.0)) .. image-sg:: /api/gallery/probability/continuous/images/sphx_glr_plot_01_gamma_generalizes_exponential_001.png :alt: Gamma :srcset: /api/gallery/probability/continuous/images/sphx_glr_plot_01_gamma_generalizes_exponential_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none max |gamma(1,r) - exponential(r)| pdf difference: 0.0 .. GENERATED FROM PYTHON SOURCE LINES 28-30 The normal distribution and its MGF ------------------------------------------------------------------ .. GENERATED FROM PYTHON SOURCE LINES 30-34 .. code-block:: Python normal = Normal(mu=0.0, sigma=1.0) print("normal MGF at t=1:", normal.mgf(1.0), "expected exp(0.5):", np.exp(0.5)) plot_distribution(normal) .. image-sg:: /api/gallery/probability/continuous/images/sphx_glr_plot_01_gamma_generalizes_exponential_002.png :alt: Normal :srcset: /api/gallery/probability/continuous/images/sphx_glr_plot_01_gamma_generalizes_exponential_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none normal MGF at t=1: 1.6487212707001282 expected exp(0.5): 1.6487212707001282 .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.046 seconds) .. _sphx_glr_download_api_gallery_probability_continuous_plot_01_gamma_generalizes_exponential.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_01_gamma_generalizes_exponential.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_01_gamma_generalizes_exponential.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_01_gamma_generalizes_exponential.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_