Showing posts with label time series. Show all posts
Showing posts with label time series. Show all posts

Saturday, September 14, 2024

traffic prediction

 

https://arxiv.org/abs/2409.03282

Interpretable mixture of experts for time series prediction under recurrent and non-recurrent conditions


temporal fusion transformer (TFT)

Time Features:

  • Time of day (cyclic encoding)
  • Day of week (cyclic encoding)
  • Month of year (cyclic encoding)
  • Holiday indicator (binary)

The Temporal Fusion Transformer (TFT) is a deep learning model designed for multi-horizon time series forecasting, which means it predicts future values over multiple time steps. It is particularly useful in scenarios involving complex temporal dependencies and multiple input features. TFT is both powerful for prediction and interpretable, making it stand out among time series forecasting models.

Key Components of TFT:

  1. Variable Selection:

    • TFT dynamically selects relevant features (both static and time-varying) that are important for making predictions at each time step. This is done using a gated residual network which assigns importance weights to different features. It allows the model to focus on the most relevant inputs for prediction, enhancing interpretability.
  2. LSTM-based Encoder-Decoder:

    • TFT employs long short-term memory (LSTM) networks, a type of recurrent neural network, for encoding past data (in a context window) and decoding future data (in the prediction window). The LSTM captures temporal patterns from the input data, which are crucial for accurate forecasting.
  3. Multi-Head Attention:

    • One of the standout features of TFT is the use of multi-head attention, inspired by the Transformer model. This mechanism helps the model focus on different parts of the time series and various time steps. Attention helps identify important temporal dependencies, such as sudden changes or long-term trends, at multiple time points.
  4. Gating Mechanisms:

    • TFT uses gating mechanisms throughout the model to regulate how information flows through its layers. These gates help prevent irrelevant information from propagating forward, improving efficiency and reducing noise in predictions.
  5. Quantile Regression:

    • Instead of just predicting a single point estimate, TFT can output quantile predictions (e.g., predictions at the 10th, 50th, and 90th percentiles), making it possible to estimate uncertainties in the forecast. This is particularly helpful when making forecasts under uncertain or volatile conditions.

Interpretability in TFT:

TFT is designed with interpretability in mind. Two main methods of interpretation are:

  1. Feature Importance: TFT quantifies the importance of each input feature in predicting the target value. This allows users to understand which features, such as weather conditions, traffic incidents, or the time of day, play the most crucial role in predictions.
  2. Temporal Attention: By utilizing multi-head attention, TFT can show which time steps in the past (within the context window) are the most influential for making predictions at future time steps.

Why TFT is Suitable for Traffic Prediction:

  • Capturing Complex Temporal Dependencies: Traffic patterns often involve recurring trends (like rush hours) as well as non-recurring events (like accidents or severe weather). TFT’s attention mechanism helps capture both short-term and long-term dependencies between these events and traffic speed.
  • Interpretability: Understanding the factors that influence traffic speeds, such as weather or incidents, is crucial for decision-making. TFT’s interpretability allows for insights into how these features affect predictions in different conditions (recurrent vs. non-recurrent).
  • Multi-Source Inputs: TFT can efficiently handle multiple sources of data (like traffic incidents, weather conditions, etc.), making it well-suited for multi-variable prediction problems like traffic speed forecasting.

In this paper, TFT is used as the backbone for expert models in both recurrent and non-recurrent traffic prediction, benefiting from its ability to handle temporal dependencies and provide interpretability​.

Friday, March 18, 2022

Saturday, March 12, 2022

Augmented Dickey–Fuller test

null H0: unit root is present in a time series sample, ie non-stationary. 
alternative H1: stationary. 

Stationary means that the characteristic is not changing over time. 


Reference: 
https://en.wikipedia.org/wiki/Augmented_Dickey%E2%80%93Fuller_test
https://en.wikipedia.org/wiki/Stationary_process

Sunday, November 7, 2021

VAR: vector autoregression model

 VAR model

https://en.wikipedia.org/wiki/Vector_autoregression

A VAR model include a set of $k$ variables. 

"VAR models are characterized by their order, which refers to the number of earlier time periods the model will use. Continuing the above example, a 5th-order VAR would model each year's wheat price as a linear combination of the last five years of wheat prices. A lag is the value of a variable in a previous time period. So in general a pth-order VAR refers to a VAR model which includes lags for the last p time periods. A pth-order VAR is denoted "VAR(p)" and sometimes called "a VAR with p lags".

"The process of choosing the maximum lag p in the VAR model requires special attention because inference is dependent on correctness of the selected lag order.[2][3]"



Thursday, April 29, 2021

testing event effect in time series

 change point analysis can be applied. 

https://www.nature.com/articles/s41598-017-19067-2


https://www.researchgate.net/post/How_to_test_the_impact_of_single_event_ie_introducing_property_tax_on_housing_market_using_time_series_data

It seems that regression were discussed by treating the even as intervention. So, before and after t-test can be used. 

For covid19 analysis, we can co-integrate deaths ~ mobility with a window around holiday events. 



