TwoHop
¶
Bases: BaseTransform
Adds the two-hop edges to the graph, as PyG's TwoHop.
An edge \((i, k)\) is added for every path \(i \rightarrow j
\rightarrow k\) with \(i \neq k\). The edges are then coalesced: sorted
by source then destination node, without duplicates. Every per-edge
attribute (e.g. edge_features) gets zeros for the new edges, and the
values of merged duplicate edges are summed.
Example:
graph = GraphData(edge_index=mx.array([[0, 1], [1, 2]]))
graph = TwoHop()(graph)
graph.edge_index
# mx.array([[0, 0, 1], [1, 2, 2]])
Methods:
| Name | Description |
|---|---|
process |
Adds the two-hop edges to |
process
¶
Adds the two-hop edges to data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
GraphData
|
The graph to transform. |
required |
Returns:
| Type | Description |
|---|---|
GraphData
|
The graph with the two-hop edges. |
Source code in mlx_graphs/transforms/topology.py
from mlx_graphs.transforms import TwoHop · mlx_graphs/transforms/topology.py