Note
Go to the end to download the full example code or to run this example in your browser via Binder.
Episodes in one long alarm stream#
Without trace boundaries, an alarm log is one long stream. Frequent episodes (Mannila, Toivonen & Verkamo, 1997) are found in sliding windows: a serial episode is ordered, a parallel one is a set. WINEPI counts the share of windows containing the episode, MINEPI its minimal occurrences; the timeline shows the minimal occurrences of the top episodes.
import matplotlib.pyplot as plt
import spmviz as sv
from spmviz.viz import plot_episode_timeline
alarm = sv.datasets.load_alarm_log()
# the busiest day of the plant as a single stream (times in minutes)
log = sv.datasets.load_alarm_log(as_frame=True)
dates = log["timestamp"].dt.date
day = log[dates == dates.value_counts().index[0]]
events = [alarm.label(e) for e in day["event"]]
minutes = (day["timestamp"] - day["timestamp"].iloc[0]).dt.total_seconds().to_numpy() / 60
ep = sv.mine_episodes(events, times=minutes, window=10, min_frequency=0.02, max_length=3)
multi = ep.filter(min_length=2)
print(multi.to_frame().sort_values("frequency", ascending=False).head(8)[["pattern", "frequency", "minimal_occurrences"]])
plot_episode_timeline(ep, top=8)

pattern frequency minimal_occurrences
50 O1132 → O1136 0.081720 12
27 O1085 → O1084 0.070784 14
22 O1084 → O1133 0.069472 14
55 O1133 → O1084 0.068102 13
20 O1084 → O1085 0.052308 10
56 O1133 → O1085 0.046610 9
28 O1085 → O1132 0.044434 8
47 O1132 → O1084 0.040532 7
<Axes: title={'left': 'minimal occurrences of the top serial episodes (window 10)'}, xlabel='time'>
Parallel episodes#
par = sv.mine_episodes(events, times=minutes, window=10, min_frequency=0.02, kind="parallel", max_length=3)
print(par.to_frame().sort_values("frequency", ascending=False).head(6)[["pattern", "frequency"]])
plt.show()
pattern frequency
16 O1084 0.217348
2 A232 0.212386
23 O1133 0.210901
17 O1085 0.187372
1 A196 0.149787
22 O1132 0.120709
Total running time of the script: (0 minutes 0.590 seconds)