GraphSizeNormalization
¶
Bases: Module
Applies graph size normalization over each individual graph in a batch of node features as described in the "Benchmarking Graph Neural Networks" paper.
where \(|\mathcal{V}|\) is the number of nodes of the graph of node
\(i\). Also available as GraphSizeNorm, its PyG name.
Example:
import mlx.core as mx
from mlx_graphs.nn import GraphSizeNormalization
norm = GraphSizeNormalization()
node_features = mx.ones((5, 2))
batch_indices = mx.array([0, 0, 0, 0, 1])
>>> norm(node_features, batch_indices)
array([[0.5, 0.5],
[0.5, 0.5],
[0.5, 0.5],
[0.5, 0.5],
[1, 1]], dtype=float32)
Methods:
| Name | Description |
|---|---|
__call__ |
Divides the features of each node by the square root of the size of |
__call__
¶
__call__(
node_features: array,
batch_indices: Optional[array] = None,
num_graphs: Optional[int] = None,
) -> array
Divides the features of each node by the square root of the size of its 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/graph_size_norm.py
from mlx_graphs.nn import GraphSizeNormalization · mlx_graphs/nn/norm/graph_size_norm.py