Time index as inputs in forward
Closed this issue · 5 comments
Hello. I'm doing load forecasting, and some algorithms suggest using day and hour indexes as input variables for models since periodicity is quite essential.
I must change the method __getitem__
in the SpatioTemporalDataset
class since the return should include the day and hour index.
Do you have any other suggestions for solving this problem? If not, would you be open to including this feature?
Thank you very much.
Best regards,
Viet
Hi. You can include any covariate you want in a batch. Checkout, eg, the traffic forecasting example at line 108.
Hi. Thank you a lot for your suggestion. I intend to use time index to learn the temporal representation similar to Node Embedding (lookup table). Would like to test that and come back if there is any problem.
Hi Viet, in our implementation of the STID model we do something similar to what you're looking for. I suggest you check out lines:
tsl/tsl/nn/models/temporal/stid_model.py
Lines 62 to 67 in f9e5081
and
tsl/tsl/nn/models/temporal/stid_model.py
Lines 130 to 139 in f9e5081
In this case, u
is the one-hot encoding of the temporal variables.
I apologize, actually an element in u
is a scalar, i.e., the index of the corresponding temporal element. Here's an example code to obtain it directly from a tsl.datasets.DatetimeDataset
with the method datetime_idx
:
# encode time of the day and use it as exogenous variable
day_enc = dataset.datetime_idx('weekday').values
slot_enc = dataset.datetime_idx(['hour', 'minute']).values
slot_enc[:, 0] *= (slot_enc[:, 1].max() + 1)
slot_enc = slot_enc.sum(1, keepdims=True)
covariates = {'u': np.concatenate([day_enc, slot_enc], -1)}
Thank you for your suggestions. That works very well.