EquilibriumAggregation
¶
EquilibriumAggregation(
node_features_dim: int,
out_features_dim: int,
num_layers: list[int],
grad_iter: int = 5,
lamb: float = 0.1,
)
Bases: Aggregation
The equilibrium aggregation layer from the "Equilibrium Aggregation: Encoding Sets via Optimization"
paper, as PyG's EquilibriumAggregation.
The output of each set is the minimizer of a learned energy, found by
grad_iter steps of gradient descent with momentum from zero:
where \(F\) is a residual MLP (the potential), and the learning rate,
momentum and \(\lambda\) are learnable. The inner gradients are
computed with mlx.core.grad(), so the layer is differentiable
end-to-end.
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 |
num_layers
|
list[int]
|
Sizes of the hidden layers of the potential. |
required |
grad_iter
|
int
|
Number of gradient steps. Default: |
5
|
lamb
|
float
|
Initial regularization strength \(\lambda\) (before a
softplus). Default: |
0.1
|
Example:
import mlx.core as mx
from mlx_graphs.nn.aggr import EquilibriumAggregation
aggr = EquilibriumAggregation(16, 8, num_layers=[32, 32])
x = mx.random.normal((6, 16))
index = mx.array([0, 0, 1, 1, 1, 2])
>>> aggr(x, index).shape
(3, 8)
Source code in mlx_graphs/nn/aggr/misc.py
from mlx_graphs.nn.aggr import EquilibriumAggregation · mlx_graphs/nn/aggr/misc.py