graphorge.gnn_base_model.model.gnn_model.TorchStandardScaler

class TorchStandardScaler(n_features, mean=None, std=None, device_type='cpu')[source]

Bases: object

PyTorch tensor standardization data scaler.

_n_features

Number of features to standardize.

Type:

int

_mean

Features standardization mean tensor stored as a torch.Tensor with shape (n_features,).

Type:

torch.Tensor

_std

Features standardization standard deviation tensor stored as a torch.Tensor with shape (n_features,).

Type:

torch.Tensor

_device

Device on which torch.Tensor is allocated.

Type:

torch.device

set_device(self, device_type)[source]

Set device on which torch.Tensor is allocated.

set_mean(self, mean)[source]

Set features standardization mean tensor.

set_std(self, std)[source]

Set features standardization standard deviation tensor.

fit(self, tensor)[source]

Fit features standardization mean and standard deviation tensors.

transform(self, tensor, is_check_data=False)[source]

Standardize features tensor.

inverse_transform(self, tensor, is_check_data=False)[source]

Destandardize features tensor.

_check_mean(self, mean):

Check features standardization mean tensor.

_check_std(self, std)[source]

Check features standardization standard deviation tensor.

_check_tensor(self, tensor):

Check features tensor to be transformed.

Constructor.

Parameters:
  • n_features (int) – Number of features to standardize.

  • mean (torch.Tensor, default=None) – Features standardization mean tensor stored as a torch.Tensor with shape (n_features,).

  • std (torch.Tensor, default=None) – Features standardization standard deviation tensor stored as a torch.Tensor with shape (n_features,).

  • device_type ({'cpu', 'cuda'}, default='cpu') – Type of device on which torch.Tensor is allocated.

List of Public Methods

fit

Fit features standardization mean and standard deviation tensors.

inverse_transform

Destandardize features tensor.

set_device

Set device on which torch.Tensor is allocated.

set_mean

Set features standardization mean tensor.

set_mean_and_std

Set features standardization mean and standard deviation tensors.

set_std

Set features standardization standard deviation tensor.

transform

Standardize features tensor.

Methods

__init__(n_features, mean=None, std=None, device_type='cpu')[source]

Constructor.

Parameters:
  • n_features (int) – Number of features to standardize.

  • mean (torch.Tensor, default=None) – Features standardization mean tensor stored as a torch.Tensor with shape (n_features,).

  • std (torch.Tensor, default=None) – Features standardization standard deviation tensor stored as a torch.Tensor with shape (n_features,).

  • device_type ({'cpu', 'cuda'}, default='cpu') – Type of device on which torch.Tensor is allocated.

_check_mean(mean)[source]

Check features standardization mean tensor.

Parameters:

mean (torch.Tensor) – Features standardization mean tensor stored as a torch.Tensor with shape (n_features,).

Returns:

mean – Features standardization mean tensor stored as a torch.Tensor with shape (n_features,).

Return type:

torch.Tensor

_check_std(std)[source]

Check features standardization standard deviation tensor.

Parameters:

std (torch.Tensor) – Features standardization standard deviation tensor stored as a torch.Tensor with shape (n_features,).

Returns:

std – Features standardization standard deviation tensor stored as a torch.Tensor with shape (n_features,).

Return type:

torch.Tensor

_check_tensor(tensor)[source]

Check features tensor to be transformed.

Parameters:

tensor (torch.Tensor) – Standardized features PyTorch tensor stored as torch.Tensor with shape (n_samples, n_features).

fit(tensor, is_bessel=False)[source]

Fit features standardization mean and standard deviation tensors.

If sequential data is provided, then all sequence times are concatenated and the standardization procedures take into account the whole sequence length data for each feature.

Parameters:
  • tensor (torch.Tensor) – Features PyTorch tensor stored as torch.Tensor with shape (n_samples, n_features) or as torch.Tensor with shape (sequence_length, n_samples, n_features).

  • is_bessel (bool, default=False) – If True, apply Bessel’s correction to compute standard deviation, False otherwise.

inverse_transform(tensor, is_check_data=False)[source]

Destandardize features tensor.

If sequential data is provided, then all sequence times are concatenated and the standardization procedures take into account the whole sequence length data for each feature.

Parameters:
  • tensor (torch.Tensor) – Standardized features PyTorch tensor stored as torch.Tensor with shape (n_samples, n_features) or as torch.Tensor with shape (sequence_length, n_samples, n_features).

  • is_check_data (bool, default=False) – If True, then check transformed tensor data.

Returns:

transformed_tensor – Features PyTorch tensor stored as torch.Tensor with shape (n_samples, n_features) or as torch.Tensor with shape (sequence_length, n_samples, n_features).

Return type:

torch.Tensor

set_device(device_type)[source]

Set device on which torch.Tensor is allocated.

Parameters:
  • device_type ({'cpu', 'cuda'}) – Type of device on which torch.Tensor is allocated.

  • device (torch.device) – Device on which torch.Tensor is allocated.

set_mean(mean)[source]

Set features standardization mean tensor.

Parameters:

mean (torch.Tensor) – Features standardization mean tensor stored as a torch.Tensor with shape (n_features,).

set_mean_and_std(mean, std)[source]

Set features standardization mean and standard deviation tensors.

Parameters:
  • mean (torch.Tensor) – Features standardization mean tensor stored as a torch.Tensor with shape (n_features,).

  • std (torch.Tensor) – Features standardization standard deviation tensor stored as a torch.Tensor with shape (n_features,).

set_std(std)[source]

Set features standardization standard deviation tensor.

Parameters:

std (torch.Tensor) – Features standardization standard deviation tensor stored as a torch.Tensor with shape (n_features,).

transform(tensor, is_check_data=False)[source]

Standardize features tensor.

If sequential data is provided, then all sequence times are concatenated and the standardization procedures take into account the whole sequence length data for each feature.

Parameters:
  • tensor (torch.Tensor) – Features PyTorch tensor stored as torch.Tensor with shape (n_samples, n_features) or as torch.Tensor with shape (sequence_length, n_samples, n_features).

  • is_check_data (bool, default=False) – If True, then check transformed tensor data.

Returns:

transformed_tensor – Standardized features PyTorch tensor stored as torch.Tensor with shape (n_samples, n_features) or as torch.Tensor with shape (sequence_length, n_samples, n_features).

Return type:

torch.Tensor