PairNormalization
¶
Bases: Module
Applies pair normalization over node features as described in the "PairNorm: Tackling Oversmoothing in GNNs" paper.
The statistics are computed separately for each graph of a batch. Also
available as PairNorm, its PyG name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scale
|
float
|
Scaling factor \(s\) of the normalization. Default: |
1.0
|
scale_individually
|
bool
|
If set to |
False
|
eps
|
float
|
A value added to the denominator for numerical stability.
Default: |
1e-05
|
Example:
import mlx.core as mx
from mlx_graphs.nn import PairNormalization
norm = PairNormalization(scale=2.0)
node_features = mx.random.normal((5, 16))
batch_indices = mx.array([0, 0, 0, 1, 1])
>>> norm(node_features, batch_indices).shape
(5, 16)
Methods:
| Name | Description |
|---|---|
__call__ |
Normalizes the node features of each graph. |
Source code in mlx_graphs/nn/norm/pair_norm.py
__call__
¶
__call__(
node_features: array,
batch_indices: Optional[array] = None,
num_graphs: Optional[int] = None,
) -> array
Normalizes the node features of each graph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_features
|
array
|
Node features of shape |
required |
batch_indices
|
Optional[array]
|
Graph of each node, of shape |
None
|
num_graphs
|
Optional[int]
|
Number of graphs. Default: |
None
|
Returns:
| Type | Description |
|---|---|
array
|
The normalized node features. |
Source code in mlx_graphs/nn/norm/pair_norm.py
from mlx_graphs.nn import PairNormalization · mlx_graphs/nn/norm/pair_norm.py