GCNConv
¶
GCNConv(
node_features_dim: int,
out_features_dim: int,
bias: bool = True,
add_self_loops: bool = True,
improved: bool = False,
**kwargs,
)
Bases: MessagePassing
Graph convolution layer from "Semi-Supervised Classification with Graph Convolutional Networks" paper.
where \(\hat{\mathbf{A}}\) is the (optionally weighted) adjacency matrix,
with self-loops if add_self_loops=True, and \(\hat{\mathbf{D}}\) its
degree matrix. A self-loop of weight 1 is added to the nodes that do not
have one; existing self-loops keep their weight.
The normalization of a graph without edge weights is cached and reused as
long as the same edge_index array is passed, which is the common case
in full-batch training. Build a new array instead of modifying an
edge_index in place between calls, or call
clear_norm_cache().
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 |
bias
|
bool
|
whether to add a bias to the output |
True
|
add_self_loops
|
bool
|
whether to add a self-loop for each node. Default:
|
True
|
improved
|
bool
|
whether the added self-loops have a weight of 2 instead of
1, i.e. \(\hat{\mathbf{A}} = \mathbf{A} + 2\mathbf{I}\).
(PyG only applies it when edge weights are given.)
Default: |
False
|
Example:
import mlx.core as mx
from mlx_graphs.nn import GCNConv
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))
conv = GCNConv(16, 32)
h = conv(edge_index, node_features)
>>> h.shape
(5, 32)
Methods:
| Name | Description |
|---|---|
__call__ |
Computes the forward pass of GCNConv. |
Source code in mlx_graphs/nn/conv/gcn_conv.py
__call__
¶
__call__(
edge_index: array,
node_features: array,
edge_weights: Optional[array] = None,
normalize: bool = True,
**kwargs: Any,
) -> array
Computes the forward pass of GCNConv.
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 weight of each edge. Default: |
None
|
normalize
|
bool
|
Whether to apply the symmetric degree normalization.
Default: |
True
|
Returns:
| Type | Description |
|---|---|
array
|
The computed node embeddings |
Source code in mlx_graphs/nn/conv/gcn_conv.py
from mlx_graphs.nn import GCNConv · mlx_graphs/nn/conv/gcn_conv.py