Sunday, April 25, 2021

time lag, Johansen test, perioditic time series

 

when random is linear, cross corelation on time lag only gave a gradual trend.  When periodic time series is gave, cross correlation gave an obvious cycling effect. 


see https://github.com/hongqin/cointegration-sandbox/blob/main/random-perioditic-walk.pdf













order of integration I(d)

 


Order of Integration I(d)

If you have unit roots in your time series, a series of successive differences, d, can transform the time series into one with stationarity. The differences are denoted by I(d), where d is the order of integration. Non-stationary time series that can be transformed in this way are called series integrated of order k. Usually, the order of integration is either I(0) or I(1); It’s rare to see values for d that are 2 or more.

From: https://www.statisticshowto.com/order-of-integration/

lag does not affect cointegration test

 



"Thus in theory you can test for cointegration either between y1,t and y2,t or y1,t and y2,th and the answer should be the same. Empirically the answer may differ, but hopefully you have a large enough sample so that it does not differ in your case."

Reference: 

https://stats.stackexchange.com/questions/285582/cointegration-with-lagged-variables

So, the lag is best analyzed from cross correlation analysis. 



Sunday, March 14, 2021

simulated time series of co-integration analysis

 

We might need to simulate two time series with pre-defined lag and linear combination to test co-integration analysis, 

 

For example, we can try: Y(t) = a * sin(X(t-DetlaT)) + b + noise

Where DeltaT is the lag. 

 

We can use Cross-correlation to verify the lag of DeltaT and linear combination. 


Wednesday, November 18, 2020

timeseries note, syed tareq



1)   A link on a write up for fitting time-series data is as follows:
            
                    http://people.duke.edu/~rnau/timereg.html

2)   Link of few articles written on model derivation on time-series data are as follows:



Wednesday, November 11, 2020

cointegration of time series


https://en.wikipedia.org/wiki/Cointegration  

https://en.wikipedia.org/wiki/Order_of_integration  

from arch import arch_model, #suggested by G-P Zhang. 


A drunk and her dog is a good article, by Michael Murray

  

Python library: 

https://pypi.org/project/arch/ 

import numpy as np import pandas as pd import seaborn import statsmodels import matplotlib.pyplot as plt from statsmodels.tsa.stattools import coint

https://bigquant.com/community/t/topic/167965 

R packages 

https://www.econometrics-with-r.org/16-3-cointegration.html 






Thursday, October 1, 2020

cross corelation

https://youtu.be/6ao9-39zw40

cross correlation between two time series

correlation is a linear measure of similarity between two signals. Cross-correlation is somewhat a generalization of the correlation measure as it takes into account the lag of one signal relative to the other. If lag == 0, then correlation = cross-correlation. Cross-correlation is particularly important to assess the causal relationship between two signals in time. If you suspect that there is a non-linear relationship between the two signals, then you should consider measures such as mutual information and partial mutual information, which are the information-theoretic equivalent of correlation and cross-correlation. 


You can refer to the comment above for information on how to compute correlation and cross-correlation. Check this paper instead (and references therein) for details on mutual information and partial mutual information http://www.sciencedirect.com/science/article/pii/S0022169400003462 https://youtu.be/6ao9-39zw40 https://youtu.be/L6YJqhbsuFY  

 ccf in R Ziwei Ma:
I checked the ccf function which calculates the correlation for x_{t+h} and y_t, so in our case, the ccf( dailyCases (x), dew_points (y) ) report they are positively relative, and the peak happen at arround 7 which says dailyCases lags dew_points or dew_points predict dailyCases in 7 days. 

The following website have more details there. https://online.stat.psu.edu/stat510/lesson/8/8.2

Wednesday, May 3, 2017

Saturday, January 21, 2017

Saturday, July 16, 2016

peak in auto correlatted time series


expression changes

auto correlation: curveA / curve B --> peak in the middle.

My LOH peak analysis is basically an auto-correlation of time-series

Wednesday, June 29, 2016

statistical tests on two arrays of dependent data (time series)

For two list of dependent data X and Y, we want to test X < Y.

The pairwised t-test is inappropriate because it violates independence assumption.

Bootstrap or permutation can only be used when there the list of observations are long.
For our H2O2-LOH dataset, we have only 10 time points (H2O2 doses), so bootstrap and permutation is inappropriate as well.

W Wu suggests that Fisher's exact test can be applied for each time point, and then apply Bonferroni correction. We think 3/4 LOH suggest a positive dependence between 1/2 and 1/4 LOH.



Tuesday, June 28, 2016

time series comparison



http://stats.stackexchange.com/questions/25228/testing-for-statistically-significant-difference-in-time-series

https://en.wikipedia.org/wiki/Bland%E2%80%93Altman_plot

http://www.r-bloggers.com/how-to-compare-two-blackbox-timeseries-generators/

Difference DID?
https://www.researchgate.net/post/How_do_I_compare_two_time_series_trends_in_terms_of_magnitude_of_decline_or_increase