dsipts 1.1.6__tar.gz → 1.1.31__tar.gz

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.
Files changed (96) hide show
  1. dsipts-1.1.31/LONG_DESCRIPTION.md +463 -0
  2. {dsipts-1.1.6 → dsipts-1.1.31}/PKG-INFO +81 -20
  3. {dsipts-1.1.6 → dsipts-1.1.31}/README.md +13 -17
  4. {dsipts-1.1.6 → dsipts-1.1.31}/pyproject.toml +25 -6
  5. {dsipts-1.1.6 → dsipts-1.1.31}/src/dsipts/__init__.py +5 -2
  6. {dsipts-1.1.6 → dsipts-1.1.31}/src/dsipts/data_structure/data_structure.py +203 -69
  7. {dsipts-1.1.6 → dsipts-1.1.31}/src/dsipts/data_structure/utils.py +19 -18
  8. {dsipts-1.1.6 → dsipts-1.1.31}/src/dsipts/models/Autoformer.py +2 -1
  9. {dsipts-1.1.6 → dsipts-1.1.31}/src/dsipts/models/CrossFormer.py +2 -1
  10. {dsipts-1.1.6 → dsipts-1.1.31}/src/dsipts/models/D3VAE.py +2 -1
  11. {dsipts-1.1.6 → dsipts-1.1.31}/src/dsipts/models/Diffusion.py +3 -0
  12. {dsipts-1.1.6 → dsipts-1.1.31}/src/dsipts/models/DilatedConv.py +5 -21
  13. {dsipts-1.1.6 → dsipts-1.1.31}/src/dsipts/models/DilatedConvED.py +2 -1
  14. {dsipts-1.1.6 → dsipts-1.1.31}/src/dsipts/models/Duet.py +2 -1
  15. {dsipts-1.1.6 → dsipts-1.1.31}/src/dsipts/models/ITransformer.py +5 -8
  16. {dsipts-1.1.6 → dsipts-1.1.31}/src/dsipts/models/Informer.py +2 -1
  17. {dsipts-1.1.6 → dsipts-1.1.31}/src/dsipts/models/LinearTS.py +2 -1
  18. {dsipts-1.1.6 → dsipts-1.1.31}/src/dsipts/models/PatchTST.py +3 -0
  19. {dsipts-1.1.6 → dsipts-1.1.31}/src/dsipts/models/Persistent.py +2 -0
  20. {dsipts-1.1.6 → dsipts-1.1.31}/src/dsipts/models/RNN.py +3 -2
  21. {dsipts-1.1.6 → dsipts-1.1.31}/src/dsipts/models/Samformer.py +3 -1
  22. dsipts-1.1.31/src/dsipts/models/Simple.py +115 -0
  23. {dsipts-1.1.6 → dsipts-1.1.31}/src/dsipts/models/TFT.py +4 -0
  24. {dsipts-1.1.6 → dsipts-1.1.31}/src/dsipts/models/TIDE.py +4 -1
  25. dsipts-1.1.31/src/dsipts/models/TTM.py +180 -0
  26. dsipts-1.1.31/src/dsipts/models/TimeKAN.py +123 -0
  27. {dsipts-1.1.6 → dsipts-1.1.31}/src/dsipts/models/TimeXER.py +3 -1
  28. dsipts-1.1.31/src/dsipts/models/TimesNet.py +96 -0
  29. {dsipts-1.1.6 → dsipts-1.1.31}/src/dsipts/models/base.py +107 -51
  30. {dsipts-1.1.6 → dsipts-1.1.31}/src/dsipts/models/base_v2.py +126 -57
  31. {dsipts-1.1.6 → dsipts-1.1.31}/src/dsipts/models/duet/layers.py +6 -2
  32. dsipts-1.1.31/src/dsipts/models/timekan/Layers.py +284 -0
  33. dsipts-1.1.31/src/dsipts/models/timesnet/Layers.py +95 -0
  34. {dsipts-1.1.6 → dsipts-1.1.31}/src/dsipts/models/utils.py +75 -1
  35. dsipts-1.1.31/src/dsipts/models/vva/__init__.py +0 -0
  36. dsipts-1.1.31/src/dsipts/models/xlstm/__init__.py +0 -0
  37. dsipts-1.1.31/src/dsipts/version.py +1 -0
  38. {dsipts-1.1.6 → dsipts-1.1.31}/src/dsipts.egg-info/PKG-INFO +81 -20
  39. {dsipts-1.1.6 → dsipts-1.1.31}/src/dsipts.egg-info/SOURCES.txt +9 -0
  40. {dsipts-1.1.6 → dsipts-1.1.31}/src/dsipts.egg-info/requires.txt +2 -2
  41. dsipts-1.1.6/src/dsipts/models/TTM.py +0 -252
  42. {dsipts-1.1.6 → dsipts-1.1.31}/setup.cfg +0 -0
  43. {dsipts-1.1.6 → dsipts-1.1.31}/src/dsipts/data_management/__init__.py +0 -0
  44. {dsipts-1.1.6 → dsipts-1.1.31}/src/dsipts/data_management/monash.py +0 -0
  45. {dsipts-1.1.6 → dsipts-1.1.31}/src/dsipts/data_management/public_datasets.py +0 -0
  46. {dsipts-1.1.6 → dsipts-1.1.31}/src/dsipts/data_structure/__init__.py +0 -0
  47. {dsipts-1.1.6 → dsipts-1.1.31}/src/dsipts/data_structure/modifiers.py +0 -0
  48. {dsipts-1.1.6 → dsipts-1.1.31}/src/dsipts/models/VQVAEA.py +0 -0
  49. {dsipts-1.1.6 → dsipts-1.1.31}/src/dsipts/models/VVA.py +0 -0
  50. {dsipts-1.1.6 → dsipts-1.1.31}/src/dsipts/models/__init__.py +0 -0
  51. {dsipts-1.1.6 → dsipts-1.1.31}/src/dsipts/models/autoformer/__init__.py +0 -0
  52. {dsipts-1.1.6 → dsipts-1.1.31}/src/dsipts/models/autoformer/layers.py +0 -0
  53. {dsipts-1.1.6 → dsipts-1.1.31}/src/dsipts/models/crossformer/__init__.py +0 -0
  54. {dsipts-1.1.6 → dsipts-1.1.31}/src/dsipts/models/crossformer/attn.py +0 -0
  55. {dsipts-1.1.6 → dsipts-1.1.31}/src/dsipts/models/crossformer/cross_decoder.py +0 -0
  56. {dsipts-1.1.6 → dsipts-1.1.31}/src/dsipts/models/crossformer/cross_embed.py +0 -0
  57. {dsipts-1.1.6 → dsipts-1.1.31}/src/dsipts/models/crossformer/cross_encoder.py +0 -0
  58. {dsipts-1.1.6 → dsipts-1.1.31}/src/dsipts/models/d3vae/__init__.py +0 -0
  59. {dsipts-1.1.6 → dsipts-1.1.31}/src/dsipts/models/d3vae/diffusion_process.py +0 -0
  60. {dsipts-1.1.6 → dsipts-1.1.31}/src/dsipts/models/d3vae/embedding.py +0 -0
  61. {dsipts-1.1.6 → dsipts-1.1.31}/src/dsipts/models/d3vae/encoder.py +0 -0
  62. {dsipts-1.1.6 → dsipts-1.1.31}/src/dsipts/models/d3vae/model.py +0 -0
  63. {dsipts-1.1.6 → dsipts-1.1.31}/src/dsipts/models/d3vae/neural_operations.py +0 -0
  64. {dsipts-1.1.6 → dsipts-1.1.31}/src/dsipts/models/d3vae/resnet.py +0 -0
  65. {dsipts-1.1.6 → dsipts-1.1.31}/src/dsipts/models/d3vae/utils.py +0 -0
  66. {dsipts-1.1.6 → dsipts-1.1.31}/src/dsipts/models/duet/__init__.py +0 -0
  67. {dsipts-1.1.6 → dsipts-1.1.31}/src/dsipts/models/duet/masked.py +0 -0
  68. {dsipts-1.1.6 → dsipts-1.1.31}/src/dsipts/models/informer/__init__.py +0 -0
  69. {dsipts-1.1.6 → dsipts-1.1.31}/src/dsipts/models/informer/attn.py +0 -0
  70. {dsipts-1.1.6 → dsipts-1.1.31}/src/dsipts/models/informer/decoder.py +0 -0
  71. {dsipts-1.1.6 → dsipts-1.1.31}/src/dsipts/models/informer/embed.py +0 -0
  72. {dsipts-1.1.6 → dsipts-1.1.31}/src/dsipts/models/informer/encoder.py +0 -0
  73. {dsipts-1.1.6 → dsipts-1.1.31}/src/dsipts/models/itransformer/Embed.py +0 -0
  74. {dsipts-1.1.6 → dsipts-1.1.31}/src/dsipts/models/itransformer/SelfAttention_Family.py +0 -0
  75. {dsipts-1.1.6 → dsipts-1.1.31}/src/dsipts/models/itransformer/Transformer_EncDec.py +0 -0
  76. {dsipts-1.1.6 → dsipts-1.1.31}/src/dsipts/models/itransformer/__init__.py +0 -0
  77. {dsipts-1.1.6 → dsipts-1.1.31}/src/dsipts/models/patchtst/__init__.py +0 -0
  78. {dsipts-1.1.6 → dsipts-1.1.31}/src/dsipts/models/patchtst/layers.py +0 -0
  79. {dsipts-1.1.6 → dsipts-1.1.31}/src/dsipts/models/samformer/__init__.py +0 -0
  80. {dsipts-1.1.6 → dsipts-1.1.31}/src/dsipts/models/samformer/utils.py +0 -0
  81. {dsipts-1.1.6 → dsipts-1.1.31}/src/dsipts/models/tft/__init__.py +0 -0
  82. {dsipts-1.1.6 → dsipts-1.1.31}/src/dsipts/models/tft/sub_nn.py +0 -0
  83. {dsipts-1.1.6/src/dsipts/models/timexer → dsipts-1.1.31/src/dsipts/models/timekan}/__init__.py +0 -0
  84. {dsipts-1.1.6/src/dsipts/models/ttm → dsipts-1.1.31/src/dsipts/models/timesnet}/__init__.py +0 -0
  85. {dsipts-1.1.6 → dsipts-1.1.31}/src/dsipts/models/timexer/Layers.py +0 -0
  86. {dsipts-1.1.6/src/dsipts/models/vva → dsipts-1.1.31/src/dsipts/models/timexer}/__init__.py +0 -0
  87. {dsipts-1.1.6/src/dsipts/models/xlstm → dsipts-1.1.31/src/dsipts/models/ttm}/__init__.py +0 -0
  88. {dsipts-1.1.6 → dsipts-1.1.31}/src/dsipts/models/ttm/configuration_tinytimemixer.py +0 -0
  89. {dsipts-1.1.6 → dsipts-1.1.31}/src/dsipts/models/ttm/consts.py +0 -0
  90. {dsipts-1.1.6 → dsipts-1.1.31}/src/dsipts/models/ttm/modeling_tinytimemixer.py +0 -0
  91. {dsipts-1.1.6 → dsipts-1.1.31}/src/dsipts/models/ttm/utils.py +0 -0
  92. {dsipts-1.1.6 → dsipts-1.1.31}/src/dsipts/models/vva/minigpt.py +0 -0
  93. {dsipts-1.1.6 → dsipts-1.1.31}/src/dsipts/models/vva/vqvae.py +0 -0
  94. {dsipts-1.1.6 → dsipts-1.1.31}/src/dsipts/models/xlstm/xLSTM.py +0 -0
  95. {dsipts-1.1.6 → dsipts-1.1.31}/src/dsipts.egg-info/dependency_links.txt +0 -0
  96. {dsipts-1.1.6 → dsipts-1.1.31}/src/dsipts.egg-info/top_level.txt +0 -0
