DirGNNConv
¶
DirGNNConv(
conv: Union[Module, Callable[[], Module]],
alpha: float = 0.5,
root_weight: bool = True,
node_features_dim: Optional[int] = None,
out_features_dim: Optional[int] = None,
)
Bases: Module
A generic wrapper for computing graph convolution on directed graphs as described in the "Edge Directionality Improves Learning on Heterophilic Graphs" paper.
DirGNNConv passes messages both from source nodes to destination
nodes (along the edges) and from destination nodes to source nodes (along
the reversed edges), with two copies of the wrapped layer, and combines
them as a convex combination:
As in PyG, the wrapped layers have their self-loops and root weight turned
off: the attributes add_self_loops, _add_self_loops and
root_weight are set to False on both copies when the layer has
them. Layers whose root/skip term cannot be turned off this way keep it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conv
|
Union[Module, Callable[[], Module]]
|
The layer to wrap, which is copied twice. Since MLX layers have
no generic way to re-initialize their parameters, both copies
start with the same weights; pass instead a function that builds
a new layer (e.g. |
required |
alpha
|
float
|
Weight of the reversed edges in the convex combination.
Default: |
0.5
|
root_weight
|
bool
|
Whether to add a linear projection of the node features
to the output. Default: |
True
|
node_features_dim
|
Optional[int]
|
Size of input node features, needed for the root
projection when the wrapped layer has no |
None
|
out_features_dim
|
Optional[int]
|
Size of output node embeddings, needed for the root
projection when the wrapped layer has no |
None
|
Example:
import mlx.core as mx
from mlx_graphs.nn import DirGNNConv, SAGEConv
conv = DirGNNConv(lambda: SAGEConv(16, 32), alpha=0.5)
edge_index = mx.array([[0, 1, 2, 3, 4], [0, 0, 1, 1, 3]])
node_features = mx.random.uniform(low=0, high=1, shape=(5, 16))
h = conv(edge_index, node_features)
>>> h.shape
(5, 32)
Methods:
| Name | Description |
|---|---|
__call__ |
Computes the forward pass of DirGNNConv. |
Source code in mlx_graphs/nn/conv/dir_gnn_conv.py
__call__
¶
__call__(edge_index: array, node_features: array, **kwargs: Any) -> array
Computes the forward pass of DirGNNConv.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
edge_index
|
array
|
Input edge index of shape |
required |
node_features
|
array
|
Input node features |
required |
**kwargs
|
Any
|
Extra per-edge arguments passed to both wrapped layers
(e.g. |
{}
|
Returns:
| Type | Description |
|---|---|
array
|
The computed node embeddings |
Source code in mlx_graphs/nn/conv/dir_gnn_conv.py
from mlx_graphs.nn import DirGNNConv · mlx_graphs/nn/conv/dir_gnn_conv.py