SGConv
¶
SGConv(
node_features_dim: int,
out_features_dim: int,
K: int = 1,
cached: bool = False,
add_self_loops: bool = True,
bias: bool = True,
**kwargs,
)
Bases: MessagePassing
Simple graph convolution layer from "Simplifying Graph Convolutional Networks" paper.
where \(\mathbf{\hat{A}} = \mathbf{A} + \mathbf{I}\) is the (weighted) adjacency matrix with self-loops and \(\mathbf{\hat{D}}\) its diagonal degree matrix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_features_dim
|
int
|
Size of input node features |
required |
out_features_dim
|
int
|
Size of output node embeddings |
required |
K
|
int
|
Number of propagation steps |
1
|
cached
|
bool
|
If |
False
|
add_self_loops
|
bool
|
Whether to add a self-loop to every node that has none |
True
|
bias
|
bool
|
Whether to use bias in the node projection |
True
|
**kwargs
|
Arguments of |
{}
|
Example:
import mlx.core as mx
from mlx_graphs.nn import SGConv
edge_index = mx.array([[0, 1, 2, 3, 4], [0, 0, 1, 1, 3]])
node_features = mx.ones((5, 16))
conv = SGConv(16, 32, K=2)
h = conv(edge_index, node_features)
>>> h.shape
(5, 32)
# Full-batch training on one graph: propagate once, then only train W
conv = SGConv(16, 32, K=2, cached=True)
h = conv(edge_index, node_features)
Methods:
| Name | Description |
|---|---|
clear_cache |
Drops the propagated features stored when |
__call__ |
Computes the forward pass of SGConv. |
Source code in mlx_graphs/nn/conv/sg_conv.py
clear_cache
¶
__call__
¶
__call__(
edge_index: array,
node_features: array,
edge_weights: Optional[array] = None,
) -> array
Computes the forward pass of SGConv.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
edge_index
|
array
|
Input edge index of shape |
required |
node_features
|
array
|
Input node features |
required |
edge_weights
|
Optional[array]
|
Optional scalar weight per edge, of shape |
None
|
Returns:
| Type | Description |
|---|---|
array
|
The computed node embeddings |
Source code in mlx_graphs/nn/conv/sg_conv.py
from mlx_graphs.nn import SGConv · mlx_graphs/nn/conv/sg_conv.py