@@ -0,0 +1,463 @@
1
+
2
+
3
+ # DSIPTS: unified library for timeseries modelling
4
+ > [!CAUTION]
5
+ The documentation, README and notebook are somehow outdated, some architectures are under review, please be patient. Moreover, there will some frequent changes due to refactoring or documentation update. Wait the version 1.2.0 for more stable library (in terms of structure and documentation) or even 2.0.0 for the tests, assertions and other standard stuff.
6
+
7
+ This library allows to:
8
+
9
+ - load timeseries in a convenient format
10
+ - create tool timeseries with controlled categorical features
11
+ - load public timeseries
12
+ - train a predictive model using different PyTorch architectures
13
+ - define more complex structures using Modifiers (e.g. combining unsupervised learning + deep learning)
14
+
15
+ ## Disclamer
16
+ The original repository is located [here](https://gitlab.fbk.eu/dsip/dsip_dlresearch/timeseries) but there is a push mirror in gitlab and you can find it [here](https://github.com/DSIP-FBK/DSIPTS/). Depending on the evolution of the library we will decide if keep both or move definitively to github.
17
+
18
+
19
+ ## Background
20
+
21
+ Let $X(t)$ be a multivariate timeseries, e.g. $\forall t, X(t)\in \mathbf{R}^k$ for some $k$. The vector space $\mathbf{R}^k$ can be partitioned into two disjoint sets: the categorical features $\mathcal{C}\subset \mathbf{N}^c$ and continuous features $\mathcal{W}\subset \mathbf{R}^{k-c}$. We assume that $\mathcal{C}$ is known for each $t$. Let $\mathcal{F}\subset\mathbf{R}^{f}$ be the set of known variables for each $t$, $\mathcal{P}\subset\mathbf{R}^{p}$ be the set of variables known until time $t$, and $\mathcal{T}\subset\mathcal{P}\subset\mathbf{R}^{s}$ the target variables. Let also define $\tau\in N$ as the number of lag for wich we want a forecast, then the aim of a predictive model is to find a function $F:\mathbf{R}^k\rightarrow\mathbf{R}^{s \times \tau}$ such as:
22
+
23
+ $$
24
+ F(\mathcal{C}(t-K,\ldots,t+\tau),\mathcal{F}(t-K,\ldots,t+\tau),\mathcal{P}(t-K,\ldots,t),\mathcal{T}(t-K,\ldots,t) ) = \mathcal{T}(t+1,\ldots,t+\tau)
25
+ $$
26
+
27
+ for some K representing the maximum past context.
28
+
29
+ In the library we adopt some convention that must be used when developing a new model:
30
+ ```
31
+ y : the target variable(s)
32
+ x_num_past: the numerical past variables
33
+ x_num_future: the numerical future variables
34
+ x_cat_past: the categorical past variables
35
+ x_cat_future: the categorical future variables
36
+ idx_target: index containing the y variables in the past dataset. Can be used during the training for train a differential model
37
+ ```
38
+ by default, during the dataset construction, the target variable will be added to the `x_num_past` list. Moreover the set of categorical variable can be different in the past and the future but we choose to distinguish the two parts during the forward loop for seek of generability.
39
+
40
+ During the forward process, the batch is a dictionary with some of the key showed above, remember that not all keys are always present (check it please) and build a model according. The shape of such tensor are in the form $[B,L,C]$ where $B$ indicates the batch size, $L$ the length and $C$ the number of channels.
41
+
42
+ The output of a new model must be $[B,L,C,1]$ in case of single prediction or $[B,L,C,3]$ in case you are using quantile loss.
43
+
44
+
45
+ Try to reuse some of the common keywords while building your model. After the initialization of the model you can use whatever variable you want but during the initialization please use the following conventions.
46
+ This first block maybe is common between several architectures:
47
+
48
+ ---
49
+
50
+ - **past_steps** = int. THIS IS CRUCIAL and self explanatory
51
+ - **future_steps** = int. THIS IS CRUCIAL and self explanatory
52
+ - **past_channels** = len(ts.num_var). THIS IS CRUCIAL and self explanatory
53
+ - **future_channels** = len(ts.future_variables). THIS IS CRUCIAL and self explanatory
54
+ - **out_channels** = len(ts.target_variables). THIS IS CRUCIAL and self explanatory
55
+ - **embs_past** = [ts.dataset[c].nunique() for c in ts.cat_past_var]. THIS IS CRUCIAL and self explanatory.
56
+ - **embs_fut** = [ts.dataset[c].nunique() for c in ts.cat_fut_var]. THIS IS CRUCIAL and self explanatory.
57
+ - **use_classical_positional_encoder** = classical positioal code are done with the combination of sin/cos/exponenstial function, otherwise the positional encoding is done with the `nn.Embedding` like the other categorical variables
58
+ - **reduction_mode** = the categorical metafeatures can be summed, averaged or stacked depending on what behavior you like more.
59
+ - **emb_dim** = int. Dimension of embedded categorical variables, the choice here is to use a constant value and let the user chose if concatenate or sum the variables
60
+ - **quantiles** =[0.1,0.5,0.9]. Quantiles for quantile loss
61
+ - **kind** =str. If there are some similar architectures with small differences maybe is better to use the same code specifying some properties (e.g. GRU vs LSTM)
62
+ - **activation** = str ('torch.nn.ReLU' default). activation function between layers (see [pytorch activation functions](https://pytorch.org/docs/stable/nn.html#non-linear-activations-weighted-sum-nonlinearity))
63
+ - **optim** = str ('torch.optim.Adam' default). optimization function see [pytorch optimization functions](https://pytorch.org/docs/stable/optim.html)
64
+ - **dropout_rate** =float. dropout rate
65
+ - **use_bn** =boolean . Use or not batch normalization
66
+ - **persistence_weight** = float . Penalization weight for persistent predictions
67
+ - **loss_type** = str . There are some other metrics implemented, see the [metric section](#metrics) for details
68
+
69
+
70
+ ---
71
+ some are more specific for RNN-CONV architectures:
72
+
73
+ ---
74
+ - **hidden_RNN** = int. If there are some RNN use this and the following
75
+ - **num_layers_RNN** = int.
76
+ - **kernel_size** = int. If there are some convolutional layers
77
+
78
+ ---
79
+
80
+ linear:
81
+
82
+ - **hidden_size** = int. Usually the hidden dimension, for some architecture maybe you can pass the list of the dimensions
83
+ - **kind** =str. Type of linear approach
84
+
85
+ ---
86
+
87
+ or attention based models:
88
+
89
+ - **d_model** = int .d_model of a typical attention layer
90
+ - **n_heads** = int .Heads
91
+ - **dropout_rate** = float. dropout
92
+ - **n_layer_encoder** = int. encoder layers
93
+ - **n_layer_decoder** = int. decoder layers
94
+ ---
95
+
96
+ ## Install
97
+ Clone the repo (gitlab or github)
98
+ The library is structured to work with [uv](https://github.com/astral-sh/uv). After installing `uv` just run
99
+ ```bash
100
+ uv pip install .
101
+ ```
102
+ You can install also the package from pip (be sure that the python version is less than 3.12, still sperimental):
103
+ ```bash
104
+ uv venv --python 3.11
105
+ uv pip install dsipts
106
+ ```
107
+
108
+
109
+ ## For developers
110
+ - Remember to update the `pyproject.toml`
111
+ - use `uv add` and `uv sync` for update the project
112
+ - `uv pip install -e .` for install dsipts
113
+ - `uv build` for building it
114
+ - `uv pip install dist/dsipts-X.Y.Z-py3-none-any.whl` for checking the installation
115
+ - generate documentation with `uv run sphinx-quickstart docs` (just the first time)
116
+ - `uv run sphinx-apidoc -o docs/source src/dsipts`
117
+ - `uv run sphinx-build -b html docs/source ../docs`
118
+ ## AIM
119
+ DSIPTS uses AIM for tracking losses, parameters and other useful information. The first time you use DSIPTS you may need to initialize aim executing:
120
+ ```bash
121
+ aim init
122
+ ```
123
+
124
+
125
+
126
+ ## Usage
127
+
128
+ Let make an example with the public weather data (you can find it [here](https://drive.google.com/drive/folders/13Cg1KYOlzM5C7K8gK8NfC-F3EYxkM3D2) or [here](https://github.com/thuml/Time-Series-Library?tab=readme-ov-file))
129
+
130
+
131
+
132
+
133
+ ```python
134
+ import pandas as pd
135
+ import numpy as np
136
+ from dsipts import TimeSeries, RNN,read_public_dataset
137
+ import matplotlib.pyplot as plt
138
+ from datetime import timedelta
139
+ import logging
140
+ import sys
141
+ data, columns = read_public_dataset(PATH_TO_DATA,'weather')
142
+ ```
143
+ define then how to use the information and define the time series. You can add automatically the `hour` categorical data using the key `enrich_cat` that will be automatically added to the categorical past and categorical future list of columns:
144
+ ```pyhon
145
+ use_covariates = False #use only y in the PAST
146
+ use_future_covariate = True #suppose to have some future covariates
147
+ ts = TimeSeries('weather')
148
+ ts.load_signal( data,enrich_cat=['hour'],target_variables=['y'],past_variables=columns if use_covariates else [], future_variables=columns if use_future_covariate else [] )
149
+ fig = ts.plot() # plot the target variable(s )
150
+ ```
151
+ The most important part is the method `ts.load_signal` where the user can specify the parameters of the timeseries such as:
152
+
153
+
154
+ - **data** (pd.DataFrame) – input dataset the column indicating the time must be called time
155
+
156
+ - **enrich_cat** (List[str], optional) – it is possible to let this function enrich the dataset for example adding the standard columns: hour, dow, month and minute. Defaults to [].
157
+
158
+ - **past_variables** (List[str], optional) – list of column names of past variables not available for future times . Defaults to [].
159
+
160
+ - **future_variables** (List[str], optional) – list of future variables available for future times. Defaults to [].
161
+
162
+ - **target_variables** (List[str], optional) – list of the target variables. They will added to past_variables by default unless check_past is false. Defaults to [].
163
+
164
+ - **cat_past_var** (List[str], optional) – list of the past categorical variables. Defaults to [].
165
+
166
+ - **cat_future_var** (List[str], optional) – list of the future categorical variables. Defaults to [].
167
+
168
+ - **check_past** (bool, optional) – see target_variables. Defaults to True.
169
+
170
+ - **group** (str or None, optional) – if not None the time series dataset is considered composed by homogeneous timeseries coming from different realization (for example point of sales, cities, locations) default None (and the relative series are not split during the sample generation. Defaults to)
171
+
172
+ - **check_holes_and_duplicates** (bool, optional) – if False duplicates or holes will not checked, the dataloader can not correctly work, disable at your own risk. Defaults True
173
+
174
+ - **silly_model (bool, optional)** – if True, target variables will be added to the pool of the future variables. This can be useful to see if information passes thought the decoder part of your model (if any)
175
+
176
+
177
+
178
+ Now we can define a forecasting problem (`past_steps` as context, `future_steps` as future horizon )
179
+
180
+ Let suppose to use a RNN encoder-decoder structure, then the model has the following parameters:
181
+ ```python
182
+ past_steps = 12*7
183
+ future_steps = 12
184
+ config = dict(model_configs =dict(
185
+
186
+ past_steps = past_steps, #TASK DEPENDENT
187
+ future_steps = future_steps,#TASK DEPENDENT
188
+
189
+ emb_dim = 16, # categorical stuff
190
+ use_classical_positional_encoder = True, # categorical stuff
191
+ reduction_mode = 'mean',# categorical stuff
192
+
193
+ kind = 'gru',# model dependent
194
+ hidden_RNN = 12,# model dependent
195
+ num_layers_RNN = 2,# model dependent
196
+ kernel_size = 15,# model dependent
197
+ dropout_rate= 0.5,# model dependent
198
+ remove_last= True,# model dependent
199
+ use_bn = False,# model dependent
200
+ activation= 'torch.nn.PReLU', # model dependent
201
+
202
+ quantiles=[0.1,0.5,0.9], #LOSS
203
+ persistence_weight= 0.010, #LOSS
204
+ loss_type= 'l1', #LOSS
205
+
206
+ optim= 'torch.optim.Adam', #OPTIMIZER
207
+
208
+ past_channels = len(ts.past_variables), #parameter that depends on the ts dataset
209
+ future_channels = len(ts.future_variables), #parameter that depends on the ts dataset
210
+ embs_past = [ts.dataset[c].nunique() for c in ts.cat_past_var], #parameter that depends on the ts dataset
211
+ embs_fut = [ts.dataset[c].nunique() for c in ts.cat_fut_var], #parameter that depends on the ts dataset
212
+ out_channels = len(ts.target_variables)), #parameter that depends on the ts dataset
213
+
214
+ scheduler_config = dict(gamma=0.1,step_size=100),
215
+ optim_config = dict(lr = 0.0005,weight_decay=0.01))
216
+ model_rnn = RNN(**config['model_configs'],optim_config = config['optim_config'],scheduler_config =config['scheduler_config'],verbose=False )
217
+
218
+ ts.set_model(model_rnn,config=config )
219
+
220
+ ```
221
+
222
+
223
+ Now we are ready to split and train our model. First define the splitting configuration:
224
+ ```python
225
+ split_params = {'perc_train':0.7,'perc_valid':0.1, ##if not None it will split 70% 10% 20%
226
+ 'range_train':None, 'range_validation':None, 'range_test':None, ## or we can split using ranges for example range_train=['2021-02-03','2022-04-08']
227
+ 'past_steps':past_steps,
228
+ 'future_steps':future_steps,
229
+ 'starting_point':None, ## do not skip samples
230
+ 'skip_step' : 10 ## distance between two consecutive samples, aka the stride (larger it is, less point we have in train)
231
+ }
232
+
233
+ ts.train_model(dirpath=PATH_TO_SAVING_STUFF,
234
+ split_params=split_params,
235
+ batch_size=128,
236
+ num_workers=4,
237
+ max_epochs=2,
238
+ gradient_clip_val= 0.0,
239
+ gradient_clip_algorithm='value',
240
+ precision='bf16',
241
+ auto_lr_find=True)
242
+
243
+ ts.losses.plot()
244
+ ts.save("weather") ##save all the metadata to use it in inference mode after
245
+
246
+ ```
247
+
248
+ It is possble to split the data indicating the percentage of data to use in train, validation, test or the ranges. The `shift` parameters indicates if there is a shift constucting the y array. It cab be used for some attention model where we need to know the first value of the timeseries to predict. It may disappear in future because it is misleading. The `skip_step` parameters indicates how many temporal steps there are between samples. If you need a future signal that is long `skip_step+future_steps` then you should put `keep_entire_seq_while_shifting` to True (see Informer model).
249
+
250
+ During the training phase a log stream will be generated. If a single process is spawned the log will be displayed, otherwise a file will be generated. Moreover, inside the `weight` path there wil be the `loss.csv` file containing the running losses.
251
+
252
+ At the end of the training process it is possible to load the model passing the model class (`RNN`) and the saving name used before (`weather`)
253
+ If the same model and the same name are used for defining the time series, the training procedure will continue from the last checkpoint. Due to lightening related usage, the counting of the epochs will start from the last stage (if you trained if for 10 epochs and you want to train 10 epochs more you need to change it to 20).
254
+
255
+
256
+
257
+ ```python
258
+
259
+ ts.load(RNN,"weather",load_last=True)
260
+ res = ts.inference_on_set(200,4,set='test',rescaling=True)
261
+ error = res.groupby('lag').apply(lambda x: np.nanmean((x.y-x.y_median)**2)).reset_index().rename(columns={0:'error'})
262
+
263
+ ```
264
+ If a quantile loss has been selected the model generates three signals `_low, _median, _high`, if not the output the model is indicated with `_pred`. Lag indicates which step the prediction is referred (eg. lag=1 is the first output of the model along the sequence output).
265
+
266
+ ```
267
+ import matplotlib.pyplot as plt
268
+ mask = res.prediction_time=='2020-10-19 19:50:00'
269
+ plt.plot(res.lag[mask],res.y[mask],label='real')
270
+ plt.plot(res.lag[mask],res.y_median[mask],label='median')
271
+ plt.legend()
272
+ ```
273
+ Another useful plot is the error plot per lag where it is possible to observe the increment of the error in correlation with the lag time:
274
+
275
+ ```
276
+ import numpy as np
277
+ res['error'] =np.abs( res['y']-res['y_median'])
278
+ res.groupby('lag').error.mean().plot()
279
+ ```
280
+
281
+
282
+
283
+ This example can be found [here](/notebooks/public_timeseries.ipynb).
284
+
285
+ # Categorical variables
286
+ Most of the models implemented can deal with categorical variables (`cat_past_var` and `cat_fut_var`). In particulare there are some variables that you don't need to computed. When declaring a `ts` obejct you can pass also the parameter `enrich_cat=['dow']` that will add to the dataframe (and to the dataloader) the day of the week. Since now you can automatically add `hour, dow, month and minute`. If there are other categorical variables pleas add it to the list while loading your data.
287
+
288
+
289
+
290
+ # Models
291
+ A description of each model can be found in the class documentation [here](https://dsip.pages.fbk.eu/dsip_dlresearch/timeseries/).
292
+ It is possible to use one of the following architectures:
293
+
294
+ - **RNN** (GRU, LSTM or xLSTM) models, (xLSTM)[https://arxiv.org/pdf/2405.04517] are taken from the [official repo](https://github.com/muditbhargava66/PyxLSTM)
295
+ - **Linear** models based on the [official repository](https://github.com/cure-lab/LTSF-Linear), [paper](https://arxiv.org/pdf/2205.13504.pdf). An alternative model (alinear) has been implemented that drop the autoregressive part and uses only covariates
296
+ - **Crossformer** [official repository](https://github.com/cheerss/CrossFormer), [paper](https://openreview.net/forum?id=vSVLM2j9eie)
297
+ - **Informer** [official repository](https://github.com/zhouhaoyi/Informer2020), [paper](https://arxiv.org/abs/2012.07436)
298
+ - **Autoformer** [non official repository](https://github.com/yuqinie98/PatchTST/tree/main), [paper](https://arxiv.org/abs/2106.13008)
299
+ - **PatchTST** [official repository](https://github.com/yuqinie98/PatchTST/tree/main), [paper](https://arxiv.org/abs/2211.14730)
300
+ - **Persistent** baseline model
301
+ - **TFT** [paper](https://arxiv.org/abs/1912.09363)
302
+ - **DilatedConv** dilated convolutional RNN: the transfer of knowledge between past and future is performed reusing the final hidden status of the RNN of the encoder as initial hidden status of the decoder.
303
+ - **DilatedConvED** dilated convolutional RNN with an encoder/decoder structure.
304
+
305
+ - **ITransformer** [paper](https://arxiv.org/abs/2310.06625), [official repo](https://github.com/thuml/iTransformer)
306
+ - **TIDE** [paper](https://arxiv.org/abs/2304.08424)
307
+ - **Samformer** [paper](https://arxiv.org/pdf/2402.10198) [official repo](https://github.com/romilbert/samformer/tree/main?tab=MIT-1-ov-)
308
+ - **Duet** [paper](https://arxiv.org/abs/2412.10859) [official repo](https://github.com/decisionintelligence/DUET)
309
+
310
+ These models are under review because broken or not aligned with the recent distinction between past and future categorical data:
311
+
312
+ - **Diffusion** custom [diffusion process](https://arxiv.org/abs/2102.09672) using the attention mechanism in the subnets.
313
+ - **D3VAE** adaptation of the [official repository](https://github.com/PaddlePaddle/PaddleSpatial), [paper](https://arxiv.org/abs/2301.03028)
314
+ - **VQVAE** adaptation of [vqvae for images](https://nbviewer.org/github/zalandoresearch/pytorch-vq-vae/blob/master/vq-vae.ipynb) decribed in this [paper](https://arxiv.org/abs/1711.00937) paired with [GPT](https://github.com/karpathy/minGPT) transformer.
315
+ - **VVA** like VQVAE but the tokenization step is performed using a clustering standard procedure.
316
+
317
+ ## Metrics
318
+ In some cases the persistence model is hard to beat and even the more complex model can fall in the persistence trap that propagates the last seen values.
319
+ For this reason a set of metrics can be used trying to avoid the model to get stuck in the trap. In particular we implemented: MSE, L1, sinkhorn divergence, dilated
320
+ loss, quantile loss, MDA and a couple of experimental losses for minimizing the variance or penalizing the persistency. See the base model definition in `dsipts/models/base.py` for more details.
321
+
322
+
323
+
324
+ # Bash experiment
325
+ Most of the time you want to train the models in a cluster with a GPU and command line training procedure can help speedup the process. DSIPTS leverages on OmegaConf-Hydra to to this and in the folder `bash_examples` you can find an examples. Please read the documentation [here](/bash_examples/README.md)
326
+
327
+ ## Losses
328
+
329
+ - `dilated`: `persistence_weight` between 0 and 1
330
+
331
+
332
+ # Modifiers
333
+
334
+ The VVA model is composed by two steps: the first is a clusterting procedure that divides the input time series in smaller segments an performs a clustering procedure in order to associate a label for each segment. A this point the GPT models works on the sequence of labels trying to predict the next cluster id. Using the centroids of the clusters (and the variace) the final ouput is reconstructed. This pipeline is quite unusual and does not fit with the automation pipeline, but it is possible to use a `Modifier` an abstract class that has 3 methods:
335
+ - **fit_transform**: called before startin the training process and returns the train/validation pytorch datasets. In the aforementioned model the clustering model is trained.
336
+ - **transform**: used during the inference phase. It is similar to fit_transform but without the training process
337
+ - **inverse_transform**: the output of the model are reverted to the original shape. In the VVA model the centroids are used for reconstruct the predicted timeseries.
338
+
339
+
340
+
341
+
342
+ For user only: be sure that the the CI file has pages enabled, see [public pages](https://roneo.org/en/gitlab-public-pages-private-repo/)
343
+
344
+ # Adding new models
345
+ If you want to add a model:
346
+
347
+ - extend the `Base` class in `dsipts/models`
348
+ - add the export line in the `dsipts/__init__.py`
349
+ - add a full configuration file in `bash_examples/config_test/architecture`
350
+ - optional: add in `bash_script/utils.py` the section to initializate and load the new model
351
+ - add the modifier in `dsipts/data_structure/modifiers.py` if it is required
352
+
353
+ # Testing
354
+ See [here](/bash_examples/README.md) for the testing session.
355
+
356
+ # Logging
357
+ From version 1.1.0, Aim is used for logging all the experiments and metrics. It is quite easy to install and to use. Just go inside the main folder (`bash_exaples`) and run:
358
+ ```
359
+ aim init #only the first time
360
+ aim up
361
+ ```
362
+ and then open the url (http://127.0.0.1:43800)[http://127.0.0.1:43800]. It will show the model parameters, some metrics and the losses during the training procedure
363
+ ![plot](bash_examples/figures/aim1.png)
364
+ but also some prediction (the first sample of the first batch of the validation set, every 10% of the maximum number of epochs.)
365
+ ![plot](bash_examples/figures/aim2.png)
366
+
367
+
368
+ ## TODO
369
+ [ ] some models can not work in a non-autoregressive way (target past variable is required). Relax some constraints in the forward loop can help this
370
+
371
+ [ ] reduce test time
372
+
373
+ [ ] add pre-commit hook for code checking (`ruff check --ignore E501,E722 .`)
374
+
375
+ [ ] add pre-commit hook testing
376
+
377
+ [ ] clean code and standardize documentation
378
+
379
+ [ ] check all the code in the README
380
+
381
+ [ ] check architecture description (which model can be used under certain assumption)
382
+
383
+ [ ] complete the classification part (loss function + inference step)
384
+
385
+ [ ] check D3VAE, it seems broken in some configurations
386
+
387
+ [ ] add hybrid models https://www.sciencedirect.com/science/article/pii/S138912862400118X
388
+
389
+ [ ] add SOFTS https://github.com/Secilia-Cxy/SOFTS/blob/main/models/SOFTS.py
390
+
391
+ [ ] add https://github.com/Hank0626/PDF/blob/main/models/PDF.py
392
+
393
+ [ ] add https://github.com/decisionintelligence/pathformer
394
+
395
+ [ ] in 1.1.5 we split the future and past categorical variables. D3VAE &^ Diffusion to be revised
396
+
397
+ [ ] all snippet of code and notebook must be review in 1.1.5 (categorical past and future, embedding layer parameters)
398
+
399
+
400
+
401
+ ## 1.1.31
402
+ - aim & logger back working
403
+ - fixed validation with few sampler
404
+
405
+ ## 1.1.21-22-23-26-27-30 (2026-02-02)
406
+ - fixing lightening version support (not yet solved for version >2.6)
407
+ - removed aim (compatibility)
408
+ - logger
409
+
410
+ ## 1.1.20 (2026-02-01)
411
+ - automation of tags, version etc using only the makefile
412
+ - update newer version of python
413
+ ## 1.1.14 (2025-12-02)
414
+ - Add CHANGELOG to the pip page
415
+ - Bug fixing for non autoregressive models
416
+ - Added TimesNet, TimeKAN
417
+ - Added 0 shot and full shot TTM
418
+ - added more option parameter to define an experiment (`split_params`, `optim_config` and `train_config`)
419
+ ## 1.1.13 (2025-12-02)
420
+
421
+ - Added weight for the WeightedRandomSampler (only for the training part)
422
+ - Bug fixing when using groups in the categorical variables
423
+ - TTM fixed for working with zeropad for shorter sequences and future covariates
424
+
425
+ ## 1.1.12 (2025-11-07)
426
+ - Bug fixing dynamo stuff for `TTM`
427
+ - Bug fixing loading weights after training process ('dynamo module can not load weights`)
428
+ - Force to not compile some models (there are piece of code that are not aligned with dynamo)
429
+ - Bug fixing test configurations
430
+
431
+ ## 1.1.11 (2025-11-06)
432
+ - Added `torch.compile` for better performance on recent GPU
433
+ - Stable `TTM` model according to version 1.1.5, still under debug, use at your own risk
434
+ - Bux Fixing `cprs` inference (now produces 3 quantiles: `[0.05, 0.5, 0.95]`). The `persistence_weight` is the value of `alpha` in the paper (between 0 and 1)
435
+
436
+ ## 1.1.9 (2025-09-19)
437
+ - Added `cprs` https://arxiv.org/pdf/2412.15832v1 loss function. In this case use the quantile parameter to ask for the ensembles: `quantiles = [1,2,3,4,5,6,7,8,9,10]` will create 10 ensembles. For now the inference part will return just the mean, TODO: estimate a confidence interval with the ensembles
438
+ - Added `long_lag` the L1 error will be modulated with a linear weight depending on the lag in the future: the penalization goes from `1` to `persistence_weight`
439
+
440
+ ## 1.1.8 (2025-09-12)
441
+ - Added `Simple` model (just two linear layers)
442
+
443
+ ## 1.1.7 (2025-09-08)
444
+ - bug fixing `DilatedConv`
445
+ ## 1.1.5 (2025-08-29)
446
+ - rewriting most of the modules for handling different future and past categorical variables
447
+ - extension of categorical and future covariates in almost all the models
448
+ - `uv` full management of the package
449
+ - refactoring almost all the structure and documentation
450
+
451
+ ## 1.1.4 (2025-08-22)
452
+ - added `restart: true` tro model configuration to restart the training procedure: carefurl the max_epochs should be increased if you need to retrain
453
+
454
+ ## 1.1.4 (2025-07-29)
455
+ - bug fixing tuner learning rate
456
+ - added TTM model and TimeXer
457
+ - added compatibility with newer version of lightening and torch
458
+
459
+ ## 1.1.1
460
+ - added [SAM optimizer](https://arxiv.org/pdf/2402.10198)
461
+ ```bash
462
+ python train.py --config-dir=config_test --config-name=config architecture=itransformer dataset.path=/home/agobbi/Projects/ExpTS/data train_config.dirpath=tmp inference=tmp model_configs.optim=SAM +optim_config.rho=0.5
463
+ ```
@@ -1,14 +1,14 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dsipts
3
- Version: 1.1.6
3
+ Version: 1.1.31
4
4
  Summary: Unified library for timeseries modelling
5
5
  Author-email: Andrea Gobbi <agobbi@fbk.eu>
6
6
  Project-URL: Homepage, https://github.com/DSIP-FBK/DSIPTS
7
7
  Project-URL: Docs, https://dsip-fbk.github.io/DSIPTS/
8
- Requires-Python: ==3.11.13
8
+ Requires-Python: >=3.12
9
9
  Description-Content-Type: text/markdown
10
- Requires-Dist: aim==3.20.1
11
10
  Requires-Dist: beautifulsoup4==4.12.0
11
+ Requires-Dist: bumpver>=2025.1131
12
12
  Requires-Dist: einops>=0.8.1
13
13
  Requires-Dist: html-table-parser-python3==0.3.1
14
14
  Requires-Dist: html5lib>=1.1
@@ -17,7 +17,7 @@ Requires-Dist: hydra-joblib-launcher>=1.2.0
17
17
  Requires-Dist: hydra-optuna-sweeper>=1.2.0
18
18
  Requires-Dist: hydra-submitit-launcher>=1.2.0
19
19
  Requires-Dist: ipykernel>=6.30.1
20
- Requires-Dist: lightning>=2.5.4
20
+ Requires-Dist: lightning==2.5.5
21
21
  Requires-Dist: matplotlib>=3.10.6
22
22
  Requires-Dist: nbformat>=5.10.4
23
23
  Requires-Dist: numba>=0.61.2
@@ -128,10 +128,14 @@ or attention based models:
128
128
  ## Install
129
129
  Clone the repo (gitlab or github)
130
130
  The library is structured to work with [uv](https://github.com/astral-sh/uv). After installing `uv` just run
131
- ```
131
+ ```bash
132
132
  uv pip install .
133
133
  ```
134
- The pip package wi
134
+ You can install also the package from pip (be sure that the python version is less than 3.12, still sperimental):
135
+ ```bash
136
+ uv venv --python 3.11
137
+ uv pip install dsipts
138
+ ```
135
139
 
136
140
 
137
141
  ## For developers
@@ -352,6 +356,9 @@ loss, quantile loss, MDA and a couple of experimental losses for minimizing the
352
356
  # Bash experiment
353
357
  Most of the time you want to train the models in a cluster with a GPU and command line training procedure can help speedup the process. DSIPTS leverages on OmegaConf-Hydra to to this and in the folder `bash_examples` you can find an examples. Please read the documentation [here](/bash_examples/README.md)
354
358
 
359
+ ## Losses
360
+
361
+ - `dilated`: `persistence_weight` between 0 and 1
355
362
 
356
363
 
357
364
  # Modifiers
@@ -362,13 +369,7 @@ The VVA model is composed by two steps: the first is a clusterting procedure tha
362
369
  - **inverse_transform**: the output of the model are reverted to the original shape. In the VVA model the centroids are used for reconstruct the predicted timeseries.
363
370
 
364
371
 
365
- ## Documentation
366
- You can find the documentation [here](https://dsip.pages.fbk.eu/dsip_dlresearch/timeseries/):
367
- or in the folder `docs/_build/html/index.html`
368
- If yon need to generate the documentation after some modification just run:
369
- ```
370
- ./make_doc.sh
371
- ```
372
+
372
373
 
373
374
  For user only: be sure that the the CI file has pages enabled, see [public pages](https://roneo.org/en/gitlab-public-pages-private-repo/)
374
375
 
@@ -397,6 +398,8 @@ and then open the url (http://127.0.0.1:43800)[http://127.0.0.1:43800]. It will
397
398
 
398
399
 
399
400
  ## TODO
401
+ [ ] some models can not work in a non-autoregressive way (target past variable is required). Relax some constraints in the forward loop can help this
402
+
400
403
  [ ] reduce test time
401
404
 
402
405
  [ ] add pre-commit hook for code checking (`ruff check --ignore E501,E722 .`)
@@ -405,15 +408,12 @@ and then open the url (http://127.0.0.1:43800)[http://127.0.0.1:43800]. It will
405
408
 
406
409
  [ ] clean code and standardize documentation
407
410
 
408
- [ ] add more sintetic data
409
-
410
411
  [ ] check all the code in the README
411
412
 
412
413
  [ ] check architecture description (which model can be used under certain assumption)
413
414
 
414
415
  [ ] complete the classification part (loss function + inference step)
415
416
 
416
-
417
417
  [ ] check D3VAE, it seems broken in some configurations
418
418
 
419
419
  [ ] add hybrid models https://www.sciencedirect.com/science/article/pii/S138912862400118X
@@ -424,11 +424,72 @@ and then open the url (http://127.0.0.1:43800)[http://127.0.0.1:43800]. It will
424
424
 
425
425
  [ ] add https://github.com/decisionintelligence/pathformer
426
426
 
427
- [x] add Duet
427
+ [ ] in 1.1.5 we split the future and past categorical variables. D3VAE &^ Diffusion to be revised
428
428
 
429
- [x] add categorical support to Crossformer, Samformer
429
+ [ ] all snippet of code and notebook must be review in 1.1.5 (categorical past and future, embedding layer parameters)
430
430
 
431
- [ ] in 1.1.5 we split the future and past categorical variables. D3VAE, Diffusion, TTM need to be revised
432
431
 
433
- [ ] all snippet of code and notebook must be review in 1.1.5 (categorical past and future, embedding layer parameters)
434
432
 
433
+ ## 1.1.31
434
+ - aim & logger back working
435
+ - fixed validation with few sampler
436
+
437
+ ## 1.1.21-22-23-26-27-30 (2026-02-02)
438
+ - fixing lightening version support (not yet solved for version >2.6)
439
+ - removed aim (compatibility)
440
+ - logger
441
+
442
+ ## 1.1.20 (2026-02-01)
443
+ - automation of tags, version etc using only the makefile
444
+ - update newer version of python
445
+ ## 1.1.14 (2025-12-02)
446
+ - Add CHANGELOG to the pip page
447
+ - Bug fixing for non autoregressive models
448
+ - Added TimesNet, TimeKAN
449
+ - Added 0 shot and full shot TTM
450
+ - added more option parameter to define an experiment (`split_params`, `optim_config` and `train_config`)
451
+ ## 1.1.13 (2025-12-02)
452
+
453
+ - Added weight for the WeightedRandomSampler (only for the training part)
454
+ - Bug fixing when using groups in the categorical variables
455
+ - TTM fixed for working with zeropad for shorter sequences and future covariates
456
+
457
+ ## 1.1.12 (2025-11-07)
458
+ - Bug fixing dynamo stuff for `TTM`
459
+ - Bug fixing loading weights after training process ('dynamo module can not load weights`)
460
+ - Force to not compile some models (there are piece of code that are not aligned with dynamo)
461
+ - Bug fixing test configurations
462
+
463
+ ## 1.1.11 (2025-11-06)
464
+ - Added `torch.compile` for better performance on recent GPU
465
+ - Stable `TTM` model according to version 1.1.5, still under debug, use at your own risk
466
+ - Bux Fixing `cprs` inference (now produces 3 quantiles: `[0.05, 0.5, 0.95]`). The `persistence_weight` is the value of `alpha` in the paper (between 0 and 1)
467
+
468
+ ## 1.1.9 (2025-09-19)
469
+ - Added `cprs` https://arxiv.org/pdf/2412.15832v1 loss function. In this case use the quantile parameter to ask for the ensembles: `quantiles = [1,2,3,4,5,6,7,8,9,10]` will create 10 ensembles. For now the inference part will return just the mean, TODO: estimate a confidence interval with the ensembles
470
+ - Added `long_lag` the L1 error will be modulated with a linear weight depending on the lag in the future: the penalization goes from `1` to `persistence_weight`
471
+
472
+ ## 1.1.8 (2025-09-12)
473
+ - Added `Simple` model (just two linear layers)
474
+
475
+ ## 1.1.7 (2025-09-08)
476
+ - bug fixing `DilatedConv`
477
+ ## 1.1.5 (2025-08-29)
478
+ - rewriting most of the modules for handling different future and past categorical variables
479
+ - extension of categorical and future covariates in almost all the models
480
+ - `uv` full management of the package
481
+ - refactoring almost all the structure and documentation
482
+
483
+ ## 1.1.4 (2025-08-22)
484
+ - added `restart: true` tro model configuration to restart the training procedure: carefurl the max_epochs should be increased if you need to retrain
485
+
486
+ ## 1.1.4 (2025-07-29)
487
+ - bug fixing tuner learning rate
488
+ - added TTM model and TimeXer
489
+ - added compatibility with newer version of lightening and torch
490
+
491
+ ## 1.1.1
492
+ - added [SAM optimizer](https://arxiv.org/pdf/2402.10198)
493
+ ```bash
494
+ python train.py --config-dir=config_test --config-name=config architecture=itransformer dataset.path=/home/agobbi/Projects/ExpTS/data train_config.dirpath=tmp inference=tmp model_configs.optim=SAM +optim_config.rho=0.5
495
+ ```