scott.geometry.measures¶
- scott.geometry.measures.forman_curvature(G, weight=None)[source]¶
Calculate Forman–Ricci curvature of a graph.
This function calculates the Forman–Ricci curvature of a graph, optionally taking (positive) node and edge weights into account.
- Parameters:
G (networkx.Graph) – Input graph
weight (str or None) – Name of an edge attribute that is supposed to be used as an edge weight. Will use the same attribute to look up node weights. If None, unweighted curvature is calculated.
- Returns:
An array of edge curvature values, following the ordering of edges of
G
.- Return type:
np.array
- scott.geometry.measures.balanced_forman_curvature(G, weight=None)[source]¶
Compute the balanced Forman curvature for each edge in a NetworkX graph.
- Parameters:
G (networkx.Graph) – Input graph (weighted or unweighted).
weight (str or None) – Name of the edge weight attribute. If None, the graph is treated as unweighted.
- Returns:
An array of balanced Forman curvature values, following the ordering of edges of
G
.- Return type:
np.array
References
Topping, Jake, et al. “Understanding Over-Squashing and Bottlenecks on Graphs via Curvature.” International Conference on Learning Representations. 2022.
- scott.geometry.measures.ollivier_ricci_curvature(G, alpha=0.0, weight=None, prob_fn=None) ndarray [source]¶
Calculate Ollivier–Ricci curvature for graphs that allows for a custom probability measure.
This function calculates the Ollivier–Ricci curvature of a graph, optionally taking (positive) edge weights into account.
- Parameters:
G (networkx.Graph) – Input graph
alpha (float) – Provides laziness parameter for default probability measure. The measure is not compatible with a user-defined
prob_fn
. If such a function is set,alpha
will be ignored.weight (str or None) – Name of an edge attribute that is supposed to be used as an edge weight. If None, unweighted curvature is calculated. Notice that if
prob_fn
is provided, this parameter will have no effect for the calculation of probability measures, but it will be used for the calculation of shortest-path distances.prob_fn (callable or None) –
If set, should refer to a function that calculate a probability measure for a given graph and a given node. This callable needs to satisfy the following signature:
prob_fn(G, node, node_to_index)
Here,
G
refers to the graph,node
to the node whose measure is to be calculated, andnode_to_index
to the lookup map that maps a node identifier to a zero-based index.If
prob_fn
is set, providingalpha
will not have an effect.
- Returns:
An array of edge curvature values, following the ordering of edges of
G
.- Return type:
np.array
- scott.geometry.measures.resistance_curvature(G, weight=None)[source]¶
Calculate Resistance Curvature of a graph.
This function calculates the resistance curvature of a graph, optionally taking (positive) edge weights into account.
- Parameters:
G (networkx.Graph) – Input graph
weight (str or None) – Name of an edge attribute that is supposed to be used as an edge weight. If None, unweighted curvature is calculated.
- Returns:
An array of edge curvature values, following the ordering of edges of
G
.- Return type:
np.array