graphorge.utilities.data_scalers.TorchMinMaxScaler¶
- class TorchMinMaxScaler(n_features, minimum=None, maximum=None, device_type='cpu')[source]¶
Bases:
object
PyTorch tensor min-max data scaler.
- _minimum¶
Features normalization minimum tensor stored as a torch.Tensor with shape (n_features,).
- Type:
torch.Tensor
- _maximum¶
Features normalization maximum 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_minimum_and_maximum(self, minimum, maximum)[source]¶
Set features normalization minimum and maximum tensors.
Constructor.
- Parameters:
n_features (int) – Number of features to scale.
minimum (torch.Tensor) – Features normalization minimum tensor stored as a torch.Tensor with shape (n_features,).
maximum (torch.Tensor) – Features normalization maximum 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 features normalization minimum and maximum tensors.
Denormalize features tensor.
Set device on which torch.Tensor is allocated.
Set features normalization maximum tensor.
Set features normalization minimum tensor.
Set features normalization minimum and maximum tensors.
Normalize features tensor.
Methods
- __init__(n_features, minimum=None, maximum=None, device_type='cpu')[source]¶
Constructor.
- Parameters:
n_features (int) – Number of features to scale.
minimum (torch.Tensor) – Features normalization minimum tensor stored as a torch.Tensor with shape (n_features,).
maximum (torch.Tensor) – Features normalization maximum 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_maximum(maximum)[source]¶
Check features normalization maximum tensor.
- Parameters:
maximum (torch.Tensor) – Features normalization maximum tensor stored as a torch.Tensor with shape (n_features,).
- Returns:
maximum – Features normalization maximum tensor stored as a torch.Tensor with shape (n_features,).
- Return type:
torch.Tensor
- _check_minimum(minimum)[source]¶
Check features normalization minimum tensor.
- Parameters:
minimum (torch.Tensor) – Features normalization minimum tensor stored as a torch.Tensor with shape (n_features,).
- Returns:
minimum – Features normalization minimum 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) – 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).
- fit(tensor)[source]¶
Fit features normalization minimum and maximum tensors.
If sequential data is provided, then all sequence times are concatenated and the normalization 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).
- inverse_transform(tensor, is_check_data=False)[source]¶
Denormalize features tensor.
If sequential data is provided, then all sequence times are concatenated and the normalization procedures take into account the whole sequence length data for each feature.
- Parameters:
tensor (torch.Tensor) – Normalized 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_maximum(maximum)[source]¶
Set features normalization maximum tensor.
- Parameters:
maximum (torch.Tensor) – Features normalization maximum tensor stored as a torch.Tensor with shape (n_features,).
- set_minimum(minimum)[source]¶
Set features normalization minimum tensor.
- Parameters:
minimum (torch.Tensor) – Features normalization minimum tensor stored as a torch.Tensor with shape (n_features,).
- set_minimum_and_maximum(minimum, maximum)[source]¶
Set features normalization minimum and maximum tensors.
- Parameters:
minimum (torch.Tensor) – Features normalization minimum tensor stored as a torch.Tensor with shape (n_features,).
maximum (torch.Tensor) – Features normalization maximum tensor stored as a torch.Tensor with shape (n_features,).
- transform(tensor, is_check_data=False)[source]¶
Normalize features tensor.
If sequential data is provided, then all sequence times are concatenated and the normalization 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 – Normalized 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