.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "api/gallery/probability/discrete/plot_03_geometric_memoryless.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_discrete_plot_03_geometric_memoryless.py: The geometric distribution: waiting for the first success ========================================================= The number of independent trials up to and including the first success, with success probability :math:`p`, has mean :math:`1/p` and is memoryless: :math:`P(X > m + n \mid X > m) = P(X > n)`. .. GENERATED FROM PYTHON SOURCE LINES 11-16 .. code-block:: Python import numpy as np from mathematicskit.probability import Geometric from mathematicskit.probability.visualizers.plots import plot_distribution .. GENERATED FROM PYTHON SOURCE LINES 17-19 Mean = 1/p ------------------------------------------------------------------ .. GENERATED FROM PYTHON SOURCE LINES 19-24 .. code-block:: Python geometric = Geometric(p=0.3) print(f"geometric(p=0.3) mean = {geometric.mean:.4f}, expected 1/p = {1.0 / 0.3:.4f}") plot_distribution(geometric) .. image-sg:: /api/gallery/probability/discrete/images/sphx_glr_plot_03_geometric_memoryless_001.png :alt: Geometric :srcset: /api/gallery/probability/discrete/images/sphx_glr_plot_03_geometric_memoryless_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none geometric(p=0.3) mean = 3.3333, expected 1/p = 3.3333 .. GENERATED FROM PYTHON SOURCE LINES 25-27 Memorylessness ------------------------------------------------------------------ .. GENERATED FROM PYTHON SOURCE LINES 27-32 .. code-block:: Python m, n = 4, 3 conditional = (1.0 - geometric.cdf(m + n)) / (1.0 - geometric.cdf(m)) print(f"P(X > {m + n} | X > {m}) = {conditional:.4f}, P(X > {n}) = {1.0 - geometric.cdf(n):.4f}") print("memoryless:", bool(np.isclose(conditional, 1.0 - geometric.cdf(n)))) .. rst-class:: sphx-glr-script-out .. code-block:: none P(X > 7 | X > 4) = 0.3430, P(X > 3) = 0.3430 memoryless: True .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.029 seconds) .. _sphx_glr_download_api_gallery_probability_discrete_plot_03_geometric_memoryless.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_03_geometric_memoryless.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_03_geometric_memoryless.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_03_geometric_memoryless.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_