Can I use a transformer or attention model with time series of different timeframes? For…
- User
Can I use a transformer or attention model with time series of different timeframes? For example, I have 4 time series with daily data and also monthly forecasts of 5 other variables for each one of the dates in daily data.
- Assistant
Yes, it is possible to use a transformer or attention model with time series of different timeframes. This is known as multi-resolution modeling or hierarchical modeling.
In your example, you have 4 time series with daily data and monthly forecasts of 5 other variables for each one of the dates in the daily data. You can use the daily data as the high-resolution time series and the monthly forecasts as the low-resolution time series. The idea is to use the low-resolution time series to provide context to the high-resolution time series. This is similar to how humans use different levels of abstraction to reason about the world.
One approach to implementing multi-resolution modeling is to use a multi-input model that takes both the high-resolution time series and the low-resolution time series as input. The low-resolution time series can be passed through a separate embedding layer before being combined with the high-resolution time series. The model can then use attention mechanisms to attend to both the high-resolution and low-resolution time series when making predictions.
- User
Can you write a python script for that?
- Assistant
Certainly! Here's an example Python script for implementing a multi-input model with a transformer architecture that can handle time series of different timeframes.
Assuming you have four daily time series data
X_dailyand five monthly forecast dataX_monthlyfor each date inX_daily, the input data shape would be and , respectively. - User
Can you add volatility modelling in this example? I'd like to generate a probability range for the output forecasts, not only a single point.
- Assistant
- User
You didn't finish the sentence
- Assistant
I apologize for that mistake. Here's the complete sentence:
We convert the variance to standard deviation and sample from the predicted Gaussian distribution to generate probabilistic forecasts. We can then compute the lower and upper bounds of a prediction interval, such as the 95% interval, to provide a range of possible outcomes.