Note
Go to the end to download the full example code or to run this example in your browser via Binder.
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).
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])
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']
Weighted network of the most frequent starting alarm#
start = top.patterns[0][0][0]
sv.NBVFS("wn", start_items=[start]).fit(ps).plot(labels=18)

<Axes: title={'left': 'NBVFS-WN weighted network'}>
Confidence and transaction maps#
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])

<Axes: title={'left': 'NBVFS-TM transaction-based MDS'}>
Alarms and operator actions#
Which patterns end with an operator action, and how confident is the step to it?
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()
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
Total running time of the script: (0 minutes 20.846 seconds)