dsipts 1.1.5__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 dsipts might be problematic. Click here for more details.

Files changed (81) hide show
  1. dsipts/__init__.py +48 -0
  2. dsipts/data_management/__init__.py +0 -0
  3. dsipts/data_management/monash.py +338 -0
  4. dsipts/data_management/public_datasets.py +162 -0
  5. dsipts/data_structure/__init__.py +0 -0
  6. dsipts/data_structure/data_structure.py +1167 -0
  7. dsipts/data_structure/modifiers.py +213 -0
  8. dsipts/data_structure/utils.py +173 -0
  9. dsipts/models/Autoformer.py +199 -0
  10. dsipts/models/CrossFormer.py +152 -0
  11. dsipts/models/D3VAE.py +196 -0
  12. dsipts/models/Diffusion.py +818 -0
  13. dsipts/models/DilatedConv.py +342 -0
  14. dsipts/models/DilatedConvED.py +310 -0
  15. dsipts/models/Duet.py +197 -0
  16. dsipts/models/ITransformer.py +167 -0
  17. dsipts/models/Informer.py +180 -0
  18. dsipts/models/LinearTS.py +222 -0
  19. dsipts/models/PatchTST.py +181 -0
  20. dsipts/models/Persistent.py +44 -0
  21. dsipts/models/RNN.py +213 -0
  22. dsipts/models/Samformer.py +139 -0
  23. dsipts/models/TFT.py +269 -0
  24. dsipts/models/TIDE.py +296 -0
  25. dsipts/models/TTM.py +252 -0
  26. dsipts/models/TimeXER.py +184 -0
  27. dsipts/models/VQVAEA.py +299 -0
  28. dsipts/models/VVA.py +247 -0
  29. dsipts/models/__init__.py +0 -0
  30. dsipts/models/autoformer/__init__.py +0 -0
  31. dsipts/models/autoformer/layers.py +352 -0
  32. dsipts/models/base.py +439 -0
  33. dsipts/models/base_v2.py +444 -0
  34. dsipts/models/crossformer/__init__.py +0 -0
  35. dsipts/models/crossformer/attn.py +118 -0
  36. dsipts/models/crossformer/cross_decoder.py +77 -0
  37. dsipts/models/crossformer/cross_embed.py +18 -0
  38. dsipts/models/crossformer/cross_encoder.py +99 -0
  39. dsipts/models/d3vae/__init__.py +0 -0
  40. dsipts/models/d3vae/diffusion_process.py +169 -0
  41. dsipts/models/d3vae/embedding.py +108 -0
  42. dsipts/models/d3vae/encoder.py +326 -0
  43. dsipts/models/d3vae/model.py +211 -0
  44. dsipts/models/d3vae/neural_operations.py +314 -0
  45. dsipts/models/d3vae/resnet.py +153 -0
  46. dsipts/models/d3vae/utils.py +630 -0
  47. dsipts/models/duet/__init__.py +0 -0
  48. dsipts/models/duet/layers.py +438 -0
  49. dsipts/models/duet/masked.py +202 -0
  50. dsipts/models/informer/__init__.py +0 -0
  51. dsipts/models/informer/attn.py +185 -0
  52. dsipts/models/informer/decoder.py +50 -0
  53. dsipts/models/informer/embed.py +125 -0
  54. dsipts/models/informer/encoder.py +100 -0
  55. dsipts/models/itransformer/Embed.py +142 -0
  56. dsipts/models/itransformer/SelfAttention_Family.py +355 -0
  57. dsipts/models/itransformer/Transformer_EncDec.py +134 -0
  58. dsipts/models/itransformer/__init__.py +0 -0
  59. dsipts/models/patchtst/__init__.py +0 -0
  60. dsipts/models/patchtst/layers.py +569 -0
  61. dsipts/models/samformer/__init__.py +0 -0
  62. dsipts/models/samformer/utils.py +154 -0
  63. dsipts/models/tft/__init__.py +0 -0
  64. dsipts/models/tft/sub_nn.py +234 -0
  65. dsipts/models/timexer/Layers.py +127 -0
  66. dsipts/models/timexer/__init__.py +0 -0
  67. dsipts/models/ttm/__init__.py +0 -0
  68. dsipts/models/ttm/configuration_tinytimemixer.py +307 -0
  69. dsipts/models/ttm/consts.py +16 -0
  70. dsipts/models/ttm/modeling_tinytimemixer.py +2099 -0
  71. dsipts/models/ttm/utils.py +438 -0
  72. dsipts/models/utils.py +624 -0
  73. dsipts/models/vva/__init__.py +0 -0
  74. dsipts/models/vva/minigpt.py +83 -0
  75. dsipts/models/vva/vqvae.py +459 -0
  76. dsipts/models/xlstm/__init__.py +0 -0
  77. dsipts/models/xlstm/xLSTM.py +255 -0
  78. dsipts-1.1.5.dist-info/METADATA +31 -0
  79. dsipts-1.1.5.dist-info/RECORD +81 -0
  80. dsipts-1.1.5.dist-info/WHEEL +5 -0
  81. dsipts-1.1.5.dist-info/top_level.txt +1 -0
