.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "api/gallery/probability/limit_theorems/plot_03_chebyshev_inequality.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_limit_theorems_plot_03_chebyshev_inequality.py: Chebyshev's inequality: one bound for every distribution ======================================================== :math:`P(|X-\mu| \geq k\sigma) \leq 1/k^2` holds for any distribution with finite variance. Comparing it with exact tails shows how conservative a universal bound has to be. .. GENERATED FROM PYTHON SOURCE LINES 11-16 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from mathematicskit.probability import Exponential, Normal, Poisson, Uniform, chebyshev_tail .. GENERATED FROM PYTHON SOURCE LINES 17-19 Exact tails against the bound ----------------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 19-33 .. code-block:: Python k = np.linspace(1.0, 5.0, 200) fig, ax = plt.subplots() ax.semilogy(k, 1.0 / k**2, "k--", lw=2, label=r"Chebyshev $1/k^2$") for name, dist in [("Normal", Normal(0.0, 1.0)), ("Exponential", Exponential(rate=1.0)), ("Uniform", Uniform(0.0, 1.0)), ("Poisson(4)", Poisson(mu=4.0))]: result = chebyshev_tail(dist, k) ax.semilogy(k, np.maximum(result.exact, 1e-8), label=name) ax.set_ylim(1e-7, 1.5) ax.set_xlabel(r"$k$ (standard deviations)") ax.set_ylabel(r"$P(|X-\mu| \geq k\sigma)$") ax.legend() ax.set_title("Bienaymé-Chebyshev inequality") print(chebyshev_tail(Normal(0.0, 1.0), [2.0, 3.0])) .. image-sg:: /api/gallery/probability/limit_theorems/images/sphx_glr_plot_03_chebyshev_inequality_001.png :alt: Bienaymé-Chebyshev inequality :srcset: /api/gallery/probability/limit_theorems/images/sphx_glr_plot_03_chebyshev_inequality_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none TailBoundResult(k=array([2., 3.]), bound=array([0.25 , 0.11111111]), exact=array([0.04550026, 0.0026998 ])) .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.068 seconds) .. _sphx_glr_download_api_gallery_probability_limit_theorems_plot_03_chebyshev_inequality.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_chebyshev_inequality.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_03_chebyshev_inequality.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_03_chebyshev_inequality.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_