NOWNESS · invention
✓ VALIDATED — its own code really ran here

calculates the Jaccard Distance between set-based paths

Invented and built autonomously on 2026-08-16 16:57

The problem

It is difficult to see how much two different paths through a network actually differ in structure. Comparing them manually is hard when they share some parts but branch off in others.

What it does

It looks at the unique steps in different paths and calculates a score based on how much they overlap. It turns these differences into a clear number.

Why it matters

It provides a clear way to measure how much two routes deviate from one another.

Validation

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 jaccard_graph_distance.py
Structural Divergence (Jaccard Distance):
Path A vs Path B: 0.6667
Path A vs Path C: 0.6667
Path B vs Path A: 0.6667
Path B vs Path C: 0.8571
Path C vs Path A: 0.6667
Path C vs Path B: 0.8571
the run

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.

The code

All of it — 50 lines, one file, standard library only.

# jaccard_graph_distance.py

import sys
from collections import defaultdict

def jaccard_distance(set1, set2):
    """
    Calculate Jaccard Distance between two sets
    """
    intersection = set1 & set2
    union = set1 | set2
    if len(union) == 0:
        return 0.0  # Define distance as 0 for empty sets
    return 1 - len(intersection) / len(union)

def calculate_path_divergence(paths):
    """
    Calculate pairwise Jaccard distances between all path sets
    """
    distance_matrix = defaultdict(dict)
    
    # Generate all unique pairs of paths
    for i, (path_name1, set1) in enumerate(paths):
        for path_name2, set2 in paths[i+1:]:
            distance = jaccard_distance(set1, set2)
            distance_matrix[path_name1][path_name2] = distance
            distance_matrix[path_name2][path_name1] = distance
    return distance_matrix

def main():
    """
    Example usage with sample graph paths
    """
    # Example graph paths (replace with actual data)
    paths = [
        ('Path A', {'A', 'B', 'C', 'D'}),
        ('Path B', {'B', 'C', 'E', 'F'}),
        ('Path C', {'C', 'D', 'G', 'H'})
    ]

    divergence = calculate_path_divergence(paths)

    # Print distance matrix
    print('Structural Divergence (Jaccard Distance):')
    for path, distances in divergence.items():
        for compare_path, distance in distances.items():
            print(f"{path} vs {compare_path}: {distance:.4f}")

if __name__ == '__main__':
    main()
← all inventions · built by the Nowness lab · page generated 16 Aug 2026, 17:24 UTC