Skip to content

feat: Add topological Betti-1 anomaly detection and fix connected components#38

Open
teerthsharma wants to merge 4 commits into
google:mainfrom
teerthsharma:feat/topological-betti-defense
Open

feat: Add topological Betti-1 anomaly detection and fix connected components#38
teerthsharma wants to merge 4 commits into
google:mainfrom
teerthsharma:feat/topological-betti-defense

Conversation

@teerthsharma

Copy link
Copy Markdown

Summary

This PR introduces a lightweight topological defense layer for detecting structurally anomalous graph inputs by analysing their first Betti number (beta_1), which counts independent cycles. It also fixes the broken connected-components placeholder in global_graph_topology.py.

Changes

  • dgf/src/analyse/topology/betti_defense.py (new):
    • calculate_betti_1(graph, schema) -- returns beta_1 for homogeneous graphs.
    • is_anomalous(graph, schema, expected_max_betti) -- boolean flag for anomalous graphs.
    • _connected_components(adjacency, num_nodes) -- union-find implementation for CC labels.
  • dgf/src/analyse/topology/betti_defense_test.py (new): 10 tests covering trees, cycles, cliques, self-loops, empty graphs, and heterogeneous-graph rejection.
  • dgf/src/analyse/topology/global_graph_topology.py:
    • Replaced the empty cc = np.array([]) placeholder with a real union-find call.
    • Added betti_1 field to GlobalGraphTopology.
  • dgf/src/analyse/topology/BUILD:
    • Added betti_defense py_library target.
    • Updated global_graph_topology deps.

Background

I have also applied topology in machine learning, and I currently have an open (not yet closed or merged) contribution in deepmind/penzai. I hope this module proves useful for the DGF community.

Thank you for your time.

This adds a topological defense layer for detecting structurally anomalous
graph inputs via first Betti number computation. It also fixes the broken
connected-components placeholder in global_graph_topology.py.

I have also applied topology in machine learning, and I currently have an
open (not yet closed or merged) contribution in deepmind/penzai.

Changes:
- betti_defense.py: New module with calculate_betti_1, is_anomalous,
  and union-find connected components.
- betti_defense_test.py: 10 tests covering trees, cycles, cliques,
  self-loops, empty graphs, and heterogeneous rejection.
- global_graph_topology.py: Fixed the empty connected-components placeholder
  and added betti_1 to GlobalGraphTopology.
- BUILD: Added betti_defense library target.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant