NNConv
¶
NNConv(
node_features_dim: Union[int, Tuple[int, int]],
out_features_dim: int,
mlp: Callable[[array], array],
aggr: str = "add",
root_weight: bool = True,
bias: bool = True,
**kwargs,
)
Bases: MessagePassing
Edge-conditioned convolution layer from the "Neural Message Passing for Quantum Chemistry" paper (also known as ECConv, from "Dynamic Edge-Conditioned Filters in Convolutional Neural Networks on Graphs").
where \(h_{\mathbf{\Theta}}\) is a neural network (mlp) that maps
the features \(\mathbf{e}_{j,i}\) of each edge to a
[node_features_dim, out_features_dim] weight matrix (flattened, i.e. an
output of size node_features_dim * out_features_dim).
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 |
mlp
|
Callable[[array], array]
|
Module mapping edge features of shape |
required |
aggr
|
str
|
Aggregation \(\bigoplus\). Default: |
'add'
|
root_weight
|
bool
|
Whether to add the transformed root node features
\(\mathbf{\Theta} \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
import mlx.nn as nn
from mlx_graphs.nn import NNConv
edge_index = mx.array([[0, 1, 2, 3, 4], [1, 0, 3, 2, 0]])
node_features = mx.random.normal((5, 16))
edge_features = mx.random.normal((5, 4))
mlp = nn.Sequential(nn.Linear(4, 32), nn.ReLU(), nn.Linear(32, 16 * 8))
conv = NNConv(16, 8, mlp, aggr="mean")
h = conv(edge_index, node_features, edge_features)
>>> h.shape
(5, 8)
References
[1] Gilmer et al. Neural Message Passing for Quantum Chemistry.
Methods:
| Name | Description |
|---|---|
__call__ |
Computes the forward pass of NNConv. |
Source code in mlx_graphs/nn/conv/nn_conv.py
__call__
¶
__call__(
edge_index: array,
node_features: Union[array, Tuple[array, array]],
edge_features: array,
) -> array
Computes the forward pass of NNConv.
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
|
array
|
Edge features of shape |
required |
Returns:
| Type | Description |
|---|---|
array
|
The computed node embeddings, one row per destination node |
Source code in mlx_graphs/nn/conv/nn_conv.py
from mlx_graphs.nn import NNConv · mlx_graphs/nn/conv/nn_conv.py