MLPAggregation
¶
MLPAggregation(
node_features_dim: int,
out_features_dim: int,
max_num_elements: int,
hidden_features_dim: Optional[int] = None,
num_layers: int = 1,
**mlp_kwargs: Any,
)
Bases: Aggregation
Aggregation with a multi-layer perceptron on the concatenated
elements of each set, from the "Graph Neural Networks with Adaptive Readouts" paper, as PyG's
MLPAggregation.
The elements of each set are padded with zeros (or truncated) to
max_num_elements, flattened, and fed to an
MLP.
Warning
The aggregation is not permutation-invariant: it depends on the order of the elements in each set.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_features_dim
|
int
|
Size of each input sample. |
required |
out_features_dim
|
int
|
Size of each output sample. |
required |
max_num_elements
|
int
|
Number of elements per set fed to the MLP. |
required |
hidden_features_dim
|
Optional[int]
|
Size of the hidden layers of the MLP. Required if
|
None
|
num_layers
|
int
|
Number of layers of the MLP. Default: |
1
|
**mlp_kwargs
|
Any
|
Other arguments of |
{}
|
Example:
import mlx.core as mx
from mlx_graphs.nn.aggr import MLPAggregation
aggr = MLPAggregation(16, 32, max_num_elements=3, hidden_features_dim=64,
num_layers=2)
x = mx.random.normal((6, 16))
index = mx.array([0, 0, 1, 1, 1, 2])
>>> aggr(x, index).shape
(3, 32)
Source code in mlx_graphs/nn/aggr/misc.py
from mlx_graphs.nn.aggr import MLPAggregation · mlx_graphs/nn/aggr/misc.py