babylon.formulas.curvature

Ollivier-Ricci curvature computation for contradiction field topology.

Dialectical Field Topology (Feature 002): Discrete Ricci curvature measures how “spread out” the neighborhoods of two connected nodes are. Positive curvature = well-connected (clustered), negative curvature = bottleneck (bridge). This captures the topological structure of class relationships.

Reference: FR-005 (Ollivier-Ricci curvature on edges) Reference: R-004 (scipy LP for Wasserstein-1 distance)

Algorithm:

For each edge (u, v): 1. Construct probability measures mu_u, mu_v over neighborhoods

with alpha self-loop weight

  1. Build cost matrix from shortest path distances

  2. Solve linear program for Wasserstein-1 (Earth Mover’s) distance

  3. kappa(u,v) = 1 - W1/d(u,v)

Functions

compute_ollivier_ricci(graph, u, v[, alpha, ...])

Compute Ollivier-Ricci curvature for a single edge (u, v).

babylon.formulas.curvature.compute_ollivier_ricci(graph, u, v, alpha=0.5, weight_attr=None)[source]

Compute Ollivier-Ricci curvature for a single edge (u, v).

Parameters:
  • graph (Graph) – Undirected or directed NetworkX graph.

  • u (int | str) – Source node.

  • v (int | str) – Target node.

  • alpha (float) – Self-loop probability weight in [0, 1]. Higher alpha = more weight on the node itself.

  • weight_attr (str | None) – Optional edge attribute name for weights. When set, probability measures distribute (1-alpha) proportional to edge weights instead of uniformly, and shortest path uses weighted distances. None = unweighted (backward compatible).

Return type:

float

Returns:

Curvature kappa(u,v) = 1 - W1(mu_u, mu_v) / d(u,v). Positive = well-connected, negative = bottleneck.

Raises:

ValueError – If u or v is not in the graph or they are not connected.