DiffGroupNormalization
¶
DiffGroupNormalization(
node_features_dim: int,
groups: int,
lamda: float = 0.01,
eps: float = 1e-05,
momentum: float = 0.1,
affine: bool = True,
track_running_stats: bool = True,
)
Bases: Module
The differentiable group normalization layer from the "Towards Deeper Graph Neural Networks with Differentiable Group Normalization" paper, which normalizes node features group-wise via a learnable soft cluster assignment.
where \(\mathbf{W} \in \mathbb{R}^{F \times G}\) denotes a trainable weight matrix mapping each node into one of \(G\) clusters. Normalization is then performed group-wise via:
Also available as DiffGroupNorm, its PyG name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_features_dim
|
int
|
Size of the input node features \(F\). |
required |
groups
|
int
|
The number of groups \(G\). |
required |
lamda
|
float
|
The balancing factor \(\lambda\) between input embeddings
and normalized embeddings. Default: |
0.01
|
eps
|
float
|
A value added to the denominator for numerical stability.
Default: |
1e-05
|
momentum
|
float
|
The value used for the running mean and running variance
computation. Default: |
0.1
|
affine
|
bool
|
If set to |
True
|
track_running_stats
|
bool
|
If set to |
True
|
Example:
import mlx.core as mx
from mlx_graphs.nn import DiffGroupNormalization
norm = DiffGroupNormalization(16, groups=4)
node_features = mx.random.normal((10, 16))
>>> norm(node_features).shape
(10, 16)
Methods:
| Name | Description |
|---|---|
__call__ |
Applies differentiable group normalization. |
group_distance_ratio |
Measures the ratio of inter-group distance over intra-group |
Source code in mlx_graphs/nn/norm/diff_group_norm.py
__call__
¶
Applies differentiable group normalization.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_features
|
array
|
Node features of shape |
required |
Returns:
| Type | Description |
|---|---|
array
|
The normalized node features. |
Source code in mlx_graphs/nn/norm/diff_group_norm.py
group_distance_ratio
staticmethod
¶
Measures the ratio of inter-group distance over intra-group distance.
where \(\mathbf{X}_i\) denotes the set of all nodes that belong to
class \(i\), and \(C\) denotes the total number of classes in
labels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_features
|
array
|
Node features of shape |
required |
labels
|
array
|
Class of each node, of shape |
required |
eps
|
float
|
A value added to the denominator for numerical stability.
Default: |
1e-05
|
Returns:
| Type | Description |
|---|---|
float
|
The group distance ratio. |
Source code in mlx_graphs/nn/norm/diff_group_norm.py
from mlx_graphs.nn import DiffGroupNormalization · mlx_graphs/nn/norm/diff_group_norm.py