Skip to content

GRUAggregation

GRUAggregation(node_features_dim: int, out_features_dim: int, bias=True)

Bases: _RecurrentAggregation

Aggregation with a GRU, from the "Graph Neural Networks with Adaptive Readouts" paper, as PyG's GRUAggregation.

The elements of each set are padded with zeros to the size of the largest set and fed to a GRU in input order. The output is the last hidden state.

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 (hidden size of the GRU).

required
bias

Whether the GRU has biases. Default: True

True

Example:

import mlx.core as mx
from mlx_graphs.nn.aggr import GRUAggregation

aggr = GRUAggregation(16, 32)
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/rnn.py
def __init__(self, node_features_dim: int, out_features_dim: int, bias=True):
    super().__init__(node_features_dim, out_features_dim)
    self.gru = nn.GRU(node_features_dim, out_features_dim, bias=bias)

from mlx_graphs.nn.aggr import GRUAggregation · mlx_graphs/nn/aggr/rnn.py