Comparing Structures¶
The knowledgespaces.metrics module provides distance measures and agreement
indices for comparing two knowledge structures or surmise relations.
Distance between structures¶
from knowledgespaces.metrics import symmetric_difference, hausdorff, directional_distances
# Symmetric difference: states in one but not the other
d = symmetric_difference(ks_human, ks_ai)
# Hausdorff distance: max min-Hamming-distance between states
h = hausdorff(ks_human, ks_ai)
# Directional distances (asymmetric)
dd = directional_distances(ks_human, ks_ai)
print(dd.forward_mean) # Human→AI: how far are Human states from AI?
print(dd.backward_mean) # AI→Human: how far are AI states from Human?
Interpretation of directional distances:
forward (H→A) |
backward (A→H) |
Meaning |
|---|---|---|
Low |
Low |
Similar structures |
Low |
High |
AI adds states beyond Human |
High |
Low |
Human has exclusive states |
High |
High |
Divergent structures |
Agreement on prerequisites¶
from knowledgespaces.metrics import cohens_kappa, graph_edit_distance
# Cohen's kappa on prerequisite relations
k = cohens_kappa(rel_human, rel_ai) # [-1, 1], 1 = perfect agreement
# Graph edit distance (edge differences)
added, removed, total = graph_edit_distance(rel_human, rel_ai)
Domain validation¶
All metric functions require matching domains:
# This raises ValueError:
symmetric_difference(ks_with_domain_abc, ks_with_domain_xyz)