LCMAggregation
¶
Bases: Aggregation
The Learnable Commutative Monoid aggregation from the "Learnable Commutative Monoids for Graph Neural Networks" paper, as PyG's LCMAggregation.
The elements of each set are (optionally) projected, then combined in a balanced binary tree whose binary operator is a symmetrized GRU cell, in \(\mathcal{O}(\log |\mathcal{V}|)\) depth:
Sets are padded with zeros to the size of the largest 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 |
project
|
bool
|
Whether to apply a linear projection followed by a ReLU
before the aggregation. Required if the two sizes differ.
Default: |
True
|
Example:
import mlx.core as mx
from mlx_graphs.nn.aggr import LCMAggregation
aggr = LCMAggregation(16, 32)
x = mx.random.normal((6, 16))
index = mx.array([0, 0, 1, 1, 1, 2])
>>> aggr(x, index).shape
(3, 32)
Methods:
| Name | Description |
|---|---|
aggregate |
Aggregates |
Source code in mlx_graphs/nn/aggr/misc.py
aggregate
¶
aggregate(
x: array,
index: array,
dim_size: int,
max_num_elements: Optional[int] = None,
**kwargs,
) -> array
Aggregates x.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
array
|
Array of shape |
required |
index
|
array
|
Set of each element. |
required |
dim_size
|
int
|
Number of sets. |
required |
max_num_elements
|
Optional[int]
|
Only the first |
None
|
Source code in mlx_graphs/nn/aggr/misc.py
from mlx_graphs.nn.aggr import LCMAggregation · mlx_graphs/nn/aggr/misc.py