Skip to content

NormalizeFeatures

NormalizeFeatures(attrs: List[str] = ['node_features'])

Bases: FeaturesNormalizedTransform

Row-normalizes the given attributes to sum up to one, as PyG's NormalizeFeatures.

Each attribute is first shifted by its global minimum, so that all its values are non-negative, then every row is divided by its sum (rows that sum to less than one are divided by one):

\[ \mathbf{x}_i \leftarrow \frac{\mathbf{x}_i - \min(\mathbf{X})} {\max\left(1, \sum_j (x_{ij} - \min(\mathbf{X}))\right)} \]

This is the PyG-named equivalent of FeaturesNormalizedTransform.

Parameters:

Name Type Description Default
attrs List[str]

Names of the attributes to normalize. PyG names ("x", "edge_attr") are accepted and mapped to node_features and edge_features. Default: ["node_features"]

['node_features']

Example:

graph = GraphData(
    edge_index=mx.array([[0, 1], [1, 0]]),
    node_features=mx.array([[1.0, 3.0], [0.0, 0.0]]),
)
graph = NormalizeFeatures()(graph)
graph.node_features
# mx.array([[0.25, 0.75], [0.0, 0.0]])
Source code in mlx_graphs/transforms/normalize_features.py
def __init__(self, attrs: List[str] = ["node_features"]):
    super().__init__([_PYG_NAMES.get(attr, attr) for attr in attrs])

from mlx_graphs.transforms import NormalizeFeatures · mlx_graphs/transforms/normalize_features.py