autogluon.timeseries 1.0.1b20240304__py3-none-any.whl → 1.4.1b20251210__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of autogluon.timeseries might be problematic. Click here for more details.
- autogluon/timeseries/configs/__init__.py +3 -2
- autogluon/timeseries/configs/hyperparameter_presets.py +62 -0
- autogluon/timeseries/configs/predictor_presets.py +84 -0
- autogluon/timeseries/dataset/ts_dataframe.py +339 -186
- autogluon/timeseries/learner.py +192 -60
- autogluon/timeseries/metrics/__init__.py +55 -11
- autogluon/timeseries/metrics/abstract.py +96 -25
- autogluon/timeseries/metrics/point.py +186 -39
- autogluon/timeseries/metrics/quantile.py +47 -20
- autogluon/timeseries/metrics/utils.py +6 -6
- autogluon/timeseries/models/__init__.py +13 -7
- autogluon/timeseries/models/abstract/__init__.py +2 -2
- autogluon/timeseries/models/abstract/abstract_timeseries_model.py +533 -273
- autogluon/timeseries/models/abstract/model_trial.py +10 -10
- autogluon/timeseries/models/abstract/tunable.py +189 -0
- autogluon/timeseries/models/autogluon_tabular/__init__.py +2 -0
- autogluon/timeseries/models/autogluon_tabular/mlforecast.py +369 -215
- autogluon/timeseries/models/autogluon_tabular/per_step.py +513 -0
- autogluon/timeseries/models/autogluon_tabular/transforms.py +67 -0
- autogluon/timeseries/models/autogluon_tabular/utils.py +3 -51
- autogluon/timeseries/models/chronos/__init__.py +4 -0
- autogluon/timeseries/models/chronos/chronos2.py +361 -0
- autogluon/timeseries/models/chronos/model.py +738 -0
- autogluon/timeseries/models/chronos/utils.py +369 -0
- autogluon/timeseries/models/ensemble/__init__.py +35 -2
- autogluon/timeseries/models/ensemble/{abstract_timeseries_ensemble.py → abstract.py} +50 -26
- autogluon/timeseries/models/ensemble/array_based/__init__.py +3 -0
- autogluon/timeseries/models/ensemble/array_based/abstract.py +236 -0
- autogluon/timeseries/models/ensemble/array_based/models.py +73 -0
- autogluon/timeseries/models/ensemble/array_based/regressor/__init__.py +12 -0
- autogluon/timeseries/models/ensemble/array_based/regressor/abstract.py +88 -0
- autogluon/timeseries/models/ensemble/array_based/regressor/linear_stacker.py +167 -0
- autogluon/timeseries/models/ensemble/array_based/regressor/per_quantile_tabular.py +94 -0
- autogluon/timeseries/models/ensemble/array_based/regressor/tabular.py +107 -0
- autogluon/timeseries/models/ensemble/ensemble_selection.py +167 -0
- autogluon/timeseries/models/ensemble/per_item_greedy.py +162 -0
- autogluon/timeseries/models/ensemble/weighted/__init__.py +8 -0
- autogluon/timeseries/models/ensemble/weighted/abstract.py +40 -0
- autogluon/timeseries/models/ensemble/weighted/basic.py +78 -0
- autogluon/timeseries/models/ensemble/weighted/greedy.py +57 -0
- autogluon/timeseries/models/gluonts/__init__.py +3 -1
- autogluon/timeseries/models/gluonts/abstract.py +583 -0
- autogluon/timeseries/models/gluonts/dataset.py +109 -0
- autogluon/timeseries/models/gluonts/{torch/models.py → models.py} +185 -44
- autogluon/timeseries/models/local/__init__.py +1 -10
- autogluon/timeseries/models/local/abstract_local_model.py +150 -97
- autogluon/timeseries/models/local/naive.py +31 -23
- autogluon/timeseries/models/local/npts.py +6 -2
- autogluon/timeseries/models/local/statsforecast.py +99 -112
- autogluon/timeseries/models/multi_window/multi_window_model.py +99 -40
- autogluon/timeseries/models/registry.py +64 -0
- autogluon/timeseries/models/toto/__init__.py +3 -0
- autogluon/timeseries/models/toto/_internal/__init__.py +9 -0
- autogluon/timeseries/models/toto/_internal/backbone/__init__.py +3 -0
- autogluon/timeseries/models/toto/_internal/backbone/attention.py +196 -0
- autogluon/timeseries/models/toto/_internal/backbone/backbone.py +262 -0
- autogluon/timeseries/models/toto/_internal/backbone/distribution.py +70 -0
- autogluon/timeseries/models/toto/_internal/backbone/kvcache.py +136 -0
- autogluon/timeseries/models/toto/_internal/backbone/rope.py +89 -0
- autogluon/timeseries/models/toto/_internal/backbone/rotary_embedding_torch.py +342 -0
- autogluon/timeseries/models/toto/_internal/backbone/scaler.py +305 -0
- autogluon/timeseries/models/toto/_internal/backbone/transformer.py +333 -0
- autogluon/timeseries/models/toto/_internal/dataset.py +165 -0
- autogluon/timeseries/models/toto/_internal/forecaster.py +423 -0
- autogluon/timeseries/models/toto/dataloader.py +108 -0
- autogluon/timeseries/models/toto/hf_pretrained_model.py +118 -0
- autogluon/timeseries/models/toto/model.py +236 -0
- autogluon/timeseries/predictor.py +826 -305
- autogluon/timeseries/regressor.py +253 -0
- autogluon/timeseries/splitter.py +10 -31
- autogluon/timeseries/trainer/__init__.py +2 -3
- autogluon/timeseries/trainer/ensemble_composer.py +439 -0
- autogluon/timeseries/trainer/model_set_builder.py +256 -0
- autogluon/timeseries/trainer/prediction_cache.py +149 -0
- autogluon/timeseries/trainer/trainer.py +1298 -0
- autogluon/timeseries/trainer/utils.py +17 -0
- autogluon/timeseries/transforms/__init__.py +2 -0
- autogluon/timeseries/transforms/covariate_scaler.py +164 -0
- autogluon/timeseries/transforms/target_scaler.py +149 -0
- autogluon/timeseries/utils/constants.py +10 -0
- autogluon/timeseries/utils/datetime/base.py +38 -20
- autogluon/timeseries/utils/datetime/lags.py +18 -16
- autogluon/timeseries/utils/datetime/seasonality.py +14 -14
- autogluon/timeseries/utils/datetime/time_features.py +17 -14
- autogluon/timeseries/utils/features.py +317 -53
- autogluon/timeseries/utils/forecast.py +31 -17
- autogluon/timeseries/utils/timer.py +173 -0
- autogluon/timeseries/utils/warning_filters.py +44 -6
- autogluon/timeseries/version.py +2 -1
- autogluon.timeseries-1.4.1b20251210-py3.11-nspkg.pth +1 -0
- {autogluon.timeseries-1.0.1b20240304.dist-info → autogluon_timeseries-1.4.1b20251210.dist-info}/METADATA +71 -47
- autogluon_timeseries-1.4.1b20251210.dist-info/RECORD +103 -0
- {autogluon.timeseries-1.0.1b20240304.dist-info → autogluon_timeseries-1.4.1b20251210.dist-info}/WHEEL +1 -1
- autogluon/timeseries/configs/presets_configs.py +0 -11
- autogluon/timeseries/evaluator.py +0 -6
- autogluon/timeseries/models/ensemble/greedy_ensemble.py +0 -170
- autogluon/timeseries/models/gluonts/abstract_gluonts.py +0 -550
- autogluon/timeseries/models/gluonts/torch/__init__.py +0 -0
- autogluon/timeseries/models/presets.py +0 -325
- autogluon/timeseries/trainer/abstract_trainer.py +0 -1144
- autogluon/timeseries/trainer/auto_trainer.py +0 -74
- autogluon.timeseries-1.0.1b20240304-py3.8-nspkg.pth +0 -1
- autogluon.timeseries-1.0.1b20240304.dist-info/RECORD +0 -58
- {autogluon.timeseries-1.0.1b20240304.dist-info → autogluon_timeseries-1.4.1b20251210.dist-info/licenses}/LICENSE +0 -0
- {autogluon.timeseries-1.0.1b20240304.dist-info → autogluon_timeseries-1.4.1b20251210.dist-info/licenses}/NOTICE +0 -0
- {autogluon.timeseries-1.0.1b20240304.dist-info → autogluon_timeseries-1.4.1b20251210.dist-info}/namespace_packages.txt +0 -0
- {autogluon.timeseries-1.0.1b20240304.dist-info → autogluon_timeseries-1.4.1b20251210.dist-info}/top_level.txt +0 -0
- {autogluon.timeseries-1.0.1b20240304.dist-info → autogluon_timeseries-1.4.1b20251210.dist-info}/zip-safe +0 -0
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
from typing import Any, Iterator, Type
|
|
2
|
+
|
|
3
|
+
import numpy as np
|
|
4
|
+
import pandas as pd
|
|
5
|
+
from gluonts.dataset.common import Dataset as GluonTSDataset
|
|
6
|
+
from gluonts.dataset.field_names import FieldName
|
|
7
|
+
|
|
8
|
+
from autogluon.timeseries.dataset import TimeSeriesDataFrame
|
|
9
|
+
from autogluon.timeseries.utils.datetime import norm_freq_str
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class SimpleGluonTSDataset(GluonTSDataset):
|
|
13
|
+
"""Wrapper for TimeSeriesDataFrame that is compatible with the GluonTS Dataset API."""
|
|
14
|
+
|
|
15
|
+
def __init__(
|
|
16
|
+
self,
|
|
17
|
+
target_df: TimeSeriesDataFrame,
|
|
18
|
+
freq: str,
|
|
19
|
+
target_column: str = "target",
|
|
20
|
+
feat_static_cat: np.ndarray | None = None,
|
|
21
|
+
feat_static_real: np.ndarray | None = None,
|
|
22
|
+
feat_dynamic_cat: np.ndarray | None = None,
|
|
23
|
+
feat_dynamic_real: np.ndarray | None = None,
|
|
24
|
+
past_feat_dynamic_cat: np.ndarray | None = None,
|
|
25
|
+
past_feat_dynamic_real: np.ndarray | None = None,
|
|
26
|
+
includes_future: bool = False,
|
|
27
|
+
prediction_length: int | None = None,
|
|
28
|
+
):
|
|
29
|
+
assert target_df is not None
|
|
30
|
+
# Convert TimeSeriesDataFrame to pd.Series for faster processing
|
|
31
|
+
self.target_array = target_df[target_column].to_numpy(np.float32)
|
|
32
|
+
self.feat_static_cat = self._astype(feat_static_cat, dtype=np.int64)
|
|
33
|
+
self.feat_static_real = self._astype(feat_static_real, dtype=np.float32)
|
|
34
|
+
self.feat_dynamic_cat = self._astype(feat_dynamic_cat, dtype=np.int64)
|
|
35
|
+
self.feat_dynamic_real = self._astype(feat_dynamic_real, dtype=np.float32)
|
|
36
|
+
self.past_feat_dynamic_cat = self._astype(past_feat_dynamic_cat, dtype=np.int64)
|
|
37
|
+
self.past_feat_dynamic_real = self._astype(past_feat_dynamic_real, dtype=np.float32)
|
|
38
|
+
self.freq = self._get_freq_for_period(freq)
|
|
39
|
+
|
|
40
|
+
# Necessary to compute indptr for known_covariates at prediction time
|
|
41
|
+
self.includes_future = includes_future
|
|
42
|
+
self.prediction_length = prediction_length
|
|
43
|
+
|
|
44
|
+
# Replace inefficient groupby ITEMID with indptr that stores start:end of each time series
|
|
45
|
+
self.item_ids = target_df.item_ids
|
|
46
|
+
self.indptr = target_df.get_indptr()
|
|
47
|
+
self.start_timestamps = target_df.index[self.indptr[:-1]].to_frame(index=False)[TimeSeriesDataFrame.TIMESTAMP]
|
|
48
|
+
assert len(self.item_ids) == len(self.start_timestamps)
|
|
49
|
+
|
|
50
|
+
@staticmethod
|
|
51
|
+
def _astype(array: np.ndarray | None, dtype: Type[np.generic]) -> np.ndarray | None:
|
|
52
|
+
if array is None:
|
|
53
|
+
return None
|
|
54
|
+
else:
|
|
55
|
+
return array.astype(dtype)
|
|
56
|
+
|
|
57
|
+
@staticmethod
|
|
58
|
+
def _get_freq_for_period(freq: str) -> str:
|
|
59
|
+
"""Convert freq to format compatible with pd.Period.
|
|
60
|
+
|
|
61
|
+
For example, ME freq must be converted to M when creating a pd.Period.
|
|
62
|
+
"""
|
|
63
|
+
offset = pd.tseries.frequencies.to_offset(freq)
|
|
64
|
+
assert offset is not None
|
|
65
|
+
freq_name = norm_freq_str(offset)
|
|
66
|
+
if freq_name == "SME":
|
|
67
|
+
# Replace unsupported frequency "SME" with "2W"
|
|
68
|
+
return "2W"
|
|
69
|
+
elif freq_name == "bh":
|
|
70
|
+
# Replace unsupported frequency "bh" with dummy value "Y"
|
|
71
|
+
return "Y"
|
|
72
|
+
else:
|
|
73
|
+
freq_name_for_period = {"YE": "Y", "QE": "Q", "ME": "M"}.get(freq_name, freq_name)
|
|
74
|
+
return f"{offset.n}{freq_name_for_period}"
|
|
75
|
+
|
|
76
|
+
def __len__(self):
|
|
77
|
+
return len(self.indptr) - 1 # noqa
|
|
78
|
+
|
|
79
|
+
def __iter__(self) -> Iterator[dict[str, Any]]:
|
|
80
|
+
for j in range(len(self.indptr) - 1):
|
|
81
|
+
start_idx = self.indptr[j]
|
|
82
|
+
end_idx = self.indptr[j + 1]
|
|
83
|
+
# GluonTS expects item_id to be a string
|
|
84
|
+
ts = {
|
|
85
|
+
FieldName.ITEM_ID: str(self.item_ids[j]),
|
|
86
|
+
FieldName.START: pd.Period(self.start_timestamps.iloc[j], freq=self.freq),
|
|
87
|
+
FieldName.TARGET: self.target_array[start_idx:end_idx],
|
|
88
|
+
}
|
|
89
|
+
if self.feat_static_cat is not None:
|
|
90
|
+
ts[FieldName.FEAT_STATIC_CAT] = self.feat_static_cat[j]
|
|
91
|
+
if self.feat_static_real is not None:
|
|
92
|
+
ts[FieldName.FEAT_STATIC_REAL] = self.feat_static_real[j]
|
|
93
|
+
if self.past_feat_dynamic_cat is not None:
|
|
94
|
+
ts[FieldName.PAST_FEAT_DYNAMIC_CAT] = self.past_feat_dynamic_cat[start_idx:end_idx].T
|
|
95
|
+
if self.past_feat_dynamic_real is not None:
|
|
96
|
+
ts[FieldName.PAST_FEAT_DYNAMIC_REAL] = self.past_feat_dynamic_real[start_idx:end_idx].T
|
|
97
|
+
|
|
98
|
+
# Dynamic features that may extend into the future
|
|
99
|
+
if self.includes_future:
|
|
100
|
+
assert self.prediction_length is not None, (
|
|
101
|
+
"Prediction length must be provided if includes_future is True"
|
|
102
|
+
)
|
|
103
|
+
start_idx = start_idx + j * self.prediction_length
|
|
104
|
+
end_idx = end_idx + (j + 1) * self.prediction_length
|
|
105
|
+
if self.feat_dynamic_cat is not None:
|
|
106
|
+
ts[FieldName.FEAT_DYNAMIC_CAT] = self.feat_dynamic_cat[start_idx:end_idx].T
|
|
107
|
+
if self.feat_dynamic_real is not None:
|
|
108
|
+
ts[FieldName.FEAT_DYNAMIC_REAL] = self.feat_dynamic_real[start_idx:end_idx].T
|
|
109
|
+
yield ts
|
|
@@ -3,28 +3,21 @@ Module including wrappers for PyTorch implementations of models in GluonTS
|
|
|
3
3
|
"""
|
|
4
4
|
|
|
5
5
|
import logging
|
|
6
|
-
from typing import Any,
|
|
6
|
+
from typing import Any, Type
|
|
7
7
|
|
|
8
8
|
from gluonts.model.estimator import Estimator as GluonTSEstimator
|
|
9
9
|
|
|
10
|
-
from autogluon.timeseries.models.gluonts.abstract_gluonts import AbstractGluonTSModel
|
|
11
10
|
from autogluon.timeseries.utils.datetime import (
|
|
12
11
|
get_lags_for_frequency,
|
|
13
12
|
get_seasonality,
|
|
14
13
|
get_time_features_for_frequency,
|
|
15
14
|
)
|
|
16
15
|
|
|
16
|
+
from .abstract import AbstractGluonTSModel
|
|
17
|
+
|
|
17
18
|
# NOTE: We avoid imports for torch and lightning.pytorch at the top level and hide them inside class methods.
|
|
18
19
|
# This is done to skip these imports during multiprocessing (which may cause bugs)
|
|
19
20
|
|
|
20
|
-
# FIXME: introduces cpflows dependency. We exclude this model until a future release.
|
|
21
|
-
# from gluonts.torch.model.mqf2 import MQF2MultiHorizonEstimator
|
|
22
|
-
|
|
23
|
-
# FIXME: DeepNPTS does not implement the GluonTS PyTorch API, and does not use
|
|
24
|
-
# PyTorch Lightning. We exclude this model until a future release.
|
|
25
|
-
# from gluonts.torch.model.deep_npts import DeepNPTSEstimator
|
|
26
|
-
|
|
27
|
-
|
|
28
21
|
logger = logging.getLogger(__name__)
|
|
29
22
|
|
|
30
23
|
|
|
@@ -61,10 +54,13 @@ class DeepARModel(AbstractGluonTSModel):
|
|
|
61
54
|
embedding_dimension : int, optional
|
|
62
55
|
Dimension of the embeddings for categorical features
|
|
63
56
|
(if None, defaults to [min(50, (cat+1)//2) for cat in cardinality])
|
|
64
|
-
|
|
65
|
-
|
|
57
|
+
max_cat_cardinality : int, default = 100
|
|
58
|
+
Maximum number of dimensions to use when one-hot-encoding categorical known_covariates.
|
|
59
|
+
distr_output : gluonts.torch.distributions.Output, default = StudentTOutput()
|
|
60
|
+
Distribution output object that defines how the model output is converted to a forecast, and how the loss is computed.
|
|
66
61
|
scaling: bool, default = True
|
|
67
|
-
|
|
62
|
+
If True, mean absolute scaling will be applied to each *context window* during training & prediction.
|
|
63
|
+
Note that this is different from the ``target_scaler`` that is applied to the *entire time series*.
|
|
68
64
|
max_epochs : int, default = 100
|
|
69
65
|
Number of epochs the model will be trained for
|
|
70
66
|
batch_size : int, default = 64
|
|
@@ -83,20 +79,25 @@ class DeepARModel(AbstractGluonTSModel):
|
|
|
83
79
|
If True, ``lightning_logs`` directory will NOT be removed after the model finished training.
|
|
84
80
|
"""
|
|
85
81
|
|
|
86
|
-
|
|
82
|
+
# TODO: Replace "scaling: bool" with "window_scaler": {"mean_abs", None} for consistency?
|
|
83
|
+
|
|
84
|
+
ag_priority = 40
|
|
85
|
+
|
|
86
|
+
_supports_known_covariates = True
|
|
87
|
+
_supports_static_features = True
|
|
87
88
|
|
|
88
89
|
def _get_estimator_class(self) -> Type[GluonTSEstimator]:
|
|
89
90
|
from gluonts.torch.model.deepar import DeepAREstimator
|
|
90
91
|
|
|
91
92
|
return DeepAREstimator
|
|
92
93
|
|
|
93
|
-
def _get_estimator_init_args(self) ->
|
|
94
|
+
def _get_estimator_init_args(self) -> dict[str, Any]:
|
|
94
95
|
init_kwargs = super()._get_estimator_init_args()
|
|
95
96
|
init_kwargs["num_feat_static_cat"] = self.num_feat_static_cat
|
|
96
97
|
init_kwargs["num_feat_static_real"] = self.num_feat_static_real
|
|
97
98
|
init_kwargs["cardinality"] = self.feat_static_cat_cardinality
|
|
98
99
|
init_kwargs["num_feat_dynamic_real"] = self.num_feat_dynamic_real
|
|
99
|
-
init_kwargs.setdefault("lags_seq", get_lags_for_frequency(self.freq))
|
|
100
|
+
init_kwargs.setdefault("lags_seq", get_lags_for_frequency(self.freq)) # type: ignore
|
|
100
101
|
init_kwargs.setdefault("time_features", get_time_features_for_frequency(self.freq))
|
|
101
102
|
return init_kwargs
|
|
102
103
|
|
|
@@ -112,14 +113,15 @@ class SimpleFeedForwardModel(AbstractGluonTSModel):
|
|
|
112
113
|
----------------
|
|
113
114
|
context_length : int, default = max(10, 2 * prediction_length)
|
|
114
115
|
Number of time units that condition the predictions
|
|
115
|
-
hidden_dimensions:
|
|
116
|
+
hidden_dimensions: list[int], default = [20, 20]
|
|
116
117
|
Size of hidden layers in the feedforward network
|
|
117
|
-
distr_output : gluonts.torch.distributions.
|
|
118
|
-
Distribution to
|
|
118
|
+
distr_output : gluonts.torch.distributions.Output, default = StudentTOutput()
|
|
119
|
+
Distribution output object that defines how the model output is converted to a forecast, and how the loss is computed.
|
|
119
120
|
batch_normalization : bool, default = False
|
|
120
121
|
Whether to use batch normalization
|
|
121
122
|
mean_scaling : bool, default = True
|
|
122
|
-
|
|
123
|
+
If True, mean absolute scaling will be applied to each *context window* during training & prediction.
|
|
124
|
+
Note that this is different from the ``target_scaler`` that is applied to the *entire time series*.
|
|
123
125
|
max_epochs : int, default = 100
|
|
124
126
|
Number of epochs the model will be trained for
|
|
125
127
|
batch_size : int, default = 64
|
|
@@ -138,6 +140,8 @@ class SimpleFeedForwardModel(AbstractGluonTSModel):
|
|
|
138
140
|
If True, ``lightning_logs`` directory will NOT be removed after the model finished training.
|
|
139
141
|
"""
|
|
140
142
|
|
|
143
|
+
ag_priority = 10
|
|
144
|
+
|
|
141
145
|
def _get_estimator_class(self) -> Type[GluonTSEstimator]:
|
|
142
146
|
from gluonts.torch.model.simple_feedforward import SimpleFeedForwardEstimator
|
|
143
147
|
|
|
@@ -162,6 +166,8 @@ class TemporalFusionTransformerModel(AbstractGluonTSModel):
|
|
|
162
166
|
----------------
|
|
163
167
|
context_length : int, default = max(64, 2 * prediction_length)
|
|
164
168
|
Number of past values used for prediction.
|
|
169
|
+
distr_output : gluonts.torch.distributions.Output, default = QuantileOutput()
|
|
170
|
+
Distribution output object that defines how the model output is converted to a forecast, and how the loss is computed.
|
|
165
171
|
disable_static_features : bool, default = False
|
|
166
172
|
If True, static features won't be used by the model even if they are present in the dataset.
|
|
167
173
|
If False, static features will be used by the model if they are present in the dataset.
|
|
@@ -197,19 +203,25 @@ class TemporalFusionTransformerModel(AbstractGluonTSModel):
|
|
|
197
203
|
If True, ``lightning_logs`` directory will NOT be removed after the model finished training.
|
|
198
204
|
"""
|
|
199
205
|
|
|
200
|
-
|
|
201
|
-
|
|
206
|
+
ag_priority = 45
|
|
207
|
+
ag_model_aliases = ["TFT"]
|
|
202
208
|
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
209
|
+
_supports_known_covariates = True
|
|
210
|
+
_supports_past_covariates = True
|
|
211
|
+
_supports_cat_covariates = True
|
|
212
|
+
_supports_static_features = True
|
|
206
213
|
|
|
207
214
|
def _get_estimator_class(self) -> Type[GluonTSEstimator]:
|
|
208
215
|
from gluonts.torch.model.tft import TemporalFusionTransformerEstimator
|
|
209
216
|
|
|
210
217
|
return TemporalFusionTransformerEstimator
|
|
211
218
|
|
|
212
|
-
def
|
|
219
|
+
def _get_default_hyperparameters(self):
|
|
220
|
+
return super()._get_default_hyperparameters() | {
|
|
221
|
+
"context_length": min(512, max(64, 2 * self.prediction_length)),
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
def _get_estimator_init_args(self) -> dict[str, Any]:
|
|
213
225
|
init_kwargs = super()._get_estimator_init_args()
|
|
214
226
|
if self.num_feat_dynamic_real > 0:
|
|
215
227
|
init_kwargs["dynamic_dims"] = [self.num_feat_dynamic_real]
|
|
@@ -219,7 +231,16 @@ class TemporalFusionTransformerModel(AbstractGluonTSModel):
|
|
|
219
231
|
init_kwargs["static_dims"] = [self.num_feat_static_real]
|
|
220
232
|
if len(self.feat_static_cat_cardinality):
|
|
221
233
|
init_kwargs["static_cardinalities"] = self.feat_static_cat_cardinality
|
|
234
|
+
if len(self.feat_dynamic_cat_cardinality):
|
|
235
|
+
init_kwargs["dynamic_cardinalities"] = self.feat_dynamic_cat_cardinality
|
|
236
|
+
if len(self.past_feat_dynamic_cat_cardinality):
|
|
237
|
+
init_kwargs["past_dynamic_cardinalities"] = self.past_feat_dynamic_cat_cardinality
|
|
238
|
+
|
|
222
239
|
init_kwargs.setdefault("time_features", get_time_features_for_frequency(self.freq))
|
|
240
|
+
|
|
241
|
+
# 'distr_output' and 'quantiles' shouldn't be included at the same time (otherwise an exception will be raised)
|
|
242
|
+
if "distr_output" in init_kwargs:
|
|
243
|
+
init_kwargs.pop("quantiles", None)
|
|
223
244
|
return init_kwargs
|
|
224
245
|
|
|
225
246
|
|
|
@@ -241,10 +262,13 @@ class DLinearModel(AbstractGluonTSModel):
|
|
|
241
262
|
Number of time units that condition the predictions
|
|
242
263
|
hidden_dimension: int, default = 20
|
|
243
264
|
Size of hidden layers in the feedforward network
|
|
244
|
-
distr_output : gluonts.torch.distributions.
|
|
245
|
-
Distribution to
|
|
265
|
+
distr_output : gluonts.torch.distributions.Output, default = StudentTOutput()
|
|
266
|
+
Distribution output object that defines how the model output is converted to a forecast, and how the loss is computed.
|
|
246
267
|
scaling : {"mean", "std", None}, default = "mean"
|
|
247
|
-
Scaling applied to
|
|
268
|
+
Scaling applied to each *context window* during training & prediction.
|
|
269
|
+
One of ``"mean"`` (mean absolute scaling), ``"std"`` (standardization), ``None`` (no scaling).
|
|
270
|
+
|
|
271
|
+
Note that this is different from the ``target_scaler`` that is applied to the *entire time series*.
|
|
248
272
|
max_epochs : int, default = 100
|
|
249
273
|
Number of epochs the model will be trained for
|
|
250
274
|
batch_size : int, default = 64
|
|
@@ -265,9 +289,12 @@ class DLinearModel(AbstractGluonTSModel):
|
|
|
265
289
|
If True, ``lightning_logs`` directory will NOT be removed after the model finished training.
|
|
266
290
|
"""
|
|
267
291
|
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
292
|
+
ag_priority = 10
|
|
293
|
+
|
|
294
|
+
def _get_default_hyperparameters(self):
|
|
295
|
+
return super()._get_default_hyperparameters() | {
|
|
296
|
+
"context_length": 96,
|
|
297
|
+
}
|
|
271
298
|
|
|
272
299
|
def _get_estimator_class(self) -> Type[GluonTSEstimator]:
|
|
273
300
|
from gluonts.torch.model.d_linear import DLinearEstimator
|
|
@@ -301,10 +328,13 @@ class PatchTSTModel(AbstractGluonTSModel):
|
|
|
301
328
|
Number of attention heads in the Transformer encoder which must divide d_model.
|
|
302
329
|
num_encoder_layers : int, default = 2
|
|
303
330
|
Number of layers in the Transformer encoder.
|
|
304
|
-
distr_output : gluonts.torch.distributions.
|
|
305
|
-
Distribution to
|
|
331
|
+
distr_output : gluonts.torch.distributions.Output, default = StudentTOutput()
|
|
332
|
+
Distribution output object that defines how the model output is converted to a forecast, and how the loss is computed.
|
|
306
333
|
scaling : {"mean", "std", None}, default = "mean"
|
|
307
|
-
Scaling applied to
|
|
334
|
+
Scaling applied to each *context window* during training & prediction.
|
|
335
|
+
One of ``"mean"`` (mean absolute scaling), ``"std"`` (standardization), ``None`` (no scaling).
|
|
336
|
+
|
|
337
|
+
Note that this is different from the ``target_scaler`` that is applied to the *entire time series*.
|
|
308
338
|
max_epochs : int, default = 100
|
|
309
339
|
Number of epochs the model will be trained for
|
|
310
340
|
batch_size : int, default = 64
|
|
@@ -319,18 +349,21 @@ class PatchTSTModel(AbstractGluonTSModel):
|
|
|
319
349
|
If True, ``lightning_logs`` directory will NOT be removed after the model finished training.
|
|
320
350
|
"""
|
|
321
351
|
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
352
|
+
ag_priority = 30
|
|
353
|
+
|
|
354
|
+
_supports_known_covariates = True
|
|
325
355
|
|
|
326
356
|
def _get_estimator_class(self) -> Type[GluonTSEstimator]:
|
|
327
357
|
from gluonts.torch.model.patch_tst import PatchTSTEstimator
|
|
328
358
|
|
|
329
359
|
return PatchTSTEstimator
|
|
330
360
|
|
|
331
|
-
def
|
|
361
|
+
def _get_default_hyperparameters(self):
|
|
362
|
+
return super()._get_default_hyperparameters() | {"context_length": 96, "patch_len": 16}
|
|
363
|
+
|
|
364
|
+
def _get_estimator_init_args(self) -> dict[str, Any]:
|
|
332
365
|
init_kwargs = super()._get_estimator_init_args()
|
|
333
|
-
init_kwargs
|
|
366
|
+
init_kwargs["num_feat_dynamic_real"] = self.num_feat_dynamic_real
|
|
334
367
|
return init_kwargs
|
|
335
368
|
|
|
336
369
|
|
|
@@ -372,6 +405,8 @@ class WaveNetModel(AbstractGluonTSModel):
|
|
|
372
405
|
If True, logarithm of the scale of the past data will be used as an additional static feature.
|
|
373
406
|
negative_data : bool, default = True
|
|
374
407
|
Flag indicating whether the time series take negative values.
|
|
408
|
+
max_cat_cardinality : int, default = 100
|
|
409
|
+
Maximum number of dimensions to use when one-hot-encoding categorical known_covariates.
|
|
375
410
|
max_epochs : int, default = 100
|
|
376
411
|
Number of epochs the model will be trained for
|
|
377
412
|
batch_size : int, default = 64
|
|
@@ -392,7 +427,10 @@ class WaveNetModel(AbstractGluonTSModel):
|
|
|
392
427
|
If True, ``lightning_logs`` directory will NOT be removed after the model finished training.
|
|
393
428
|
"""
|
|
394
429
|
|
|
395
|
-
|
|
430
|
+
ag_priority = 25
|
|
431
|
+
|
|
432
|
+
_supports_known_covariates = True
|
|
433
|
+
_supports_static_features = True
|
|
396
434
|
default_num_samples: int = 100
|
|
397
435
|
|
|
398
436
|
def _get_estimator_class(self) -> Type[GluonTSEstimator]:
|
|
@@ -400,7 +438,7 @@ class WaveNetModel(AbstractGluonTSModel):
|
|
|
400
438
|
|
|
401
439
|
return WaveNetEstimator
|
|
402
440
|
|
|
403
|
-
def _get_estimator_init_args(self) ->
|
|
441
|
+
def _get_estimator_init_args(self) -> dict[str, Any]:
|
|
404
442
|
init_kwargs = super()._get_estimator_init_args()
|
|
405
443
|
init_kwargs["num_feat_static_cat"] = self.num_feat_static_cat
|
|
406
444
|
init_kwargs["num_feat_static_real"] = self.num_feat_static_real
|
|
@@ -410,6 +448,109 @@ class WaveNetModel(AbstractGluonTSModel):
|
|
|
410
448
|
init_kwargs.setdefault("seasonality", get_seasonality(self.freq))
|
|
411
449
|
init_kwargs.setdefault("time_features", get_time_features_for_frequency(self.freq))
|
|
412
450
|
init_kwargs.setdefault("num_parallel_samples", self.default_num_samples)
|
|
413
|
-
|
|
414
|
-
|
|
451
|
+
return init_kwargs
|
|
452
|
+
|
|
453
|
+
|
|
454
|
+
class TiDEModel(AbstractGluonTSModel):
|
|
455
|
+
"""Time series dense encoder model from [Das2023]_.
|
|
456
|
+
|
|
457
|
+
Based on `gluonts.torch.model.tide.TiDEEstimator <https://ts.gluon.ai/stable/api/gluonts/gluonts.torch.model.tide.html>`_.
|
|
458
|
+
See GluonTS documentation for additional hyperparameters.
|
|
459
|
+
|
|
460
|
+
|
|
461
|
+
References
|
|
462
|
+
----------
|
|
463
|
+
.. [Das2023] Das, Abhimanyu, et al.
|
|
464
|
+
"Long-term Forecasting with TiDE: Time-series Dense Encoder."
|
|
465
|
+
Transactions of Machine Learning Research. 2023.
|
|
466
|
+
|
|
467
|
+
Other Parameters
|
|
468
|
+
----------------
|
|
469
|
+
context_length : int, default = max(64, 2 * prediction_length)
|
|
470
|
+
Number of past values used for prediction.
|
|
471
|
+
disable_static_features : bool, default = False
|
|
472
|
+
If True, static features won't be used by the model even if they are present in the dataset.
|
|
473
|
+
If False, static features will be used by the model if they are present in the dataset.
|
|
474
|
+
disable_known_covariates : bool, default = False
|
|
475
|
+
If True, known covariates won't be used by the model even if they are present in the dataset.
|
|
476
|
+
If False, known covariates will be used by the model if they are present in the dataset.
|
|
477
|
+
feat_proj_hidden_dim : int, default = 4
|
|
478
|
+
Size of the feature projection layer.
|
|
479
|
+
encoder_hidden_dim : int, default = 64
|
|
480
|
+
Size of the dense encoder layer.
|
|
481
|
+
decoder_hidden_dim : int, default = 64
|
|
482
|
+
Size of the dense decoder layer.
|
|
483
|
+
temporal_hidden_dim : int, default = 64
|
|
484
|
+
Size of the temporal decoder layer.
|
|
485
|
+
distr_hidden_dim : int, default = 64
|
|
486
|
+
Size of the distribution projection layer.
|
|
487
|
+
num_layers_encoder : int, default = 2
|
|
488
|
+
Number of layers in dense encoder.
|
|
489
|
+
num_layers_decoder : int, default = 2
|
|
490
|
+
Number of layers in dense decoder.
|
|
491
|
+
decoder_output_dim : int, default = 16
|
|
492
|
+
Output size of the dense decoder.
|
|
493
|
+
dropout_rate : float, default = 0.2
|
|
494
|
+
Dropout regularization parameter.
|
|
495
|
+
num_feat_dynamic_proj : int, default = 2
|
|
496
|
+
Output size of feature projection layer.
|
|
497
|
+
embedding_dimension : int, default = [16] * num_feat_static_cat
|
|
498
|
+
Dimension of the embeddings for categorical features
|
|
499
|
+
layer_norm : bool, default = True
|
|
500
|
+
Should layer normalization be enabled?
|
|
501
|
+
scaling : {"mean", "std", None}, default = "mean"
|
|
502
|
+
Scaling applied to each *context window* during training & prediction.
|
|
503
|
+
One of ``"mean"`` (mean absolute scaling), ``"std"`` (standardization), ``None`` (no scaling).
|
|
504
|
+
|
|
505
|
+
Note that this is different from the ``target_scaler`` that is applied to the *entire time series*.
|
|
506
|
+
max_epochs : int, default = 100
|
|
507
|
+
Number of epochs the model will be trained for
|
|
508
|
+
batch_size : int, default = 256
|
|
509
|
+
Size of batches used during training
|
|
510
|
+
predict_batch_size : int, default = 500
|
|
511
|
+
Size of batches used during prediction.
|
|
512
|
+
num_batches_per_epoch : int, default = 50
|
|
513
|
+
Number of batches processed every epoch
|
|
514
|
+
lr : float, default = 1e-4,
|
|
515
|
+
Learning rate used during training
|
|
516
|
+
trainer_kwargs : dict, optional
|
|
517
|
+
Optional keyword arguments passed to ``lightning.Trainer``.
|
|
518
|
+
early_stopping_patience : int or None, default = 20
|
|
519
|
+
Early stop training if the validation loss doesn't improve for this many epochs.
|
|
520
|
+
keep_lightning_logs : bool, default = False
|
|
521
|
+
If True, ``lightning_logs`` directory will NOT be removed after the model finished training.
|
|
522
|
+
"""
|
|
523
|
+
|
|
524
|
+
ag_priority = 30
|
|
525
|
+
|
|
526
|
+
_supports_known_covariates = True
|
|
527
|
+
_supports_static_features = True
|
|
528
|
+
|
|
529
|
+
def _get_estimator_class(self) -> Type[GluonTSEstimator]:
|
|
530
|
+
from gluonts.torch.model.tide import TiDEEstimator
|
|
531
|
+
|
|
532
|
+
return TiDEEstimator
|
|
533
|
+
|
|
534
|
+
def _get_default_hyperparameters(self):
|
|
535
|
+
return super()._get_default_hyperparameters() | {
|
|
536
|
+
"context_length": min(512, max(64, 2 * self.prediction_length)),
|
|
537
|
+
"encoder_hidden_dim": 64,
|
|
538
|
+
"decoder_hidden_dim": 64,
|
|
539
|
+
"temporal_hidden_dim": 64,
|
|
540
|
+
"distr_hidden_dim": 64,
|
|
541
|
+
"num_layers_encoder": 2,
|
|
542
|
+
"num_layers_decoder": 2,
|
|
543
|
+
"decoder_output_dim": 16,
|
|
544
|
+
"dropout_rate": 0.2,
|
|
545
|
+
"layer_norm": True,
|
|
546
|
+
"lr": 1e-4,
|
|
547
|
+
"batch_size": 256,
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
def _get_estimator_init_args(self) -> dict[str, Any]:
|
|
551
|
+
init_kwargs = super()._get_estimator_init_args()
|
|
552
|
+
init_kwargs["num_feat_static_cat"] = self.num_feat_static_cat
|
|
553
|
+
init_kwargs["num_feat_static_real"] = self.num_feat_static_real
|
|
554
|
+
init_kwargs["cardinality"] = self.feat_static_cat_cardinality
|
|
555
|
+
init_kwargs["num_feat_dynamic_real"] = self.num_feat_dynamic_real
|
|
415
556
|
return init_kwargs
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import joblib.externals.loky
|
|
2
|
-
|
|
3
1
|
from .naive import AverageModel, NaiveModel, SeasonalAverageModel, SeasonalNaiveModel
|
|
4
2
|
from .npts import NPTSModel
|
|
5
3
|
from .statsforecast import (
|
|
@@ -8,17 +6,10 @@ from .statsforecast import (
|
|
|
8
6
|
AutoARIMAModel,
|
|
9
7
|
AutoCESModel,
|
|
10
8
|
AutoETSModel,
|
|
11
|
-
|
|
12
|
-
CrostonOptimizedModel,
|
|
13
|
-
CrostonSBAModel,
|
|
9
|
+
CrostonModel,
|
|
14
10
|
DynamicOptimizedThetaModel,
|
|
15
11
|
ETSModel,
|
|
16
12
|
IMAPAModel,
|
|
17
13
|
ThetaModel,
|
|
18
14
|
ZeroModel,
|
|
19
15
|
)
|
|
20
|
-
|
|
21
|
-
# By default, joblib w/ loky backend kills processes that take >300MB of RAM assuming that this is caused by a memory
|
|
22
|
-
# leak. This leads to problems for some memory-hungry models like AutoARIMA/Theta.
|
|
23
|
-
# This monkey patch removes this undesired behavior
|
|
24
|
-
joblib.externals.loky.process_executor._MAX_MEMORY_LEAK_SIZE = int(3e10)
|