ResGatedGraphConv
¶
ResGatedGraphConv(
node_features_dim: Union[int, Tuple[int, int]],
out_features_dim: int,
act: Optional[Callable[[array], array]] = sigmoid,
edge_features_dim: Optional[int] = None,
root_weight: bool = True,
bias: bool = True,
**kwargs,
)
Bases: MessagePassing
Residual gated graph convolution layer from the "Residual Gated Graph ConvNets" paper.
where the gate \(\eta_{i,j}\) is defined as
with \(\sigma\) the sigmoid function. With edge features
(edge_features_dim set), the features of the edge from \(j\) to
\(i\) are concatenated to \(\mathbf{x}_i\) and \(\mathbf{x}_j\)
before the projections \(\mathbf{W}_2\), \(\mathbf{W}_3\) and
\(\mathbf{W}_4\).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_features_dim
|
Union[int, Tuple[int, int]]
|
Size of input node features, or a |
required |
out_features_dim
|
int
|
Size of output node embeddings |
required |
act
|
Optional[Callable[[array], array]]
|
Gating function \(\sigma\). Default: |
sigmoid
|
edge_features_dim
|
Optional[int]
|
Size of the edge features, if any. Default: |
None
|
root_weight
|
bool
|
Whether to add the transformed root node features
\(\mathbf{W}_1 \mathbf{x}_i\). Default: |
True
|
bias
|
bool
|
Whether to add a bias to the output. Default: |
True
|
**kwargs
|
Arguments of |
{}
|
Example:
import mlx.core as mx
from mlx_graphs.nn import ResGatedGraphConv
edge_index = mx.array([[0, 1, 2, 3, 4], [1, 0, 3, 2, 0]])
node_features = mx.random.normal((5, 16))
conv = ResGatedGraphConv(16, 32)
h = conv(edge_index, node_features)
>>> h.shape
(5, 32)
conv = ResGatedGraphConv(16, 32, edge_features_dim=4)
h = conv(edge_index, node_features, mx.random.normal((5, 4)))
References
Methods:
| Name | Description |
|---|---|
__call__ |
Computes the forward pass of ResGatedGraphConv. |
Source code in mlx_graphs/nn/conv/res_gated_graph_conv.py
__call__
¶
__call__(
edge_index: array,
node_features: Union[array, Tuple[array, array]],
edge_features: Optional[array] = None,
) -> array
Computes the forward pass of ResGatedGraphConv.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
edge_index
|
array
|
Input edge index of shape |
required |
node_features
|
Union[array, Tuple[array, array]]
|
Input node features, or a |
required |
edge_features
|
Optional[array]
|
Edge features of shape |
None
|
Returns:
| Type | Description |
|---|---|
array
|
The computed node embeddings, one row per destination node |
Source code in mlx_graphs/nn/conv/res_gated_graph_conv.py
from mlx_graphs.nn import ResGatedGraphConv · mlx_graphs/nn/conv/res_gated_graph_conv.py