MeanSubtractionNormalization
¶
Bases: Module
Applies layer normalization by subtracting the mean from the inputs as described in the "Revisiting 'Over-smoothing' in Deep GCNs" paper.
\[
\mathbf{x}_i = \mathbf{x}_i - \frac{1}{|\mathcal{V}|}
\sum_{j \in \mathcal{V}} \mathbf{x}_j
\]
The mean is computed separately for each graph of a batch. Also available
as MeanSubtractionNorm, its PyG name.
Example:
import mlx.core as mx
from mlx_graphs.nn import MeanSubtractionNormalization
norm = MeanSubtractionNormalization()
node_features = mx.array([[1.0], [3.0], [5.0]])
batch_indices = mx.array([0, 0, 1])
>>> norm(node_features, batch_indices)
array([[-1],
[1],
[0]], dtype=float32)
Methods:
| Name | Description |
|---|---|
__call__ |
Subtracts the mean node features of each graph. |
__call__
¶
__call__(
node_features: array,
batch_indices: Optional[array] = None,
num_graphs: Optional[int] = None,
) -> array
Subtracts the mean 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 centered node features. |
Source code in mlx_graphs/nn/norm/mean_subtraction_norm.py
from mlx_graphs.nn import MeanSubtractionNormalization · mlx_graphs/nn/norm/mean_subtraction_norm.py