Note
Go to the end to download the full example code or to run this example in your browser via Binder.
Comparing two versions of a production system#
The suggestions of the HyperGodot case study — drop the redundant final inspection (E7) and automate the manual assembly (E5) — define a redesigned system. The difference hypergraph marks the hyperedges kept, removed and added; group statistics compare human and machine work before and after.
import matplotlib.pyplot as plt
import pandas as pd
import hatvis as hv
from hatvis.plotting import draw_hypergraph
before = hv.datasets.load_manufacturing_cps()
# [snippet:redesign]
after = before.remove_edges(["E7", "E5"]).add_edges({"E5r": ["R3", "C2", "C3", "C4", "FP"]}, weights=[18])
after.edge_data.loc["E5r", ["task", "group"]] = ["Robotic assembly", "M"]
diff = hv.temporal.difference(before, after, labels=("before", "after"))
stats = pd.concat({"before": hv.temporal.group_statistics(before, weight_name="minutes"),
"after": hv.temporal.group_statistics(after, weight_name="minutes")})
# [/snippet:redesign]
print(diff.edge_data["status"].value_counts())
print(stats[["hyperedges", "total minutes", "mean size"]])
# [snippet:distance]
dist = {kind: hv.similarity.hypergraph_distance(before, after, kind) for kind in ("jaccard", "hamming", "spectral", "degree")}
# [/snippet:distance]
print({k: round(v, 3) for k, v in dist.items()})
status
both 5
only before 2
only after 1
Name: count, dtype: int64
hyperedges total minutes mean size
before H 5 85.0 3.6
M 2 45.0 4.0
after H 3 40.0 3.333333
M 3 63.0 4.333333
{'jaccard': 0.375, 'hamming': 0.067, 'spectral': 0.094, 'degree': 0.258}
fig, ax = plt.subplots(figsize=(8.5, 6.5))
draw_hypergraph(diff, layout="force", group="status", edge_color="status", ax=ax, random_state=3,
edge_labels=True, title="difference: kept (solid), removed and added (dashed, dotted)")
plt.tight_layout()

Total running time of the script: (0 minutes 0.309 seconds)