CGConv
¶
CGConv(
node_features_dim: Union[int, Tuple[int, int]],
edge_features_dim: int = 0,
aggr: str = "add",
batch_norm: bool = False,
bias: bool = True,
**kwargs,
)
Bases: MessagePassing
Crystal graph convolution layer from the "Crystal Graph Convolutional Neural Networks for an Accurate and Interpretable Prediction of Material Properties" paper.
where \(\mathbf{z}_{i,j} = [ \mathbf{x}_i, \mathbf{x}_j, \mathbf{e}_{j,i} ]\) concatenates the features of the destination node, the source node and (optionally) the edge, \(\sigma\) is the sigmoid and \(g\) the softplus function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_features_dim
|
Union[int, Tuple[int, int]]
|
Size of input node features, or a |
required |
edge_features_dim
|
int
|
Size of the edge features. Default: |
0
|
aggr
|
str
|
Aggregation function. Default: |
'add'
|
batch_norm
|
bool
|
Whether to apply batch normalization to the aggregated
messages. Default: |
False
|
bias
|
bool
|
Whether the two projections use a bias. Default: |
True
|
**kwargs
|
Arguments of |
{}
|
Example:
import mlx.core as mx
from mlx_graphs.nn import CGConv
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))
conv = CGConv(16, edge_features_dim=4)
h = conv(edge_index, node_features, edge_features)
>>> h.shape
(5, 16)
References
Methods:
| Name | Description |
|---|---|
__call__ |
Computes the forward pass of CGConv. |
Source code in mlx_graphs/nn/conv/cg_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 CGConv.
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]
|
Optional 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/cg_conv.py
from mlx_graphs.nn import CGConv · mlx_graphs/nn/conv/cg_conv.py