LineGraph
¶
LineGraph(force_directed: bool = False)
Bases: BaseTransform
Converts a graph to its line graph, as PyG's LineGraph.
The edges are first coalesced (sorted, duplicates merged by summing their
edge_features), and the nodes of the line graph follow that order.
- For directed graphs (or with
force_directed), every edge is a node of the line graph, and there is a line edge from \((u, v)\) to every edge \((v, w)\). - For undirected graphs, every pair of reciprocal edges \((u, v)\), \((v, u)\) is a single node of the line graph (numbered in the order of the coalesced edges with \(u < v\)), and two such nodes are connected in both directions if they share an endpoint.
The new node_features are the (coalesced) old edge_features, the
features of reciprocal edges being summed for undirected graphs, and
edge_features is removed. The number of nodes is stored explicitly.
As in PyG, the other attributes are left unchanged.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
force_directed
|
bool
|
If |
False
|
Example:
# The path 0 - 1 - 2, undirected.
graph = GraphData(edge_index=mx.array([[0, 1, 1, 2], [1, 0, 2, 1]]))
graph = LineGraph()(graph)
graph.edge_index
# mx.array([[0, 1], [1, 0]])
graph.num_nodes
# 2
Methods:
| Name | Description |
|---|---|
process |
Converts |
Source code in mlx_graphs/transforms/topology.py
process
¶
Converts data to its line graph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
GraphData
|
The graph to transform. |
required |
Returns:
| Type | Description |
|---|---|
GraphData
|
The line graph. |
Source code in mlx_graphs/transforms/topology.py
from mlx_graphs.transforms import LineGraph · mlx_graphs/transforms/topology.py