scott.geometry.measures¶
- scott.geometry.measures.forman_curvature(G, weight=None, n_jobs=-1)[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, n_jobs=-1)[source]¶
Compute the balanced Forman curvature for each edge in a NetworkX graph. Defaults to parallel processing.
- 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.
n_jobs (int, optional) – Number of parallel jobs. -1 means use all available cores. Set to 1 for sequential processing. Default is -1.
- 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, n_jobs=-1) 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,alphawill 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_fnis 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,
Grefers to the graph,nodeto the node whose measure is to be calculated, andnode_to_indexto the lookup map that maps a node identifier to a zero-based index.If
prob_fnis set, providingalphawill not have an effect.n_jobs (int, optional) – Number of parallel jobs. -1 means use all available cores. Set to 1 for sequential processing. Default is -1.
- 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, n_jobs=-1)[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.
n_jobs (int, optional) – Number of parallel jobs. -1 means use all available cores. Set to 1 for sequential processing. Default is -1.
- Returns:
An array of edge curvature values, following the ordering of edges of
G.- Return type:
np.array