SimpleConv
¶
SimpleConv(
aggr: ScatterAggregations = "add",
combine_root_func: Optional[CombineRootFunctions] = None,
**kwargs,
)
Bases: MessagePassing
A simple non-trainable message passing layer.
where \(\bigoplus\) denotes an aggregation strategy (e.g. 'add', 'mean'), and \(e_{j,i}\) denotes the edge weight between the source node \(j\) and the target node \(i\) and \(\mathcal{N(i)}\) denotes the neighbors of node \(i\) and \(\mathbf{x}_j\) denotes the features of node \(j\).
Inspired by the SimpleConv PyG layer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
aggr
|
ScatterAggregations
|
Aggregation strategy used to aggregate messages,
e.g. |
'add'
|
combine_root_func
|
Optional[CombineRootFunctions]
|
Strategy used to combine the features from the root nodes. Available values: |
None
|
Example:
import mlx.core as mx
from mlx_graphs.nn import SimpleConv
# Sum the messages from the neighbors.
# Use a self-loop for each root node.
conv = SimpleConv(aggr="add", combine_root_func="self_loop")
node_features = mx.ones((5, 3))
edge_index = mx.array([[0, 1, 2, 3, 4], [0, 0, 1, 1, 3]])
edge_weights = mx.array([10, 20, 5, 2, 15])
h = conv(edge_index, node_features, edge_weights)
Methods:
| Name | Description |
|---|---|
__call__ |
Computes the forward pass of SimpleConv. |
Source code in mlx_graphs/nn/conv/simple_conv.py
__call__
¶
__call__(
edge_index: array,
node_features: array,
edge_weights: Optional[array] = None,
) -> array
Computes the forward pass of SimpleConv.
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]
|
Edge weights leveraged in message passing. Default: |
None
|
Returns:
| Type | Description |
|---|---|
array
|
The computed node embeddings |
Source code in mlx_graphs/nn/conv/simple_conv.py
from mlx_graphs.nn import SimpleConv · mlx_graphs/nn/conv/simple_conv.py