GCN2Conv
¶
GCN2Conv(
node_features_dim: int,
alpha: float,
theta: Optional[float] = None,
layer: Optional[int] = None,
shared_weights: bool = True,
cached: bool = False,
add_self_loops: bool = True,
normalize: bool = True,
**kwargs,
)
Bases: MessagePassing
Graph convolution with initial residual connections and identity mapping (GCNII) from the "Simple and Deep Graph Convolutional Networks" paper.
with \(\hat{\mathbf{P}} = \hat{\mathbf{D}}^{-1/2} \hat{\mathbf{A}}
\hat{\mathbf{D}}^{-1/2}\), where \(\hat{\mathbf{A}} = \mathbf{A} +
\mathbf{I}\) is the (weighted) adjacency matrix with self-loops,
\(\mathbf{H}^{(0)}\) the initial node features, and \(\beta =
\log(\theta / \ell + 1)\) (beta = 1 if theta and layer are not
given). With shared_weights=False, the initial features get their own
weight matrix:
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_features_dim
|
int
|
Size of the input and output node features |
required |
alpha
|
float
|
Strength \(\alpha\) of the initial residual connection |
required |
theta
|
Optional[float]
|
Hyperparameter \(\theta\) used to compute the strength of the
identity mapping. Default: |
None
|
layer
|
Optional[int]
|
Index \(\ell\) of the layer (starting from 1), used to
compute the strength of the identity mapping. Default: |
None
|
shared_weights
|
bool
|
If |
True
|
cached
|
bool
|
If |
False
|
add_self_loops
|
bool
|
Whether to add a self-loop to every node that has none.
Default: |
True
|
normalize
|
bool
|
Whether to apply the symmetric degree normalization.
Default: |
True
|
**kwargs
|
Arguments of |
{}
|
Example:
import mlx.core as mx
from mlx_graphs.nn import GCN2Conv
edge_index = mx.array([[0, 1, 2, 3, 4], [0, 0, 1, 1, 3]])
initial_features = mx.random.normal((5, 16))
conv = GCN2Conv(16, alpha=0.1, theta=0.5, layer=1)
h = conv(edge_index, initial_features, initial_features)
>>> h.shape
(5, 16)
References
[1] Chen et al. Simple and Deep Graph Convolutional Networks.
Methods:
| Name | Description |
|---|---|
clear_cache |
Drops the normalized graph stored when |
__call__ |
Computes the forward pass of GCN2Conv. |
Source code in mlx_graphs/nn/conv/gcn2_conv.py
clear_cache
¶
__call__
¶
__call__(
edge_index: array,
node_features: array,
initial_node_features: array,
edge_weights: Optional[array] = None,
) -> array
Computes the forward pass of GCN2Conv.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
edge_index
|
array
|
Input edge index of shape |
required |
node_features
|
array
|
Node features of the previous layer \(\mathbf{H}^{(\ell)}\) |
required |
initial_node_features
|
array
|
Initial node features \(\mathbf{H}^{(0)}\) (usually the output of the first projection of the model) |
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/gcn2_conv.py
from mlx_graphs.nn import GCN2Conv · mlx_graphs/nn/conv/gcn2_conv.py