.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/02_nbvfs/plot_04_alarm_log.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 Binder. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_02_nbvfs_plot_04_alarm_log.py: The industrial alarm log of the paper ===================================== The log of a hydrofluoric-acid alkylation plant (Bántay & Abonyi, 2024): 28,536 alarms (codes 100–499, printed ``A…``) and operator actions (codes above 1000, printed ``O…``) in 3,956 traces. As in the paper, CM-SPAM mines it with 1% minimum support and maximum gap 2. The three maps answer three questions: which alarm follows which (WN), which scenarios belong to the same alarm chain (CM), and which scenarios occur in the same traces (TM). .. GENERATED FROM PYTHON SOURCE LINES 12-21 .. code-block:: Python import matplotlib.pyplot as plt import spmviz as sv db = sv.datasets.load_alarm_log() ps = sv.mine(db, min_support=0.01, algorithm="cmspam", max_gap=2, max_length=10) print(ps, "lengths", ps.lengths.min(), "-", ps.lengths.max()) top = ps.filter(min_length=1, max_length=1).sort("support") print("most frequent events:", top.labels()[:8]) .. rst-class:: sphx-glr-script-out .. code-block:: none PatternSet(n_patterns=421, algorithm='cmspam', min_support=0.01, n_sequences=3956) lengths 1 - 6 most frequent events: ['O1084', 'O1085', 'O1080', 'O1081', 'A309', 'A330', 'O1082', 'O1133'] .. GENERATED FROM PYTHON SOURCE LINES 22-24 Weighted network of the most frequent starting alarm ---------------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 24-27 .. code-block:: Python start = top.patterns[0][0][0] sv.NBVFS("wn", start_items=[start]).fit(ps).plot(labels=18) .. image-sg:: /auto_examples/02_nbvfs/images/sphx_glr_plot_04_alarm_log_001.png :alt: NBVFS-WN weighted network :srcset: /auto_examples/02_nbvfs/images/sphx_glr_plot_04_alarm_log_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 28-30 Confidence and transaction maps ------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 30-34 .. code-block:: Python fig, axes = plt.subplots(1, 2, figsize=(15, 6)) sv.NBVFS("cm").fit(ps).plot(ax=axes[0], legend=False, labels=12, start_items=top.start_items()[:3]) sv.NBVFS("tm").fit(ps).plot(ax=axes[1], legend=False, labels=12, start_items=top.start_items()[:3]) .. image-sg:: /auto_examples/02_nbvfs/images/sphx_glr_plot_04_alarm_log_002.png :alt: NBVFS-CM confidence-based MDS, NBVFS-TM transaction-based MDS :srcset: /auto_examples/02_nbvfs/images/sphx_glr_plot_04_alarm_log_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 35-38 Alarms and operator actions --------------------------- Which patterns end with an operator action, and how confident is the step to it? .. GENERATED FROM PYTHON SOURCE LINES 38-41 .. code-block:: Python ops = ps.filter(min_length=2).filter(mask=[db.label(p[-1][-1]).startswith("O") for p in ps.filter(min_length=2).patterns]) print(ops.sort("confidence").to_frame()[["pattern", "support", "confidence"]].head(10)) plt.show() .. rst-class:: sphx-glr-script-out .. code-block:: none pattern support confidence 0 O1082 → O1083 → O1145 55 0.916667 1 O1083 → O1145 59 0.867647 2 O1144 → O1145 40 0.800000 3 O1133 → O1085 → O1133 → O1084 53 0.736111 4 O1149 → O1133 → O1084 46 0.707692 5 O1085 → O1086 → O1133 44 0.698413 6 O1085 → O1084 → O1085 → O1084 → O1085 → O1084 44 0.698413 7 O1084 → O1085 → O1084 → O1085 → O1084 → O1085 43 0.661538 8 O1085 → O1085 → O1084 → O1085 → O1084 46 0.657143 9 O1084 → O1085 → O1085 → O1084 → O1085 49 0.644737 .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 17.655 seconds) .. _sphx_glr_download_auto_examples_02_nbvfs_plot_04_alarm_log.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: binder-badge .. image:: images/binder_badge_logo.svg :target: https://mybinder.org/v2/gh/ComplexSystemsIntelligence/spmviz/main?urlpath=lab/tree/notebooks/auto_examples/02_nbvfs/plot_04_alarm_log.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_04_alarm_log.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_04_alarm_log.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_04_alarm_log.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_