Graph utils
torchmil.utils.degree(index, edge_weight=None, n_nodes=None)
Compute the degree of the adjacency matrix. Assumes that the graph is undirected.
Parameters:
-
index(ndarray) –Edge index of the adjacency matrix, shape (2, n_edges).
-
edge_weight(ndarray, default:None) –Edge weight of the adjacency matrix, shape (n_edges,).
-
n_nodes(int, default:None) –Number of nodes in the graph.
Returns:
-
degree(ndarray) –Degree of the adjacency matrix.
torchmil.utils.add_self_loops(edge_index, edge_weight=None, n_nodes=None)
Add self-loops to the adjacency matrix.
Parameters:
-
edge_index(ndarray) –Edge index of the adjacency matrix, shape (2, n_edges).
-
edge_weight(ndarray, default:None) –Edge weight of the adjacency matrix, shape (n_edges,).
-
n_nodes(int, default:None) –Number of nodes in the graph.
Returns:
-
new_edge_index(ndarray) –Edge index of the adjacency matrix with self-loops.
-
new_edge_weight(ndarray) –Edge weight of the adjacency matrix with self-loops.
torchmil.utils.normalize_adj(edge_index, edge_weight=None, n_nodes=None)
Normalize the adjacency matrix.
Parameters:
-
edge_index(ndarray) –Edge index of the adjacency matrix.
-
edge_weight(ndarray, default:None) –Edge weight of the adjacency matrix.
-
n_nodes(int, default:None) –Number of nodes in the graph.
Returns:
-
edge_weight(ndarray) –Edge weight of the normalized adjacency matrix.
torchmil.utils.build_adj(coords, feat=None, dist_thr=1.0, add_self_loops=False)
Build the adjacency matrix for a general graph given the coordinates and features of the nodes.
Parameters:
-
coords(ndarray) –Coordinates of the nodes.
-
feat(ndarray, default:None) –Features of the nodes, used to compute the edge weights. If None, the adjacency matrix is binary.
-
dist_thr(float, default:1.0) –Distance threshold to consider two nodes as neighbors. Default is 1.0.
-
add_self_loops(bool, default:False) –Whether to add self-loops.
Returns:
-
edge_index(ndarray) –Edge index of the adjacency matrix.
-
edge_weight(ndarray) –Edge weight of the adjacency matrix