easygraph.datapipe.normalize module#

easygraph.datapipe.normalize.min_max_scaler(X: Tensor, ft_min: float, ft_max: float) Tensor[source]#

Normalize the input feature matrix with min-max scaling.

Parameters:
  • X (torch.Tensor) – The input feature.

  • ft_min (float) – The minimum value of the output feature.

  • ft_max (float) – The maximum value of the output feature.

Examples

>>> import easygraph.datapipe as dd
>>> import torch
>>> X = torch.tensor([
            [0.1, 0.2, 0.5],
            [0.5, 0.2, 0.3],
            [0.3, 0.2, 0.0]
        ])
>>> dd.min_max_scaler(X, -1, 1)
tensor([[-0.6000, -0.2000,  1.0000],
        [ 1.0000, -0.2000,  0.2000],
        [ 0.2000, -0.2000, -1.0000]])
easygraph.datapipe.normalize.norm_ft(X: Tensor, ord: int | float | None = None) Tensor[source]#

Normalize the input feature matrix with specified ord refer to pytorch’s torch.linalg.norm function.

Note

The input feature matrix is expected to be a 1D vector or a 2D tensor with shape (num_samples, num_features).

Parameters:
  • X (torch.Tensor) – The input feature.

  • ord (Union[int, float], optional) – The order of the norm can be either an int, float. If ord is None, the norm is computed with the 2-norm. Defaults to None.

Examples

>>> import easygraph.datapipe as dd
>>> import torch
>>> X = torch.tensor([
            [0.1, 0.2, 0.5],
            [0.5, 0.2, 0.3],
            [0.3, 0.2, 0]
        ])
>>> dd.norm_ft(X)
tensor([[0.1826, 0.3651, 0.9129],
        [0.8111, 0.3244, 0.4867],
        [0.8321, 0.5547, 0.0000]])