@@ -0,0 +1,307 @@
1
+ # Copyright contributors to the TSFM project
2
+ #
3
+ """TinyTimeMixer model configuration"""
4
+
5
+ from typing import Optional, Union
6
+
7
+ from transformers.utils import logging
8
+ from transformers.configuration_utils import PretrainedConfig
9
+
10
+
11
+ TINYTIMEMIXER_PRETRAINED_CONFIG_ARCHIVE_MAP = {}
12
+
13
+
14
+ class TinyTimeMixerConfig(PretrainedConfig):
15
+ r"""
16
+ This is the configuration class to store the configuration of a [`TinyTimeMixerModel`]. It is used to instantiate a
17
+ TinyTimeMixer model according to the specified arguments, defining the model architecture. Instantiating a
18
+ configuration with the defaults will yield a similar configuration to that of the TinyTimeMixer {} architecture.
19
+
20
+ Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
21
+ documentation from [`PretrainedConfig`] for more information.
22
+
23
+ Args:
24
+ context_length (`int`, *optional*, defaults to 64)
25
+ The context/history length for the input sequence.
26
+ patch_length (`int`, *optional*, defaults to 8)
27
+ The patch length for the input sequence.
28
+ num_input_channels (`int`):
29
+ Number of input variates. For Univariate, set it to 1.
30
+ patch_stride (`int`, *optional*, defaults to 8):
31
+ Amount of points to stride. If its value is same as patch_length, we get non-overlapping patches.
32
+ d_model (`int`, *optional*, defaults to 16):
33
+ Hidden feature size of the model.
34
+ prediction_length (`int`, *optional*, defaults to 16)
35
+ Number of time steps to forecast for a forecasting task. Also known as the Forecast Horizon.
36
+ num_parallel_samples (`int`, *optional*, defaults to 100):
37
+ The number of samples to generate in parallel for probabilistic forecast.
38
+ expansion_factor (`int`, *optional*, defaults to 2):
39
+ Expansion factor to use inside MLP. Recommended range is 2-5. Larger value indicates more complex model.
40
+ num_layers (`int`, *optional*, defaults to 3):
41
+ Number of layers to use. Recommended range is 3-15. Larger value indicates more complex model.
42
+ dropout (`float`, *optional*, defaults to 0.2):
43
+ The dropout probability the `TinyTimeMixer` backbone. Recommended range is 0.2-0.7
44
+ mode (`str`, *optional*, defaults to `"common_channel"`):
45
+ Mixer Mode. Determines how to process the channels. Allowed values: "common_channel", "mix_channel". In
46
+ "common_channel" mode, we follow Channel-independent modelling with no explicit channel-mixing. Channel
47
+ mixing happens in an implicit manner via shared weights across channels. (preferred first approach) In
48
+ "mix_channel" mode, we follow explicit channel-mixing in addition to patch and feature mixer. (preferred
49
+ approach when channel correlations are very important to model)
50
+ gated_attn (`bool`, *optional*, defaults to `True`):
51
+ Enable Gated Attention.
52
+ norm_mlp (`str`, *optional*, defaults to `"LayerNorm"`):
53
+ Normalization layer (BatchNorm or LayerNorm).
54
+ self_attn (`bool`, *optional*, defaults to `False`):
55
+ Enable Tiny self attention across patches. This can be enabled when the output of Vanilla TinyTimeMixer with
56
+ gated attention is not satisfactory. Enabling this leads to explicit pair-wise attention and modelling
57
+ across patches.
58
+ self_attn_heads (`int`, *optional*, defaults to 1):
59
+ Number of self-attention heads. Works only when `self_attn` is set to `True`.
60
+ use_positional_encoding (`bool`, *optional*, defaults to `False`):
61
+ Enable the use of positional embedding for the tiny self-attention layers. Works only when `self_attn` is
62
+ set to `True`.
63
+ positional_encoding_type (`str`, *optional*, defaults to `"sincos"`):
64
+ Positional encodings. Options `"random"` and `"sincos"` are supported. Works only when
65
+ `use_positional_encoding` is set to `True`
66
+ scaling (`string` or `bool`, *optional*, defaults to `"std"`):
67
+ Whether to scale the input targets via "mean" scaler, "std" scaler or no scaler if `None`. If `True`, the
68
+ scaler is set to "mean".
69
+ loss (`string`, *optional*, defaults to `"mse"`):
70
+ The loss function to finetune or pretrain the the model. Allowed values are "mse" or "mae" or "pinball" or "huber".
71
+ Use pinball loss for probabilistic forecasts of different quantiles.
72
+ Distribution head (nll) is currently disabled and not allowed.
73
+ init_std (`float`, *optional*, defaults to 0.02):
74
+ The standard deviation of the truncated normal weight initialization distribution.
75
+ post_init (`bool`, *optional*, defaults to `False`):
76
+ Whether to use custom weight initialization from `transformers` library, or the default initialization in
77
+ `PyTorch`. Setting it to `False` performs `PyTorch` weight initialization.
78
+ norm_eps (`float`, *optional*, defaults to 1e-05):
79
+ A value added to the denominator for numerical stability of normalization.
80
+ adaptive_patching_levels (`int`, *optional*, defaults to 0):
81
+ If adaptive_patching_levels is i, then we will have i levels with each level having n_layers.
82
+ Level id starts with 0. num_patches at level i will be multipled by (2^i) and num_features at level i will be divided by (2^i).
83
+ For Ex. if adaptive_patching_levels is 3 - then we will have 3 levels:
84
+ level 2: num_features//(2^2), num_patches*(2^2)
85
+ level 1: num_features//(2^1), num_patches*(2^1)
86
+ level 0: num_features//(2^0), num_patches*(2^0)
87
+ adaptive_patching_levels = 1 is same as one level PatchTSMixer. This module gets disabled when adaptive_patching_levels is 0 or neg value. Defaults to 0 (off mode).
88
+ resolution_prefix_tuning (`bool`, *optional*, defaults to `False`):
89
+ Enable if your dataloader has time resolution information as defined in `get_freq_mapping` function in `modelling_tinytimemixer`.
90
+ frequency_token_vocab_size (`int`, *optional*, defaults to 5):
91
+ Vocab size to use when resolution_prefix_tuning is enabled.
92
+ head_dropout (`float`, *optional*, defaults to 0.2):
93
+ The dropout probability the `TinyTimeMixer` head.
94
+ distribution_output (`string`, *optional*, defaults to `"student_t"`):
95
+ The distribution emission head for the model when loss is "nll". Could be either "student_t", "normal" or
96
+ "negative_binomial".
97
+ prediction_channel_indices (`list`, *optional*):
98
+ List of channel indices to forecast. If None, forecast all channels. Target data is expected to have all
99
+ channels and we explicitly filter the channels in prediction and target before loss computation. Please provide the indices
100
+ in sorted ascending order.
101
+ exogenous_channel_indices (`list`, *optional*):
102
+ List of channel indices whose values are known in the forecast period. Please provide the indices
103
+ in sorted ascending order.
104
+ decoder_num_layers (`int`, *optional*, defaults to 8):
105
+ Number of layers to use in decoder
106
+ decoder_d_model(`int`, *optional*, defaults to 16):
107
+ Defines the hidden feature size of the decoder.
108
+ decoder_adaptive_patching_levels (`int`, *optional*, defaults to 0):
109
+ Adaptive Patching levels for decoder. Preferable to set it to 0 for decoder to keep it light weight.
110
+ decoder_raw_residual (`bool`, *optional*, defaults to `False`):
111
+ Flag to enable merging of raw embedding with encoder embedding for decoder input. Defaults to False.
112
+ decoder_mode (`string`, *optional*, defaults to `"common_channel"`):
113
+ Decoder channel mode. Use `"common_channel" for channel-independent modelling and `"mix_channel"` for channel-mixing modelling
114
+ use_decoder (`bool`, *optional*, defaults to `True`):
115
+ Enable to use decoder.
116
+ enable_forecast_channel_mixing (`bool`, *optional*, defaults to `False`):
117
+ Enable if we want to reconcile forecasts across all channels and also to enable exogenous infusion, if you have them.
118
+ fcm_gated_attn (`bool`, *optional*, defaults to `True`):
119
+ Enable gated attention in forecast channel mixing block.
120
+ fcm_context_length (`int`, *optional*, defaults to `1):
121
+ Surrounding context length to use. For Ex. If we want to consider 2 lag point before and after a data point, provide value 2 for `fcm_context_length`
122
+ fcm_use_mixer (`bool`, *optional*, defaults to `True`):
123
+ Enable Mixing in forecast channel mixing block.
124
+ fcm_mix_layers (`int`, *optional*, defaults to 2):
125
+ Number of mixer layers to use if fcm_use_mixer is enabled
126
+ fcm_prepend_past (`bool`, *optional*, defaults to `True`):
127
+ Prepend last context for forecast reconciliation
128
+ fcm_prepend_past_offset (`int`, *optional*, defaults to None):
129
+
130
+ categorical_vocab_size_list (`list`, *optional*):
131
+ List of vocab size for all the tokenized categorical variables to use. Pass it in the same order as used in the foreward call param `static_categorical_values`.
132
+ prediction_filter_length (`int`,*optional*, defaults to None):
133
+ Actual length in the prediction output to use for loss calculations.
134
+
135
+
136
+ Example:
137
+
138
+ ```python
139
+ >>> from transformers import TinyTimeMixerConfig, TinyTimeMixerModel
140
+
141
+ >>> # Initializing a default TinyTimeMixer configuration
142
+ >>> configuration = TinyTimeMixerConfig()
143
+
144
+ >>> # Randomly initializing a model (with random weights) from the configuration
145
+ >>> model = TinyTimeMixerModel(configuration)
146
+
147
+ >>> # Accessing the model configuration
148
+ >>> configuration = model.config
149
+ ```"""
150
+
151
+ model_type = "tinytimemixer"
152
+ attribute_map = {
153
+ "hidden_size": "d_model",
154
+ "num_hidden_layers": "num_layers",
155
+ }
156
+
157
+ def __init__(
158
+ self,
159
+ # Time series specific configuration
160
+ context_length: int = 64,
161
+ patch_length: int = 8,
162
+ num_input_channels: int = 1,
163
+ prediction_length: int = 16,
164
+ patch_stride: int = 8,
165
+ prediction_channel_indices: Optional[list] = None,
166
+ exogenous_channel_indices: Optional[list] = None,
167
+ # General model configuration
168
+ d_model: int = 16,
169
+ expansion_factor: int = 2,
170
+ num_layers: int = 3,
171
+ dropout: float = 0.2,
172
+ mode: str = "common_channel",
173
+ gated_attn: bool = True,
174
+ norm_mlp: str = "LayerNorm",
175
+ self_attn: bool = False,
176
+ self_attn_heads: int = 1,
177
+ use_positional_encoding: bool = False,
178
+ positional_encoding_type: str = "sincos",
179
+ scaling: Optional[Union[str, bool]] = "std",
180
+ loss: Optional[str] = "mse",
181
+ init_std: float = 0.02,
182
+ post_init: bool = False,
183
+ norm_eps: float = 1e-5,
184
+ adaptive_patching_levels: int = 0,
185
+ resolution_prefix_tuning: bool = False,
186
+ frequency_token_vocab_size: int = 5,
187
+ # General head configuration
188
+ head_dropout: float = 0.2,
189
+ distribution_output: str = "student_t",
190
+ num_parallel_samples: int = 100,
191
+ # decoder parameters
192
+ decoder_num_layers: int = 8,
193
+ decoder_d_model: int = 8,
194
+ decoder_adaptive_patching_levels: int = 0,
195
+ decoder_raw_residual: bool = False,
196
+ decoder_mode: str = "common_channel",
197
+ use_decoder: bool = True,
198
+ # forecast channel mixing wit exog support
199
+ enable_forecast_channel_mixing: bool = False,
200
+ fcm_gated_attn: bool = True,
201
+ fcm_context_length: int = 1,
202
+ fcm_use_mixer: bool = False,
203
+ fcm_mix_layers: int = 2,
204
+ fcm_prepend_past: bool = True,
205
+ fcm_prepend_past_offset: Optional[int] = None,
206
+ # static categorical
207
+ categorical_vocab_size_list: Optional[list] = None,
208
+ # prediction length filtering
209
+ prediction_filter_length: Optional[int] = None,
210
+ # initialization parameters
211
+ init_linear: str = "pytorch",
212
+ init_embed: str = "pytorch",
213
+ quantile: float = 0.5,
214
+ huber_delta: float = 1,
215
+ # masked prediction,
216
+ mask_value: int = 0,
217
+ **kwargs,
218
+ ):
219
+ self.num_input_channels = num_input_channels
220
+ self.context_length = context_length
221
+ self.patch_length = patch_length
222
+ self.expansion_factor = expansion_factor
223
+ self.num_layers = num_layers
224
+ self.dropout = dropout
225
+ self.mode = mode
226
+ self.gated_attn = gated_attn
227
+ self.norm_mlp = norm_mlp
228
+ self.scaling = scaling
229
+ self.head_dropout = head_dropout
230
+
231
+ self.patch_last = True
232
+ self.use_positional_encoding = use_positional_encoding
233
+ self.positional_encoding_type = positional_encoding_type
234
+ self.prediction_length = prediction_length
235
+ self.prediction_channel_indices = prediction_channel_indices
236
+ self.self_attn = self_attn
237
+ self.self_attn_heads = self_attn_heads
238
+ self.init_std = init_std
239
+ self.post_init = post_init
240
+ self.distribution_output = distribution_output
241
+ self.loss = loss
242
+ self.num_parallel_samples = num_parallel_samples
243
+ self.norm_eps = norm_eps
244
+
245
+ self.use_decoder = use_decoder
246
+
247
+ self.adaptive_patching_levels = adaptive_patching_levels
248
+ self.resolution_prefix_tuning = resolution_prefix_tuning
249
+ self.exogenous_channel_indices = exogenous_channel_indices
250
+ self.decoder_num_layers = decoder_num_layers
251
+ self.decoder_adaptive_patching_levels = decoder_adaptive_patching_levels
252
+ self.decoder_raw_residual = decoder_raw_residual
253
+ self.decoder_mode = decoder_mode
254
+ self.fcm_gated_attn = fcm_gated_attn
255
+ self.fcm_context_length = fcm_context_length
256
+ self.fcm_use_mixer = fcm_use_mixer
257
+ self.fcm_mix_layers = fcm_mix_layers
258
+ self.fcm_prepend_past = fcm_prepend_past
259
+ self.fcm_prepend_past_offset = fcm_prepend_past_offset
260
+ self.enable_forecast_channel_mixing = enable_forecast_channel_mixing
261
+ self.frequency_token_vocab_size = frequency_token_vocab_size
262
+
263
+ self.d_model = d_model
264
+ self.patch_stride = patch_stride
265
+ self.decoder_d_model = decoder_d_model
266
+ self.categorical_vocab_size_list = categorical_vocab_size_list
267
+ self.init_processing = False
268
+ self.prediction_filter_length = prediction_filter_length
269
+ self.init_linear = init_linear
270
+ self.init_embed = init_embed
271
+ self.quantile = quantile
272
+ self.huber_delta = huber_delta
273
+ self.mask_value = mask_value
274
+ self.masked_context_length = None
275
+
276
+ super().__init__(**kwargs)
277
+
278
+ def check_and_init_preprocessing(self):
279
+ self.init_processing = True
280
+
281
+ if not hasattr(self, "num_patches"):
282
+ context_length = (
283
+ self.masked_context_length if self.masked_context_length is not None else self.context_length
284
+ )
285
+ self.num_patches = (max(context_length, self.patch_length) - self.patch_length) // self.patch_stride + 1
286
+
287
+ if self.resolution_prefix_tuning:
288
+ self.num_patches += 1
289
+
290
+ if self.prediction_filter_length is not None:
291
+ if self.prediction_filter_length > self.prediction_length or self.prediction_filter_length <= 0:
292
+ raise ValueError("prediction_filter_length should be positive and less than prediction_length")
293
+
294
+ if self.loss == "nll" and self.enable_forecast_channel_mixing:
295
+ raise ValueError("Distribution head cannot be enabled when enable_forecast_channel_mixing is set to True")
296
+
297
+ if self.prediction_channel_indices is not None:
298
+ self.prediction_channel_indices.sort()
299
+
300
+ if self.exogenous_channel_indices is not None:
301
+ self.exogenous_channel_indices.sort()
302
+
303
+ if self.exogenous_channel_indices is not None and self.prediction_channel_indices is None:
304
+ self.prediction_channel_indices = list(
305
+ set(range(self.num_input_channels)) - set(self.exogenous_channel_indices)
306
+ )
307
+ self.prediction_channel_indices.sort()
@@ -0,0 +1,16 @@
1
+ DEFAULT_FREQUENCY_MAPPING = {
2
+ "oov": 0,
3
+ "min": 1, # minutely
4
+ "2min": 2,
5
+ "5min": 3,
6
+ "10min": 4,
7
+ "15min": 5,
8
+ "30min": 6,
9
+ "h": 7, # hourly
10
+ "H": 7, # hourly, for compatibility
11
+ "d": 8, # daily, for compatibility
12
+ "D": 8, # daily
13
+ "W": 9, # weekly
14
+ }
15
+
16
+ TTM_LOW_RESOLUTION_MODELS_MAX_CONTEXT = 512