scott.kilt¶
KILT
stands for Krvature-Informed Links and Topology, and is an object that can compute curvature filtrations for single graphs.
Example of KILT usage:
import networkx as nx
from scott import KILT,Comparator
G = nx.erdos_reyni(14,0.4)
kilt = KILT(measure="forman_curvature")
D = kilt.fit_transform(G)
print(f"Forman Curvature Filtration:")
print(f"Curvature Filtration Values:{kilt.curvature}")
print(D)
- class scott.kilt.KILT(measure='forman_curvature', weight=None, alpha=0.0, prob_fn=None)[source]¶
- Krvature-Informed Links and Topology (KILT) is a class that faciltates computing discrete curvature values for graphs.
Curvature values can be used as a filtration for persistent homology (as done in https://openreview.net/forum?id=Dt71xKyabn), providing even more expressive descriptors for the structure of a graph.
- measure¶
The type of curvature measure to be calculated. See CURVATURE_MEASURES for the methods that KILT functionality currently supports.
- Type:
string, default= “forman_curvature”
- alpha¶
Only used if Olivier–Ricci curvature is calculated, with default 0.0. 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.- Type:
float, default=0.0
- weight¶
Can be specified for (weighted) Forman–Ricci, Olivier–Ricci and Resistance curvature measures. Name of an edge attribute that is supposed to be used as an edge weight. If None, unweighted curvature is calculated. Notice that for Ollivier–Ricci curvature, 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.- Type:
str or None, default=None
- prob_fn¶
Used only if Ollivier–Ricci curvature is calculated, with default 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.- Type:
callable or None, default=None
- __init__(measure='forman_curvature', weight=None, alpha=0.0, prob_fn=None) None [source]¶
Creates an instance of the KILT class with the desired specifications for the method of computing curvature in a graph.
- property G: Graph¶
Getter method for the graph associated with the KILT object.
- property curvature: array¶
Getter method for the curvature values of the graph.
- fit(graph) None [source]¶
Calculates the curvature values for the edges of the given graph according to the specifications of the KILT object Curvature values are can then be retrieved via the curvature attribute.
- Parameters:
graph (networkx.Graph) – Input graph for which curvature values will be calculated.
- Return type:
None
Examples
>>> import networkx as nx >>> from scott.topology.kilt import KILT >>> G = nx.Graph() >>> edges = [(0, 1),(0, 2),(0, 3),(0, 4),(1, 2),(2, 3),(3, 5),(4, 5),(5, 6),(3, 7)] >>> kilt = KILT() >>> kilt.fit(G) >>> print(kilt.curvature) [ 1. 3. -1. -2. 2. 0. -3. -1. -1. 0.]
- transform(homology_dims: List[int] | None = [0, 1], mask_infinite_features: bool = False, extended_persistence: bool = True) PersistenceDiagram [source]¶
Executes a curvature filtration for the given homology dimensions. Can only be run after fit(), as it requires edge curvature values to execute a filtration.
- Parameters:
homology_dims (List[int]) – A list of the homology dimensions for which persistence points should be calculated, with default being [0,1].
- Returns:
A persistence diagram wrapper for the topological information resulting from a curvature filtration. Attribute persistence_pts stores a Dict[int, np.array] that a maps homology dimension key to a np.array of its persistence pairs.
- Return type:
PersistenceDiagram (Dict[int, np.array])
- fit_transform(graph, homology_dims: List[int] | None = [0, 1], mask_infinite_features: bool = False, extended_persistence: bool = False) PersistenceDiagram [source]¶
Runs fit(graph) and transform(homology_dims) in succession. Thus computes the curvature values for the given graph and executes a filtration for the given homology dimensions.
- Parameters:
graph (networkx.Graph) – Input graph for which curvature values will be calculated.
homology_dims (List[int]) – A list of the homology dimensions for which persistence points should be calculated, with default being [0,1].
mask_infinite_features (bool, default=False) – Whether to mask infinite persistence pairs in the resulting persistence diagrams.
extended_persistence (bool, default=False) – Whether to compute extended persistence. Default is False, computing standard persistence.
- Returns:
A persistence diagram wrapper for the topological information resulting from a curvature filtration. Attribute persistence_pts stores a Dict[int, np.array] that a maps homology dimension key to a np.array of its persistence pairs.
- Return type:
PersistenceDiagram (Dict[int, np.array])
Examples
>>> import networkx as nx >>> from scott.topology.kilt import KILT >>> G = nx.Graph() >>> edges = [(0, 1),(0, 2),(0, 3),(0, 4),(1, 2),(2, 3),(3, 5),(4, 5),(5, 6),(3, 7)] >>> G.add_edges_from(edges) >>> kilt = KILT() >>> diagram = kilt.fit_transform(G,mask_infinite_features=False,extended_persistence=False) >>> print(diagram.persistence_pts) {0: array([[-2., -1.], [-3., inf]]), 1: array([[ 2., 3.], [-1., inf]])}