It is difficult to measure how similar two sequences of actions are when they might follow different paths.
It compares two sets of actions and calculates both their shared overlap and their overall similarity score.
It provides a clear way to see how much two paths differ or align in a single calculation.
It was run inside an isolated container with no network access. This is the exact command and the real output it produced — captured process output, not written by a model.
$ python3 path_similarity.py Path-Step Jaccard Similarity: 0.5 Path Overlap Count: 2
A screenshot of that run.
A clean run proves this does what is shown above, in a CPU-only sandbox. It is a small research demo — not a production tool, and nothing here was published anywhere.
All of it — 20 lines, one file, standard library only.
# path_similarity.py
def path_step_jaccard(path1, path2):
set1 = set(path1)
set2 = set(path2)
intersection = set1 & set2
union = set1 | set2
return len(intersection) / len(union) if union else 0.0
def path_overlap_count(path1, path2):
return len(set(path1) & set(path2))
if __name__ == "__main__":
# Example usage
path_a = ['node1', 'node2', 'node3']
path_b = ['node2', 'node3', 'node4']
jaccard = path_step_jaccard(path_a, path_b)
overlap = path_overlap_count(path_a, path_b)
print(f'Path-Step Jaccard Similarity: {jaccard}')
print(f'Path Overlap Count: {overlap}')