Scaling¶
Feature scalers and normalized model wrappers for time series models.
Scaler ¶
Bases: Module
Base class for feature scaling on [batch, seq, features] tensors.
from_stats
classmethod
¶
StandardScaler ¶
Bases: Scaler
Normalize by (x - mean) / std.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mean
|
per-feature mean, as ndarray or tensor |
required | |
std
|
per-feature standard deviation, as ndarray or tensor |
required |
Source code in tsfast/models/scaling.py
MinMaxScaler ¶
Bases: Scaler
Normalize by (x - min) / (max - min) to [0, 1].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
min_val
|
per-feature minimum, as ndarray or tensor |
required | |
max_val
|
per-feature maximum, as ndarray or tensor |
required |
Source code in tsfast/models/scaling.py
MaxAbsScaler ¶
Bases: Scaler
Normalize by x / max(|min|, |max|).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
min_val
|
per-feature minimum, as ndarray or tensor |
required | |
max_val
|
per-feature maximum, as ndarray or tensor |
required |
Source code in tsfast/models/scaling.py
ScaledModel ¶
Bases: Module
Wraps a model with input normalization and optional output denormalization.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Module
|
inner model to wrap |
required |
input_norm
|
Scaler
|
scaler applied to inputs before the model |
required |
output_norm
|
Scaler | None
|
scaler applied to outputs after the model |
None
|
Source code in tsfast/models/scaling.py
from_stats
classmethod
¶
from_stats(model: Module, input_stats, output_stats=None, scaler_cls: type | None = None) -> ScaledModel
Create from NormPair stats with the given Scaler class.
Source code in tsfast/models/scaling.py
from_dls
classmethod
¶
from_dls(model: Module, dls, input_norm: type[Scaler] | None = StandardScaler, output_norm: type[Scaler] | None = None, *, autoregressive: bool = False) -> nn.Module
Create from DataLoaders norm_stats, or return model unchanged if input_norm is None.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Module
|
inner model to wrap |
required |
dls
|
DataLoaders with |
required | |
input_norm
|
type[Scaler] | None
|
scaler class for input normalization, or None to skip wrapping |
StandardScaler
|
output_norm
|
type[Scaler] | None
|
scaler class for output denormalization, or None to skip |
None
|
autoregressive
|
bool
|
if True, input stats are |
False
|
Source code in tsfast/models/scaling.py
unwrap_model ¶
Get the inner model, unwrapping DDP/DP and ScaledModel if present.