.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "api/gallery/reliability/systems/plot_03_k_out_of_n.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 or to run this example in your browser via JupyterLite. .. rst-class:: sphx-glr-example-title .. _sphx_glr_api_gallery_reliability_systems_plot_03_k_out_of_n.py: Birnbaum, Esary and Saunders's k-out-of-n systems (1961) ======================================================== Birnbaum, Esary and Saunders (1961) put system reliability on a general footing: a *structure function* says which combinations of working components keep the system working. The :math:`k`-out-of-:math:`n` system, which works if at least :math:`k` of :math:`n` identical components do, spans the range from parallel (:math:`k = 1`) to series (:math:`k = n`), and its reliability is a binomial tail (:func:`~engineeringkit.reliability.k_of_n_reliability`). The example checks it by enumerating component states and recovers the mean life of each architecture. .. GENERATED FROM PYTHON SOURCE LINES 17-25 .. code-block:: Python import itertools import matplotlib.pyplot as plt import numpy as np from scipy.integrate import quad from engineeringkit.reliability import exponential_reliability, k_of_n_reliability .. GENERATED FROM PYTHON SOURCE LINES 26-31 Enumerate the structure function -------------------------------- Four engines, aircraft safe with any :math:`k` working, each with reliability 0.95 for the flight. .. GENERATED FROM PYTHON SOURCE LINES 31-39 .. code-block:: Python n, r = 4, 0.95 for k in range(1, n + 1): states = itertools.product([0, 1], repeat=n) exact = sum(np.prod([r if s else 1 - r for s in state]) for state in states if sum(state) >= k) print(f"{k}-out-of-{n}: binomial {k_of_n_reliability(n, k, r):.6f}, enumeration {exact:.6f}") assert np.isclose(k_of_n_reliability(n, k, r), exact) .. rst-class:: sphx-glr-script-out .. code-block:: none 1-out-of-4: binomial 0.999994, enumeration 0.999994 2-out-of-4: binomial 0.999519, enumeration 0.999519 3-out-of-4: binomial 0.985981, enumeration 0.985981 4-out-of-4: binomial 0.814506, enumeration 0.814506 .. GENERATED FROM PYTHON SOURCE LINES 40-45 Mean life of each architecture ------------------------------ With exponential components the :math:`k`-out-of-:math:`n` MTTF is :math:`\frac{1}{\lambda}\sum_{i=k}^{n} 1/i`. Time unit: hours. .. GENERATED FROM PYTHON SOURCE LINES 45-60 .. code-block:: Python lam = 1e-3 t = np.linspace(0, 4000, 300) fig, ax = plt.subplots(figsize=(6.5, 3.8)) for k in range(1, n + 1): R = [k_of_n_reliability(n, k, float(x)) for x in exponential_reliability(t, lam)] mttf = quad(lambda s, k=k: k_of_n_reliability(n, k, float(exponential_reliability(s, lam))), 0, np.inf)[0] exact = sum(1 / i for i in range(k, n + 1)) / lam ax.plot(t, R, label=f"{k}-out-of-{n}, MTTF {mttf:.0f} h") assert np.isclose(mttf, exact) ax.set(xlabel="time [h]", ylabel="system reliability") ax.legend() fig.tight_layout() plt.show() .. image-sg:: /api/gallery/reliability/systems/images/sphx_glr_plot_03_k_out_of_n_001.png :alt: plot 03 k out of n :srcset: /api/gallery/reliability/systems/images/sphx_glr_plot_03_k_out_of_n_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.070 seconds) .. _sphx_glr_download_api_gallery_reliability_systems_plot_03_k_out_of_n.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: lite-badge .. image:: images/jupyterlite_badge_logo.svg :target: ../../../../lite/lab/index.html?path=api/gallery/reliability/systems/plot_03_k_out_of_n.ipynb :alt: Launch JupyterLite :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_03_k_out_of_n.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_03_k_out_of_n.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_03_k_out_of_n.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_