Showing preview only (1,355K chars total). Download the full file or copy to clipboard to get everything.
Repository: thuml/Time-Series-Library
Branch: main
Commit: 7c2820986dcd
Files: 363
Total size: 1.2 MB
Directory structure:
gitextract_frlvujza/
├── .gitignore
├── CONTRIBUTING.md
├── Dockerfile
├── LICENSE
├── README.md
├── README_zh.md
├── data_provider/
│ ├── __init__.py
│ ├── data_factory.py
│ ├── data_loader.py
│ ├── m4.py
│ └── uea.py
├── docker-compose.yml
├── exp/
│ ├── __init__.py
│ ├── exp_anomaly_detection.py
│ ├── exp_basic.py
│ ├── exp_classification.py
│ ├── exp_imputation.py
│ ├── exp_long_term_forecasting.py
│ ├── exp_short_term_forecasting.py
│ └── exp_zero_shot_forecasting.py
├── layers/
│ ├── AutoCorrelation.py
│ ├── Autoformer_EncDec.py
│ ├── Conv_Blocks.py
│ ├── Crossformer_EncDec.py
│ ├── DWT_Decomposition.py
│ ├── ETSformer_EncDec.py
│ ├── Embed.py
│ ├── FourierCorrelation.py
│ ├── MSGBlock.py
│ ├── MambaBlock.py
│ ├── MultiWaveletCorrelation.py
│ ├── Pyraformer_EncDec.py
│ ├── SelfAttention_Family.py
│ ├── StandardNorm.py
│ ├── TimeFilter_layers.py
│ ├── Transformer_EncDec.py
│ └── __init__.py
├── models/
│ ├── Autoformer.py
│ ├── Chronos.py
│ ├── Chronos2.py
│ ├── Crossformer.py
│ ├── DLinear.py
│ ├── ETSformer.py
│ ├── FEDformer.py
│ ├── FiLM.py
│ ├── FreTS.py
│ ├── Informer.py
│ ├── KANAD.py
│ ├── Koopa.py
│ ├── LightTS.py
│ ├── MICN.py
│ ├── MSGNet.py
│ ├── Mamba.py
│ ├── MambaSimple.py
│ ├── MambaSingleLayer.py
│ ├── Moirai.py
│ ├── MultiPatchFormer.py
│ ├── Nonstationary_Transformer.py
│ ├── PAttn.py
│ ├── PatchTST.py
│ ├── Pyraformer.py
│ ├── Reformer.py
│ ├── SCINet.py
│ ├── SegRNN.py
│ ├── Sundial.py
│ ├── TSMixer.py
│ ├── TemporalFusionTransformer.py
│ ├── TiDE.py
│ ├── TiRex.py
│ ├── TimeFilter.py
│ ├── TimeMixer.py
│ ├── TimeMoE.py
│ ├── TimeXer.py
│ ├── TimesFM.py
│ ├── TimesNet.py
│ ├── Transformer.py
│ ├── WPMixer.py
│ ├── __init__.py
│ └── iTransformer.py
├── requirements.txt
├── run.py
├── scripts/
│ ├── anomaly_detection/
│ │ ├── MSL/
│ │ │ ├── Autoformer.sh
│ │ │ ├── Crossformer.sh
│ │ │ ├── DLinear.sh
│ │ │ ├── ETSformer.sh
│ │ │ ├── FEDformer.sh
│ │ │ ├── FiLM.sh
│ │ │ ├── Informer.sh
│ │ │ ├── KANAD.sh
│ │ │ ├── LightTS.sh
│ │ │ ├── MICN.sh
│ │ │ ├── Pyraformer.sh
│ │ │ ├── Reformer.sh
│ │ │ ├── TimesNet.sh
│ │ │ ├── Transformer.sh
│ │ │ └── iTransformer.sh
│ │ ├── PSM/
│ │ │ ├── Autoformer.sh
│ │ │ ├── DLinear.sh
│ │ │ ├── KANAD.sh
│ │ │ ├── TimesNet.sh
│ │ │ └── Transformer.sh
│ │ ├── SMAP/
│ │ │ ├── Autoformer.sh
│ │ │ ├── KANAD.sh
│ │ │ ├── TimesNet.sh
│ │ │ └── Transformer.sh
│ │ ├── SMD/
│ │ │ ├── Autoformer.sh
│ │ │ ├── KANAD.sh
│ │ │ ├── TimesNet.sh
│ │ │ └── Transformer.sh
│ │ └── SWAT/
│ │ ├── Autoformer.sh
│ │ ├── KANAD.sh
│ │ ├── TimesNet.sh
│ │ └── Transformer.sh
│ ├── classification/
│ │ ├── Autoformer.sh
│ │ ├── Crossformer.sh
│ │ ├── DLinear.sh
│ │ ├── ETSformer.sh
│ │ ├── FEDformer.sh
│ │ ├── FiLM.sh
│ │ ├── Informer.sh
│ │ ├── LightTS.sh
│ │ ├── MICN.sh
│ │ ├── MambaSL.out
│ │ ├── MambaSL.sh
│ │ ├── PatchTST.sh
│ │ ├── Pyraformer.sh
│ │ ├── Reformer.sh
│ │ ├── TimesNet.sh
│ │ ├── Transformer.sh
│ │ └── iTransformer.sh
│ ├── exogenous_forecast/
│ │ ├── ECL/
│ │ │ └── TimeXer.sh
│ │ ├── EPF/
│ │ │ └── TimeXer.sh
│ │ ├── ETTh1/
│ │ │ └── TimeXer.sh
│ │ ├── ETTh2/
│ │ │ └── TimeXer.sh
│ │ ├── ETTm1/
│ │ │ └── TimeXer.sh
│ │ ├── ETTm2/
│ │ │ └── TimeXer.sh
│ │ ├── Traffic/
│ │ │ └── TimeXer.sh
│ │ └── Weather/
│ │ └── TimeXer.sh
│ ├── imputation/
│ │ ├── ECL_script/
│ │ │ ├── Autoformer.sh
│ │ │ ├── DLinear.sh
│ │ │ ├── ETSformer.sh
│ │ │ ├── FEDformer.sh
│ │ │ ├── Informer.sh
│ │ │ ├── LightTS.sh
│ │ │ ├── Pyraformer.sh
│ │ │ ├── Reformer.sh
│ │ │ ├── TimesNet.sh
│ │ │ ├── Transformer.sh
│ │ │ └── iTransformer.sh
│ │ ├── ETT_script/
│ │ │ ├── Autoformer_ETTh1.sh
│ │ │ ├── Autoformer_ETTh2.sh
│ │ │ ├── Autoformer_ETTm1.sh
│ │ │ ├── Autoformer_ETTm2.sh
│ │ │ ├── Crossformer_ETTh1.sh
│ │ │ ├── DLinear_ETTh1.sh
│ │ │ ├── FiLM_ETTh1.sh
│ │ │ ├── MICN_ETTh1.sh
│ │ │ ├── Nonstationary_Transformer_ETTh1.sh
│ │ │ ├── TiDE_ETTh1.sh
│ │ │ ├── TimesNet_ETTh1.sh
│ │ │ ├── TimesNet_ETTh2.sh
│ │ │ ├── TimesNet_ETTm1.sh
│ │ │ ├── TimesNet_ETTm2.sh
│ │ │ ├── Transformer_ETTh1.sh
│ │ │ ├── Transformer_ETTh2.sh
│ │ │ ├── Transformer_ETTm1.sh
│ │ │ ├── Transformer_ETTm2.sh
│ │ │ └── iTransformer_ETTh2.sh
│ │ └── Weather_script/
│ │ ├── Autoformer.sh
│ │ ├── TimesNet.sh
│ │ └── Transformer.sh
│ ├── long_term_forecast/
│ │ ├── AugmentSample/
│ │ │ ├── Classification/
│ │ │ │ └── PatchTST.sh
│ │ │ ├── Forecasting/
│ │ │ │ └── PatchTST.sh
│ │ │ └── ReadMe.md
│ │ ├── ECL_script/
│ │ │ ├── Autoformer.sh
│ │ │ ├── Crossformer.sh
│ │ │ ├── DLinear.sh
│ │ │ ├── ETSformer.sh
│ │ │ ├── FEDformer.sh
│ │ │ ├── FiLM.sh
│ │ │ ├── Informer.sh
│ │ │ ├── Koopa.sh
│ │ │ ├── LightTS.sh
│ │ │ ├── MICN.sh
│ │ │ ├── Mamba.sh
│ │ │ ├── MultiPatchFormer.sh
│ │ │ ├── Nonstationary_Transformer.sh
│ │ │ ├── PatchTST.sh
│ │ │ ├── Pyraformer.sh
│ │ │ ├── Reformer.sh
│ │ │ ├── SegRNN.sh
│ │ │ ├── TSMixer.sh
│ │ │ ├── TimeMixer.sh
│ │ │ ├── TimeXer.sh
│ │ │ ├── TimesNet.sh
│ │ │ ├── Transformer.sh
│ │ │ ├── WPMixer.sh
│ │ │ └── iTransformer.sh
│ │ ├── ETT_script/
│ │ │ ├── Autoformer_ETTh1.sh
│ │ │ ├── Autoformer_ETTh2.sh
│ │ │ ├── Autoformer_ETTm1.sh
│ │ │ ├── Autoformer_ETTm2.sh
│ │ │ ├── Crossformer_ETTh1.sh
│ │ │ ├── Crossformer_ETTh2.sh
│ │ │ ├── Crossformer_ETTm1.sh
│ │ │ ├── Crossformer_ETTm2.sh
│ │ │ ├── DLinear_ETTh1.sh
│ │ │ ├── ETSformer_ETTh1.sh
│ │ │ ├── FEDformer_ETTh1.sh
│ │ │ ├── FiLM_ETTh1.sh
│ │ │ ├── FiLM_ETTh2.sh
│ │ │ ├── FiLM_ETTm1.sh
│ │ │ ├── FiLM_ETTm2.sh
│ │ │ ├── Informer_ETTh1.sh
│ │ │ ├── Koopa_ETTh1.sh
│ │ │ ├── Koopa_ETTh2.sh
│ │ │ ├── Koopa_ETTm1.sh
│ │ │ ├── Koopa_ETTm2.sh
│ │ │ ├── LTSM.sh
│ │ │ ├── LightTS_ETTh1.sh
│ │ │ ├── MICN_ETTh1.sh
│ │ │ ├── MICN_ETTh2.sh
│ │ │ ├── MICN_ETTm1.sh
│ │ │ ├── MICN_ETTm2.sh
│ │ │ ├── MambaSimple_ETTh1.sh
│ │ │ ├── Mamba_ETT_all.sh
│ │ │ ├── Mamba_ETTh1.sh
│ │ │ ├── Mamba_ETTh2.sh
│ │ │ ├── Mamba_ETTm1.sh
│ │ │ ├── Mamba_ETTm2.sh
│ │ │ ├── MultiPatchFormer_ETTh1.sh
│ │ │ ├── MultiPatchFormer_ETTm1.sh
│ │ │ ├── Nonstationary_Transformer_ETTh1.sh
│ │ │ ├── Nonstationary_Transformer_ETTh2.sh
│ │ │ ├── Nonstationary_Transformer_ETTm1.sh
│ │ │ ├── Nonstationary_Transformer_ETTm2.sh
│ │ │ ├── PAttn_ETTh1.sh
│ │ │ ├── PatchTST_ETTh1.sh
│ │ │ ├── PatchTST_ETTh2.sh
│ │ │ ├── PatchTST_ETTm1.sh
│ │ │ ├── PatchTST_ETTm2.sh
│ │ │ ├── Pyraformer_ETTh1.sh
│ │ │ ├── Pyraformer_ETTh2.sh
│ │ │ ├── Pyraformer_ETTm1.sh
│ │ │ ├── Pyraformer_ETTm2.sh
│ │ │ ├── Reformer_ETTh1.sh
│ │ │ ├── SegRNN_ETTh1.sh
│ │ │ ├── SegRNN_ETTh2.sh
│ │ │ ├── SegRNN_ETTm1.sh
│ │ │ ├── SegRNN_ETTm2.sh
│ │ │ ├── TSMixer_ETTh1.sh
│ │ │ ├── TSMixer_ETTh2.sh
│ │ │ ├── TSMixer_ETTm1.sh
│ │ │ ├── TSMixer_ETTm2.sh
│ │ │ ├── TiDE_ETTh1.sh
│ │ │ ├── TimeMixer_ETTh1.sh
│ │ │ ├── TimeMixer_ETTh2.sh
│ │ │ ├── TimeMixer_ETTm1.sh
│ │ │ ├── TimeMixer_ETTm2.sh
│ │ │ ├── TimeXer_ETTh1.sh
│ │ │ ├── TimeXer_ETTh2.sh
│ │ │ ├── TimeXer_ETTm1.sh
│ │ │ ├── TimeXer_ETTm2.sh
│ │ │ ├── TimesNet_ETTh1.sh
│ │ │ ├── TimesNet_ETTh2.sh
│ │ │ ├── TimesNet_ETTm1.sh
│ │ │ ├── TimesNet_ETTm2.sh
│ │ │ ├── Transformer_ETTh1.sh
│ │ │ ├── Transformer_ETTh2.sh
│ │ │ ├── Transformer_ETTm1.sh
│ │ │ ├── Transformer_ETTm2.sh
│ │ │ ├── WPMixer_ETTh1.sh
│ │ │ ├── WPMixer_ETTh2.sh
│ │ │ ├── WPMixer_ETTm1.sh
│ │ │ ├── WPMixer_ETTm2.sh
│ │ │ └── iTransformer_ETTh2.sh
│ │ ├── Exchange_script/
│ │ │ ├── Autoformer.sh
│ │ │ ├── Crossformer.sh
│ │ │ ├── FiLM.sh
│ │ │ ├── Koopa.sh
│ │ │ ├── MICN.sh
│ │ │ ├── Mamba.sh
│ │ │ ├── Nonstationary_Transformer.sh
│ │ │ ├── PatchTST.sh
│ │ │ ├── Pyraformer.sh
│ │ │ ├── TimesNet.sh
│ │ │ └── Transformer.sh
│ │ ├── ILI_script/
│ │ │ ├── Autoformer.sh
│ │ │ ├── Crossformer.sh
│ │ │ ├── FiLM.sh
│ │ │ ├── Koopa.sh
│ │ │ ├── MICN.sh
│ │ │ ├── Nonstationary_Transformer.sh
│ │ │ ├── PatchTST.sh
│ │ │ ├── TimesNet.sh
│ │ │ └── Transformer.sh
│ │ ├── Mamba_all.sh
│ │ ├── Traffic_script/
│ │ │ ├── Autoformer.sh
│ │ │ ├── Crossformer.sh
│ │ │ ├── FiLM.sh
│ │ │ ├── Koopa.sh
│ │ │ ├── MICN.sh
│ │ │ ├── Mamba.sh
│ │ │ ├── MultiPatchFormer.sh
│ │ │ ├── Nonstationary_Transformer.sh
│ │ │ ├── PatchTST.sh
│ │ │ ├── Pyraformer.sh
│ │ │ ├── SegRNN.sh
│ │ │ ├── TSMixer.sh
│ │ │ ├── TimeMixer.sh
│ │ │ ├── TimeXer.sh
│ │ │ ├── TimesNet.sh
│ │ │ ├── Transformer.sh
│ │ │ ├── WPMixer.sh
│ │ │ └── iTransformer.sh
│ │ └── Weather_script/
│ │ ├── Autoformer.sh
│ │ ├── Crossformer.sh
│ │ ├── FiLM.sh
│ │ ├── MICN.sh
│ │ ├── Mamba.sh
│ │ ├── MultiPatchFormer.sh
│ │ ├── Nonstationary_Transformer.sh
│ │ ├── PatchTST.sh
│ │ ├── Pyraformer.sh
│ │ ├── SegRNN.sh
│ │ ├── TSMixer.sh
│ │ ├── TimeMixer.sh
│ │ ├── TimeXer.sh
│ │ ├── TimesNet.sh
│ │ ├── Transformer.sh
│ │ ├── WPMixer.sh
│ │ └── iTransformer.sh
│ └── short_term_forecast/
│ ├── Autoformer_M4.sh
│ ├── Crossformer_M4.sh
│ ├── DLinear_M4.sh
│ ├── ETSformer_M4.sh
│ ├── FEDformer_M4.sh
│ ├── FiLM_M4.sh
│ ├── Informer_M4.sh
│ ├── LightTS_M4.sh
│ ├── MICN_M4.sh
│ ├── Mamba_M4.sh
│ ├── Nonstationary_Transformer_M4.sh
│ ├── Pyraformer_M4.sh
│ ├── Reformer_M4.sh
│ ├── TSMixer_M4.sh
│ ├── TimeMixer_M4.sh
│ ├── TimesNet_M4.sh
│ ├── Transformer_M4.sh
│ └── iTransformer_M4.sh
├── tutorial/
│ └── TimesNet_tutorial.ipynb
└── utils/
├── ADFtest.py
├── __init__.py
├── augmentation.py
├── dtw.py
├── dtw_metric.py
├── losses.py
├── m4_summary.py
├── masking.py
├── metrics.py
├── print_args.py
├── timefeatures.py
└── tools.py
================================================
FILE CONTENTS
================================================
================================================
FILE: .gitignore
================================================
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
target/
# Jupyter Notebook
.ipynb_checkpoints
# IPython
profile_default/
ipython_config.py
# pyenv
.python-version
# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/
# Celery stuff
celerybeat-schedule
celerybeat.pid
# SageMath parsed files
*.sage.py
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
.dmypy.json
dmypy.json
# Pyre type checker
.pyre/
/scripts/long_term_forecast/Traffic_script/PatchTST1.sh
/backups/
/result.xlsx
/~$result.xlsx
/Time-Series-Library.zip
/temp.sh
.idea
/tv_result.xlsx
/test.py
/m4_results/
/test_results/
/PatchTST_results.xlsx
/seq_len_long_term_forecast/
/progress.xlsx
/scripts/short_term_forecast/PatchTST_M4.sh
/run_tv.py
/scripts/long_term_forecast/ETT_tv_script/
/dataset/
/data/
data_factory_all.py
data_loader_all.py
/scripts/short_term_forecast/tv_script/
/exp/exp_short_term_forecasting_tv.py
/exp/exp_long_term_forecasting_tv.py
/timesnetv2.xlsx
/scripts/anomaly_detection/tmp/
/scripts/imputation/tmp/
/utils/self_tools.py
/scripts/exp_scripts/
checkpoints/
results/
result_long_term_forecast.txt
result_anomaly_detection.txt
scripts/augmentation/
run_anylearn.py
environment.txt
================================================
FILE: CONTRIBUTING.md
================================================
## Instructions for Contributing to TSlib
Sincerely thanks to all the researchers who want to use or contribute to TSlib.
Since our team may not have enough time to fix all the bugs and catch up with the latest model, your contribution is essential to this project.
### (1) Fix Bug
You can directly propose a pull request and add detailed descriptions to the comment, such as [this pull request](https://github.com/thuml/Time-Series-Library/pull/498).
### (2) Add a new time series model
Thanks to creative researchers, extensive great TS models are presented, which advance this community significantly. If you want to add your model to TSlib, here are some instructions:
- Propose an issue to describe your model and give a link to your paper and official code. We will discuss whether your model is suitable for this library, such as [this issue](https://github.com/thuml/Time-Series-Library/issues/346).
- Propose a pull request in a similar style as TSlib, which means adding an additional file to ./models and providing corresponding scripts for reproduction, such as [this pull request](https://github.com/thuml/Time-Series-Library/pull/446).
Note: Given that there are a lot of TS models that have been proposed, we may not have enough time to judge which model can be a remarkable supplement to the current library. Thus, we decide ONLY to add the officially published paper to our library. Peer review can be a reliable criterion.
Thanks again for your valuable contributions.
================================================
FILE: Dockerfile
================================================
# syntax=docker/dockerfile:1.4
FROM pytorch/pytorch:2.5.1-cuda12.1-cudnn9-devel AS tslib
WORKDIR /workspace
ARG http_proxy
ARG https_proxy
ENV http_proxy=${http_proxy}
ENV https_proxy=${https_proxy}
ENV PYTHONPATH=/workspace/Time-Series-Library:$PYTHONPATH
COPY requirements.txt .
RUN --mount=type=cache,target=/root/.cache/pip \
pip install -r requirements.txt
# mamba-ssm (cxx11abiFALSE) (Time-Series-Library/models/Mamba.py)
RUN --mount=type=cache,target=/root/.cache/pip \
pip install https://github.com/state-spaces/mamba/releases/download/v2.2.6.post3/mamba_ssm-2.2.6.post3+cu12torch2.5cxx11abiFALSE-cp311-cp311-linux_x86_64.whl
# uni2ts (--no-deps)(Time-Series-Library/models/Moirai.py)
RUN --mount=type=cache,target=/root/.cache/pip \
pip install uni2ts --no-deps
COPY . .
CMD ["bash"]
================================================
FILE: LICENSE
================================================
MIT License
Copyright (c) 2021 THUML @ Tsinghua University
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
================================================
FILE: README.md
================================================
# Time Series Library (TSLib)
TSLib is an open-source library for deep learning researchers, especially for deep time series analysis.
> **中文文档**:[README_zh.md](./README_zh.md)
We provide a neat code base to evaluate advanced deep time series models or develop your model, which covers five mainstream tasks: **long- and short-term forecasting, imputation, anomaly detection, and classification.**
:triangular_flag_on_post:**News** (2025.12) Many thanks to the great work from [ailuntz](https://github.com/thuml/Time-Series-Library/pull/805), which provides an updated requirements and docker deployment, as well as a well-organized document. This is quite meaningful to this project and beginners.
:triangular_flag_on_post:**News** (2025.11) Considering the rapid development of Large Time Series Models (LTSMs), we have newly added a [[zero-shot forecasting]](https://github.com/thuml/Time-Series-Library/blob/main/exp/exp_zero_shot_forecasting.py) feature in TSLib. You can try [this script](https://github.com/thuml/Time-Series-Library/blob/main/scripts/long_term_forecast/ETT_script/LTSM.sh) to evaluate LTSMs.
:triangular_flag_on_post:**News** (2025.10) Given the recent confusion among researchers regarding minor improvements on standard benchmarks, we propose the [[Accuracy Law]](https://arxiv.org/abs/2510.02729) to characterize the objectives of deep time series forecasting tasks, which can be used to identify saturated datasets.
:triangular_flag_on_post:**News** (2024.10) We have included [[TimeXer]](https://arxiv.org/abs/2402.19072), which defined a practical forecasting paradigm: Forecasting with Exogenous Variables. Considering both practicability and computation efficiency, we believe the new forecasting paradigm defined in TimeXer can be the "right" task for future research.
:triangular_flag_on_post:**News** (2024.10) Our lab has open-sourced [[OpenLTM]](https://github.com/thuml/OpenLTM), which provides a distinct pretrain-finetuning paradigm compared to TSLib. If you are interested in Large Time Series Models, you may find this repository helpful.
:triangular_flag_on_post:**News** (2024.07) We wrote a comprehensive survey of [[Deep Time Series Models]](https://arxiv.org/abs/2407.13278) with a rigorous benchmark based on TSLib. In this paper, we summarized the design principles of current time series models supported by insightful experiments, hoping to be helpful to future research.
:triangular_flag_on_post:**News** (2024.04) Many thanks for the great work from [frecklebars](https://github.com/thuml/Time-Series-Library/pull/378). The famous sequential model [Mamba](https://arxiv.org/abs/2312.00752) has been included in our library. See [this file](https://github.com/thuml/Time-Series-Library/blob/main/models/Mamba.py), where you need to install `mamba_ssm` with pip at first.
:triangular_flag_on_post:**News** (2024.03) Given the inconsistent look-back length of various papers, we split the long-term forecasting in the leaderboard into two categories: Look-Back-96 and Look-Back-Searching. We recommend researchers read [TimeMixer](https://openreview.net/pdf?id=7oLshfEIC2), which includes both look-back length settings in experiments for scientific rigor.
:triangular_flag_on_post:**News** (2023.10) We add an implementation to [iTransformer](https://arxiv.org/abs/2310.06625), which is the state-of-the-art model for long-term forecasting. The official code and complete scripts of iTransformer can be found [here](https://github.com/thuml/iTransformer).
:triangular_flag_on_post:**News** (2023.09) We added a detailed [tutorial](https://github.com/thuml/Time-Series-Library/blob/main/tutorial/TimesNet_tutorial.ipynb) for [TimesNet](https://openreview.net/pdf?id=ju_Uqw384Oq) and this library, which is quite friendly to beginners of deep time series analysis.
:triangular_flag_on_post:**News** (2023.02) We release the TSlib as a comprehensive benchmark and code base for time series models, which is extended from our previous GitHub repository [Autoformer](https://github.com/thuml/Autoformer).
## Leaderboard for Time Series Analysis
Till March 2024, the top three models for five different tasks are:
| Model<br>Ranking | Long-term<br>Forecasting<br>Look-Back-96 | Long-term<br/>Forecasting<br/>Look-Back-Searching | Short-term<br>Forecasting | Imputation | Classification | Anomaly<br>Detection |
| ---------------- | ----------------------------------------------------- | ----------------------------------------------------- | ------------------------------------------------------------ | ------------------------------------------------------------ | ------------------------------------------------------------ | -------------------------------------------------- |
| 🥇 1st | [TimeXer](https://arxiv.org/abs/2402.19072) | [TimeMixer](https://openreview.net/pdf?id=7oLshfEIC2) | [TimesNet](https://arxiv.org/abs/2210.02186) | [TimesNet](https://arxiv.org/abs/2210.02186) | [TimesNet](https://arxiv.org/abs/2210.02186) | [TimesNet](https://arxiv.org/abs/2210.02186) |
| 🥈 2nd | [iTransformer](https://arxiv.org/abs/2310.06625) | [PatchTST](https://github.com/yuqinie98/PatchTST) | [Non-stationary<br/>Transformer](https://github.com/thuml/Nonstationary_Transformers) | [Non-stationary<br/>Transformer](https://github.com/thuml/Nonstationary_Transformers) | [Non-stationary<br/>Transformer](https://github.com/thuml/Nonstationary_Transformers) | [FEDformer](https://github.com/MAZiqing/FEDformer) |
| 🥉 3rd | [TimeMixer](https://openreview.net/pdf?id=7oLshfEIC2) | [DLinear](https://arxiv.org/pdf/2205.13504.pdf) | [FEDformer](https://github.com/MAZiqing/FEDformer) | [Autoformer](https://github.com/thuml/Autoformer) | [Informer](https://github.com/zhouhaoyi/Informer2020) | [Autoformer](https://github.com/thuml/Autoformer) |
**Note: We will keep updating this leaderboard.** If you have proposed advanced and awesome models, you can send us your paper/code link or raise a pull request. We will add them to this repo and update the leaderboard as soon as possible.
**Compared models of this leaderboard.** ☑ means that their codes have already been included in this repo.
- [x] **TimeXer** - TimeXer: Empowering Transformers for Time Series Forecasting with Exogenous Variables [[NeurIPS 2024]](https://arxiv.org/abs/2402.19072) [[Code]](https://github.com/thuml/Time-Series-Library/blob/main/models/TimeXer.py)
- [x] **TimeMixer** - TimeMixer: Decomposable Multiscale Mixing for Time Series Forecasting [[ICLR 2024]](https://openreview.net/pdf?id=7oLshfEIC2) [[Code]](https://github.com/thuml/Time-Series-Library/blob/main/models/TimeMixer.py).
- [x] **TSMixer** - TSMixer: An All-MLP Architecture for Time Series Forecasting [[arXiv 2023]](https://arxiv.org/pdf/2303.06053.pdf) [[Code]](https://github.com/thuml/Time-Series-Library/blob/main/models/TSMixer.py)
- [x] **iTransformer** - iTransformer: Inverted Transformers Are Effective for Time Series Forecasting [[ICLR 2024]](https://arxiv.org/abs/2310.06625) [[Code]](https://github.com/thuml/Time-Series-Library/blob/main/models/iTransformer.py).
- [x] **PatchTST** - A Time Series is Worth 64 Words: Long-term Forecasting with Transformers [[ICLR 2023]](https://openreview.net/pdf?id=Jbdc0vTOcol) [[Code]](https://github.com/thuml/Time-Series-Library/blob/main/models/PatchTST.py).
- [x] **TimesNet** - TimesNet: Temporal 2D-Variation Modeling for General Time Series Analysis [[ICLR 2023]](https://openreview.net/pdf?id=ju_Uqw384Oq) [[Code]](https://github.com/thuml/Time-Series-Library/blob/main/models/TimesNet.py).
- [x] **DLinear** - Are Transformers Effective for Time Series Forecasting? [[AAAI 2023]](https://arxiv.org/pdf/2205.13504.pdf) [[Code]](https://github.com/thuml/Time-Series-Library/blob/main/models/DLinear.py).
- [x] **LightTS** - Less Is More: Fast Multivariate Time Series Forecasting with Light Sampling-oriented MLP Structures [[arXiv 2022]](https://arxiv.org/abs/2207.01186) [[Code]](https://github.com/thuml/Time-Series-Library/blob/main/models/LightTS.py).
- [x] **ETSformer** - ETSformer: Exponential Smoothing Transformers for Time-series Forecasting [[arXiv 2022]](https://arxiv.org/abs/2202.01381) [[Code]](https://github.com/thuml/Time-Series-Library/blob/main/models/ETSformer.py).
- [x] **Non-stationary Transformer** - Non-stationary Transformers: Exploring the Stationarity in Time Series Forecasting [[NeurIPS 2022]](https://openreview.net/pdf?id=ucNDIDRNjjv) [[Code]](https://github.com/thuml/Time-Series-Library/blob/main/models/Nonstationary_Transformer.py).
- [x] **FEDformer** - FEDformer: Frequency Enhanced Decomposed Transformer for Long-term Series Forecasting [[ICML 2022]](https://proceedings.mlr.press/v162/zhou22g.html) [[Code]](https://github.com/thuml/Time-Series-Library/blob/main/models/FEDformer.py).
- [x] **Pyraformer** - Pyraformer: Low-complexity Pyramidal Attention for Long-range Time Series Modeling and Forecasting [[ICLR 2022]](https://openreview.net/pdf?id=0EXmFzUn5I) [[Code]](https://github.com/thuml/Time-Series-Library/blob/main/models/Pyraformer.py).
- [x] **Autoformer** - Autoformer: Decomposition Transformers with Auto-Correlation for Long-Term Series Forecasting [[NeurIPS 2021]](https://openreview.net/pdf?id=I55UqU-M11y) [[Code]](https://github.com/thuml/Time-Series-Library/blob/main/models/Autoformer.py).
- [x] **Informer** - Informer: Beyond Efficient Transformer for Long Sequence Time-Series Forecasting [[AAAI 2021]](https://ojs.aaai.org/index.php/AAAI/article/view/17325/17132) [[Code]](https://github.com/thuml/Time-Series-Library/blob/main/models/Informer.py).
- [x] **Reformer** - Reformer: The Efficient Transformer [[ICLR 2020]](https://openreview.net/forum?id=rkgNKkHtvB) [[Code]](https://github.com/thuml/Time-Series-Library/blob/main/models/Reformer.py).
- [x] **Transformer** - Attention is All You Need [[NeurIPS 2017]](https://proceedings.neurips.cc/paper/2017/file/3f5ee243547dee91fbd053c1c4a845aa-Paper.pdf) [[Code]](https://github.com/thuml/Time-Series-Library/blob/main/models/Transformer.py).
See our latest paper [[TimesNet]](https://arxiv.org/abs/2210.02186) for the comprehensive benchmark. We will release a real-time updated online version soon.
**Newly added baselines.** We will add them to the leaderboard after a comprehensive evaluation.
- [x] **MambaSL** - MambaSL: Exploring Single-Layer Mamba for Time Series Classification [[ICLR 2026]](https://openreview.net/forum?id=YDl4vqQqGP) [[Code]](https://github.com/thuml/Time-Series-Library/blob/main/models/MambaSingleLayer.py)
- [x] **TimeFilter** - TimeFilter: Patch-Specific Spatial-Temporal Graph Filtration for Time Series Forecasting [[ICML 2025]](https://arxiv.org/abs/2501.13041) [[Code]](https://github.com/thuml/Time-Series-Library/blob/main/models/TimeFilter.py)
- [x] **KAN-AD** - KAN-AD: Time Series Anomaly Detection with Kolmogorov-Arnold Networks [[ICML 2025]](https://arxiv.org/abs/2411.00278) [[Code]](https://github.com/thuml/Time-Series-Library/blob/main/models/KANAD.py)
- [x] **MultiPatchFormer** - A multiscale model for multivariate time series forecasting [[Scientific Reports 2025]](https://www.nature.com/articles/s41598-024-82417-4) [[Code]](https://github.com/thuml/Time-Series-Library/blob/main/models/MultiPatchFormer.py)
- [x] **WPMixer** - WPMixer: Efficient Multi-Resolution Mixing for Long-Term Time Series Forecasting [[AAAI 2025]](https://arxiv.org/abs/2412.17176) [[Code]](https://github.com/thuml/Time-Series-Library/blob/main/models/WPMixer.py)
- [x] **MSGNet** - MSGNet: Learning Multi-Scale Inter-Series Correlations for Multivariate Time Series Forecasting [[AAAI 2024]](https://dl.acm.org/doi/10.1609/aaai.v38i10.28991) [[Code]](https://github.com/thuml/Time-Series-Library/blob/main/models/MSGNet.py)
- [x] **PAttn** - Are Language Models Actually Useful for Time Series Forecasting? [[NeurIPS 2024]](https://arxiv.org/pdf/2406.16964) [[Code]](https://github.com/thuml/Time-Series-Library/blob/main/models/PAttn.py)
- [x] **Mamba** - Mamba: Linear-Time Sequence Modeling with Selective State Spaces [[arXiv 2023]](https://arxiv.org/abs/2312.00752) [[Code]](https://github.com/thuml/Time-Series-Library/blob/main/models/Mamba.py)
- [x] **SegRNN** - SegRNN: Segment Recurrent Neural Network for Long-Term Time Series Forecasting [[arXiv 2023]](https://arxiv.org/abs/2308.11200.pdf) [[Code]](https://github.com/thuml/Time-Series-Library/blob/main/models/SegRNN.py).
- [x] **Koopa** - Koopa: Learning Non-stationary Time Series Dynamics with Koopman Predictors [[NeurIPS 2023]](https://arxiv.org/pdf/2305.18803.pdf) [[Code]](https://github.com/thuml/Time-Series-Library/blob/main/models/Koopa.py).
- [x] **FreTS** - Frequency-domain MLPs are More Effective Learners in Time Series Forecasting [[NeurIPS 2023]](https://arxiv.org/pdf/2311.06184.pdf) [[Code]](https://github.com/thuml/Time-Series-Library/blob/main/models/FreTS.py).
- [x] **MICN** - MICN: Multi-scale Local and Global Context Modeling for Long-term Series Forecasting [[ICLR 2023]](https://openreview.net/pdf?id=zt53IDUR1U)[[Code]](https://github.com/thuml/Time-Series-Library/blob/main/models/MICN.py).
- [x] **Crossformer** - Crossformer: Transformer Utilizing Cross-Dimension Dependency for Multivariate Time Series Forecasting [[ICLR 2023]](https://openreview.net/pdf?id=vSVLM2j9eie)[[Code]](https://github.com/thuml/Time-Series-Library/blob/main/models/Crossformer.py).
- [x] **TiDE** - Long-term Forecasting with TiDE: Time-series Dense Encoder [[arXiv 2023]](https://arxiv.org/pdf/2304.08424.pdf) [[Code]](https://github.com/thuml/Time-Series-Library/blob/main/models/TiDE.py).
- [x] **SCINet** - SCINet: Time Series Modeling and Forecasting with Sample Convolution and Interaction [[NeurIPS 2022]](https://openreview.net/pdf?id=AyajSjTAzmg)[[Code]](https://github.com/thuml/Time-Series-Library/blob/main/models/SCINet.py).
- [x] **FiLM** - FiLM: Frequency improved Legendre Memory Model for Long-term Time Series Forecasting [[NeurIPS 2022]](https://openreview.net/forum?id=zTQdHSQUQWc)[[Code]](https://github.com/thuml/Time-Series-Library/blob/main/models/FiLM.py).
- [x] **TFT** - Temporal Fusion Transformers for Interpretable Multi-horizon Time Series Forecasting [[arXiv 2019]](https://arxiv.org/abs/1912.09363)[[Code]](https://github.com/thuml/Time-Series-Library/blob/main/models/TemporalFusionTransformer.py).
**Newly added Large Time Series Models.** This library also supports the zero-shot evaluation of the following LTSMs.
- [x] **Chronos2** - Chronos-2: From Univariate to Universal Forecasting [[arXiv 2025]](https://arxiv.org/abs/2510.15821) [[Code]](https://github.com/thuml/Time-Series-Library/blob/main/models/Chronos2.py)
- [x] **TiRex** - TiRex: Zero-Shot Forecasting Across Long and Short Horizons with Enhanced In-Context Learning [[NeurIPS 2025]](https://arxiv.org/pdf/2505.23719) [[Code]](https://github.com/thuml/Time-Series-Library/blob/main/models/TiRex.py)
- [x] **Sundial** - Sundial: A Family of Highly Capable Time Series Foundation Models [[ICML 2025]](https://arxiv.org/pdf/2502.00816) [[Code]](https://github.com/thuml/Time-Series-Library/blob/main/models/Sundial.py)
- [x] **Time-MoE** - Time-MoE: Billion-Scale Time Series Foundation Models with Mixture of Experts [[ICLR 2025]](https://arxiv.org/pdf/2409.16040) [[Code]](https://github.com/thuml/Time-Series-Library/blob/main/models/TimeMoE.py)
- [x] **Toto** - Toto: Time Series Optimized Transformer for Observability [arXiv 2024](https://arxiv.org/pdf/2407.07874)
- [x] **Chronos** - Chronos: Learning the Language of Time Series [[TMLR 2024]](https://arxiv.org/pdf/2403.07815) [[Code]](https://github.com/thuml/Time-Series-Library/blob/main/models/Chronos.py)
- [x] **Moirai** - Unified Training of Universal Time Series Forecasting Transformers [[ICML 2024]](https://arxiv.org/pdf/2402.02592)
- [x] **TimesFM** - A decoder-only foundation model for time-series forecasting [[ICML 2024]](https://arxiv.org/abs/2310.10688) [[Code]](https://github.com/thuml/Time-Series-Library/blob/main/models/TimesFM.py)
## Getting Started
### Prepare Data
You can obtain the well-preprocessed datasets from [[Google Drive]](https://drive.google.com/drive/folders/13Cg1KYOlzM5C7K8gK8NfC-F3EYxkM3D2?usp=sharing), [[Baidu Drive]](https://pan.baidu.com/s/1r3KhGd0Q9PJIUZdfEYoymg?pwd=i9iy) or [[Hugging Face]](https://huggingface.co/datasets/thuml/Time-Series-Library). Then place the downloaded data in the folder `./dataset`.
### Installation
1. Clone this repository.
```bash
git clone https://github.com/thuml/Time-Series-Library.git
cd Time-Series-Library
```
2. Create a new Conda environment.
```bash
conda create -n tslib python=3.11
conda activate tslib
```
3. Install Core Dependencies
> ⚠️ **CUDA Compatibility Notice**
> The torch prebuilt package is **CUDA-version specific**. (See https://pytorch.org/get-started/previous-versions/)
> Please make sure to install the package that matches your local CUDA version (e.g., `cu118` or `cu121`).
> Recommended: torch==2.5.1
```bash
pip install torch==2.5.1 --index-url https://download.pytorch.org/whl/cu121
pip install -r requirements.txt
```
4. Install Dependencies for Mamba Model (Required for Time-Series-Library/models/Mamba.py)
> ⚠️ **Linux only**
> ⚠️ **CUDA Compatibility Notice**
> The prebuilt Mamba wheel is **CUDA-version specific**.
> Please make sure to install the wheel that matches your local CUDA version
> (e.g., `cu11` or `cu12`). Installing a mismatched version may result in
> runtime errors or import failures.
Example for **CUDA 12**:
```bash
pip install https://github.com/state-spaces/mamba/releases/download/v2.2.6.post3/mamba_ssm-2.2.6.post3+cu12torch2.5cxx11abiFALSE-cp311-cp311-linux_x86_64.whl
```
5. Install Dependencies for Moirai Model (Required for Time-Series-Library/models/Moirai.py)
```bash
pip install uni2ts --no-deps
```
### Docker Deployment
```bash
# Build and start the Docker container in detached mode
docker compose -f 'Time-Series-Library/docker-compose.yml' up -d --build
# Download / place the dataset into a newly created folder ./dataset at the repository root
mkdir -p dataset # create the dataset directory
# Copy the local dataset into the container at /workspace/dataset
docker cp ./dataset tslib:/workspace/dataset
# Enter the running container to continue training / evaluation
docker exec -it tslib bash
# Switch to the workspace directory inside the container
cd /workspace
# Run zero-shot forecasting with the pre-trained Moirai model
python -u run.py \
--task_name zero_shot_forecast \ # task type: zero-shot forecasting
--is_training 0 \ # 0 = inference only (no training)
--root_path ./dataset/ETT-small/ \ # root directory of the dataset
--data_path ETTh1.csv \ # dataset file name
--model_id ETTh1_512_96 \ # experiment/model identifier
--model Moirai \ # model name (TimesFM / Moirai)
--data ETTh1 \ # dataset name
--features M \ # multivariate forecasting
--seq_len 512 \ # input sequence length
--pred_len 96 \ # prediction horizon
--enc_in 7 \ # number of input variables
--des 'Exp' \ # experiment description
--itr 1 # number of runs
```
### Quick Test
Quick test for all 5 tasks (1 epoch each):
```bash
# Run quick tests for all 5 tasks
export CUDA_VISIBLE_DEVICES=0
# 1. Long-term forecasting
python -u run.py --task_name long_term_forecast --is_training 1 --root_path ./dataset/ETT-small/ --data_path ETTh1.csv --model_id test_long --model DLinear --data ETTh1 --features M --seq_len 96 --pred_len 96 --enc_in 7 --dec_in 7 --c_out 7 --train_epochs 1 --num_workers 2
# 2. Short-term forecasting (using ETT dataset with shorter prediction length)
python -u run.py --task_name long_term_forecast --is_training 1 --root_path ./dataset/ETT-small/ --data_path ETTh1.csv --model_id test_short --model TimesNet --data ETTh1 --features M --seq_len 24 --label_len 12 --pred_len 24 --e_layers 2 --d_layers 1 --d_model 16 --d_ff 32 --enc_in 7 --dec_in 7 --c_out 7 --top_k 5 --train_epochs 1 --num_workers 2
# 3. Imputation
python -u run.py --task_name imputation --is_training 1 --root_path ./dataset/ETT-small/ --data_path ETTh1.csv --model_id test_imp --model TimesNet --data ETTh1 --features M --seq_len 96 --e_layers 2 --d_layers 1 --d_model 16 --d_ff 32 --enc_in 7 --dec_in 7 --c_out 7 --top_k 3 --train_epochs 1 --num_workers 2 --label_len 0 --pred_len 0 --mask_rate 0.125 --learning_rate 0.001
# 4. Anomaly detection
python -u run.py --task_name anomaly_detection --is_training 1 --root_path ./dataset/PSM --model_id test_ad --model TimesNet --data PSM --features M --seq_len 100 --pred_len 0 --d_model 64 --d_ff 64 --e_layers 2 --enc_in 25 --c_out 25 --anomaly_ratio 1.0 --top_k 3 --train_epochs 1 --batch_size 128 --num_workers 2
# 5. Classification
python -u run.py --task_name classification --is_training 1 --root_path ./dataset/Heartbeat/ --model_id Heartbeat --model TimesNet --data UEA --e_layers 2 --d_layers 1 --factor 3 --d_model 64 --d_ff 128 --top_k 3 --train_epochs 1 --batch_size 16 --learning_rate 0.001 --num_workers 0
```
### Train and Evaluate
We provide the experiment scripts for all benchmarks under the folder `./scripts/`. You can reproduce the experiment results as the following examples:
> ⚠️ Some scripts have `CUDA_VISIBLE_DEVICES` set by default. Please modify or remove this setting according to your actual GPU configuration, otherwise it may prevent GPU usage.
```bash
# long-term forecast
bash ./scripts/long_term_forecast/ETT_script/TimesNet_ETTh1.sh
# short-term forecast
bash ./scripts/short_term_forecast/TimesNet_M4.sh
# imputation
bash ./scripts/imputation/ETT_script/TimesNet_ETTh1.sh
# anomaly detection
bash ./scripts/anomaly_detection/PSM/TimesNet.sh
# classification
bash ./scripts/classification/TimesNet.sh
```
### Develop Your Own Model
- Add the model file to the folder `./models`. You can follow the `./models/Transformer.py`.
- Create the corresponding scripts under the folder `./scripts`.
### Note:
(1) About classification: Since we include all five tasks in a unified code base, the accuracy of each subtask may fluctuate but the average performance can be reproduced (even a bit better). We have provided the reproduced checkpoints [here](https://github.com/thuml/Time-Series-Library/issues/494).
(2) About anomaly detection: Some discussion about the adjustment strategy in anomaly detection can be found [here](https://github.com/thuml/Anomaly-Transformer/issues/14). The key point is that the adjustment strategy corresponds to an event-level metric.
### Inspect the project structure:
```
Time-Series-Library/
├── README.md # Official README with tasks, leaderboard, usage
├── requirements.txt # pip dependency list for quick environment setup
├── LICENSE / CONTRIBUTING.md # Upstream license and contribution guide
├── run.py # Unified entry that parses args and dispatches tasks
├── exp/ # Task pipelines wrapping train/val/test
│ ├── exp_basic.py # Experiment base class, registers models, builds flows
│ ├── exp_long_term_forecasting.py # Long-term forecasting logic
│ ├── exp_short_term_forecasting.py # Short-term forecasting logic
│ ├── exp_imputation.py # Missing-value imputation
│ ├── exp_anomaly_detection.py # Anomaly detection
│ ├── exp_classification.py # Classification
│ └── exp_zero_shot_forecasting.py # LTSM zero-shot evaluation
├── data_provider/ # Dataset loaders and splits
│ ├── data_factory.py # Chooses the proper DataLoader per task
│ ├── data_loader.py # Generic TS reader with sliding-window logic
│ ├── uea.py / m4.py # Parsers for UEA, M4 and other formats
│ └── __init__.py # Exposes factory interfaces upward
├── models/ # All model implementations
│ ├── TimesNet.py, TimeMixer.py # Main forecasting models
│ ├── Chronos2.py, TiRex.py # LTSM zero-shot models
│ └── __init__.py # Enables name-based instantiation inside exp
├── layers/ # Reusable attention / conv / embedding blocks
│ ├── Transformer_EncDec.py # Transformer stacks
│ ├── AutoCorrelation.py # Auto-correlation operator
│ ├── MultiWaveletCorrelation.py# Frequency-domain unit
│ └── Embed.py etc. # Shared primitives
├── utils/ # Utility toolbox
│ ├── metrics.py # MSE / MAE / DTW and other metrics
│ ├── tools.py # General helpers such as EarlyStopping
│ ├── augmentation.py # Augmentations for classification / detection
│ ├── print_args.py # Unified argument printer
│ └── masking.py / losses.py # Task-specific helpers
├── scripts/ # Bash recipes for reproducible experiments
│ ├── long_term_forecast/ # Long-term forecasting per dataset/model
│ ├── short_term_forecast/ # M4 and other short-term scripts
│ ├── imputation/ # Imputation scripts
│ ├── anomaly_detection/ # SMD / SMAP / SWAT detection scripts
│ ├── classification/ # UEA classification scripts
│ └── exogenous_forecast/ # TimeXer exogenous forecasting flow
├── tutorial/ # TimesNet tutorial notebook and figures
└── pic/ # README figures (dataset overview, etc.)
```
### Understand the project architecture:
- **E2E flow**: configure experiments via `scripts/*.sh` → run `python run.py ...` → `run.py` parses arguments and selects the proper `Exp_*` via `task_name` → the experiment builds datasets through `data_provider`, instantiates networks from `models`, and drives train/val/test with utilities in `utils` → metrics and checkpoints are written to `./checkpoints`.
- **Experiment layer (`exp/`)**: `Exp_Basic` registers models and devices; subclasses implement `_get_data`, `train`, and `test` to encapsulate task-specific differences so the same model can be reused.
- **Model & layer layer (`models/` + `layers/`)**: model files define architectures, while reusable attention/conv/frequency components live in `layers/` to minimize duplication.
- **Data layer (`data_provider/`)**: `data_factory` returns the correct `Dataset/DataLoader`; `data_loader` handles windowing, masking, and sampling, with arguments controlling window length, missing ratio, anomaly ratio, etc.
- **Script layer (`scripts/`)**: bash scripts capture paper configurations (dataset, window, model, GPU) for reproducibility and serve as templates for custom runs.
- **Utility layer (`utils/`)**: `metrics` centralizes evaluation, `tools` bundles essentials like `EarlyStopping` and `adjust_learning_rate`, while `augmentation`/`masking` cover task-specific preprocessing.
- **Learning path**: recommended reading order is `scripts -> run.py -> exp/exp_basic.py -> corresponding Exp subclass -> data_provider -> models`, using `tutorial/TimesNet_tutorial.ipynb` as a guided walkthrough before diving deeper.
## Citation
If you find this repo useful, please cite our paper.
```
@inproceedings{wu2023timesnet,
title={TimesNet: Temporal 2D-Variation Modeling for General Time Series Analysis},
author={Haixu Wu and Tengge Hu and Yong Liu and Hang Zhou and Jianmin Wang and Mingsheng Long},
booktitle={International Conference on Learning Representations},
year={2023},
}
@article{wang2024tssurvey,
title={Deep Time Series Models: A Comprehensive Survey and Benchmark},
author={Yuxuan Wang and Haixu Wu and Jiaxiang Dong and Yong Liu and Mingsheng Long and Jianmin Wang},
booktitle={arXiv preprint arXiv:2407.13278},
year={2024},
}
```
## Contact
If you have any questions or suggestions, feel free to contact our maintenance team:
Current:
- Haixu Wu (Ph.D., wuhaixu98@gmail.com)
- Yuxuan Wang (Ph.D. student, wangyuxu22@mails.tsinghua.edu.cn)
- Yong Liu (Ph.D. student, liuyong21@mails.tsinghua.edu.cn)
- Ailuntz (Student from Open-source Community, ailuntz@icloud.com)
Previous:
- Huikun Weng (Undergraduate, wenghk22@mails.tsinghua.edu.cn)
- Tengge Hu (Master student, htg21@mails.tsinghua.edu.cn)
- Haoran Zhang (Master student, z-hr20@mails.tsinghua.edu.cn)
- Jiawei Guo (Undergraduate, guo-jw21@mails.tsinghua.edu.cn)
Or describe it in Issues.
## Acknowledgement
This library is constructed based on the following repos:
- Forecasting: https://github.com/thuml/Autoformer.
- Anomaly Detection: https://github.com/thuml/Anomaly-Transformer.
- Classification: https://github.com/thuml/Flowformer.
All the experiment datasets are public, and we obtain them from the following links:
- Long-term Forecasting and Imputation: https://github.com/thuml/Autoformer.
- Short-term Forecasting: https://github.com/ServiceNow/N-BEATS.
- Anomaly Detection: https://github.com/thuml/Anomaly-Transformer.
- Classification: https://www.timeseriesclassification.com/.
## All Thanks To Our Contributors
<a href="https://github.com/thuml/Time-Series-Library/graphs/contributors">
<img src="https://contrib.rocks/image?repo=thuml/Time-Series-Library" />
</a>
================================================
FILE: README_zh.md
================================================
# 时间序列库(TSLib)
TSLib 是一个面向深度学习研究者的开源库,特别适用于深度时间序列分析。
> **English README**:[README.md](./README.md)
我们提供了一个整洁的代码库,用于评测先进的深度时间序列模型或开发自定义模型,覆盖 **长短期预测、插补、异常检测和分类** 等五大主流任务。
:triangular_flag_on_post:**最新动态**(2025.12)非常感谢 [ailuntz](https://github.com/thuml/Time-Series-Library/pull/805) 的杰出贡献,提供了更新的依赖要求和 Docker 部署,以及完善的文档。这对本项目和初学者都很有意义。
:triangular_flag_on_post:**最新动态**(2025.11)鉴于大型时间序列模型(LTSM)的快速发展,我们在 TSLib 中新增了[[零样本预测]](https://github.com/thuml/Time-Series-Library/blob/main/exp/exp_zero_shot_forecasting.py)功能,可参考 [此脚本](https://github.com/thuml/Time-Series-Library/blob/main/scripts/long_term_forecast/ETT_script/LTSM.sh) 评测 LTSM。
:triangular_flag_on_post:**最新动态**(2025.10)针对近期研究者在标准基准上追求微小提升而产生的困惑,我们提出了[[精度定律]](https://arxiv.org/abs/2510.02729),以刻画深度时间序列预测任务的目标,并可据此识别已饱和的数据集。
:triangular_flag_on_post:**最新动态**(2024.10)我们已纳入 [[TimeXer]](https://arxiv.org/abs/2402.19072),其定义了一个实用的预测范式:带外生变量的预测。考虑到实用性与计算效率,我们认为 TimeXer 所定义的新范式将成为未来研究的“正确”任务。
:triangular_flag_on_post:**最新动态**(2024.10)实验室已开源 [[OpenLTM]](https://github.com/thuml/OpenLTM),提供了有别于 TSLib 的预训练 - 微调范式。如果您对大型时间序列模型感兴趣,该仓库值得参考。
:triangular_flag_on_post:**最新动态**(2024.07)我们撰写了关于[[深度时间序列模型]](https://arxiv.org/abs/2407.13278)的综述,并基于 TSLib 构建了严谨的基准。论文总结了当前时间序列模型的设计原则,并通过深入实验验证,期望对未来研究有所帮助。
:triangular_flag_on_post:**最新动态**(2024.04)感谢 [frecklebars](https://github.com/thuml/Time-Series-Library/pull/378) 的贡献,著名的序列模型 [Mamba](https://arxiv.org/abs/2312.00752) 已加入本库。参见[该文件](https://github.com/thuml/Time-Series-Library/blob/main/models/Mamba.py),需要先用 pip 安装 `mamba_ssm`。
:triangular_flag_on_post:**最新动态**(2024.03)鉴于各论文使用的回溯窗口长度不一致,我们将排行榜中的长期预测拆分为 Look-Back-96 与 Look-Back-Searching 两类。建议阅读 [TimeMixer](https://openreview.net/pdf?id=7oLshfEIC2),其实验同时包含两种窗口设置,更具科学性。
:triangular_flag_on_post:**最新动态**(2023.10)我们添加了 [iTransformer](https://arxiv.org/abs/2310.06625) 的实现,这是长期预测领域的最新 SOTA。官方代码与完整脚本参见 [此处](https://github.com/thuml/iTransformer)。
:triangular_flag_on_post:**最新动态**(2023.09)我们为 [TimesNet](https://openreview.net/pdf?id=ju_Uqw384Oq) 及本库添加了详细[教程](https://github.com/thuml/Time-Series-Library/blob/main/tutorial/TimesNet_tutorial.ipynb),对时间序列初学者十分友好。
:triangular_flag_on_post:**最新动态**(2023.02)我们发布了 TSlib,作为一个面向时间序列模型的综合基准与代码库,扩展自此前的 [Autoformer](https://github.com/thuml/Autoformer) 仓库。
## 时间序列分析排行榜
截至 2024 年 3 月,各任务排行榜前三名如下:
| 模型<br>排名 | 长期预测<br>Look-Back-96 | 长期预测<br/>Look-Back-Searching | 短期预测 | 插补 | 分类 | 异常检测 |
| ------------ | ------------------------ | -------------------------------- | -------- | ---- | ---- | -------- |
| 🥇 第一名 | [TimeXer](https://arxiv.org/abs/2402.19072) | [TimeMixer](https://openreview.net/pdf?id=7oLshfEIC2) | [TimesNet](https://arxiv.org/abs/2210.02186) | [TimesNet](https://arxiv.org/abs/2210.02186) | [TimesNet](https://arxiv.org/abs/2210.02186) | [TimesNet](https://arxiv.org/abs/2210.02186) |
| 🥈 第二名 | [iTransformer](https://arxiv.org/abs/2310.06625) | [PatchTST](https://github.com/yuqinie98/PatchTST) | [Non-stationary<br/>Transformer](https://github.com/thuml/Nonstationary_Transformers) | [Non-stationary<br/>Transformer](https://github.com/thuml/Nonstationary_Transformers) | [Non-stationary<br/>Transformer](https://github.com/thuml/Nonstationary_Transformers) | [FEDformer](https://github.com/MAZiqing/FEDformer) |
| 🥉 第三名 | [TimeMixer](https://openreview.net/pdf?id=7oLshfEIC2) | [DLinear](https://arxiv.org/pdf/2205.13504.pdf) | [FEDformer](https://github.com/MAZiqing/FEDformer) | [Autoformer](https://github.com/thuml/Autoformer) | [Informer](https://github.com/zhouhaoyi/Informer2020) | [Autoformer](https://github.com/thuml/Autoformer) |
**说明:排行榜会持续更新。** 如果您提出了先进的模型,可通过发送论文或代码链接、或提交 PR 与我们联系,我们会尽快将其加入仓库并更新排行榜。
**排行榜中的对比模型**(☑ 表示代码已收录)。
- [x] **TimeXer** - TimeXer: Empowering Transformers for Time Series Forecasting with Exogenous Variables [[NeurIPS 2024]](https://arxiv.org/abs/2402.19072) [[代码]](https://github.com/thuml/Time-Series-Library/blob/main/models/TimeXer.py)
- [x] **TimeMixer** - TimeMixer: Decomposable Multiscale Mixing for Time Series Forecasting [[ICLR 2024]](https://openreview.net/pdf?id=7oLshfEIC2) [[代码]](https://github.com/thuml/Time-Series-Library/blob/main/models/TimeMixer.py)
- [x] **TSMixer** - TSMixer: An All-MLP Architecture for Time Series Forecasting [[arXiv 2023]](https://arxiv.org/pdf/2303.06053.pdf) [[代码]](https://github.com/thuml/Time-Series-Library/blob/main/models/TSMixer.py)
- [x] **iTransformer** - iTransformer: Inverted Transformers Are Effective for Time Series Forecasting [[ICLR 2024]](https://arxiv.org/abs/2310.06625) [[代码]](https://github.com/thuml/Time-Series-Library/blob/main/models/iTransformer.py)
- [x] **PatchTST** - A Time Series is Worth 64 Words: Long-term Forecasting with Transformers [[ICLR 2023]](https://openreview.net/pdf?id=Jbdc0vTOcol) [[代码]](https://github.com/thuml/Time-Series-Library/blob/main/models/PatchTST.py)
- [x] **TimesNet** - TimesNet: Temporal 2D-Variation Modeling for General Time Series Analysis [[ICLR 2023]](https://openreview.net/pdf?id=ju_Uqw384Oq) [[代码]](https://github.com/thuml/Time-Series-Library/blob/main/models/TimesNet.py)
- [x] **DLinear** - Are Transformers Effective for Time Series Forecasting? [[AAAI 2023]](https://arxiv.org/pdf/2205.13504.pdf) [[代码]](https://github.com/thuml/Time-Series-Library/blob/main/models/DLinear.py)
- [x] **LightTS** - Less Is More: Fast Multivariate Time Series Forecasting with Light Sampling-oriented MLP Structures [[arXiv 2022]](https://arxiv.org/abs/2207.01186) [[代码]](https://github.com/thuml/Time-Series-Library/blob/main/models/LightTS.py)
- [x] **ETSformer** - ETSformer: Exponential Smoothing Transformers for Time-series Forecasting [[arXiv 2022]](https://arxiv.org/abs/2202.01381) [[代码]](https://github.com/thuml/Time-Series-Library/blob/main/models/ETSformer.py)
- [x] **Non-stationary Transformer** - Non-stationary Transformers: Exploring the Stationarity in Time Series Forecasting [[NeurIPS 2022]](https://openreview.net/pdf?id=ucNDIDRNjjv) [[代码]](https://github.com/thuml/Time-Series-Library/blob/main/models/Nonstationary_Transformer.py)
- [x] **FEDformer** - FEDformer: Frequency Enhanced Decomposed Transformer for Long-term Series Forecasting [[ICML 2022]](https://proceedings.mlr.press/v162/zhou22g.html) [[代码]](https://github.com/thuml/Time-Series-Library/blob/main/models/FEDformer.py)
- [x] **Pyraformer** - Pyraformer: Low-complexity Pyramidal Attention for Long-range Time Series Modeling and Forecasting [[ICLR 2022]](https://openreview.net/pdf?id=0EXmFzUn5I) [[代码]](https://github.com/thuml/Time-Series-Library/blob/main/models/Pyraformer.py)
- [x] **Autoformer** - Autoformer: Decomposition Transformers with Auto-Correlation for Long-Term Series Forecasting [[NeurIPS 2021]](https://openreview.net/pdf?id=I55UqU-M11y) [[代码]](https://github.com/thuml/Time-Series-Library/blob/main/models/Autoformer.py)
- [x] **Informer** - Informer: Beyond Efficient Transformer for Long Sequence Time-Series Forecasting [[AAAI 2021]](https://ojs.aaai.org/index.php/AAAI/article/view/17325/17132) [[代码]](https://github.com/thuml/Time-Series-Library/blob/main/models/Informer.py)
- [x] **Reformer** - Reformer: The Efficient Transformer [[ICLR 2020]](https://openreview.net/forum?id=rkgNKkHtvB) [[代码]](https://github.com/thuml/Time-Series-Library/blob/main/models/Reformer.py)
- [x] **Transformer** - Attention is All You Need [[NeurIPS 2017]](https://proceedings.neurips.cc/paper/2017/file/3f5ee243547dee91fbd053c1c4a845aa-Paper.pdf) [[代码]](https://github.com/thuml/Time-Series-Library/blob/main/models/Transformer.py)
更多详情可参考我们关于 [[TimesNet]](https://arxiv.org/abs/2210.02186) 的最新论文,实时在线版本即将发布。
**新增基线模型**(综合评测后将加入排行榜)。
- [x] **MambaSL** - MambaSL: Exploring Single-Layer Mamba for Time Series Classification [[ICLR 2026]](https://openreview.net/forum?id=YDl4vqQqGP) [[Code]](https://github.com/thuml/Time-Series-Library/blob/main/models/MambaSingleLayer.py)
- [x] **TimeFilter** - TimeFilter: Patch-Specific Spatial-Temporal Graph Filtration for Time Series Forecasting [[ICML 2025]](https://arxiv.org/abs/2501.13041) [[代码]](https://github.com/thuml/Time-Series-Library/blob/main/models/TimeFilter.py)
- [x] **KAN-AD** - KAN-AD: Time Series Anomaly Detection with Kolmogorov-Arnold Networks [[ICML 2025]](https://arxiv.org/abs/2411.00278) [[代码]](https://github.com/thuml/Time-Series-Library/blob/main/models/KANAD.py)
- [x] **MultiPatchFormer** - A multiscale model for multivariate time series forecasting [[Scientific Reports 2025]](https://www.nature.com/articles/s41598-024-82417-4) [[代码]](https://github.com/thuml/Time-Series-Library/blob/main/models/MultiPatchFormer.py)
- [x] **WPMixer** - WPMixer: Efficient Multi-Resolution Mixing for Long-Term Time Series Forecasting [[AAAI 2025]](https://arxiv.org/abs/2412.17176) [[代码]](https://github.com/thuml/Time-Series-Library/blob/main/models/WPMixer.py)
- [x] **MSGNet** - MSGNet: Learning Multi-Scale Inter-Series Correlations for Multivariate Time Series Forecasting [[AAAI 2024]](https://dl.acm.org/doi/10.1609/aaai.v38i10.28991) [[代码]](https://github.com/thuml/Time-Series-Library/blob/main/models/MSGNet.py)
- [x] **PAttn** - Are Language Models Actually Useful for Time Series Forecasting? [[NeurIPS 2024]](https://arxiv.org/pdf/2406.16964) [[代码]](https://github.com/thuml/Time-Series-Library/blob/main/models/PAttn.py)
- [x] **Mamba** - Mamba: Linear-Time Sequence Modeling with Selective State Spaces [[arXiv 2023]](https://arxiv.org/abs/2312.00752) [[代码]](https://github.com/thuml/Time-Series-Library/blob/main/models/Mamba.py)
- [x] **SegRNN** - SegRNN: Segment Recurrent Neural Network for Long-Term Time Series Forecasting [[arXiv 2023]](https://arxiv.org/abs/2308.11200.pdf) [[代码]](https://github.com/thuml/Time-Series-Library/blob/main/models/SegRNN.py)
- [x] **Koopa** - Koopa: Learning Non-stationary Time Series Dynamics with Koopman Predictors [[NeurIPS 2023]](https://arxiv.org/pdf/2305.18803.pdf) [[代码]](https://github.com/thuml/Time-Series-Library/blob/main/models/Koopa.py)
- [x] **FreTS** - Frequency-domain MLPs are More Effective Learners in Time Series Forecasting [[NeurIPS 2023]](https://arxiv.org/pdf/2311.06184.pdf) [[代码]](https://github.com/thuml/Time-Series-Library/blob/main/models/FreTS.py)
- [x] **MICN** - MICN: Multi-scale Local and Global Context Modeling for Long-term Series Forecasting [[ICLR 2023]](https://openreview.net/pdf?id=zt53IDUR1U) [[代码]](https://github.com/thuml/Time-Series-Library/blob/main/models/MICN.py)
- [x] **Crossformer** - Crossformer: Transformer Utilizing Cross-Dimension Dependency for Multivariate Time Series Forecasting [[ICLR 2023]](https://openreview.net/pdf?id=vSVLM2j9eie) [[代码]](https://github.com/thuml/Time-Series-Library/blob/main/models/Crossformer.py)
- [x] **TiDE** - Long-term Forecasting with TiDE: Time-series Dense Encoder [[arXiv 2023]](https://arxiv.org/pdf/2304.08424.pdf) [[代码]](https://github.com/thuml/Time-Series-Library/blob/main/models/TiDE.py)
- [x] **SCINet** - SCINet: Time Series Modeling and Forecasting with Sample Convolution and Interaction [[NeurIPS 2022]](https://openreview.net/pdf?id=AyajSjTAzmg) [[代码]](https://github.com/thuml/Time-Series-Library/blob/main/models/SCINet.py)
- [x] **FiLM** - FiLM: Frequency improved Legendre Memory Model for Long-term Time Series Forecasting [[NeurIPS 2022]](https://openreview.net/forum?id=zTQdHSQUQWc) [[代码]](https://github.com/thuml/Time-Series-Library/blob/main/models/FiLM.py)
- [x] **TFT** - Temporal Fusion Transformers for Interpretable Multi-horizon Time Series Forecasting [[arXiv 2019]](https://arxiv.org/abs/1912.09363) [[代码]](https://github.com/thuml/Time-Series-Library/blob/main/models/TemporalFusionTransformer.py)
**新增大型时间序列模型**。本库同样支持以下 LTSM 的零样本评测:
- [x] **Chronos2** - Chronos-2: From Univariate to Universal Forecasting [[arXiv 2025]](https://arxiv.org/abs/2510.15821) [[代码]](https://github.com/thuml/Time-Series-Library/blob/main/models/Chronos2.py)
- [x] **TiRex** - TiRex: Zero-Shot Forecasting Across Long and Short Horizons with Enhanced In-Context Learning [[NeurIPS 2025]](https://arxiv.org/pdf/2505.23719) [[代码]](https://github.com/thuml/Time-Series-Library/blob/main/models/TiRex.py)
- [x] **Sundial** - Sundial: A Family of Highly Capable Time Series Foundation Models [[ICML 2025]](https://arxiv.org/pdf/2502.00816) [[代码]](https://github.com/thuml/Time-Series-Library/blob/main/models/Sundial.py)
- [x] **Time-MoE** - Time-MoE: Billion-Scale Time Series Foundation Models with Mixture of Experts [[ICLR 2025]](https://arxiv.org/pdf/2409.16040) [[代码]](https://github.com/thuml/Time-Series-Library/blob/main/models/TimeMoE.py)
- [x] **Toto** - Toto: Time Series Optimized Transformer for Observability [[arXiv 2024]](https://arxiv.org/pdf/2407.07874)
- [x] **Chronos** - Chronos: Learning the Language of Time Series [[TMLR 2024]](https://arxiv.org/pdf/2403.07815) [[代码]](https://github.com/thuml/Time-Series-Library/blob/main/models/Chronos.py)
- [x] **Moirai** - Unified Training of Universal Time Series Forecasting Transformers [[ICML 2024]](https://arxiv.org/pdf/2402.02592)
- [x] **TimesFM** - TimesFM: A decoder-only foundation model for time-series forecasting [[ICML 2024]](https://arxiv.org/abs/2310.10688) [[代码]](https://github.com/thuml/Time-Series-Library/blob/main/models/TimesFM.py)
## 快速开始
### 准备数据
可从 [[Google Drive]](https://drive.google.com/drive/folders/13Cg1KYOlzM5C7K8gK8NfC-F3EYxkM3D2?usp=sharing)、[[Baidu Drive]](https://pan.baidu.com/s/1r3KhGd0Q9PJIUZdfEYoymg?pwd=i9iy) 或 [[Hugging Face]](https://huggingface.co/datasets/thuml/Time-Series-Library) 下载预处理数据,并置于 `./dataset` 目录。
### 安装
1. 克隆本仓库
```bash
git clone https://github.com/thuml/Time-Series-Library.git
cd Time-Series-Library
```
2. 创建新的 Conda 环境
```bash
conda create -n tslib python=3.11
conda activate tslib
```
3. 安装核心依赖
> ⚠️ **CUDA 兼容性提示**
> torch 预编译包与 **CUDA 版本强相关**。(查看 https://pytorch.org/get-started/previous-versions/ )
> 请确保torch安装与本地 CUDA 版本匹配的包(如 `cu118` 或 `cu121`)。
> 推荐torch==2.5.1
```bash
pip install torch==2.5.1 --index-url https://download.pytorch.org/whl/cu121
pip install -r requirements.txt
```
4. 安装 Mamba 模型依赖(models/Mamba.py 需要)
> ⚠️ **只有linux版本**
> ⚠️ **CUDA 兼容性提示**
> Mamba 预编译包与 **CUDA 版本强相关**。
> 请确保安装与本地 CUDA 版本匹配的包(如 `cu11` 或 `cu12`)。
> 版本不匹配可能导致运行时错误或导入失败。
**CUDA 12** 示例:
```bash
pip install https://github.com/state-spaces/mamba/releases/download/v2.2.6.post3/mamba_ssm-2.2.6.post3+cu12torch2.5cxx11abiFALSE-cp311-cp311-linux_x86_64.whl
```
5. 安装 Moirai 模型依赖(models/Moirai.py 需要)
```bash
pip install uni2ts --no-deps
```
### Docker 部署
```bash
# 构建并以后台模式启动容器
docker compose -f 'Time-Series-Library/docker-compose.yml' up -d --build
# 在仓库根目录创建 ./dataset 并下载/放置数据集
mkdir -p dataset
# 将本地数据集复制到容器内 /workspace/dataset
docker cp ./dataset tslib:/workspace/dataset
# 进入运行中的容器
docker exec -it tslib bash
# 切换到容器内的工作目录
cd /workspace
# 使用预训练 Moirai 模型进行零样本预测
python -u run.py \
--task_name zero_shot_forecast \ # 任务类型:零样本预测
--is_training 0 \ # 0 = 仅推理
--root_path ./dataset/ETT-small/ \ # 数据集根路径
--data_path ETTh1.csv \ # 数据文件名
--model_id ETTh1_512_96 \ # 实验/模型标识
--model Moirai \ # 模型名称(TimesFM / Moirai)
--data ETTh1 \ # 数据集名称
--features M \ # 多变量预测
--seq_len 512 \ # 输入序列长度
--pred_len 96 \ # 预测步长
--enc_in 7 \ # 输入变量数
--des 'Exp' \ # 实验描述
--itr 1 # 运行次数
```
### 快速测试
5个任务快速测试(每个任务1个epoch):
```bash
# 执行所有5个任务的快速测试
export CUDA_VISIBLE_DEVICES=0
# 1. 长期预测
python -u run.py --task_name long_term_forecast --is_training 1 --root_path ./dataset/ETT-small/ --data_path ETTh1.csv --model_id test_long --model DLinear --data ETTh1 --features M --seq_len 96 --pred_len 96 --enc_in 7 --dec_in 7 --c_out 7 --train_epochs 1 --num_workers 2
# 2. 短期预测(使用ETT数据集,较短预测长度)
python -u run.py --task_name long_term_forecast --is_training 1 --root_path ./dataset/ETT-small/ --data_path ETTh1.csv --model_id test_short --model TimesNet --data ETTh1 --features M --seq_len 24 --label_len 12 --pred_len 24 --e_layers 2 --d_layers 1 --d_model 16 --d_ff 32 --enc_in 7 --dec_in 7 --c_out 7 --top_k 5 --train_epochs 1 --num_workers 2
# 3. 插补
python -u run.py --task_name imputation --is_training 1 --root_path ./dataset/ETT-small/ --data_path ETTh1.csv --model_id test_imp --model TimesNet --data ETTh1 --features M --seq_len 96 --e_layers 2 --d_layers 1 --d_model 16 --d_ff 32 --enc_in 7 --dec_in 7 --c_out 7 --top_k 3 --train_epochs 1 --num_workers 2 --label_len 0 --pred_len 0 --mask_rate 0.125 --learning_rate 0.001
# 4. 异常检测
python -u run.py --task_name anomaly_detection --is_training 1 --root_path ./dataset/PSM --model_id test_ad --model TimesNet --data PSM --features M --seq_len 100 --pred_len 0 --d_model 64 --d_ff 64 --e_layers 2 --enc_in 25 --c_out 25 --anomaly_ratio 1.0 --top_k 3 --train_epochs 1 --batch_size 128 --num_workers 2
# 5. 分类
python -u run.py --task_name classification --is_training 1 --root_path ./dataset/Heartbeat/ --model_id Heartbeat --model TimesNet --data UEA --e_layers 2 --d_layers 1 --factor 3 --d_model 64 --d_ff 128 --top_k 3 --train_epochs 1 --batch_size 16 --learning_rate 0.001 --num_workers 0
```
### 训练与评测
`./scripts/` 目录下提供了全部基准的实验脚本,可参考下列示例复现实验:
> ⚠️ 部分脚本中默认设置了 `CUDA_VISIBLE_DEVICES`,请根据实际 GPU 配置修改或删除该设置,否则可能导致无法使用 GPU。
```bash
# 长期预测
bash ./scripts/long_term_forecast/ETT_script/TimesNet_ETTh1.sh
# 短期预测
bash ./scripts/short_term_forecast/TimesNet_M4.sh
# 插补
bash ./scripts/imputation/ETT_script/TimesNet_ETTh1.sh
# 异常检测
bash ./scripts/anomaly_detection/PSM/TimesNet.sh
# 分类
bash ./scripts/classification/TimesNet.sh
```
### 开发自定义模型
- 将模型文件放入 `./models`,可参考 `./models/Transformer.py`。
- 在 `./scripts` 下创建对应的运行脚本。
### 注意事项:
(1) 关于分类:由于我们在统一代码库中涵盖五大任务,各子任务的精度可能略有波动,但平均性能可复现(甚至略高)。复现用 checkpoint 可在 [此处](https://github.com/thuml/Time-Series-Library/issues/494) 下载。
(2) 关于异常检测:有关异常检测调整策略的讨论见[这里](https://github.com/thuml/Anomaly-Transformer/issues/14),核心是该调整策略对应事件级指标。
### 查看项目文件结构:
```
Time-Series-Library/
├── README.md # 官方README,包含任务、榜单、使用方法
├── requirements.txt # pip依赖列表,直接pip install复现环境
├── LICENSE / CONTRIBUTING.md # 原项目许可与贡献指南
├── run.py # 单入口脚本,解析参数并调度各任务
├── exp/ # 各任务实验管线,封装训练/验证/测试
│ ├── exp_basic.py # 实验基类,注册所有模型,统一构建流程
│ ├── exp_long_term_forecasting.py # 长期预测实验逻辑
│ ├── exp_short_term_forecasting.py # 短期预测实验逻辑
│ ├── exp_imputation.py # 缺失值填充实验
│ ├── exp_anomaly_detection.py # 异常检测实验
│ ├── exp_classification.py # 分类实验
│ └── exp_zero_shot_forecasting.py # LTSM零样本预测评估
├── data_provider/ # 数据入口,负责数据集载入与切分
│ ├── data_factory.py # 根据任务选择对应DataLoader
│ ├── data_loader.py # 通用时序数据读取与滑窗逻辑
│ ├── uea.py / m4.py # UEA、M4等特定数据格式处理
│ └── __init__.py # 暴露上层可用的数据工厂接口
├── models/ # 所有模型实现,文件名即模型名
│ ├── TimesNet.py、TimeMixer.py 等 # 主流预测模型
│ ├── Chronos2.py、TiRex.py # LTSM零样本模型
│ └── __init__.py # 统一导出供实验模块按名称实例化
├── layers/ # 复用层/块,如注意力、卷积、嵌入
│ ├── Transformer_EncDec.py # Transformer编解码堆栈
│ ├── AutoCorrelation.py # 自相关算子
│ ├── MultiWaveletCorrelation.py# 频域单元
│ └── Embed.py 等 # 各模型共享基元
├── utils/ # 工具集合
│ ├── metrics.py # MSE/MAE/DTW等评估指标
│ ├── tools.py # 训练通用工具,比如EarlyStopping
│ ├── augmentation.py # 分类/检测任务增强策略
│ ├── print_args.py # 统一打印参数
│ └── masking.py / losses.py # 任务相关辅助函数
├── scripts/ # 复现实验的bash脚本
│ ├── long_term_forecast/ # 按数据集/模型划分的长期预测脚本
│ ├── short_term_forecast/ # M4等短期预测脚本
│ ├── imputation/ # 多数据集缺失填充脚本
│ ├── anomaly_detection/ # SMD/SMAP/SWAT等检测脚本
│ ├── classification/ # UEA分类脚本
│ └── exogenous_forecast/ # TimeXer外生变量预测流程
├── tutorial/ # 官方TimesNet教学notebook与插图
└── pic/ # README插图(数据集分布等)
```
### 理解项目架构:
- **整体流程**:通过 `scripts/*.sh` 设定实验参数 → 调用 `python run.py ...` → `run.py` 解析参数并根据 `task_name` 选择对应 `Exp_*` 类 → `Exp_*` 内部利用 `data_provider` 构造数据加载器、`models` 实例化网络、`utils` 中的工具完成训练/验证/测试 → 结果与模型参数写入 `./checkpoints`。
- **实验层(exp/)**:`Exp_Basic` 负责注册模型与设备,子类实现 `_get_data/train/test`,将不同任务的差异隔离,方便模型在多任务间复用。
- **模型与层(models/ + layers/)**:模型文件集中定义各网络结构,公用的注意力、卷积、频域块等沉淀在 `layers/`,减少重复实现。
- **数据层(data_provider/)**:`data_factory` 按任务返回 Dataset/DataLoader,`data_loader` 封装序列裁剪、滑动窗口、掩码策略,不同任务通过参数控制窗口长度、缺失率、异常比例。
- **脚本层(scripts/)**:提供与论文一致的复现实验脚本,涵盖各种数据集/模型/GPU 配置,便于批量跑榜,也可作为自定义实验的起点。
- **辅助层(utils/)**:`metrics` 统一评估指标,`tools` 中的 `EarlyStopping`、`adjust_learning_rate` 等负责训练调度;`augmentation`/`masking` 等用于任务特定的数据增强或预处理。
- **学习建议**:阅读顺序推荐 `scripts -> run.py -> exp/exp_basic.py -> 对应 Exp 子类 -> data_provider -> models`,并结合 `tutorial/TimesNet_tutorial.ipynb` 快速熟悉整体调用链,再按需深入模型或层级实现。
## 引用
如果本仓库对您有帮助,请引用以下论文:
```
@inproceedings{wu2023timesnet,
title={TimesNet: Temporal 2D-Variation Modeling for General Time Series Analysis},
author={Haixu Wu and Tengge Hu and Yong Liu and Hang Zhou and Jianmin Wang and Mingsheng Long},
booktitle={International Conference on Learning Representations},
year={2023},
}
@article{wang2024tssurvey,
title={Deep Time Series Models: A Comprehensive Survey and Benchmark},
author={Yuxuan Wang and Haixu Wu and Jiaxiang Dong and Yong Liu and Mingsheng Long and Jianmin Wang},
booktitle={arXiv preprint arXiv:2407.13278},
year={2024},
}
```
## 联系方式
如有问题或建议,欢迎联系维护团队:
现任:
- Haixu Wu(博士,wuhaixu98@gmail.com)
- Yuxuan Wang(博士生,wangyuxu22@mails.tsinghua.edu.cn)
- Yong Liu(博士生,liuyong21@mails.tsinghua.edu.cn)
- Ailuntz(开源社区学生,ailuntz@icloud.com)
往届:
- Huikun Weng(本科生,wenghk22@mails.tsinghua.edu.cn)
- Tengge Hu(硕士,htg21@mails.tsinghua.edu.cn)
- Haoran Zhang(硕士,z-hr20@mails.tsinghua.edu.cn)
- Jiawei Guo(本科生,guo-jw21@mails.tsinghua.edu.cn)
也欢迎在 Issues 中反馈。
## 致谢
本库参考了以下仓库:
- 预测:https://github.com/thuml/Autoformer
- 异常检测:https://github.com/thuml/Anomaly-Transformer
- 分类:https://github.com/thuml/Flowformer
实验所用数据集均为公开数据,来源如下:
- 长期预测与插补:https://github.com/thuml/Autoformer
- 短期预测:https://github.com/ServiceNow/N-BEATS
- 异常检测:https://github.com/thuml/Anomaly-Transformer
- 分类:https://www.timeseriesclassification.com/
## 感谢所有贡献者
<a href="https://github.com/thuml/Time-Series-Library/graphs/contributors">
<img src="https://contrib.rocks/image?repo=thuml/Time-Series-Library" />
</a>
================================================
FILE: data_provider/__init__.py
================================================
================================================
FILE: data_provider/data_factory.py
================================================
from data_provider.data_loader import Dataset_ETT_hour, Dataset_ETT_minute, Dataset_Custom, Dataset_M4, PSMSegLoader, \
MSLSegLoader, SMAPSegLoader, SMDSegLoader, SWATSegLoader, UEAloader
from data_provider.uea import collate_fn
from torch.utils.data import DataLoader
data_dict = {
'ETTh1': Dataset_ETT_hour,
'ETTh2': Dataset_ETT_hour,
'ETTm1': Dataset_ETT_minute,
'ETTm2': Dataset_ETT_minute,
'custom': Dataset_Custom,
'm4': Dataset_M4,
'PSM': PSMSegLoader,
'MSL': MSLSegLoader,
'SMAP': SMAPSegLoader,
'SMD': SMDSegLoader,
'SWAT': SWATSegLoader,
'UEA': UEAloader
}
def data_provider(args, flag):
Data = data_dict[args.data]
timeenc = 0 if args.embed != 'timeF' else 1
shuffle_flag = False if (flag == 'test' or flag == 'TEST') else True
drop_last = False
batch_size = args.batch_size
freq = args.freq
if args.task_name == 'anomaly_detection':
drop_last = False
data_set = Data(
args = args,
root_path=args.root_path,
win_size=args.seq_len,
flag=flag,
)
print(flag, len(data_set))
data_loader = DataLoader(
data_set,
batch_size=batch_size,
shuffle=shuffle_flag,
num_workers=args.num_workers,
drop_last=drop_last)
return data_set, data_loader
elif args.task_name == 'classification':
drop_last = False
data_set = Data(
args = args,
root_path=args.root_path,
flag=flag,
)
data_loader = DataLoader(
data_set,
batch_size=batch_size,
shuffle=shuffle_flag,
num_workers=args.num_workers,
drop_last=drop_last,
collate_fn=lambda x: collate_fn(x, max_len=args.seq_len)
)
return data_set, data_loader
else:
if args.data == 'm4':
drop_last = False
data_set = Data(
args = args,
root_path=args.root_path,
data_path=args.data_path,
flag=flag,
size=[args.seq_len, args.label_len, args.pred_len],
features=args.features,
target=args.target,
timeenc=timeenc,
freq=freq,
seasonal_patterns=args.seasonal_patterns
)
print(flag, len(data_set))
data_loader = DataLoader(
data_set,
batch_size=batch_size,
shuffle=shuffle_flag,
num_workers=args.num_workers,
drop_last=drop_last)
return data_set, data_loader
================================================
FILE: data_provider/data_loader.py
================================================
import os
import numpy as np
import pandas as pd
import glob
import re
import torch
from torch.utils.data import Dataset, DataLoader
from sklearn.preprocessing import StandardScaler
from utils.timefeatures import time_features
from data_provider.m4 import M4Dataset, M4Meta
from data_provider.uea import subsample, interpolate_missing, Normalizer
from sktime.datasets import load_from_tsfile_to_dataframe
import warnings
from utils.augmentation import run_augmentation_single
from datasets import load_dataset
from huggingface_hub import hf_hub_download
warnings.filterwarnings('ignore')
HUGGINGFACE_REPO = "thuml/Time-Series-Library"
class Dataset_ETT_hour(Dataset):
def __init__(self, args, root_path, flag='train', size=None,
features='S', data_path='ETTh1.csv',
target='OT', scale=True, timeenc=0, freq='h', seasonal_patterns=None):
# size [seq_len, label_len, pred_len]
self.args = args
# info
if size == None:
self.seq_len = 24 * 4 * 4
self.label_len = 24 * 4
self.pred_len = 24 * 4
else:
self.seq_len = size[0]
self.label_len = size[1]
self.pred_len = size[2]
# init
assert flag in ['train', 'test', 'val']
type_map = {'train': 0, 'val': 1, 'test': 2}
self.set_type = type_map[flag]
self.features = features
self.target = target
self.scale = scale
self.timeenc = timeenc
self.freq = freq
self.root_path = root_path
self.data_path = data_path
self.__read_data__()
def __read_data__(self):
self.scaler = StandardScaler()
local_fp = os.path.join(self.root_path, self.data_path)
cfg_name = os.path.splitext(os.path.basename(self.data_path))[0]
if os.path.exists(local_fp):
df_raw = pd.read_csv(local_fp)
else:
ds = load_dataset(HUGGINGFACE_REPO, name=cfg_name)
df_raw = ds["train"].to_pandas()
border1s = [0, 12 * 30 * 24 - self.seq_len, 12 * 30 * 24 + 4 * 30 * 24 - self.seq_len]
border2s = [12 * 30 * 24, 12 * 30 * 24 + 4 * 30 * 24, 12 * 30 * 24 + 8 * 30 * 24]
border1 = border1s[self.set_type]
border2 = border2s[self.set_type]
if self.features == 'M' or self.features == 'MS':
cols_data = df_raw.columns[1:]
df_data = df_raw[cols_data]
elif self.features == 'S':
df_data = df_raw[[self.target]]
if self.scale:
train_data = df_data[border1s[0]:border2s[0]]
self.scaler.fit(train_data.values)
data = self.scaler.transform(df_data.values)
else:
data = df_data.values
df_stamp = df_raw[['date']][border1:border2]
df_stamp['date'] = pd.to_datetime(df_stamp.date)
if self.timeenc == 0:
df_stamp['month'] = df_stamp.date.apply(lambda row: row.month, 1)
df_stamp['day'] = df_stamp.date.apply(lambda row: row.day, 1)
df_stamp['weekday'] = df_stamp.date.apply(lambda row: row.weekday(), 1)
df_stamp['hour'] = df_stamp.date.apply(lambda row: row.hour, 1)
data_stamp = df_stamp.drop(['date'], 1).values
elif self.timeenc == 1:
data_stamp = time_features(pd.to_datetime(df_stamp['date'].values), freq=self.freq)
data_stamp = data_stamp.transpose(1, 0)
self.data_x = data[border1:border2]
self.data_y = data[border1:border2]
if self.set_type == 0 and self.args.augmentation_ratio > 0:
self.data_x, self.data_y, augmentation_tags = run_augmentation_single(self.data_x, self.data_y, self.args)
self.data_stamp = data_stamp
def __getitem__(self, index):
s_begin = index
s_end = s_begin + self.seq_len
r_begin = s_end - self.label_len
r_end = r_begin + self.label_len + self.pred_len
seq_x = self.data_x[s_begin:s_end]
seq_y = self.data_y[r_begin:r_end]
seq_x_mark = self.data_stamp[s_begin:s_end]
seq_y_mark = self.data_stamp[r_begin:r_end]
return seq_x, seq_y, seq_x_mark, seq_y_mark
def __len__(self):
return len(self.data_x) - self.seq_len - self.pred_len + 1
def inverse_transform(self, data):
return self.scaler.inverse_transform(data)
class Dataset_ETT_minute(Dataset):
def __init__(self, args, root_path, flag='train', size=None,
features='S', data_path='ETTm1.csv',
target='OT', scale=True, timeenc=0, freq='t', seasonal_patterns=None):
# size [seq_len, label_len, pred_len]
self.args = args
# info
if size == None:
self.seq_len = 24 * 4 * 4
self.label_len = 24 * 4
self.pred_len = 24 * 4
else:
self.seq_len = size[0]
self.label_len = size[1]
self.pred_len = size[2]
# init
assert flag in ['train', 'test', 'val']
type_map = {'train': 0, 'val': 1, 'test': 2}
self.set_type = type_map[flag]
self.features = features
self.target = target
self.scale = scale
self.timeenc = timeenc
self.freq = freq
self.root_path = root_path
self.data_path = data_path
self.__read_data__()
def __read_data__(self):
self.scaler = StandardScaler()
local_fp = os.path.join(self.root_path, self.data_path)
cfg_name = os.path.splitext(os.path.basename(self.data_path))[0]
if os.path.exists(local_fp):
df_raw = pd.read_csv(local_fp)
else:
ds = load_dataset(HUGGINGFACE_REPO, name=cfg_name)
df_raw = ds["train"].to_pandas()
border1s = [0, 12 * 30 * 24 * 4 - self.seq_len, 12 * 30 * 24 * 4 + 4 * 30 * 24 * 4 - self.seq_len]
border2s = [12 * 30 * 24 * 4, 12 * 30 * 24 * 4 + 4 * 30 * 24 * 4, 12 * 30 * 24 * 4 + 8 * 30 * 24 * 4]
border1 = border1s[self.set_type]
border2 = border2s[self.set_type]
if self.features == 'M' or self.features == 'MS':
cols_data = df_raw.columns[1:]
df_data = df_raw[cols_data]
elif self.features == 'S':
df_data = df_raw[[self.target]]
if self.scale:
train_data = df_data[border1s[0]:border2s[0]]
self.scaler.fit(train_data.values)
data = self.scaler.transform(df_data.values)
else:
data = df_data.values
df_stamp = df_raw[['date']][border1:border2]
df_stamp['date'] = pd.to_datetime(df_stamp.date)
if self.timeenc == 0:
df_stamp['month'] = df_stamp.date.apply(lambda row: row.month, 1)
df_stamp['day'] = df_stamp.date.apply(lambda row: row.day, 1)
df_stamp['weekday'] = df_stamp.date.apply(lambda row: row.weekday(), 1)
df_stamp['hour'] = df_stamp.date.apply(lambda row: row.hour, 1)
df_stamp['minute'] = df_stamp.date.apply(lambda row: row.minute, 1)
df_stamp['minute'] = df_stamp.minute.map(lambda x: x // 15)
data_stamp = df_stamp.drop(['date'], 1).values
elif self.timeenc == 1:
data_stamp = time_features(pd.to_datetime(df_stamp['date'].values), freq=self.freq)
data_stamp = data_stamp.transpose(1, 0)
self.data_x = data[border1:border2]
self.data_y = data[border1:border2]
if self.set_type == 0 and self.args.augmentation_ratio > 0:
self.data_x, self.data_y, augmentation_tags = run_augmentation_single(self.data_x, self.data_y, self.args)
self.data_stamp = data_stamp
def __getitem__(self, index):
s_begin = index
s_end = s_begin + self.seq_len
r_begin = s_end - self.label_len
r_end = r_begin + self.label_len + self.pred_len
seq_x = self.data_x[s_begin:s_end]
seq_y = self.data_y[r_begin:r_end]
seq_x_mark = self.data_stamp[s_begin:s_end]
seq_y_mark = self.data_stamp[r_begin:r_end]
return seq_x, seq_y, seq_x_mark, seq_y_mark
def __len__(self):
return len(self.data_x) - self.seq_len - self.pred_len + 1
def inverse_transform(self, data):
return self.scaler.inverse_transform(data)
class Dataset_Custom(Dataset):
def __init__(self, args, root_path, flag='train', size=None,
features='S', data_path='ETTh1.csv',
target='OT', scale=True, timeenc=0, freq='h', seasonal_patterns=None):
# size [seq_len, label_len, pred_len]
self.args = args
# info
if size == None:
self.seq_len = 24 * 4 * 4
self.label_len = 24 * 4
self.pred_len = 24 * 4
else:
self.seq_len = size[0]
self.label_len = size[1]
self.pred_len = size[2]
# init
assert flag in ['train', 'test', 'val']
type_map = {'train': 0, 'val': 1, 'test': 2}
self.set_type = type_map[flag]
self.features = features
self.target = target
self.scale = scale
self.timeenc = timeenc
self.freq = freq
self.root_path = root_path
self.data_path = data_path
self.__read_data__()
def __read_data__(self):
self.scaler = StandardScaler()
local_fp = os.path.join(self.root_path, self.data_path)
cfg_name = os.path.splitext(os.path.basename(self.data_path))[0]
if os.path.exists(local_fp):
df_raw = pd.read_csv(local_fp)
else:
ds = load_dataset(HUGGINGFACE_REPO, name=cfg_name)
split_name = "train" if "train" in ds else list(ds.keys())[0]
df_raw = ds[split_name].to_pandas()
'''
df_raw.columns: ['date', ...(other features), target feature]
'''
cols = list(df_raw.columns)
cols.remove(self.target)
cols.remove('date')
df_raw = df_raw[['date'] + cols + [self.target]]
num_train = int(len(df_raw) * 0.7)
num_test = int(len(df_raw) * 0.2)
num_vali = len(df_raw) - num_train - num_test
border1s = [0, num_train - self.seq_len, len(df_raw) - num_test - self.seq_len]
border2s = [num_train, num_train + num_vali, len(df_raw)]
border1 = border1s[self.set_type]
border2 = border2s[self.set_type]
if self.features == 'M' or self.features == 'MS':
cols_data = df_raw.columns[1:]
df_data = df_raw[cols_data]
elif self.features == 'S':
df_data = df_raw[[self.target]]
if self.scale:
train_data = df_data[border1s[0]:border2s[0]]
self.scaler.fit(train_data.values)
data = self.scaler.transform(df_data.values)
else:
data = df_data.values
df_stamp = df_raw[['date']][border1:border2]
df_stamp['date'] = pd.to_datetime(df_stamp.date)
if self.timeenc == 0:
df_stamp['month'] = df_stamp.date.apply(lambda row: row.month, 1)
df_stamp['day'] = df_stamp.date.apply(lambda row: row.day, 1)
df_stamp['weekday'] = df_stamp.date.apply(lambda row: row.weekday(), 1)
df_stamp['hour'] = df_stamp.date.apply(lambda row: row.hour, 1)
data_stamp = df_stamp.drop(['date'], 1).values
elif self.timeenc == 1:
data_stamp = time_features(pd.to_datetime(df_stamp['date'].values), freq=self.freq)
data_stamp = data_stamp.transpose(1, 0)
self.data_x = data[border1:border2]
self.data_y = data[border1:border2]
if self.set_type == 0 and self.args.augmentation_ratio > 0:
self.data_x, self.data_y, augmentation_tags = run_augmentation_single(self.data_x, self.data_y, self.args)
self.data_stamp = data_stamp
def __getitem__(self, index):
s_begin = index
s_end = s_begin + self.seq_len
r_begin = s_end - self.label_len
r_end = r_begin + self.label_len + self.pred_len
seq_x = self.data_x[s_begin:s_end]
seq_y = self.data_y[r_begin:r_end]
seq_x_mark = self.data_stamp[s_begin:s_end]
seq_y_mark = self.data_stamp[r_begin:r_end]
return seq_x, seq_y, seq_x_mark, seq_y_mark
def __len__(self):
return len(self.data_x) - self.seq_len - self.pred_len + 1
def inverse_transform(self, data):
return self.scaler.inverse_transform(data)
class Dataset_M4(Dataset):
def __init__(self, args, root_path, flag='pred', size=None,
features='S', data_path='ETTh1.csv',
target='OT', scale=False, inverse=False, timeenc=0, freq='15min',
seasonal_patterns='Yearly'):
# size [seq_len, label_len, pred_len]
# init
self.features = features
self.target = target
self.scale = scale
self.inverse = inverse
self.timeenc = timeenc
self.root_path = root_path
self.seq_len = size[0]
self.label_len = size[1]
self.pred_len = size[2]
self.seasonal_patterns = seasonal_patterns
self.history_size = M4Meta.history_size[seasonal_patterns]
self.window_sampling_limit = int(self.history_size * self.pred_len)
self.flag = flag
self.__read_data__()
def __read_data__(self):
# M4Dataset.initialize()
if self.flag == 'train':
dataset = M4Dataset.load(training=True, dataset_file=self.root_path)
else:
dataset = M4Dataset.load(training=False, dataset_file=self.root_path)
training_values = np.array(
[v[~np.isnan(v)] for v in
dataset.values[dataset.groups == self.seasonal_patterns]]) # split different frequencies
self.ids = np.array([i for i in dataset.ids[dataset.groups == self.seasonal_patterns]])
self.timeseries = [ts for ts in training_values]
def __getitem__(self, index):
insample = np.zeros((self.seq_len, 1))
insample_mask = np.zeros((self.seq_len, 1))
outsample = np.zeros((self.pred_len + self.label_len, 1))
outsample_mask = np.zeros((self.pred_len + self.label_len, 1)) # m4 dataset
sampled_timeseries = self.timeseries[index]
cut_point = np.random.randint(low=max(1, len(sampled_timeseries) - self.window_sampling_limit),
high=len(sampled_timeseries),
size=1)[0]
insample_window = sampled_timeseries[max(0, cut_point - self.seq_len):cut_point]
insample[-len(insample_window):, 0] = insample_window
insample_mask[-len(insample_window):, 0] = 1.0
outsample_window = sampled_timeseries[
max(0, cut_point - self.label_len):min(len(sampled_timeseries), cut_point + self.pred_len)]
outsample[:len(outsample_window), 0] = outsample_window
outsample_mask[:len(outsample_window), 0] = 1.0
return insample, outsample, insample_mask, outsample_mask
def __len__(self):
return len(self.timeseries)
def inverse_transform(self, data):
return self.scaler.inverse_transform(data)
def last_insample_window(self):
"""
The last window of insample size of all timeseries.
This function does not support batching and does not reshuffle timeseries.
:return: Last insample window of all timeseries. Shape "timeseries, insample size"
"""
insample = np.zeros((len(self.timeseries), self.seq_len))
insample_mask = np.zeros((len(self.timeseries), self.seq_len))
for i, ts in enumerate(self.timeseries):
ts_last_window = ts[-self.seq_len:]
insample[i, -len(ts):] = ts_last_window
insample_mask[i, -len(ts):] = 1.0
return insample, insample_mask
class PSMSegLoader(Dataset):
def __init__(self, args, root_path, win_size, step=1, flag="train"):
self.flag = flag
self.step = step
self.win_size = win_size
self.scaler = StandardScaler()
train_path = os.path.join(root_path, "train.csv")
test_path = os.path.join(root_path, "test.csv")
label_path = os.path.join(root_path, "test_label.csv")
if all(os.path.exists(p) for p in [train_path, test_path, label_path]):
train_df = pd.read_csv(train_path)
test_df = pd.read_csv(test_path)
test_label_df = pd.read_csv(label_path)
else:
ds_data = load_dataset(HUGGINGFACE_REPO, name="PSM-data")
ds_label = load_dataset(HUGGINGFACE_REPO, name="PSM-label")
train_df = ds_data["train"].to_pandas()
test_df = ds_data["test"].to_pandas()
test_label_df = ds_label[next(iter(ds_label))].to_pandas()
data = train_df.values[:, 1:]
data = np.nan_to_num(data)
self.scaler.fit(data)
data = self.scaler.transform(data)
test_data = test_df.values[:, 1:]
test_data = np.nan_to_num(test_data)
self.test = self.scaler.transform(test_data)
self.train = data
data_len = len(self.train)
self.val = self.train[(int)(data_len * 0.8):]
self.test_labels = test_label_df.values[:, 1:]
print("test:", self.test.shape)
print("train:", self.train.shape)
def __len__(self):
if self.flag == "train":
return (self.train.shape[0] - self.win_size) // self.step + 1
elif (self.flag == 'val'):
return (self.val.shape[0] - self.win_size) // self.step + 1
elif (self.flag == 'test'):
return (self.test.shape[0] - self.win_size) // self.step + 1
else:
return (self.test.shape[0] - self.win_size) // self.win_size + 1
def __getitem__(self, index):
index = index * self.step
if self.flag == "train":
return np.float32(self.train[index:index + self.win_size]), np.float32(self.test_labels[0:self.win_size])
elif (self.flag == 'val'):
return np.float32(self.val[index:index + self.win_size]), np.float32(self.test_labels[0:self.win_size])
elif (self.flag == 'test'):
return np.float32(self.test[index:index + self.win_size]), np.float32(
self.test_labels[index:index + self.win_size])
else:
return np.float32(self.test[
index // self.step * self.win_size:index // self.step * self.win_size + self.win_size]), np.float32(
self.test_labels[index // self.step * self.win_size:index // self.step * self.win_size + self.win_size])
class MSLSegLoader(Dataset):
def __init__(self, args, root_path, win_size, step=1, flag="train"):
self.flag = flag
self.step = step
self.win_size = win_size
self.scaler = StandardScaler()
train_path = os.path.join(root_path, "MSL_train.npy")
test_path = os.path.join(root_path, "MSL_test.npy")
label_path = os.path.join(root_path, "MSL_test_label.npy")
if all(os.path.exists(p) for p in [train_path, test_path, label_path]):
train_data = np.load(train_path)
test_data = np.load(test_path)
test_label = np.load(label_path)
else:
train_path = hf_hub_download(repo_id=HUGGINGFACE_REPO, filename="MSL/MSL_train.npy",repo_type="dataset")
test_path = hf_hub_download(repo_id=HUGGINGFACE_REPO, filename="MSL/MSL_test.npy",repo_type="dataset")
label_path = hf_hub_download(repo_id=HUGGINGFACE_REPO, filename="MSL/MSL_test_label.npy",repo_type="dataset")
train_data = np.load(train_path)
test_data = np.load(test_path)
test_label = np.load(label_path)
self.scaler.fit(train_data)
train_data = self.scaler.transform(train_data)
test_data = self.scaler.transform(test_data)
self.train = train_data
self.test = test_data
self.test_labels = test_label
data_len = len(self.train)
self.val = self.train[int(data_len * 0.8):]
print("test:", self.test.shape)
print("train:", self.train.shape)
def __len__(self):
if self.flag == "train":
return (self.train.shape[0] - self.win_size) // self.step + 1
elif (self.flag == 'val'):
return (self.val.shape[0] - self.win_size) // self.step + 1
elif (self.flag == 'test'):
return (self.test.shape[0] - self.win_size) // self.step + 1
else:
return (self.test.shape[0] - self.win_size) // self.win_size + 1
def __getitem__(self, index):
index = index * self.step
if self.flag == "train":
return np.float32(self.train[index:index + self.win_size]), np.float32(self.test_labels[0:self.win_size])
elif (self.flag == 'val'):
return np.float32(self.val[index:index + self.win_size]), np.float32(self.test_labels[0:self.win_size])
elif (self.flag == 'test'):
return np.float32(self.test[index:index + self.win_size]), np.float32(
self.test_labels[index:index + self.win_size])
else:
return np.float32(self.test[
index // self.step * self.win_size:index // self.step * self.win_size + self.win_size]), np.float32(
self.test_labels[index // self.step * self.win_size:index // self.step * self.win_size + self.win_size])
class SMAPSegLoader(Dataset):
def __init__(self, args, root_path, win_size, step=1, flag="train"):
self.flag = flag
self.step = step
self.win_size = win_size
self.scaler = StandardScaler()
train_path = os.path.join(root_path, "SMAP_train.npy")
test_path = os.path.join(root_path, "SMAP_test.npy")
label_path = os.path.join(root_path, "SMAP_test_label.npy")
if all(os.path.exists(p) for p in [train_path, test_path, label_path]):
train_data = np.load(train_path)
test_data = np.load(test_path)
test_label = np.load(label_path)
else:
train_path = hf_hub_download(repo_id=HUGGINGFACE_REPO, filename="SMAP/SMAP_train.npy",repo_type="dataset")
test_path = hf_hub_download(repo_id=HUGGINGFACE_REPO, filename="SMAP/SMAP_test.npy",repo_type="dataset")
label_path = hf_hub_download(repo_id=HUGGINGFACE_REPO, filename="SMAP/SMAP_test_label.npy",repo_type="dataset")
train_data = np.load(train_path)
test_data = np.load(test_path)
test_label = np.load(label_path)
# 标准化
self.scaler.fit(train_data)
train_data = self.scaler.transform(train_data)
test_data = self.scaler.transform(test_data)
self.train = train_data
self.test = test_data
self.test_labels = test_label
data_len = len(self.train)
self.val = self.train[int(data_len * 0.8):]
print("test:", self.test.shape)
print("train:", self.train.shape)
def __len__(self):
if self.flag == "train":
return (self.train.shape[0] - self.win_size) // self.step + 1
elif (self.flag == 'val'):
return (self.val.shape[0] - self.win_size) // self.step + 1
elif (self.flag == 'test'):
return (self.test.shape[0] - self.win_size) // self.step + 1
else:
return (self.test.shape[0] - self.win_size) // self.win_size + 1
def __getitem__(self, index):
index = index * self.step
if self.flag == "train":
return np.float32(self.train[index:index + self.win_size]), np.float32(self.test_labels[0:self.win_size])
elif (self.flag == 'val'):
return np.float32(self.val[index:index + self.win_size]), np.float32(self.test_labels[0:self.win_size])
elif (self.flag == 'test'):
return np.float32(self.test[index:index + self.win_size]), np.float32(
self.test_labels[index:index + self.win_size])
else:
return np.float32(self.test[
index // self.step * self.win_size:index // self.step * self.win_size + self.win_size]), np.float32(
self.test_labels[index // self.step * self.win_size:index // self.step * self.win_size + self.win_size])
class SMDSegLoader(Dataset):
def __init__(self, args, root_path, win_size, step=100, flag="train"):
self.flag = flag
self.step = step
self.win_size = win_size
self.scaler = StandardScaler()
train_path = os.path.join(root_path, "SMD_train.npy")
test_path = os.path.join(root_path, "SMD_test.npy")
label_path = os.path.join(root_path, "SMD_test_label.npy")
if all(os.path.exists(p) for p in [train_path, test_path, label_path]):
train_data = np.load(train_path)
test_data = np.load(test_path)
test_label = np.load(label_path)
else:
train_path = hf_hub_download(repo_id=HUGGINGFACE_REPO, filename="SMD/SMD_train.npy",repo_type="dataset")
test_path = hf_hub_download(repo_id=HUGGINGFACE_REPO, filename="SMD/SMD_test.npy",repo_type="dataset")
label_path = hf_hub_download(repo_id=HUGGINGFACE_REPO, filename="SMD/SMD_test_label.npy",repo_type="dataset")
train_data = np.load(train_path)
test_data = np.load(test_path)
test_label = np.load(label_path)
self.scaler.fit(train_data)
train_data = self.scaler.transform(train_data)
test_data = self.scaler.transform(test_data)
self.train = train_data
self.test = test_data
data_len = len(self.train)
self.val = self.train[(int)(data_len * 0.8):]
self.test_labels = test_label
print("test:", self.test.shape)
print("train:", self.train.shape)
def __len__(self):
if self.flag == "train":
return (self.train.shape[0] - self.win_size) // self.step + 1
elif (self.flag == 'val'):
return (self.val.shape[0] - self.win_size) // self.step + 1
elif (self.flag == 'test'):
return (self.test.shape[0] - self.win_size) // self.step + 1
else:
return (self.test.shape[0] - self.win_size) // self.win_size + 1
def __getitem__(self, index):
index = index * self.step
if self.flag == "train":
return np.float32(self.train[index:index + self.win_size]), np.float32(self.test_labels[0:self.win_size])
elif (self.flag == 'val'):
return np.float32(self.val[index:index + self.win_size]), np.float32(self.test_labels[0:self.win_size])
elif (self.flag == 'test'):
return np.float32(self.test[index:index + self.win_size]), np.float32(
self.test_labels[index:index + self.win_size])
else:
return np.float32(self.test[
index // self.step * self.win_size:index // self.step * self.win_size + self.win_size]), np.float32(
self.test_labels[index // self.step * self.win_size:index // self.step * self.win_size + self.win_size])
class SWATSegLoader(Dataset):
def __init__(self, args, root_path, win_size, step=1, flag="train"):
self.flag = flag
self.step = step
self.win_size = win_size
self.scaler = StandardScaler()
train2_path = os.path.join(root_path, "swat_train2.csv")
test_path = os.path.join(root_path, "swat2.csv")
if all(os.path.exists(p) for p in [train2_path, test_path]):
train_data = pd.read_csv(train2_path)
test_data = pd.read_csv(test_path)
else:
ds = load_dataset(HUGGINGFACE_REPO, name="SWaT")
train_data = ds["train"].to_pandas()
test_data = ds["test"].to_pandas()
labels = test_data.values[:, -1:]
train_data = train_data.values[:, :-1]
test_data = test_data.values[:, :-1]
self.scaler.fit(train_data)
train_data = self.scaler.transform(train_data)
test_data = self.scaler.transform(test_data)
self.train = train_data
self.test = test_data
data_len = len(self.train)
self.val = self.train[(int)(data_len * 0.8):]
self.test_labels = labels
print("test:", self.test.shape)
print("train:", self.train.shape)
def __len__(self):
"""
Number of images in the object dataset.
"""
if self.flag == "train":
return (self.train.shape[0] - self.win_size) // self.step + 1
elif (self.flag == 'val'):
return (self.val.shape[0] - self.win_size) // self.step + 1
elif (self.flag == 'test'):
return (self.test.shape[0] - self.win_size) // self.step + 1
else:
return (self.test.shape[0] - self.win_size) // self.win_size + 1
def __getitem__(self, index):
index = index * self.step
if self.flag == "train":
return np.float32(self.train[index:index + self.win_size]), np.float32(self.test_labels[0:self.win_size])
elif (self.flag == 'val'):
return np.float32(self.val[index:index + self.win_size]), np.float32(self.test_labels[0:self.win_size])
elif (self.flag == 'test'):
return np.float32(self.test[index:index + self.win_size]), np.float32(
self.test_labels[index:index + self.win_size])
else:
return np.float32(self.test[
index // self.step * self.win_size:index // self.step * self.win_size + self.win_size]), np.float32(
self.test_labels[index // self.step * self.win_size:index // self.step * self.win_size + self.win_size])
class UEAloader(Dataset):
"""
Dataset class for datasets included in:
Time Series Classification Archive (www.timeseriesclassification.com)
Argument:
limit_size: float in (0, 1) for debug
Attributes:
all_df: (num_samples * seq_len, num_columns) dataframe indexed by integer indices, with multiple rows corresponding to the same index (sample).
Each row is a time step; Each column contains either metadata (e.g. timestamp) or a feature.
feature_df: (num_samples * seq_len, feat_dim) dataframe; contains the subset of columns of `all_df` which correspond to selected features
feature_names: names of columns contained in `feature_df` (same as feature_df.columns)
all_IDs: (num_samples,) series of IDs contained in `all_df`/`feature_df` (same as all_df.index.unique() )
labels_df: (num_samples, num_labels) pd.DataFrame of label(s) for each sample
max_seq_len: maximum sequence (time series) length. If None, script argument `max_seq_len` will be used.
(Moreover, script argument overrides this attribute)
"""
def __init__(self, args, root_path, file_list=None, limit_size=None, flag=None):
self.args = args
self.root_path = root_path
self.flag = flag
self.all_df, self.labels_df = self.load_all(root_path, file_list=file_list, flag=flag)
self.all_IDs = self.all_df.index.unique() # all sample IDs (integer indices 0 ... num_samples-1)
if limit_size is not None:
if limit_size > 1:
limit_size = int(limit_size)
else: # interpret as proportion if in (0, 1]
limit_size = int(limit_size * len(self.all_IDs))
self.all_IDs = self.all_IDs[:limit_size]
self.all_df = self.all_df.loc[self.all_IDs]
# use all features
self.feature_names = self.all_df.columns
self.feature_df = self.all_df
# pre_process
normalizer = Normalizer()
self.feature_df = normalizer.normalize(self.feature_df)
print(len(self.all_IDs))
def _resolve_ts_path(self, root_path, dataset_name, flag):
split = "TRAIN" if "train" in str(flag).lower() else "TEST"
fname = f"{dataset_name}_{split}.ts"
local = os.path.join(root_path, fname)
if os.path.exists(local):
return local
return hf_hub_download(HUGGINGFACE_REPO, filename=f"{dataset_name}/{fname}", repo_type="dataset")
def load_all(self, root_path, file_list=None, flag=None):
"""
Loads datasets from ts files contained in `root_path` into a dataframe, optionally choosing from `pattern`
Args:
root_path: directory containing all individual .ts files
file_list: optionally, provide a list of file paths within `root_path` to consider.
Otherwise, entire `root_path` contents will be used.
Returns:
all_df: a single (possibly concatenated) dataframe with all data corresponding to specified files
labels_df: dataframe containing label(s) for each sample
"""
# Select paths for training and evaluation
dataset_name = self.args.model_id
ts_path = self._resolve_ts_path(root_path, dataset_name, flag or "train")
all_df, labels_df = self.load_single(ts_path)
return all_df, labels_df
def load_single(self, filepath):
df, labels = load_from_tsfile_to_dataframe(filepath, return_separate_X_and_y=True,
replace_missing_vals_with='NaN')
labels = pd.Series(labels, dtype="category")
self.class_names = labels.cat.categories
labels_df = pd.DataFrame(labels.cat.codes,
dtype=np.int8) # int8-32 gives an error when using nn.CrossEntropyLoss
lengths = df.applymap(
lambda x: len(x)).values # (num_samples, num_dimensions) array containing the length of each series
horiz_diffs = np.abs(lengths - np.expand_dims(lengths[:, 0], -1))
if np.sum(horiz_diffs) > 0: # if any row (sample) has varying length across dimensions
df = df.applymap(subsample)
lengths = df.applymap(lambda x: len(x)).values
vert_diffs = np.abs(lengths - np.expand_dims(lengths[0, :], 0))
if np.sum(vert_diffs) > 0: # if any column (dimension) has varying length across samples
self.max_seq_len = int(np.max(lengths[:, 0]))
else:
self.max_seq_len = lengths[0, 0]
# First create a (seq_len, feat_dim) dataframe for each sample, indexed by a single integer ("ID" of the sample)
# Then concatenate into a (num_samples * seq_len, feat_dim) dataframe, with multiple rows corresponding to the
# sample index (i.e. the same scheme as all datasets in this project)
df = pd.concat((pd.DataFrame({col: df.loc[row, col] for col in df.columns}).reset_index(drop=True).set_index(
pd.Series(lengths[row, 0] * [row])) for row in range(df.shape[0])), axis=0)
# Replace NaN values
grp = df.groupby(by=df.index)
df = grp.transform(interpolate_missing)
return df, labels_df
def instance_norm(self, case):
if self.root_path.count('EthanolConcentration') > 0: # special process for numerical stability
mean = case.mean(0, keepdim=True)
case = case - mean
stdev = torch.sqrt(torch.var(case, dim=1, keepdim=True, unbiased=False) + 1e-5)
case /= stdev
return case
else:
return case
def __getitem__(self, ind):
batch_x = self.feature_df.loc[self.all_IDs[ind]].values
labels = self.labels_df.loc[self.all_IDs[ind]].values
if self.flag == "TRAIN" and self.args.augmentation_ratio > 0:
num_samples = len(self.all_IDs)
num_columns = self.feature_df.shape[1]
seq_len = int(self.feature_df.shape[0] / num_samples)
batch_x = batch_x.reshape((1, seq_len, num_columns))
batch_x, labels, augmentation_tags = run_augmentation_single(batch_x, labels, self.args)
batch_x = batch_x.reshape((1 * seq_len, num_columns))
return self.instance_norm(torch.from_numpy(batch_x)), \
torch.from_numpy(labels)
def __len__(self):
return len(self.all_IDs)
================================================
FILE: data_provider/m4.py
================================================
# This source code is provided for the purposes of scientific reproducibility
# under the following limited license from Element AI Inc. The code is an
# implementation of the N-BEATS model (Oreshkin et al., N-BEATS: Neural basis
# expansion analysis for interpretable time series forecasting,
# https://arxiv.org/abs/1905.10437). The copyright to the source code is
# licensed under the Creative Commons - Attribution-NonCommercial 4.0
# International license (CC BY-NC 4.0):
# https://creativecommons.org/licenses/by-nc/4.0/. Any commercial use (whether
# for the benefit of third parties or internally in production) requires an
# explicit license. The subject-matter of the N-BEATS model and associated
# materials are the property of Element AI Inc. and may be subject to patent
# protection. No license to patents is granted hereunder (whether express or
# implied). Copyright © 2020 Element AI Inc. All rights reserved.
"""
M4 Dataset
"""
import logging
import os
from collections import OrderedDict
from dataclasses import dataclass
from glob import glob
import numpy as np
import pandas as pd
import patoolib
from tqdm import tqdm
import logging
import os
import pathlib
import sys
from urllib import request
from huggingface_hub import hf_hub_download
HUGGINGFACE_REPO = "thuml/Time-Series-Library"
def _ensure_m4_triplet(root_dir="./dataset/m4", repo_id=HUGGINGFACE_REPO):
root_dir = os.path.abspath(root_dir)
os.makedirs(root_dir, exist_ok=True)
files = {
"M4-info.csv": "m4/M4-info.csv",
"training.npz": "m4/training.npz",
"test.npz": "m4/test.npz",
}
for name, remote in files.items():
dst = os.path.join(root_dir, name)
if not os.path.exists(dst):
path = hf_hub_download(
repo_id=repo_id,
filename=remote,
repo_type="dataset",
local_dir="./dataset",
local_dir_use_symlinks=False
)
def url_file_name(url: str) -> str:
"""
Extract file name from url.
:param url: URL to extract file name from.
:return: File name.
"""
return url.split('/')[-1] if len(url) > 0 else ''
def download(url: str, file_path: str) -> None:
"""
Download a file to the given path.
:param url: URL to download
:param file_path: Where to download the content.
"""
def progress(count, block_size, total_size):
progress_pct = float(count * block_size) / float(total_size) * 100.0
sys.stdout.write('\rDownloading {} to {} {:.1f}%'.format(url, file_path, progress_pct))
sys.stdout.flush()
if not os.path.isfile(file_path):
opener = request.build_opener()
opener.addheaders = [('User-agent', 'Mozilla/5.0')]
request.install_opener(opener)
pathlib.Path(os.path.dirname(file_path)).mkdir(parents=True, exist_ok=True)
f, _ = request.urlretrieve(url, file_path, progress)
sys.stdout.write('\n')
sys.stdout.flush()
file_info = os.stat(f)
logging.info(f'Successfully downloaded {os.path.basename(file_path)} {file_info.st_size} bytes.')
else:
file_info = os.stat(file_path)
logging.info(f'File already exists: {file_path} {file_info.st_size} bytes.')
@dataclass()
class M4Dataset:
ids: np.ndarray
groups: np.ndarray
frequencies: np.ndarray
horizons: np.ndarray
values: np.ndarray
@staticmethod
def load(training: bool = True, dataset_file: str = '../dataset/m4') -> 'M4Dataset':
"""
Load cached dataset.
:param training: Load training part if training is True, test part otherwise.
"""
_ensure_m4_triplet(dataset_file, repo_id=HUGGINGFACE_REPO)
info_file = os.path.join(dataset_file, 'M4-info.csv')
train_cache_file = os.path.join(dataset_file, 'training.npz')
test_cache_file = os.path.join(dataset_file, 'test.npz')
m4_info = pd.read_csv(info_file)
return M4Dataset(ids=m4_info.M4id.values,
groups=m4_info.SP.values,
frequencies=m4_info.Frequency.values,
horizons=m4_info.Horizon.values,
values=np.load(
train_cache_file if training else test_cache_file,
allow_pickle=True))
@dataclass()
class M4Meta:
seasonal_patterns = ['Yearly', 'Quarterly', 'Monthly', 'Weekly', 'Daily', 'Hourly']
horizons = [6, 8, 18, 13, 14, 48]
frequencies = [1, 4, 12, 1, 1, 24]
horizons_map = {
'Yearly': 6,
'Quarterly': 8,
'Monthly': 18,
'Weekly': 13,
'Daily': 14,
'Hourly': 48
} # different predict length
frequency_map = {
'Yearly': 1,
'Quarterly': 4,
'Monthly': 12,
'Weekly': 1,
'Daily': 1,
'Hourly': 24
}
history_size = {
'Yearly': 1.5,
'Quarterly': 1.5,
'Monthly': 1.5,
'Weekly': 10,
'Daily': 10,
'Hourly': 10
} # from interpretable.gin
def load_m4_info() -> pd.DataFrame:
"""
Load M4Info file.
:return: Pandas DataFrame of M4Info.
"""
# return pd.read_csv(INFO_FILE_PATH)
================================================
FILE: data_provider/uea.py
================================================
import os
import numpy as np
import pandas as pd
import torch
def collate_fn(data, max_len=None):
"""Build mini-batch tensors from a list of (X, mask) tuples. Mask input. Create
Args:
data: len(batch_size) list of tuples (X, y).
- X: torch tensor of shape (seq_length, feat_dim); variable seq_length.
- y: torch tensor of shape (num_labels,) : class indices or numerical targets
(for classification or regression, respectively). num_labels > 1 for multi-task models
max_len: global fixed sequence length. Used for architectures requiring fixed length input,
where the batch length cannot vary dynamically. Longer sequences are clipped, shorter are padded with 0s
Returns:
X: (batch_size, padded_length, feat_dim) torch tensor of masked features (input)
targets: (batch_size, padded_length, feat_dim) torch tensor of unmasked features (output)
target_masks: (batch_size, padded_length, feat_dim) boolean torch tensor
0 indicates masked values to be predicted, 1 indicates unaffected/"active" feature values
padding_masks: (batch_size, padded_length) boolean tensor, 1 means keep vector at this position, 0 means padding
"""
batch_size = len(data)
features, labels = zip(*data)
# Stack and pad features and masks (convert 2D to 3D tensors, i.e. add batch dimension)
lengths = [X.shape[0] for X in features] # original sequence length for each time series
if max_len is None:
max_len = max(lengths)
X = torch.zeros(batch_size, max_len, features[0].shape[-1]) # (batch_size, padded_length, feat_dim)
for i in range(batch_size):
end = min(lengths[i], max_len)
X[i, :end, :] = features[i][:end, :]
targets = torch.stack(labels, dim=0) # (batch_size, num_labels)
padding_masks = padding_mask(torch.tensor(lengths, dtype=torch.int16),
max_len=max_len) # (batch_size, padded_length) boolean tensor, "1" means keep
return X, targets, padding_masks
def padding_mask(lengths, max_len=None):
"""
Used to mask padded positions: creates a (batch_size, max_len) boolean mask from a tensor of sequence lengths,
where 1 means keep element at this position (time step)
"""
batch_size = lengths.numel()
max_len = max_len or lengths.max_val() # trick works because of overloading of 'or' operator for non-boolean types
return (torch.arange(0, max_len, device=lengths.device)
.type_as(lengths)
.repeat(batch_size, 1)
.lt(lengths.unsqueeze(1)))
class Normalizer(object):
"""
Normalizes dataframe across ALL contained rows (time steps). Different from per-sample normalization.
"""
def __init__(self, norm_type='standardization', mean=None, std=None, min_val=None, max_val=None):
"""
Args:
norm_type: choose from:
"standardization", "minmax": normalizes dataframe across ALL contained rows (time steps)
"per_sample_std", "per_sample_minmax": normalizes each sample separately (i.e. across only its own rows)
mean, std, min_val, max_val: optional (num_feat,) Series of pre-computed values
"""
self.norm_type = norm_type
self.mean = mean
self.std = std
self.min_val = min_val
self.max_val = max_val
def normalize(self, df):
"""
Args:
df: input dataframe
Returns:
df: normalized dataframe
"""
if self.norm_type == "standardization":
if self.mean is None:
self.mean = df.mean()
self.std = df.std()
return (df - self.mean) / (self.std + np.finfo(float).eps)
elif self.norm_type == "minmax":
if self.max_val is None:
self.max_val = df.max()
self.min_val = df.min()
return (df - self.min_val) / (self.max_val - self.min_val + np.finfo(float).eps)
elif self.norm_type == "per_sample_std":
grouped = df.groupby(by=df.index)
return (df - grouped.transform('mean')) / grouped.transform('std')
elif self.norm_type == "per_sample_minmax":
grouped = df.groupby(by=df.index)
min_vals = grouped.transform('min')
return (df - min_vals) / (grouped.transform('max') - min_vals + np.finfo(float).eps)
else:
raise (NameError(f'Normalize method "{self.norm_type}" not implemented'))
def interpolate_missing(y):
"""
Replaces NaN values in pd.Series `y` using linear interpolation
"""
if y.isna().any():
y = y.interpolate(method='linear', limit_direction='both')
return y
def subsample(y, limit=256, factor=2):
"""
If a given Series is longer than `limit`, returns subsampled sequence by the specified integer factor
"""
if len(y) > limit:
return y[::factor].reset_index(drop=True)
return y
================================================
FILE: docker-compose.yml
================================================
services:
dev_tslib:
image: tslib
build:
context: .
target: tslib
# args:
# http_proxy: "http://192.168.8.135:7897" #optional, Modify it to your agent address
# https_proxy: "http://192.168.8.135:7897" #optional, Modify it to your agent address
container_name: tslib
shm_size: 8gb
tty: true
restart: always
environment:
- NVIDIA_VISIBLE_DEVICES=all
- NVIDIA_DRIVER_CAPABILITIES=compute,utility
# - http_proxy=http://192.168.8.135:7897 #optional, Modify it to your agent address
# - https_proxy=http://192.168.8.135:7897 #optional, Modify it to your agent address
# ports:
# - "8888:8888"
# - "6006:6006"
volumes:
- workspace_data:/workspace
working_dir: /workspace
volumes:
workspace_data:
================================================
FILE: exp/__init__.py
================================================
================================================
FILE: exp/exp_anomaly_detection.py
================================================
from data_provider.data_factory import data_provider
from exp.exp_basic import Exp_Basic
from utils.tools import EarlyStopping, adjust_learning_rate, adjustment
from sklearn.metrics import precision_recall_fscore_support
from sklearn.metrics import accuracy_score
import torch.multiprocessing
torch.multiprocessing.set_sharing_strategy('file_system')
import torch
import torch.nn as nn
from torch import optim
import os
import time
import warnings
import numpy as np
warnings.filterwarnings('ignore')
class Exp_Anomaly_Detection(Exp_Basic):
def __init__(self, args):
super(Exp_Anomaly_Detection, self).__init__(args)
def _build_model(self):
model = self.model_dict[self.args.model](self.args).float()
if self.args.use_multi_gpu and self.args.use_gpu:
model = nn.DataParallel(model, device_ids=self.args.device_ids)
return model
def _get_data(self, flag):
data_set, data_loader = data_provider(self.args, flag)
return data_set, data_loader
def _select_optimizer(self):
model_optim = optim.Adam(self.model.parameters(), lr=self.args.learning_rate)
return model_optim
def _select_criterion(self):
criterion = nn.MSELoss()
return criterion
def vali(self, vali_data, vali_loader, criterion):
total_loss = []
self.model.eval()
with torch.no_grad():
for i, (batch_x, _) in enumerate(vali_loader):
batch_x = batch_x.float().to(self.device)
outputs = self.model(batch_x, None, None, None)
f_dim = -1 if self.args.features == 'MS' else 0
outputs = outputs[:, :, f_dim:]
pred = outputs.detach()
true = batch_x.detach()
loss = criterion(pred, true)
total_loss.append(loss.item())
total_loss = np.average(total_loss)
self.model.train()
return total_loss
def train(self, setting):
train_data, train_loader = self._get_data(flag='train')
vali_data, vali_loader = self._get_data(flag='val')
test_data, test_loader = self._get_data(flag='test')
path = os.path.join(self.args.checkpoints, setting)
if not os.path.exists(path):
os.makedirs(path)
time_now = time.time()
train_steps = len(train_loader)
early_stopping = EarlyStopping(patience=self.args.patience, verbose=True)
model_optim = self._select_optimizer()
criterion = self._select_criterion()
for epoch in range(self.args.train_epochs):
iter_count = 0
train_loss = []
self.model.train()
epoch_time = time.time()
for i, (batch_x, batch_y) in enumerate(train_loader):
iter_count += 1
model_optim.zero_grad()
batch_x = batch_x.float().to(self.device)
outputs = self.model(batch_x, None, None, None)
f_dim = -1 if self.args.features == 'MS' else 0
outputs = outputs[:, :, f_dim:]
loss = criterion(outputs, batch_x)
train_loss.append(loss.item())
if (i + 1) % 100 == 0:
print("\titers: {0}, epoch: {1} | loss: {2:.7f}".format(i + 1, epoch + 1, loss.item()))
speed = (time.time() - time_now) / iter_count
left_time = speed * ((self.args.train_epochs - epoch) * train_steps - i)
print('\tspeed: {:.4f}s/iter; left time: {:.4f}s'.format(speed, left_time))
iter_count = 0
time_now = time.time()
loss.backward()
model_optim.step()
print("Epoch: {} cost time: {}".format(epoch + 1, time.time() - epoch_time))
train_loss = np.average(train_loss)
vali_loss = self.vali(vali_data, vali_loader, criterion)
test_loss = self.vali(test_data, test_loader, criterion)
print("Epoch: {0}, Steps: {1} | Train Loss: {2:.7f} Vali Loss: {3:.7f} Test Loss: {4:.7f}".format(
epoch + 1, train_steps, train_loss, vali_loss, test_loss))
early_stopping(vali_loss, self.model, path)
if early_stopping.early_stop:
print("Early stopping")
break
adjust_learning_rate(model_optim, epoch + 1, self.args)
best_model_path = path + '/' + 'checkpoint.pth'
self.model.load_state_dict(torch.load(best_model_path))
return self.model
def test(self, setting, test=0):
test_data, test_loader = self._get_data(flag='test')
train_data, train_loader = self._get_data(flag='train')
if test:
print('loading model')
self.model.load_state_dict(torch.load(os.path.join('./checkpoints/' + setting, 'checkpoint.pth')))
attens_energy = []
folder_path = './test_results/' + setting + '/'
if not os.path.exists(folder_path):
os.makedirs(folder_path)
self.model.eval()
self.anomaly_criterion = nn.MSELoss(reduce=False)
# (1) stastic on the train set
with torch.no_grad():
for i, (batch_x, batch_y) in enumerate(train_loader):
batch_x = batch_x.float().to(self.device)
# reconstruction
outputs = self.model(batch_x, None, None, None)
# criterion
score = torch.mean(self.anomaly_criterion(batch_x, outputs), dim=-1)
score = score.detach().cpu().numpy()
attens_energy.append(score)
attens_energy = np.concatenate(attens_energy, axis=0).reshape(-1)
train_energy = np.array(attens_energy)
# (2) find the threshold
attens_energy = []
test_labels = []
for i, (batch_x, batch_y) in enumerate(test_loader):
batch_x = batch_x.float().to(self.device)
# reconstruction
outputs = self.model(batch_x, None, None, None)
# criterion
score = torch.mean(self.anomaly_criterion(batch_x, outputs), dim=-1)
score = score.detach().cpu().numpy()
attens_energy.append(score)
test_labels.append(batch_y)
attens_energy = np.concatenate(attens_energy, axis=0).reshape(-1)
test_energy = np.array(attens_energy)
combined_energy = np.concatenate([train_energy, test_energy], axis=0)
threshold = np.percentile(combined_energy, 100 - self.args.anomaly_ratio)
print("Threshold :", threshold)
# (3) evaluation on the test set
pred = (test_energy > threshold).astype(int)
test_labels = np.concatenate(test_labels, axis=0).reshape(-1)
test_labels = np.array(test_labels)
gt = test_labels.astype(int)
print("pred: ", pred.shape)
print("gt: ", gt.shape)
# (4) detection adjustment
gt, pred = adjustment(gt, pred)
pred = np.array(pred)
gt = np.array(gt)
print("pred: ", pred.shape)
print("gt: ", gt.shape)
accuracy = accuracy_score(gt, pred)
precision, recall, f_score, support = precision_recall_fscore_support(gt, pred, average='binary')
print("Accuracy : {:0.4f}, Precision : {:0.4f}, Recall : {:0.4f}, F-score : {:0.4f} ".format(
accuracy, precision,
recall, f_score))
f = open("result_anomaly_detection.txt", 'a')
f.write(setting + " \n")
f.write("Accuracy : {:0.4f}, Precision : {:0.4f}, Recall : {:0.4f}, F-score : {:0.4f} ".format(
accuracy, precision,
recall, f_score))
f.write('\n')
f.write('\n')
f.close()
return
================================================
FILE: exp/exp_basic.py
================================================
import os
import torch
import importlib
import pkgutil
# Just put your model files under models/ folder
# e.g., models/Transformer.py, models/LSTM.py, etc.
# All models will be automatically detected and can be used by specifying their names.
class Exp_Basic(object):
def __init__(self, args):
self.args = args
# -------------------------------------------------------
# Automatically generate model map
# -------------------------------------------------------
model_map = self._scan_models_directory()
# Use smart dictionary
self.model_dict = LazyModelDict(model_map)
self.device = self._acquire_device()
self.model = self._build_model().to(self.device)
def _scan_models_directory(self):
"""
Automatically scan all .py files in the models folder
"""
model_map = {}
models_dir = 'models'
# Iterate through all files in 'models' directory
if os.path.exists(models_dir):
for filename in os.listdir(models_dir):
# Ignore __init__.py and non-.py files
if filename.endswith('.py') and filename != '__init__.py':
# Remove .py extension to get module name
module_name = filename[:-3]
# Build full import path
full_path = f"{models_dir}.{module_name}"
# loading dict: {'Transformer': 'models.Transformer'}
model_map[module_name] = full_path
return model_map
def _build_model(self):
raise NotImplementedError
return None
def _acquire_device(self):
if self.args.use_gpu and self.args.gpu_type == 'cuda':
os.environ["CUDA_VISIBLE_DEVICES"] = str(
self.args.gpu) if not self.args.use_multi_gpu else self.args.devices
device = torch.device('cuda:{}'.format(self.args.gpu))
print('Use GPU: cuda:{}'.format(self.args.gpu))
elif self.args.use_gpu and self.args.gpu_type == 'mps':
device = torch.device('mps')
print('Use GPU: mps')
else:
device = torch.device('cpu')
print('Use CPU')
return device
def _get_data(self):
pass
def vali(self):
pass
def train(self):
pass
def test(self):
pass
class LazyModelDict(dict):
"""
Smart Lazy-Loading Dictionary
"""
def __init__(self, model_map):
self.model_map = model_map
super().__init__()
def __getitem__(self, key):
if key in self:
return super().__getitem__(key)
if key not in self.model_map:
raise NotImplementedError(f"Model [{key}] not found in 'models' directory.")
module_path = self.model_map[key]
try:
print(f"🚀 Lazy Loading: {key} ...")
module = importlib.import_module(module_path)
except ImportError as e:
print(f"❌ Error: Failed to import model [{key}]. Dependencies missing?")
raise e
# Try to find the model class
if hasattr(module, 'Model'):
model_class = module.Model
elif hasattr(module, key):
model_class = getattr(module, key)
else:
raise AttributeError(f"Module {module_path} has no class 'Model' or '{key}'")
self[key] = model_class
return model_class
================================================
FILE: exp/exp_classification.py
================================================
from data_provider.data_factory import data_provider
from exp.exp_basic import Exp_Basic
from utils.tools import EarlyStopping, adjust_learning_rate, cal_accuracy
import torch
import torch.nn as nn
from torch import optim
import os
import time
import warnings
import numpy as np
import pdb
warnings.filterwarnings('ignore')
class Exp_Classification(Exp_Basic):
def __init__(self, args):
super(Exp_Classification, self).__init__(args)
def _build_model(self):
# model input depends on data
train_data, train_loader = self._get_data(flag='TRAIN')
test_data, test_loader = self._get_data(flag='TEST')
self.args.seq_len = max(train_data.max_seq_len, test_data.max_seq_len)
self.args.pred_len = 0
self.args.enc_in = train_data.feature_df.shape[1]
self.args.num_class = len(train_data.class_names)
# model init
model = self.model_dict[self.args.model](self.args).float()
if self.args.use_multi_gpu and self.args.use_gpu:
model = nn.DataParallel(model, device_ids=self.args.device_ids)
return model
def _get_data(self, flag):
data_set, data_loader = data_provider(self.args, flag)
return data_set, data_loader
def _select_optimizer(self):
# model_optim = optim.Adam(self.model.parameters(), lr=self.args.learning_rate)
model_optim = optim.RAdam(self.model.parameters(), lr=self.args.learning_rate)
return model_optim
def _select_criterion(self):
criterion = nn.CrossEntropyLoss()
return criterion
def vali(self, vali_data, vali_loader, criterion):
total_loss = []
preds = []
trues = []
self.model.eval()
with torch.no_grad():
for i, (batch_x, label, padding_mask) in enumerate(vali_loader):
batch_x = batch_x.float().to(self.device)
padding_mask = padding_mask.float().to(self.device)
label = label.to(self.device)
outputs = self.model(batch_x, padding_mask, None, None)
pred = outputs.detach()
loss = criterion(pred, label.long().squeeze())
total_loss.append(loss.item())
preds.append(outputs.detach())
trues.append(label)
total_loss = np.average(total_loss)
preds = torch.cat(preds, 0)
trues = torch.cat(trues, 0)
probs = torch.nn.functional.softmax(preds) # (total_samples, num_classes) est. prob. for each class and sample
predictions = torch.argmax(probs, dim=1).cpu().numpy() # (total_samples,) int class index for each sample
trues = trues.flatten().cpu().numpy()
accuracy = cal_accuracy(predictions, trues)
self.model.train()
return total_loss, accuracy
def train(self, setting):
train_data, train_loader = self._get_data(flag='TRAIN')
vali_data, vali_loader = self._get_data(flag='TEST')
test_data, test_loader = self._get_data(flag='TEST')
path = os.path.join(self.args.checkpoints, setting)
if not os.path.exists(path):
os.makedirs(path)
time_now = time.time()
train_steps = len(train_loader)
early_stopping = EarlyStopping(patience=self.args.patience, verbose=True)
model_optim = self._select_optimizer()
criterion = self._select_criterion()
for epoch in range(self.args.train_epochs):
iter_count = 0
train_loss = []
self.model.train()
epoch_time = time.time()
for i, (batch_x, label, padding_mask) in enumerate(train_loader):
iter_count += 1
model_optim.zero_grad()
batch_x = batch_x.float().to(self.device)
padding_mask = padding_mask.float().to(self.device)
label = label.to(self.device)
outputs = self.model(batch_x, padding_mask, None, None)
loss = criterion(outputs, label.long().squeeze(-1))
train_loss.append(loss.item())
if (i + 1) % 100 == 0:
print("\titers: {0}, epoch: {1} | loss: {2:.7f}".format(i + 1, epoch + 1, loss.item()))
speed = (time.time() - time_now) / iter_count
left_time = speed * ((self.args.train_epochs - epoch) * train_steps - i)
print('\tspeed: {:.4f}s/iter; left time: {:.4f}s'.format(speed, left_time))
iter_count = 0
time_now = time.time()
loss.backward()
nn.utils.clip_grad_norm_(self.model.parameters(), max_norm=4.0)
model_optim.step()
print("Epoch: {} cost time: {}".format(epoch + 1, time.time() - epoch_time))
train_loss = np.average(train_loss)
vali_loss, val_accuracy = self.vali(vali_data, vali_loader, criterion)
test_loss, test_accuracy = self.vali(test_data, test_loader, criterion)
print(
"Epoch: {0}, Steps: {1} | Train Loss: {2:.3f} Vali Loss: {3:.3f} Vali Acc: {4:.3f} Test Loss: {5:.3f} Test Acc: {6:.3f}"
.format(epoch + 1, train_steps, train_loss, vali_loss, val_accuracy, test_loss, test_accuracy))
early_stopping(-val_accuracy, self.model, path)
if early_stopping.early_stop:
print("Early stopping")
break
best_model_path = path + '/' + 'checkpoint.pth'
self.model.load_state_dict(torch.load(best_model_path))
return self.model
def test(self, setting, test=0):
test_data, test_loader = self._get_data(flag='TEST')
if test:
print('loading model')
self.model.load_state_dict(torch.load(os.path.join(self.args.checkpoints, setting, 'checkpoint.pth')))
preds = []
trues = []
folder_path = './test_results/' + setting + '/'
if not os.path.exists(folder_path):
os.makedirs(folder_path)
self.model.eval()
with torch.no_grad():
for i, (batch_x, label, padding_mask) in enumerate(test_loader):
batch_x = batch_x.float().to(self.device)
padding_mask = padding_mask.float().to(self.device)
label = label.to(self.device)
outputs = self.model(batch_x, padding_mask, None, None)
preds.append(outputs.detach())
trues.append(label)
preds = torch.cat(preds, 0)
trues = torch.cat(trues, 0)
print('test shape:', preds.shape, trues.shape)
probs = torch.nn.functional.softmax(preds) # (total_samples, num_classes) est. prob. for each class and sample
predictions = torch.argmax(probs, dim=1).cpu().numpy() # (total_samples,) int class index for each sample
trues = trues.flatten().cpu().numpy()
accuracy = cal_accuracy(predictions, trues)
# result save
folder_path = './results/' + setting + '/'
if not os.path.exists(folder_path):
os.makedirs(folder_path)
print('accuracy:{}'.format(accuracy))
file_name='result_classification.txt'
f = open(os.path.join(folder_path,file_name), 'a')
f.write(setting + " \n")
f.write('accuracy:{}'.format(accuracy))
f.write('\n')
f.write('\n')
f.close()
return
================================================
FILE: exp/exp_imputation.py
================================================
from data_provider.data_factory import data_provider
from exp.exp_basic import Exp_Basic
from utils.tools import EarlyStopping, adjust_learning_rate, visual
from utils.metrics import metric
import torch
import torch.nn as nn
from torch import optim
import os
import time
import warnings
import numpy as np
warnings.filterwarnings('ignore')
class Exp_Imputation(Exp_Basic):
def __init__(self, args):
super(Exp_Imputation, self).__init__(args)
def _build_model(self):
model = self.model_dict[self.args.model](self.args).float()
if self.args.use_multi_gpu and self.args.use_gpu:
model = nn.DataParallel(model, device_ids=self.args.device_ids)
return model
def _get_data(self, flag):
data_set, data_loader = data_provider(self.args, flag)
return data_set, data_loader
def _select_optimizer(self):
model_optim = optim.Adam(self.model.parameters(), lr=self.args.learning_rate)
return model_optim
def _select_criterion(self):
criterion = nn.MSELoss()
return criterion
def vali(self, vali_data, vali_loader, criterion):
total_loss = []
self.model.eval()
with torch.no_grad():
for i, (batch_x, batch_y, batch_x_mark, batch_y_mark) in enumerate(vali_loader):
batch_x = batch_x.float().to(self.device)
batch_x_mark = batch_x_mark.float().to(self.device)
# random mask
B, T, N = batch_x.shape
"""
B = batch size
T = seq len
N = number of features
"""
mask = torch.rand((B, T, N)).to(self.device)
mask[mask <= self.args.mask_rate] = 0 # masked
mask[mask > self.args.mask_rate] = 1 # remained
inp = batch_x.masked_fill(mask == 0, 0)
outputs = self.model(inp, batch_x_mark, None, None, mask)
f_dim = -1 if self.args.features == 'MS' else 0
outputs = outputs[:, :, f_dim:]
# add support for MS
batch_x = batch_x[:, :, f_dim:]
mask = mask[:, :, f_dim:]
pred = outputs.detach()
true = batch_x.detach()
mask = mask.detach()
loss = criterion(pred[mask == 0], true[mask == 0])
total_loss.append(loss.item())
total_loss = np.average(total_loss)
self.model.train()
return total_loss
def train(self, setting):
train_data, train_loader = self._get_data(flag='train')
vali_data, vali_loader = self._get_data(flag='val')
test_data, test_loader = self._get_data(flag='test')
path = os.path.join(self.args.checkpoints, setting)
if not os.path.exists(path):
os.makedirs(path)
time_now = time.time()
train_steps = len(train_loader)
early_stopping = EarlyStopping(patience=self.args.patience, verbose=True)
model_optim = self._select_optimizer()
criterion = self._select_criterion()
for epoch in range(self.args.train_epochs):
iter_count = 0
train_loss = []
self.model.train()
epoch_time = time.time()
for i, (batch_x, batch_y, batch_x_mark, batch_y_mark) in enumerate(train_loader):
iter_count += 1
model_optim.zero_grad()
batch_x = batch_x.float().to(self.device)
batch_x_mark = batch_x_mark.float().to(self.device)
# random mask
B, T, N = batch_x.shape
mask = torch.rand((B, T, N)).to(self.device)
mask[mask <= self.args.mask_rate] = 0 # masked
mask[mask > self.args.mask_rate] = 1 # remained
inp = batch_x.masked_fill(mask == 0, 0)
outputs = self.model(inp, batch_x_mark, None, None, mask)
f_dim = -1 if self.args.features == 'MS' else 0
outputs = outputs[:, :, f_dim:]
# add support for MS
batch_x = batch_x[:, :, f_dim:]
mask = mask[:, :, f_dim:]
loss = criterion(outputs[mask == 0], batch_x[mask == 0])
train_loss.append(loss.item())
if (i + 1) % 100 == 0:
print("\titers: {0}, epoch: {1} | loss: {2:.7f}".format(i + 1, epoch + 1, loss.item()))
speed = (time.time() - time_now) / iter_count
left_time = speed * ((self.args.train_epochs - epoch) * train_steps - i)
print('\tspeed: {:.4f}s/iter; left time: {:.4f}s'.format(speed, left_time))
iter_count = 0
time_now = time.time()
loss.backward()
model_optim.step()
print("Epoch: {} cost time: {}".format(epoch + 1, time.time() - epoch_time))
train_loss = np.average(train_loss)
vali_loss = self.vali(vali_data, vali_loader, criterion)
test_loss = self.vali(test_data, test_loader, criterion)
print("Epoch: {0}, Steps: {1} | Train Loss: {2:.7f} Vali Loss: {3:.7f} Test Loss: {4:.7f}".format(
epoch + 1, train_steps, train_loss, vali_loss, test_loss))
early_stopping(vali_loss, self.model, path)
if early_stopping.early_stop:
print("Early stopping")
break
adjust_learning_rate(model_optim, epoch + 1, self.args)
best_model_path = path + '/' + 'checkpoint.pth'
self.model.load_state_dict(torch.load(best_model_path))
return self.model
def test(self, setting, test=0):
test_data, test_loader = self._get_data(flag='test')
if test:
print('loading model')
self.model.load_state_dict(torch.load(os.path.join('./checkpoints/' + setting, 'checkpoint.pth')))
preds = []
trues = []
masks = []
folder_path = './test_results/' + setting + '/'
if not os.path.exists(folder_path):
os.makedirs(folder_path)
self.model.eval()
with torch.no_grad():
for i, (batch_x, batch_y, batch_x_mark, batch_y_mark) in enumerate(test_loader):
batch_x = batch_x.float().to(self.device)
batch_x_mark = batch_x_mark.float().to(self.device)
# random mask
B, T, N = batch_x.shape
mask = torch.rand((B, T, N)).to(self.device)
mask[mask <= self.args.mask_rate] = 0 # masked
mask[mask > self.args.mask_rate] = 1 # remained
inp = batch_x.masked_fill(mask == 0, 0)
# imputation
outputs = self.model(inp, batch_x_mark, None, None, mask)
# eval
f_dim = -1 if self.args.features == 'MS' else 0
outputs = outputs[:, :, f_dim:]
# add support for MS
batch_x = batch_x[:, :, f_dim:]
mask = mask[:, :, f_dim:]
outputs = outputs.detach().cpu().numpy()
pred = outputs
true = batch_x.detach().cpu().numpy()
preds.append(pred)
trues.append(true)
masks.append(mask.detach().cpu())
if i % 20 == 0:
filled = true[0, :, -1].copy()
filled = filled * mask[0, :, -1].detach().cpu().numpy() + \
pred[0, :, -1] * (1 - mask[0, :, -1].detach().cpu().numpy())
visual(true[0, :, -1], filled, os.path.join(folder_path, str(i) + '.pdf'))
preds = np.concatenate(preds, 0)
trues = np.concatenate(trues, 0)
masks = np.concatenate(masks, 0)
print('test shape:', preds.shape, trues.shape)
# result save
folder_path = './results/' + setting + '/'
if not os.path.exists(folder_path):
os.makedirs(folder_path)
mae, mse, rmse, mape, mspe = metric(preds[masks == 0], trues[masks == 0])
print('mse:{}, mae:{}'.format(mse, mae))
f = open("result_imputation.txt", 'a')
f.write(setting + " \n")
f.write('mse:{}, mae:{}'.format(mse, mae))
f.write('\n')
f.write('\n')
f.close()
np.save(folder_path + 'metrics.npy', np.array([mae, mse, rmse, mape, mspe]))
np.save(folder_path + 'pred.npy', preds)
np.save(folder_path + 'true.npy', trues)
return
================================================
FILE: exp/exp_long_term_forecasting.py
================================================
from data_provider.data_factory import data_provider
from exp.exp_basic import Exp_Basic
from utils.tools import EarlyStopping, adjust_learning_rate, visual
from utils.metrics import metric
import torch
import torch.nn as nn
from torch import optim
import os
import time
import warnings
import numpy as np
from utils.dtw_metric import dtw, accelerated_dtw
from utils.augmentation import run_augmentation, run_augmentation_single
warnings.filterwarnings('ignore')
class Exp_Long_Term_Forecast(Exp_Basic):
def __init__(self, args):
super(Exp_Long_Term_Forecast, self).__init__(args)
def _build_model(self):
model = self.model_dict[self.args.model](self.args).float()
if self.args.use_multi_gpu and self.args.use_gpu:
model = nn.DataParallel(model, device_ids=self.args.device_ids)
return model
def _get_data(self, flag):
data_set, data_loader = data_provider(self.args, flag)
return data_set, data_loader
def _select_optimizer(self):
model_optim = optim.Adam(self.model.parameters(), lr=self.args.learning_rate)
return model_optim
def _select_criterion(self):
criterion = nn.MSELoss()
return criterion
def vali(self, vali_data, vali_loader, criterion):
total_loss = []
self.model.eval()
with torch.no_grad():
for i, (batch_x, batch_y, batch_x_mark, batch_y_mark) in enumerate(vali_loader):
batch_x = batch_x.float().to(self.device)
batch_y = batch_y.float()
batch_x_mark = batch_x_mark.float().to(self.device)
batch_y_mark = batch_y_mark.float().to(self.device)
# decoder input
dec_inp = torch.zeros_like(batch_y[:, -self.args.pred_len:, :]).float()
dec_inp = torch.cat([batch_y[:, :self.args.label_len, :], dec_inp], dim=1).float().to(self.device)
# encoder - decoder
if self.args.use_amp:
with torch.cuda.amp.autocast():
outputs = self.model(batch_x, batch_x_mark, dec_inp, batch_y_mark)
else:
outputs = self.model(batch_x, batch_x_mark, dec_inp, batch_y_mark)
f_dim = -1 if self.args.features == 'MS' else 0
outputs = outputs[:, -self.args.pred_len:, f_dim:]
batch_y = batch_y[:, -self.args.pred_len:, f_dim:].to(self.device)
pred = outputs.detach()
true = batch_y.detach()
loss = criterion(pred, true)
total_loss.append(loss.item())
total_loss = np.average(total_loss)
self.model.train()
return total_loss
def train(self, setting):
train_data, train_loader = self._get_data(flag='train')
vali_data, vali_loader = self._get_data(flag='val')
test_data, test_loader = self._get_data(flag='test')
path = os.path.join(self.args.checkpoints, setting)
if not os.path.exists(path):
os.makedirs(path)
time_now = time.time()
train_steps = len(train_loader)
early_stopping = EarlyStopping(patience=self.args.patience, verbose=True)
model_optim = self._select_optimizer()
criterion = self._select_criterion()
if self.args.use_amp:
scaler = torch.cuda.amp.GradScaler()
for epoch in range(self.args.train_epochs):
iter_count = 0
train_loss = []
self.model.train()
epoch_time = time.time()
for i, (batch_x, batch_y, batch_x_mark, batch_y_mark) in enumerate(train_loader):
iter_count += 1
model_optim.zero_grad()
batch_x = batch_x.float().to(self.device)
batch_y = batch_y.float().to(self.device)
batch_x_mark = batch_x_mark.float().to(self.device)
batch_y_mark = batch_y_mark.float().to(self.device)
# decoder input
dec_inp = torch.zeros_like(batch_y[:, -self.args.pred_len:, :]).float()
dec_inp = torch.cat([batch_y[:, :self.args.label_len, :], dec_inp], dim=1).float().to(self.device)
# encoder - decoder
if self.args.use_amp:
with torch.cuda.amp.autocast():
outputs = self.model(batch_x, batch_x_mark, dec_inp, batch_y_mark)
f_dim = -1 if self.args.features == 'MS' else 0
outputs = outputs[:, -self.args.pred_len:, f_dim:]
batch_y = batch_y[:, -self.args.pred_len:, f_dim:].to(self.device)
loss = criterion(outputs, batch_y)
train_loss.append(loss.item())
else:
outputs = self.model(batch_x, batch_x_mark, dec_inp, batch_y_mark)
f_dim = -1 if self.args.features == 'MS' else 0
outputs = outputs[:, -self.args.pred_len:, f_dim:]
batch_y = batch_y[:, -self.args.pred_len:, f_dim:].to(self.device)
loss = criterion(outputs, batch_y)
train_loss.append(loss.item())
if (i + 1) % 100 == 0:
print("\titers: {0}, epoch: {1} | loss: {2:.7f}".format(i + 1, epoch + 1, loss.item()))
speed = (time.time() - time_now) / iter_count
left_time = speed * ((self.args.train_epochs - epoch) * train_steps - i)
print('\tspeed: {:.4f}s/iter; left time: {:.4f}s'.format(speed, left_time))
iter_count = 0
time_now = time.time()
if self.args.use_amp:
scaler.scale(loss).backward()
scaler.step(model_optim)
scaler.update()
else:
loss.backward()
model_optim.step()
print("Epoch: {} cost time: {}".format(epoch + 1, time.time() - epoch_time))
train_loss = np.average(train_loss)
vali_loss = self.vali(vali_data, vali_loader, criterion)
test_loss = self.vali(test_data, test_loader, criterion)
print("Epoch: {0}, Steps: {1} | Train Loss: {2:.7f} Vali Loss: {3:.7f} Test Loss: {4:.7f}".format(
epoch + 1, train_steps, train_loss, vali_loss, test_loss))
early_stopping(vali_loss, self.model, path)
if early_stopping.early_stop:
print("Early stopping")
break
adjust_learning_rate(model_optim, epoch + 1, self.args)
best_model_path = path + '/' + 'checkpoint.pth'
self.model.load_state_dict(torch.load(best_model_path))
return self.model
def test(self, setting, test=0):
test_data, test_loader = self._get_data(flag='test')
if test:
print('loading model')
self.model.load_state_dict(torch.load(os.path.join('./checkpoints/' + setting, 'checkpoint.pth')))
preds = []
trues = []
folder_path = './test_results/' + setting + '/'
if not os.path.exists(folder_path):
os.makedirs(folder_path)
self.model.eval()
with torch.no_grad():
for i, (batch_x, batch_y, batch_x_mark, batch_y_mark) in enumerate(test_loader):
batch_x = batch_x.float().to(self.device)
batch_y = batch_y.float().to(self.device)
batch_x_mark = batch_x_mark.float().to(self.device)
batch_y_mark = batch_y_mark.float().to(self.device)
# decoder input
dec_inp = torch.zeros_like(batch_y[:, -self.args.pred_len:, :]).float()
dec_inp = torch.cat([batch_y[:, :self.args.label_len, :], dec_inp], dim=1).float().to(self.device)
# encoder - decoder
if self.args.use_amp:
with torch.cuda.amp.autocast():
outputs = self.model(batch_x, batch_x_mark, dec_inp, batch_y_mark)
else:
outputs = self.model(batch_x, batch_x_mark, dec_inp, batch_y_mark)
f_dim = -1 if self.args.features == 'MS' else 0
outputs = outputs[:, -self.args.pred_len:, :]
batch_y = batch_y[:, -self.args.pred_len:, :].to(self.device)
outputs = outputs.detach().cpu().numpy()
batch_y = batch_y.detach().cpu().numpy()
if test_data.scale and self.args.inverse:
shape = batch_y.shape
if outputs.shape[-1] != batch_y.shape[-1]:
outputs = np.tile(outputs, [1, 1, int(batch_y.shape[-1] / outputs.shape[-1])])
outputs = test_data.inverse_transform(outputs.reshape(shape[0] * shape[1], -1)).reshape(shape)
batch_y = test_data.inverse_transform(batch_y.reshape(shape[0] * shape[1], -1)).reshape(shape)
outputs = outputs[:, :, f_dim:]
batch_y = batch_y[:, :, f_dim:]
pred = outputs
true = batch_y
preds.append(pred)
trues.append(true)
if i % 20 == 0:
input = batch_x.detach().cpu().numpy()
if test_data.scale and self.args.inverse:
shape = input.shape
input = test_data.inverse_transform(input.reshape(shape[0] * shape[1], -1)).reshape(shape)
gt = np.concatenate((input[0, :, -1], true[0, :, -1]), axis=0)
pd = np.concatenate((input[0, :, -1], pred[0, :, -1]), axis=0)
visual(gt, pd, os.path.join(folder_path, str(i) + '.pdf'))
preds = np.concatenate(preds, axis=0)
trues = np.concatenate(trues, axis=0)
print('test shape:', preds.shape, trues.shape)
preds = preds.reshape(-1, preds.shape[-2], preds.shape[-1])
trues = trues.reshape(-1, trues.shape[-2], trues.shape[-1])
print('test shape:', preds.shape, trues.shape)
# result save
folder_path = './results/' + setting + '/'
if not os.path.exists(folder_path):
os.makedirs(folder_path)
# dtw calculation
if self.args.use_dtw:
dtw_list = []
manhattan_distance = lambda x, y: np.abs(x - y)
for i in range(preds.shape[0]):
x = preds[i].reshape(-1, 1)
y = trues[i].reshape(-1, 1)
if i % 100 == 0:
print("calculating dtw iter:", i)
d, _, _, _ = accelerated_dtw(x, y, dist=manhattan_distance)
dtw_list.append(d)
dtw = np.array(dtw_list).mean()
else:
dtw = 'Not calculated'
mae, mse, rmse, mape, mspe = metric(preds, trues)
print('mse:{}, mae:{}, dtw:{}'.format(mse, mae, dtw))
f = open("result_long_term_forecast.txt", 'a')
f.write(setting + " \n")
f.write('mse:{}, mae:{}, dtw:{}'.format(mse, mae, dtw))
f.write('\n')
f.write('\n')
f.close()
np.save(folder_path + 'metrics.npy', np.array([mae, mse, rmse, mape, mspe]))
np.save(folder_path + 'pred.npy', preds)
np.save(folder_path + 'true.npy', trues)
return
================================================
FILE: exp/exp_short_term_forecasting.py
================================================
from data_provider.data_factory import data_provider
from data_provider.m4 import M4Meta
from exp.exp_basic import Exp_Basic
from utils.tools import EarlyStopping, adjust_learning_rate, visual
from utils.losses import mape_loss, mase_loss, smape_loss
from utils.m4_summary import M4Summary
import torch
import torch.nn as nn
from torch import optim
import os
import time
import warnings
import numpy as np
import pandas
warnings.filterwarnings('ignore')
class Exp_Short_Term_Forecast(Exp_Basic):
def __init__(self, args):
super(Exp_Short_Term_Forecast, self).__init__(args)
def _build_model(self):
if self.args.data == 'm4':
self.args.pred_len = M4Meta.horizons_map[self.args.seasonal_patterns] # Up to M4 config
self.args.seq_len = 2 * self.args.pred_len # input_len = 2*pred_len
self.args.label_len = self.args.pred_len
self.args.frequency_map = M4Meta.frequency_map[self.args.seasonal_patterns]
model = self.model_dict[self.args.model](self.args).float()
if self.args.use_multi_gpu and self.args.use_gpu:
model = nn.DataParallel(model, device_ids=self.args.device_ids)
return model
def _get_data(self, flag):
data_set, data_loader = data_provider(self.args, flag)
return data_set, data_loader
def _select_optimizer(self):
model_optim = optim.Adam(self.model.parameters(), lr=self.args.learning_rate)
return model_optim
def _select_criterion(self, loss_name='MSE'):
if loss_name == 'MSE':
return nn.MSELoss()
elif loss_name == 'MAPE':
return mape_loss()
elif loss_name == 'MASE':
return mase_loss()
elif loss_name == 'SMAPE':
return smape_loss()
def train(self, setting):
train_data, train_loader = self._get_data(flag='train')
vali_data, vali_loader = self._get_data(flag='val')
path = os.path.join(self.args.checkpoints, setting)
if not os.path.exists(path):
os.makedirs(path)
time_now = time.time()
train_steps = len(train_loader)
early_stopping = EarlyStopping(patience=self.args.patience, verbose=True)
model_optim = self._select_optimizer()
criterion = self._select_criterion(self.args.loss)
mse = nn.MSELoss()
for epoch in range(self.args.train_epochs):
iter_count = 0
train_loss = []
self.model.train()
epoch_time = time.time()
for i, (batch_x, batch_y, batch_x_mark, batch_y_mark) in enumerate(train_loader):
iter_count += 1
model_optim.zero_grad()
batch_x = batch_x.float().to(self.device)
batch_y = batch_y.float().to(self.device)
batch_y_mark = batch_y_mark.float().to(self.device)
# decoder input
dec_inp = torch.zeros_like(batch_y[:, -self.args.pred_len:, :]).float()
dec_inp = torch.cat([batch_y[:, :self.args.label_len, :], dec_inp], dim=1).float().to(self.device)
outputs = self.model(batch_x, None, dec_inp, None)
f_dim = -1 if self.args.features == 'MS' else 0
outputs = outputs[:, -self.args.pred_len:, f_dim:]
batch_y = batch_y[:, -self.args.pred_len:, f_dim:].to(self.device)
batch_y_mark = batch_y_mark[:, -self.args.pred_len:, f_dim:].to(self.device)
loss_value = criterion(batch_x, self.args.frequency_map, outputs, batch_y, batch_y_mark)
loss_sharpness = mse((outputs[:, 1:, :] - outputs[:, :-1, :]), (batch_y[:, 1:, :] - batch_y[:, :-1, :]))
loss = loss_value # + loss_sharpness * 1e-5
train_loss.append(loss.item())
if (i + 1) % 100 == 0:
print("\titers: {0}, epoch: {1} | loss: {2:.7f}".format(i + 1, epoch + 1, loss.item()))
speed = (time.time() - time_now) / iter_count
left_time = speed * ((self.args.train_epochs - epoch) * train_steps - i)
print('\tspeed: {:.4f}s/iter; left time: {:.4f}s'.format(speed, left_time))
iter_count = 0
time_now = time.time()
loss.backward()
model_optim.step()
print("Epoch: {} cost time: {}".format(epoch + 1, time.time() - epoch_time))
train_loss = np.average(train_loss)
vali_loss = self.vali(train_loader, vali_loader, criterion)
test_loss = vali_loss
print("Epoch: {0}, Steps: {1} | Train Loss: {2:.7f} Vali Loss: {3:.7f} Test Loss: {4:.7f}".format(
epoch + 1, train_steps, train_loss, vali_loss, test_loss))
early_stopping(vali_loss, self.model, path)
if early_stopping.early_stop:
print("Early stopping")
break
adjust_learning_rate(model_optim, epoch + 1, self.args)
best_model_path = path + '/' + 'checkpoint.pth'
self.model.load_state_dict(torch.load(best_model_path))
return self.model
def vali(self, train_loader, vali_loader, criterion):
x, _ = train_loader.dataset.last_insample_window()
y = vali_loader.dataset.timeseries
x = torch.tensor(x, dtype=torch.float32).to(self.device)
x = x.unsqueeze(-1)
self.model.eval()
with torch.no_grad():
# decoder input
B, _, C = x.shape
dec_inp = torch.zeros((B, self.args.pred_len, C)).float().to(self.device)
dec_inp = torch.cat([x[:, -self.args.label_len:, :], dec_inp], dim=1).float()
# encoder - decoder
outputs = torch.zeros((B, self.args.pred_len, C)).float() # .to(self.device)
id_list = np.arange(0, B, 500) # validation set size
id_list = np.append(id_list, B)
for i in range(len(id_list) - 1):
outputs[id_list[i]:id_list[i + 1], :, :] = self.model(x[id_list[i]:id_list[i + 1]], None,
dec_inp[id_list[i]:id_list[i + 1]],
None).detach().cpu()
f_dim = -1 if self.args.features == 'MS' else 0
outputs = outputs[:, -self.args.pred_len:, f_dim:]
pred = outputs
true = torch.from_numpy(np.array(y))
batch_y_mark = torch.ones(true.shape)
loss = criterion(x.detach().cpu()[:, :, 0], self.args.frequency_map, pred[:, :, 0], true, batch_y_mark)
self.model.train()
return loss
def test(self, setting, test=0):
_, train_loader = self._get_data(flag='train')
_, test_loader = self._get_data(flag='test')
x, _ = train_loader.dataset.last_insample_window()
y = test_loader.dataset.timeseries
x = torch.tensor(x, dtype=torch.float32).to(self.device)
x = x.unsqueeze(-1)
if test:
print('loading model')
self.model.load_state_dict(torch.load(os.path.join('./checkpoints/' + setting, 'checkpoint.pth')))
folder_path = './test_results/' + setting + '/'
if not os.path.exists(folder_path):
os.makedirs(folder_path)
self.model.eval()
with torch.no_grad():
B, _, C = x.shape
dec_inp = torch.zeros((B, self.args.pred_len, C)).float().to(self.device)
dec_inp = torch.cat([x[:, -self.args.label_len:, :], dec_inp], dim=1).float()
# encoder - decoder
outputs = torch.zeros((B, self.args.pred_len, C)).float().to(self.device)
id_list = np.arange(0, B, 1)
id_list = np.append(id_list, B)
for i in range(len(id_list) - 1):
outputs[id_list[i]:id_list[i + 1], :, :] = self.model(x[id_list[i]:id_list[i + 1]], None,
dec_inp[id_list[i]:id_list[i + 1]], None)
if id_list[i] % 1000 == 0:
print(id_list[i])
f_dim = -1 if self.args.features == 'MS' else 0
outputs = outputs[:, -self.args.pred_len:, f_dim:]
outputs = outputs.detach().cpu().numpy()
preds = outputs
trues = y
x = x.detach().cpu().numpy()
for i in range(0, preds.shape[0], preds.shape[0] // 10):
gt = np.concatenate((x[i, :, 0], trues[i]), axis=0)
pd = np.concatenate((x[i, :, 0], preds[i, :, 0]), axis=0)
visual(gt, pd, os.path.join(folder_path, str(i) + '.pdf'))
print('test shape:', preds.shape)
# result save
folder_path = './m4_results/' + self.args.model + '/'
if not os.path.exists(folder_path):
os.makedirs(folder_path)
forecasts_df = pandas.DataFrame(preds[:, :, 0], columns=[f'V{i + 1}' for i in range(self.args.pred_len)])
forecasts_df.index = test_loader.dataset.ids[:preds.shape[0]]
forecasts_df.index.name = 'id'
forecasts_df.set_index(forecasts_df.columns[0], inplace=True)
forecasts_df.to_csv(folder_path + self.args.seasonal_patterns + '_forecast.csv')
print(self.args.model)
file_path = './m4_results/' + self.args.model + '/'
if 'Weekly_forecast.csv' in os.listdir(file_path) \
and 'Monthly_forecast.csv' in os.listdir(file_path) \
and 'Yearly_forecast.csv' in os.listdir(file_path) \
and 'Daily_forecast.csv' in os.listdir(file_path) \
and 'Hourly_forecast.csv' in os.listdir(file_path) \
and 'Quarterly_forecast.csv' in os.listdir(file_path):
m4_summary = M4Summary(file_path, self.args.root_path)
# m4_forecast.set_index(m4_winner_forecast.columns[0], inplace=True)
smape_results, owa_results, mape, mase = m4_summary.evaluate()
print('smape:', smape_results)
print('mape:', mape)
print('mase:', mase)
print('owa:', owa_results)
else:
print('After all 6 tasks are finished, you can calculate the averaged index')
return
================================================
FILE: exp/exp_zero_shot_forecasting.py
================================================
from data_provider.data_factory import data_provider
from exp.exp_basic import Exp_Basic
from utils.tools import EarlyStopping, adjust_learning_rate, visual
from utils.metrics import metric
import torch
import torch.nn as nn
from torch import optim
import os
import time
import warnings
import numpy as np
from utils.dtw_metric import dtw, accelerated_dtw
from utils.augmentation import run_augmentation, run_augmentation_single
warnings.filterwarnings('ignore')
class Exp_Zero_Shot_Forecast(Exp_Basic):
def __init__(self, args):
super(Exp_Zero_Shot_Forecast, self).__init__(args)
def _build_model(self):
model = self.model_dict[self.args.model](self.args).float()
if self.args.use_multi_gpu and self.args.use_gpu:
model = nn.DataParallel(model, device_ids=self.args.device_ids)
return model
def _get_data(self, flag):
data_set, data_loader = data_provider(self.args, flag)
return data_set, data_loader
def _select_optimizer(self):
model_optim = optim.Adam(self.model.parameters(), lr=self.args.learning_rate)
return model_optim
def _select_criterion(self):
criterion = nn.MSELoss()
return criterion
def test(self, setting, test=0):
test_data, test_loader = self._get_data(flag='test')
preds = []
trues = []
folder_path = './test_results/' + setting + '/'
if not os.path.exists(folder_path):
os.makedirs(folder_path)
self.model.eval()
with torch.no_grad():
for i, (batch_x, batch_y, batch_x_mark, batch_y_mark) in enumerate(test_loader):
# start_time = time.time()
batch_x = batch_x.float().to(self.device)
batch_y = batch_y.float().to(self.device)
batch_x_mark = batch_x_mark.float().to(self.device)
batch_y_mark = batch_y_mark.float().to(self.device)
# decoder input
dec_inp = torch.zeros_like(batch_y[:, -self.args.pred_len:, :]).float()
dec_inp = torch.cat([batch_y[:, :self.args.label_len, :], dec_inp], dim=1).float().to(self.device)
# encoder - decoder
if self.args.use_amp:
with torch.cuda.amp.autocast():
outputs = self.model(batch_x, batch_x_mark, dec_inp, batch_y_mark)
else:
outputs = self.model(batch_x, batch_x_mark, dec_inp, batch_y_mark)
# print("Test cost time: {}".format(time.time() - start_time))
f_dim = -1 if self.args.features == 'MS' else 0
outputs = outputs[:, -self.args.pred_len:, :]
batch_y = batch_y[:, -self.args.pred_len:, :].to(self.device)
outputs = outputs.detach().cpu().numpy()
batch_y = batch_y.detach().cpu().numpy()
if test_data.scale and self.args.inverse:
shape = batch_y.shape
if outputs.shape[-1] != batch_y.shape[-1]:
outputs = np.tile(outputs, [1, 1, int(batch_y.shape[-1] / outputs.shape[-1])])
outputs = test_data.inverse_transform(outputs.reshape(shape[0] * shape[1], -1)).reshape(shape)
batch_y = test_data.inverse_transform(batch_y.reshape(shape[0] * shape[1], -1)).reshape(shape)
outputs = outputs[:, :, f_dim:]
batch_y = batch_y[:, :, f_dim:]
pred = outputs
true = batch_y
preds.append(pred)
trues.append(true)
if i % 20 == 0:
input = batch_x.detach().cpu().numpy()
if test_data.scale and self.args.inverse:
shape = input.shape
input = test_data.inverse_transform(input.reshape(shape[0] * shape[1], -1)).reshape(shape)
gt = np.concatenate((input[0, :, -1], true[0, :, -1]), axis=0)
pd = np.concatenate((input[0, :, -1], pred[0, :, -1]), axis=0)
visual(gt, pd, os.path.join(folder_path, str(i) + '.pdf'))
preds = np.concatenate(preds, axis=0)
trues = np.concatenate(trues, axis=0)
print('test shape:', preds.shape, trues.shape)
preds = preds.reshape(-1, preds.shape[-2], preds.shape[-1])
trues = trues.reshape(-1, trues.shape[-2], trues.shape[-1])
print('test shape:', preds.shape, trues.shape)
# result save
folder_path = './results/' + setting + '/'
if not os.path.exists(folder_path):
os.makedirs(folder_path)
# dtw calculation
if self.args.use_dtw:
dtw_list = []
manhattan_distance = lambda x, y: np.abs(x - y)
for i in range(preds.shape[0]):
x = preds[i].reshape(-1, 1)
y = trues[i].reshape(-1, 1)
if i % 100 == 0:
print("calculating dtw iter:", i)
d, _, _, _ = accelerated_dtw(x, y, dist=manhattan_distance)
dtw_list.append(d)
dtw = np.array(dtw_list).mean()
else:
dtw = 'Not calculated'
mae, mse, rmse, mape, mspe = metric(preds, trues)
print('mse:{}, mae:{}, dtw:{}'.format(mse, mae, dtw))
f = open("result_zero_shot_forecast_search.txt", 'a')
f.write(setting + " \n")
f.write('mse:{}, mae:{}, dtw:{}'.format(mse, mae, dtw))
f.write('\n')
f.write('\n')
f.close()
np.save(folder_path + 'metrics.npy', np.array([mae, mse, rmse, mape, mspe]))
np.save(folder_path + 'pred.npy', preds)
np.save(folder_path + 'true.npy', trues)
return
================================================
FILE: layers/AutoCorrelation.py
================================================
import torch
import torch.nn as nn
import torch.nn.functional as F
import matplotlib.pyplot as plt
import numpy as np
import math
from math import sqrt
import os
class AutoCorrelation(nn.Module):
"""
AutoCorrelation Mechanism with the following two phases:
(1) period-based dependencies discovery
(2) time delay aggregation
This block can replace the self-attention family mechanism seamlessly.
"""
def __init__(self, mask_flag=True, factor=1, scale=None, attention_dropout=0.1, output_attention=False):
super(AutoCorrelation, self).__init__()
self.factor = factor
self.scale = scale
self.mask_flag = mask_flag
self.output_attention = output_attention
self.dropout = nn.Dropout(attention_dropout)
def time_delay_agg_training(self, values, corr):
"""
SpeedUp version of Autocorrelation (a batch-normalization style design)
This is for the training phase.
"""
head = values.shape[1]
channel = values.shape[2]
length = values.shape[3]
# find top k
top_k = int(self.factor * math.log(length))
mean_value = torch.mean(torch.mean(corr, dim=1), dim=1)
index = torch.topk(torch.mean(mean_value, dim=0), top_k, dim=-1)[1]
weights = torch.stack([mean_value[:, index[i]] for i in range(top_k)], dim=-1)
# update corr
tmp_corr = torch.softmax(weights, dim=-1)
# aggregation
tmp_values = values
delays_agg = torch.zeros_like(values).float()
for i in range(top_k):
pattern = torch.roll(tmp_values, -int(index[i]), -1)
delays_agg = delays_agg + pattern * \
(tmp_corr[:, i].unsqueeze(1).unsqueeze(1).unsqueeze(1).repeat(1, head, channel, length))
return delays_agg
def time_delay_agg_inference(self, values, corr):
"""
SpeedUp version of Autocorrelation (a batch-normalization style design)
This is for the inference phase.
"""
batch = values.shape[0]
head = values.shape[1]
channel = values.shape[2]
length = values.shape[3]
# index init
init_index = torch.arange(length).unsqueeze(0).unsqueeze(0).unsqueeze(0).repeat(batch, head, channel, 1).to(values.device)
# find top k
top_k = int(self.factor * math.log(length))
mean_value = torch.mean(torch.mean(corr, dim=1), dim=1)
weights, delay = torch.topk(mean_value, top_k, dim=-1)
# update corr
tmp_corr = torch.softmax(weights, dim=-1)
# aggregation
tmp_values = values.repeat(1, 1, 1, 2)
delays_agg = torch.zeros_like(values).float()
for i in range(top_k):
tmp_delay = init_index + delay[:, i].unsqueeze(1).unsqueeze(1).unsqueeze(1).repeat(1, head, channel, length)
pattern = torch.gather(tmp_values, dim=-1, index=tmp_delay)
delays_agg = delays_agg + pattern * \
(tmp_corr[:, i].unsqueeze(1).unsqueeze(1).unsqueeze(1).repeat(1, head, channel, length))
return delays_agg
def time_delay_agg_full(self, values, corr):
"""
Standard version of Autocorrelation
"""
batch = values.shape[0]
head = values.shape[1]
channel = values.shape[2]
length = values.shape[3]
# index init
init_index = torch.arange(length).unsqueeze(0).unsqueeze(0).unsqueeze(0).repeat(batch, head, channel, 1).to(values.device)
# find top k
top_k = int(self.factor * math.log(length))
weights, delay = torch.topk(corr, top_k, dim=-1)
# update corr
tmp_corr = torch.softmax(weights, dim=-1)
# aggregation
tmp_values = values.repeat(1, 1, 1, 2)
delays_agg = torch.zeros_like(values).float()
for i in range(top_k):
tmp_delay = init_index + delay[..., i].unsqueeze(-1)
pattern = torch.gather(tmp_values, dim=-1, index=tmp_delay)
delays_agg = delays_agg + pattern * (tmp_corr[..., i].unsqueeze(-1))
return delays_agg
def forward(self, queries, keys, values, attn_mask):
B, L, H, E = queries.shape
_, S, _, D = values.shape
if L > S:
zeros = torch.zeros_like(queries[:, :(L - S), :]).float()
values = torch.cat([values, zeros], dim=1)
keys = torch.cat([keys, zeros], dim=1)
else:
values = values[:, :L, :, :]
keys = keys[:, :L, :, :]
# period-based dependencies
q_fft = torch.fft.rfft(queries.permute(0, 2, 3, 1).contiguous(), dim=-1)
k_fft = torch.fft.rfft(keys.permute(0, 2, 3, 1).contiguous(), dim=-1)
res = q_fft * torch.conj(k_fft)
corr = torch.fft.irfft(res, dim=-1)
# time delay agg
if self.training:
V = self.time_delay_agg_training(values.permute(0, 2, 3, 1).contiguous(), corr).permute(0, 3, 1, 2)
else:
V = self.time_delay_agg_inference(values.permute(0, 2, 3, 1).contiguous(), corr).permute(0, 3, 1, 2)
if self.output_attention:
return (V.contiguous(), corr.permute(0, 3, 1, 2))
else:
return (V.contiguous(), None)
class AutoCorrelationLayer(nn.Module):
def __init__(self, correlation, d_model, n_heads, d_keys=None,
d_values=None):
super(AutoCorrelationLayer, self).__init__()
d_keys = d_keys or (d_model // n_heads)
d_values = d_values or (d_model // n_heads)
self.inner_correlation = correlation
self.query_projection = nn.Linear(d_model, d_keys * n_heads)
self.key_projection = nn.Linear(d_model, d_keys * n_heads)
self.value_projection = nn.Linear(d_model, d_values * n_heads)
self.out_projection = nn.Linear(d_values * n_heads, d_model)
self.n_heads = n_heads
def forward(self, queries, keys, values, attn_mask):
B, L, _ = queries.shape
_, S, _ = keys.shape
H = self.n_heads
queries = self.query_projection(queries).view(B, L, H, -1)
keys = self.key_projection(keys).view(B, S, H, -1)
values = self.value_projection(values).view(B, S, H, -1)
out, attn = self.inner_correlation(
queries,
keys,
values,
attn_mask
)
out = out.view(B, L, -1)
return self.out_projection(out), attn
================================================
FILE: layers/Autoformer_EncDec.py
================================================
import torch
import torch.nn as nn
import torch.nn.functional as F
class my_Layernorm(nn.Module):
"""
Special designed layernorm for the seasonal part
"""
def __init__(self, channels):
super(my_Layernorm, self).__init__()
self.layernorm = nn.LayerNorm(channels)
def forward(self, x):
x_hat = self.layernorm(x)
bias = torch.mean(x_hat, dim=1).unsqueeze(1).repeat(1, x.shape[1], 1)
return x_hat - bias
class moving_avg(nn.Module):
"""
Moving average block to highlight the trend of time series
"""
def __init__(self, kernel_size, stride):
super(moving_avg, self).__init__()
self.kernel_size = kernel_size
self.avg = nn.AvgPool1d(kernel_size=kernel_size, stride=stride, padding=0)
def forward(self, x):
# padding on the both ends of time series
front = x[:, 0:1, :].repeat(1, (self.kernel_size - 1) // 2, 1)
end = x[:, -1:, :].repeat(1, (self.kernel_size - 1) // 2, 1)
x = torch.cat([front, x, end], dim=1)
x = self.avg(x.permute(0, 2, 1))
x = x.permute(0, 2, 1)
return x
class series_decomp(nn.Module):
"""
Series decomposition block
"""
def __init__(self, kernel_size):
super(series_decomp, self).__init__()
self.moving_avg = moving_avg(kernel_size, stride=1)
def forward(self, x):
moving_mean = self.moving_avg(x)
res = x - moving_mean
return res, moving_mean
class series_decomp_multi(nn.Module):
"""
Multiple Series decomposition block from FEDformer
"""
def __init__(self, kernel_size):
super(series_decomp_multi, self).__init__()
self.kernel_size = kernel_size
self.series_decomp = [series_decomp(kernel) for kernel in kernel_size]
def forward(self, x):
moving_mean = []
res = []
for func in self.series_decomp:
sea, moving_avg = func(x)
moving_mean.append(moving_avg)
res.append(sea)
sea = sum(res) / len(res)
moving_mean = sum(moving_mean) / len(moving_mean)
return sea, moving_mean
class EncoderLayer(nn.Module):
"""
Autoformer encoder layer with the progressive decomposition architecture
"""
def __init__(self, attention, d_model, d_ff=None, moving_avg=25, dropout=0.1, activation="relu"):
super(EncoderLayer, self).__init__()
d_ff = d_ff or 4 * d_model
self.attention = attention
self.conv1 = nn.Conv1d(in_channels=d_model, out_channels=d_ff, kernel_size=1, bias=False)
self.conv2 = nn.Conv1d(in_channels=d_ff, out_channels=d_model, kernel_size=1, bias=False)
self.decomp1 = series_decomp(moving_avg)
self.decomp2 = series_decomp(moving_avg)
self.dropout = nn.Dropout(dropout)
self.activation = F.relu if activation == "relu" else F.gelu
def forward(self, x, attn_mask=None):
new_x, attn = self.attention(
x, x, x,
attn_mask=attn_mask
)
x = x + self.dropout(new_x)
x, _ = self.decomp1(x)
y = x
y = self.dropout(self.activation(self.conv1(y.transpose(-1, 1))))
y = self.dropout(self.conv2(y).transpose(-1, 1))
res, _ = self.decomp2(x + y)
return res, attn
class Encoder(nn.Module):
"""
Autoformer encoder
"""
def __init__(self, attn_layers, conv_layers=None, norm_layer=None):
super(Encoder, self).__init__()
self.attn_layers = nn.ModuleList(attn_layers)
self.conv_layers = nn.ModuleList(conv_layers) if conv_layers is not None else None
self.norm = norm_layer
def forward(self, x, attn_mask=None):
attns = []
if self.conv_layers is not None:
for attn_layer, conv_layer in zip(self.attn_layers, self.conv_layers):
x, attn = attn_layer(x, attn_mask=attn_mask)
x = conv_layer(x)
attns.append(attn)
x, attn = self.attn_layers[-1](x)
attns.append(attn)
else:
for attn_layer in self.attn_layers:
x, attn = attn_layer(x, attn_mask=attn_mask)
attns.append(attn)
if self.norm is not None:
x = self.norm(x)
return x, attns
class DecoderLayer(nn.Module):
"""
Autoformer decoder layer with the progressive decomposition architecture
"""
def __init__(self, self_attention, cross_attention, d_model, c_out, d_ff=None,
moving_avg=25, dropout=0.1, activation="relu"):
super(DecoderLayer, self).__init__()
d_ff = d_ff or 4 * d_model
self.self_attention = self_attention
self.cross_attention = cross_attention
self.conv1 = nn.Conv1d(in_channels=d_model, out_channels=d_ff, kernel_size=1, bias=False)
self.conv2 = nn.Conv1d(in_channels=d_ff, out_channels=d_model, kernel_size=1, bias=False)
self.decomp1 = series_decomp(moving_avg)
self.decomp2 = series_decomp(moving_avg)
self.decomp3 = series_decomp(moving_avg)
self.dropout = nn.Dropout(dropout)
self.projection = nn.Conv1d(in_channels=d_model, out_channels=c_out, kernel_size=3, stride=1, padding=1,
padding_mode='circular', bias=False)
self.activation = F.relu if activation == "relu" else F.gelu
def forward(self, x, cross, x_mask=None, cross_mask=None):
x = x + self.dropout(self.self_attention(
x, x, x,
attn_mask=x_mask
)[0])
x, trend1 = self.decomp1(x)
x = x + self.dropout(self.cross_attention(
x, cross, cross,
attn_mask=cross_mask
)[0])
x, trend2 = self.decomp2(x)
y = x
y = self.dropout(self.activation(self.conv1(y.transpose(-1, 1))))
y = self.dropout(self.conv2(y).transpose(-1, 1))
x, trend3 = self.decomp3(x + y)
residual_trend = trend1 + trend2 + trend3
residual_trend = self.projection(residual_trend.permute(0, 2, 1)).transpose(1, 2)
return x, residual_trend
class Decoder(nn.Module):
"""
Autoformer encoder
"""
def __init__(self, layers, norm_layer=None, projection=None):
super(Decoder, self).__init__()
self.layers = nn.ModuleList(layers)
self.norm = norm_layer
self.projection = projection
def forward(self, x, cross, x_mask=None, cross_mask=None, trend=None):
for layer in self.layers:
x, residual_trend = layer(x, cross, x_mask=x_mask, cross_mask=cross_mask)
trend = trend + residual_trend
if self.norm is not None:
x = self.norm(x)
if self.projection is not None:
x = self.projection(x)
return x, trend
================================================
FILE: layers/Conv_Blocks.py
================================================
import torch
import torch.nn as nn
class Inception_Block_V1(nn.Module):
def __init__(self, in_channels, out_channels, num_kernels=6, init_weight=True):
super(Inception_Block_V1, self).__init__()
self.in_channels = in_channels
self.out_channels = out_channels
self.num_kernels = num_kernels
kernels = []
for i in range(self.num_kernels):
kernels.append(nn.Conv2d(in_channels, out_channels, kernel_size=2 * i + 1, padding=i))
self.kernels = nn.ModuleList(kernels)
if init_weight:
self._initialize_weights()
def _initialize_weights(self):
for m in self.modules():
if isinstance(m, nn.Conv2d):
nn.init.kaiming_normal_(m.weight, mode='fan_out', nonlinearity='relu')
if m.bias is not None:
nn.init.constant_(m.bias, 0)
def forward(self, x):
res_list = []
for i in range(self.num_kernels):
res_list.append(self.kernels[i](x))
res = torch.stack(res_list, dim=-1).mean(-1)
return res
class Inception_Block_V2(nn.Module):
def __init__(self, in_channels, out_channels, num_kernels=6, init_weight=True):
super(Inception_Block_V2, self).__init__()
self.in_channels = in_channels
self.out_channels = out_channels
self.num_kernels = num_kernels
kernels = []
for i in range(self.num_kernels // 2):
kernels.append(nn.Conv2d(in_channels, out_channels, kernel_size=[1, 2 * i + 3], padding=[0, i + 1]))
kernels.append(nn.Conv2d(in_channels, out_channels, kernel_size=[2 * i + 3, 1], padding=[i + 1, 0]))
kernels.append(nn.Conv2d(in_channels, out_channels, kernel_size=1))
self.kernels = nn.ModuleList(kernels)
if init_weight:
self._initialize_weights()
def _initialize_weights(self):
for m in self.modules():
if isinstance(m, nn.Conv2d):
nn.init.kaiming_normal_(m.weight, mode='fan_out', nonlinearity='relu')
if m.bias is not None:
nn.init.constant_(m.bias, 0)
def forward(self, x):
res_list = []
for i in range(self.num_kernels // 2 * 2 + 1):
res_list.append(self.kernels[i](x))
res = torch.stack(res_list, dim=-1).mean(-1)
return res
================================================
FILE: layers/Crossformer_EncDec.py
================================================
import torch
import torch.nn as nn
from einops import rearrange, repeat
from layers.SelfAttention_Family import TwoStageAttentionLayer
class SegMerging(nn.Module):
def __init__(self, d_model, win_size, norm_layer=nn.LayerNorm):
super().__init__()
self.d_model = d_model
self.win_size = win_size
self.linear_trans = nn.Linear(win_size * d_model, d_model)
self.norm = norm_layer(win_size * d_model)
def forward(self, x):
batch_size, ts_d, seg_num, d_model = x.shape
pad_num = seg_num % self.win_size
if pad_num != 0:
pad_num = self.win_size - pad_num
x = torch.cat((x, x[:, :, -pad_num:, :]), dim=-2)
seg_to_merge = []
for i in range(self.win_size):
seg_to_merge.append(x[:, :, i::self.win_size, :])
x = torch.cat(seg_to_merge, -1)
x = self.norm(x)
x = self.linear_trans(x)
return x
class scale_block(nn.Module):
def __init__(self, configs, win_size, d_model, n_heads, d_ff, depth, dropout, \
seg_num=10, factor=10):
super(scale_block, self).__init__()
if win_size > 1:
self.merge_layer = SegMerging(d_model, win_size, nn.LayerNorm)
else:
self.merge_layer = None
self.encode_layers = nn.ModuleList()
for i in range(depth):
self.encode_layers.append(TwoStageAttentionLayer(configs, seg_num, factor, d_model, n_heads, \
d_ff, dropout))
def forward(self, x, attn_mask=None, tau=None, delta=None):
_, ts_dim, _, _ = x.shape
if self.merge_layer is not None:
x = self.merge_layer(x)
for layer in self.encode_layers:
x = layer(x)
return x, None
class Encoder(nn.Module):
def __init__(self, attn_layers):
super(Encoder, self).__init__()
self.encode_blocks = nn.ModuleList(attn_layers)
def forward(self, x):
encode_x = []
encode_x.append(x)
for block in self.encode_blocks:
x, attns = block(x)
encode_x.append(x)
return encode_x, None
class DecoderLayer(nn.Module):
def __init__(self, self_attention, cross_attention, seg_len, d_model, d_ff=None, dropout=0.1):
super(DecoderLayer, self).__init__()
self.self_attention = self_attention
self.cross_attention = cross_attention
self.norm1 = nn.LayerNorm(d_model)
self.norm2 = nn.LayerNorm(d_model)
self.dropout = nn.Dropout(dropout)
self.MLP1 = nn.Sequential(nn.Linear(d_model, d_model),
nn.GELU(),
nn.Linear(d_model, d_model))
self.linear_pred = nn.Linear(d_model, seg_len)
def forward(self, x, cross):
batch = x.shape[0]
x = self.self_attention(x)
x = rearrange(x, 'b ts_d out_seg_num d_model -> (b ts_d) out_seg_num d_model')
cross = rearrange(cross, 'b ts_d in_seg_num d_model -> (b ts_d) in_seg_num d_model')
tmp, attn = self.cross_attention(x, cross, cross, None, None, None,)
x = x + self.dropout(tmp)
y = x = self.norm1(x)
y = self.MLP1(y)
dec_output = self.norm2(x + y)
dec_output = rearrange(dec_output, '(b ts_d) seg_dec_num d_model -> b ts_d seg_dec_num d_model', b=batch)
layer_predict = self.linear_pred(dec_output)
layer_predict = rearrange(layer_predict, 'b out_d seg_num seg_len -> b (out_d seg_num) seg_len')
return dec_output, layer_predict
class Decoder(nn.Module):
def __init__(self, layers):
super(Decoder, self).__init__()
self.decode_layers = nn.ModuleList(layers)
def forward(self, x, cross):
final_predict = None
i = 0
ts_d = x.shape[1]
for layer in self.decode_layers:
cross_enc = cross[i]
x, layer_predict = layer(x, cross_enc)
if final_predict is None:
final_predict = layer_predict
else:
final_predict = final_predict + layer_predict
i += 1
final_predict = rearrange(final_predict, 'b (out_d seg_num) seg_len -> b (seg_num seg_len) out_d', out_d=ts_d)
return final_predict
================================================
FILE: layers/DWT_Decomposition.py
================================================
# -*- coding: utf-8 -*-
"""
Created on Sun Jan 5
@author: Murad
SISLab, USF
mmurad@usf.edu
https://github.com/Secure-and-Intelligent-Systems-Lab/WPMixer
"""
import torch
import torch.nn as nn
import pywt
import numpy as np
import torch.nn.functional as F
from torch.autograd import Function
class Decomposition(nn.Module):
def __init__(self,
input_length=[],
pred_length=[],
wavelet_name=[],
level=[],
batch_size=[],
channel=[],
d_model=[],
tfactor=[],
dfactor=[],
device=[],
no_decomposition=[],
use_amp=[]):
super(Decomposition, self).__init__()
self.input_length = input_length
self.pred_length = pred_length
self.wavelet_name = wavelet_name
self.level = level
self.batch_size = batch_size
self.channel = channel
self.d_model = d_model
self.device = device
self.no_decomposition = no_decomposition
self.use_amp = use_amp
self.eps = 1e-5
self.dwt = DWT1DForward(wave=self.wavelet_name, J=self.level,
use_amp=self.use_amp).cuda() if self.device.type == 'cuda' else DWT1DForward(
wave=self.wavelet_name, J=self.level, use_amp=self.use_amp)
self.idwt = DWT1DInverse(wave=self.wavelet_name,
use_amp=self.use_amp).cuda() if self.device.type == 'cuda' else DWT1DInverse(
wave=self.wavelet_name, use_amp=self.use_amp)
self.input_w_dim = self._dummy_forward(self.input_length) if not self.no_decomposition else [
self.input_length] # length of the input seq after decompose
self.pred_w_dim = self._dummy_forward(self.pred_length) if not self.no_decomposition else [
self.pred_length] # required length of the pred seq after decom
self.tfactor = tfactor
self.dfactor = dfactor
#################################
self.affine = False
#################################
if self.affine:
self._init_params()
def transform(self, x):
# input: x shape: batch, channel, seq
if not self.no_decomposition:
yl, yh = self._wavelet_decompose(x)
else:
yl, yh = x, [] # no decompose: returning the same value in yl
return yl, yh
def inv_transform(self, yl, yh):
if not self.no_decomposition:
x = self._wavelet_reverse_decompose(yl, yh)
else:
x = yl # no decompose: returning the same value in x
return x
def _dummy_forward(self, input_length):
dummy_x = torch.ones((self.batch_size, self.channel, input_length)).to(self.device)
yl, yh = self.dwt(dummy_x)
l = []
l.append(yl.shape[-1])
for i in range(len(yh)):
l.append(yh[i].shape[-1])
return l
def _init_params(self):
self.affine_weight = nn.Parameter(torch.ones((self.level + 1, self.channel)))
self.affine_bias = nn.Parameter(torch.zeros((self.level + 1, self.channel)))
def _wavelet_decompose(self, x):
# input: x shape: batch, channel, seq
yl, yh = self.dwt(x)
if self.affine:
yl = yl.transpose(1, 2) # batch, seq, channel
yl = yl * self.affine_weight[0]
yl = yl + self.affine_bias[0]
yl = yl.transpose(1, 2) # batch, channel, seq
for i in range(self.level):
yh_ = yh[i].transpose(1, 2) # batch, seq, channel
yh_ = yh_ * self.affine_weight[i + 1]
yh_ = yh_ + self.affine_bias[i + 1]
yh[i] = yh_.transpose(1, 2) # batch, channel, seq
return yl, yh
def _wavelet_reverse_decompose(self, yl, yh):
if self.affine:
yl = yl.transpose(1, 2) # batch, seq, channel
yl = yl - self.affine_bias[0]
yl = yl / (self.affine_weight[0] + self.eps)
yl = yl.transpose(1, 2) # batch, channel, seq
for i in range(self.level):
yh_ = yh[i].transpose(1, 2) # batch, seq, channel
yh_ = yh_ - self.affine_bias[i + 1]
yh_ = yh_ / (self.affine_weight[i + 1] + self.eps)
yh[i] = yh_.transpose(1, 2) # batch, channel, seq
x = self.idwt((yl, yh))
return x # shape: batch, channel, seq
###############################################################################################
"""
Following codes are combined from https://github.com/fbcotter/pytorch_wavelets.
To use Wavelet decomposition, you do not need to modify any of the codes below this line,
we can just play with the class Decomposition(above)
"""
###############################################################################################
class DWT1DForward(nn.Module):
""" Performs a 1d DWT Forward decomposition of an image
Args:
J (int): Number of levels of decomposition
wave (str or pywt.Wavelet or tuple(ndarray)): Which wavelet to use.
Can be:
1) a string to pass to pywt.Wavelet constructor
2) a pywt.Wavelet class
3) a tuple of numpy arrays (h0, h1)
mode (str): 'zero', 'symmetric', 'reflect' or 'periodization'. The
padding scheme
"""
def __init__(self, J=1, wave='db1', mode='zero', use_amp=False):
super().__init__()
self.use_amp = use_amp
if isinstance(wave, str):
wave = pywt.Wavelet(wave)
if isinstance(wave, pywt.Wavelet):
h0, h1 = wave.dec_lo, wave.dec_hi
else:
assert len(wave) == 2
h0, h1 = wave[0], wave[1]
# Prepare the filters - this makes them into column filters
filts = prep_filt_afb1d(h0, h1)
self.register_buffer('h0', filts[0])
self.register_buffer('h1', filts[1])
self.J = J
self.mode = mode
def forward(self, x):
""" Forward pass of the DWT.
Args:
x (tensor): Input of shape :math:`(N, C_{in}, L_{in})`
Returns:
(yl, yh)
tuple of lowpass (yl) and bandpass (yh) coefficients.
yh is a list of length J with the first entry
being the finest scale coefficients.
"""
assert x.ndim == 3, "Can only handle 3d inputs (N, C, L)"
highs = []
x0 = x
mode = mode_to_int(self.mode)
# Do a multilevel transform
for j in range(self.J):
x0, x1 = AFB1D.apply(x0, self.h0, self.h1, mode, self.use_amp)
highs.append(x1)
return x0, highs
class DWT1DInverse(nn.Module):
""" Performs a 1d DWT Inverse reconstruction of an image
Args:
wave (str or pywt.Wavelet or tuple(ndarray)): Which wavelet to use.
Can be:
1) a string to pass to pywt.Wavelet constructor
2) a pywt.Wavelet class
3) a tuple of numpy arrays (h0, h1)
mode (str): 'zero', 'symmetric', 'reflect' or 'periodization'. The
padding scheme
"""
def __init__(self, wave='db1', mode='zero', use_amp=False):
super().__init__()
self.use_amp = use_amp
if isinstance(wave, str):
wave = pywt.Wavelet(wave)
if isinstance(wave, pywt.Wavelet):
g0, g1 = wave.rec_lo, wave.rec_hi
else:
assert len(wave) == 2
g0, g1 = wave[0], wave[1]
# Prepare the filters
filts = prep_filt_sfb1d(g0, g1)
self.register_buffer('g0', filts[0])
self.register_buffer('g1', filts[1])
self.mode = mode
def forward(self, coeffs):
"""
Args:
coeffs (yl, yh): tuple of lowpass and bandpass coefficients, should
match the format returned by DWT1DForward.
Returns:
Reconstructed input of shape :math:`(N, C_{in}, L_{in})`
Note:
Can have None for any of the highpass scales and will treat the
values as zeros (not in an efficient way though).
"""
x0, highs = coeffs
assert x0.ndim == 3, "Can only handle 3d inputs (N, C, L)"
mode = mode_to_int(self.mode)
# Do a multilevel inverse transform
for x1 in highs[::-1]:
if x1 is None:
x1 = torch.zeros_like(x0)
# 'Unpad' added signal
if x0.shape[-1] > x1.shape[-1]:
x0 = x0[..., :-1]
x0 = SFB1D.apply(x0, x1, self.g0, self.g1, mode, self.use_amp)
return x0
def roll(x, n, dim, make_even=False):
if n < 0:
n = x.shape[dim] + n
if make_even and x.shape[dim] % 2 == 1:
end = 1
else:
end = 0
if dim == 0:
return torch.cat((x[-n:], x[:-n + end]), dim=0)
elif dim == 1:
return torch.cat((x[:, -n:], x[:, :-n + end]), dim=1)
elif dim == 2 or dim == -2:
return torch.cat((x[:, :, -n:], x[:, :, :-n + end]), dim=2)
elif dim == 3 or dim == -1:
return torch.cat((x[:, :, :, -n:], x[:, :, :, :-n + end]), dim=3)
def mypad(x, pad, mode='constant', value=0):
""" Function to do numpy like padding on tensors. Only works for 2-D
padding.
Inputs:
x (tensor): tensor to pad
pad (tuple): tuple of (left, right, top, bottom) pad sizes
mode (str): 'symmetric', 'wrap', 'constant, 'reflect', 'replicate', or
'zero'. The padding technique.
"""
if mode == 'symmetric':
# Vertical only
if pad[0] == 0 and pad[1] == 0:
m1, m2 = pad[2], pad[3]
l = x.shape[-2]
xe = reflect(np.arange(-m1, l + m2, dtype='int32'), -0.5, l - 0.5)
return x[:, :, xe]
# horizontal only
elif pad[2] == 0 and pad[3] == 0:
m1, m2 = pad[0], pad[1]
l = x.shape[-1]
xe = reflect(np.arange(-m1, l + m2, dtype='int32'), -0.5, l - 0.5)
return x[:, :, :, xe]
# Both
else:
m1, m2 = pad[0], pad[1]
l1 = x.shape[-1]
xe_row = reflect(np.arange(-m1, l1 + m2, dtype='int32'), -0.5, l1 - 0.5)
m1, m2 = pad[2], pad[3]
l2 = x.shape[-2]
xe_col = reflect(np.arange(-m1, l2 + m2, dtype='int32'), -0.5, l2 - 0.5)
i = np.outer(xe_col, np.ones(xe_row.shape[0]))
j = np.outer(np.ones(xe_col.shape[0]), xe_row)
return x[:, :, i, j]
elif mode == 'periodic':
# Vertical only
if pad[0] == 0 and pad[1] == 0:
xe = np.arange(x.shape[-2])
xe = np.pad(xe, (pad[2], pad[3]), mode='wrap')
return x[:, :, xe]
# Horizontal only
elif pad[2] == 0 and pad[3] == 0:
xe = np.arange(x.shape[-1])
xe = np.pad(xe, (pad[0], pad[1]), mode='wrap')
return x[:, :, :, xe]
# Both
else:
xe_col = np.arange(x.shape[-2])
xe_col = np.pad(xe_col, (pad[2], pad[3]), mode='wrap')
xe_row = np.arange(x.shape[-1])
xe_row = np.pad(xe_row, (pad[0], pad[1]), mode='wrap')
i = np.outer(xe_col, np.ones(xe_row.shape[0]))
j = np.outer(np.ones(xe_col.shape[0]), xe_row)
return x[:, :, i, j]
elif mode == 'constant' or mode == 'reflect' or mode == 'replicate':
return F.pad(x, pad, mode, value)
elif mode == 'zero':
return F.pad(x, pad)
else:
raise ValueError("Unkown pad type: {}".format(mode))
def afb1d(x, h0, h1, use_amp, mode='zero', dim=-1):
""" 1D analysis filter bank (along one dimension only) of an image
Inputs:
x (tensor): 4D input with the last two dimensions the spatial input
h0 (tensor): 4D input for the lowpass filter. Should have shape (1, 1,
h, 1) or (1, 1, 1, w)
h1 (tensor): 4D input for the highpass filter. Should have shape (1, 1,
h, 1) or (1, 1, 1, w)
mode (str): padding method
dim (int) - dimension of filtering. d=2 is for a vertical filter (called
column filtering but filters across the rows). d=3 is for a
horizontal filter, (called row filtering but filters across the
columns).
Returns:
lohi: lowpass and highpass subbands concatenated along the channel
dimension
"""
C = x.shape[1]
# Convert the dim to positive
d = dim % 4
s = (2, 1) if d == 2 else (1, 2)
N = x.shape[d]
# If h0, h1 are not tensors, make them. If they are, then assume that they
# are in the right order
if not isinstance(h0, torch.Tensor):
h0 = torch.tensor(np.copy(np.array(h0).ravel()[::-1]),
dtype=torch.float, device=x.device)
if not isinstance(h1, torch.Tensor):
h1 = torch.tensor(np.copy(np.array(h1).ravel()[::-1]),
dtype=torch.float, device=x.device)
L = h0.numel()
L2 = L // 2
shape = [1, 1, 1, 1]
s
gitextract_frlvujza/
├── .gitignore
├── CONTRIBUTING.md
├── Dockerfile
├── LICENSE
├── README.md
├── README_zh.md
├── data_provider/
│ ├── __init__.py
│ ├── data_factory.py
│ ├── data_loader.py
│ ├── m4.py
│ └── uea.py
├── docker-compose.yml
├── exp/
│ ├── __init__.py
│ ├── exp_anomaly_detection.py
│ ├── exp_basic.py
│ ├── exp_classification.py
│ ├── exp_imputation.py
│ ├── exp_long_term_forecasting.py
│ ├── exp_short_term_forecasting.py
│ └── exp_zero_shot_forecasting.py
├── layers/
│ ├── AutoCorrelation.py
│ ├── Autoformer_EncDec.py
│ ├── Conv_Blocks.py
│ ├── Crossformer_EncDec.py
│ ├── DWT_Decomposition.py
│ ├── ETSformer_EncDec.py
│ ├── Embed.py
│ ├── FourierCorrelation.py
│ ├── MSGBlock.py
│ ├── MambaBlock.py
│ ├── MultiWaveletCorrelation.py
│ ├── Pyraformer_EncDec.py
│ ├── SelfAttention_Family.py
│ ├── StandardNorm.py
│ ├── TimeFilter_layers.py
│ ├── Transformer_EncDec.py
│ └── __init__.py
├── models/
│ ├── Autoformer.py
│ ├── Chronos.py
│ ├── Chronos2.py
│ ├── Crossformer.py
│ ├── DLinear.py
│ ├── ETSformer.py
│ ├── FEDformer.py
│ ├── FiLM.py
│ ├── FreTS.py
│ ├── Informer.py
│ ├── KANAD.py
│ ├── Koopa.py
│ ├── LightTS.py
│ ├── MICN.py
│ ├── MSGNet.py
│ ├── Mamba.py
│ ├── MambaSimple.py
│ ├── MambaSingleLayer.py
│ ├── Moirai.py
│ ├── MultiPatchFormer.py
│ ├── Nonstationary_Transformer.py
│ ├── PAttn.py
│ ├── PatchTST.py
│ ├── Pyraformer.py
│ ├── Reformer.py
│ ├── SCINet.py
│ ├── SegRNN.py
│ ├── Sundial.py
│ ├── TSMixer.py
│ ├── TemporalFusionTransformer.py
│ ├── TiDE.py
│ ├── TiRex.py
│ ├── TimeFilter.py
│ ├── TimeMixer.py
│ ├── TimeMoE.py
│ ├── TimeXer.py
│ ├── TimesFM.py
│ ├── TimesNet.py
│ ├── Transformer.py
│ ├── WPMixer.py
│ ├── __init__.py
│ └── iTransformer.py
├── requirements.txt
├── run.py
├── scripts/
│ ├── anomaly_detection/
│ │ ├── MSL/
│ │ │ ├── Autoformer.sh
│ │ │ ├── Crossformer.sh
│ │ │ ├── DLinear.sh
│ │ │ ├── ETSformer.sh
│ │ │ ├── FEDformer.sh
│ │ │ ├── FiLM.sh
│ │ │ ├── Informer.sh
│ │ │ ├── KANAD.sh
│ │ │ ├── LightTS.sh
│ │ │ ├── MICN.sh
│ │ │ ├── Pyraformer.sh
│ │ │ ├── Reformer.sh
│ │ │ ├── TimesNet.sh
│ │ │ ├── Transformer.sh
│ │ │ └── iTransformer.sh
│ │ ├── PSM/
│ │ │ ├── Autoformer.sh
│ │ │ ├── DLinear.sh
│ │ │ ├── KANAD.sh
│ │ │ ├── TimesNet.sh
│ │ │ └── Transformer.sh
│ │ ├── SMAP/
│ │ │ ├── Autoformer.sh
│ │ │ ├── KANAD.sh
│ │ │ ├── TimesNet.sh
│ │ │ └── Transformer.sh
│ │ ├── SMD/
│ │ │ ├── Autoformer.sh
│ │ │ ├── KANAD.sh
│ │ │ ├── TimesNet.sh
│ │ │ └── Transformer.sh
│ │ └── SWAT/
│ │ ├── Autoformer.sh
│ │ ├── KANAD.sh
│ │ ├── TimesNet.sh
│ │ └── Transformer.sh
│ ├── classification/
│ │ ├── Autoformer.sh
│ │ ├── Crossformer.sh
│ │ ├── DLinear.sh
│ │ ├── ETSformer.sh
│ │ ├── FEDformer.sh
│ │ ├── FiLM.sh
│ │ ├── Informer.sh
│ │ ├── LightTS.sh
│ │ ├── MICN.sh
│ │ ├── MambaSL.out
│ │ ├── MambaSL.sh
│ │ ├── PatchTST.sh
│ │ ├── Pyraformer.sh
│ │ ├── Reformer.sh
│ │ ├── TimesNet.sh
│ │ ├── Transformer.sh
│ │ └── iTransformer.sh
│ ├── exogenous_forecast/
│ │ ├── ECL/
│ │ │ └── TimeXer.sh
│ │ ├── EPF/
│ │ │ └── TimeXer.sh
│ │ ├── ETTh1/
│ │ │ └── TimeXer.sh
│ │ ├── ETTh2/
│ │ │ └── TimeXer.sh
│ │ ├── ETTm1/
│ │ │ └── TimeXer.sh
│ │ ├── ETTm2/
│ │ │ └── TimeXer.sh
│ │ ├── Traffic/
│ │ │ └── TimeXer.sh
│ │ └── Weather/
│ │ └── TimeXer.sh
│ ├── imputation/
│ │ ├── ECL_script/
│ │ │ ├── Autoformer.sh
│ │ │ ├── DLinear.sh
│ │ │ ├── ETSformer.sh
│ │ │ ├── FEDformer.sh
│ │ │ ├── Informer.sh
│ │ │ ├── LightTS.sh
│ │ │ ├── Pyraformer.sh
│ │ │ ├── Reformer.sh
│ │ │ ├── TimesNet.sh
│ │ │ ├── Transformer.sh
│ │ │ └── iTransformer.sh
│ │ ├── ETT_script/
│ │ │ ├── Autoformer_ETTh1.sh
│ │ │ ├── Autoformer_ETTh2.sh
│ │ │ ├── Autoformer_ETTm1.sh
│ │ │ ├── Autoformer_ETTm2.sh
│ │ │ ├── Crossformer_ETTh1.sh
│ │ │ ├── DLinear_ETTh1.sh
│ │ │ ├── FiLM_ETTh1.sh
│ │ │ ├── MICN_ETTh1.sh
│ │ │ ├── Nonstationary_Transformer_ETTh1.sh
│ │ │ ├── TiDE_ETTh1.sh
│ │ │ ├── TimesNet_ETTh1.sh
│ │ │ ├── TimesNet_ETTh2.sh
│ │ │ ├── TimesNet_ETTm1.sh
│ │ │ ├── TimesNet_ETTm2.sh
│ │ │ ├── Transformer_ETTh1.sh
│ │ │ ├── Transformer_ETTh2.sh
│ │ │ ├── Transformer_ETTm1.sh
│ │ │ ├── Transformer_ETTm2.sh
│ │ │ └── iTransformer_ETTh2.sh
│ │ └── Weather_script/
│ │ ├── Autoformer.sh
│ │ ├── TimesNet.sh
│ │ └── Transformer.sh
│ ├── long_term_forecast/
│ │ ├── AugmentSample/
│ │ │ ├── Classification/
│ │ │ │ └── PatchTST.sh
│ │ │ ├── Forecasting/
│ │ │ │ └── PatchTST.sh
│ │ │ └── ReadMe.md
│ │ ├── ECL_script/
│ │ │ ├── Autoformer.sh
│ │ │ ├── Crossformer.sh
│ │ │ ├── DLinear.sh
│ │ │ ├── ETSformer.sh
│ │ │ ├── FEDformer.sh
│ │ │ ├── FiLM.sh
│ │ │ ├── Informer.sh
│ │ │ ├── Koopa.sh
│ │ │ ├── LightTS.sh
│ │ │ ├── MICN.sh
│ │ │ ├── Mamba.sh
│ │ │ ├── MultiPatchFormer.sh
│ │ │ ├── Nonstationary_Transformer.sh
│ │ │ ├── PatchTST.sh
│ │ │ ├── Pyraformer.sh
│ │ │ ├── Reformer.sh
│ │ │ ├── SegRNN.sh
│ │ │ ├── TSMixer.sh
│ │ │ ├── TimeMixer.sh
│ │ │ ├── TimeXer.sh
│ │ │ ├── TimesNet.sh
│ │ │ ├── Transformer.sh
│ │ │ ├── WPMixer.sh
│ │ │ └── iTransformer.sh
│ │ ├── ETT_script/
│ │ │ ├── Autoformer_ETTh1.sh
│ │ │ ├── Autoformer_ETTh2.sh
│ │ │ ├── Autoformer_ETTm1.sh
│ │ │ ├── Autoformer_ETTm2.sh
│ │ │ ├── Crossformer_ETTh1.sh
│ │ │ ├── Crossformer_ETTh2.sh
│ │ │ ├── Crossformer_ETTm1.sh
│ │ │ ├── Crossformer_ETTm2.sh
│ │ │ ├── DLinear_ETTh1.sh
│ │ │ ├── ETSformer_ETTh1.sh
│ │ │ ├── FEDformer_ETTh1.sh
│ │ │ ├── FiLM_ETTh1.sh
│ │ │ ├── FiLM_ETTh2.sh
│ │ │ ├── FiLM_ETTm1.sh
│ │ │ ├── FiLM_ETTm2.sh
│ │ │ ├── Informer_ETTh1.sh
│ │ │ ├── Koopa_ETTh1.sh
│ │ │ ├── Koopa_ETTh2.sh
│ │ │ ├── Koopa_ETTm1.sh
│ │ │ ├── Koopa_ETTm2.sh
│ │ │ ├── LTSM.sh
│ │ │ ├── LightTS_ETTh1.sh
│ │ │ ├── MICN_ETTh1.sh
│ │ │ ├── MICN_ETTh2.sh
│ │ │ ├── MICN_ETTm1.sh
│ │ │ ├── MICN_ETTm2.sh
│ │ │ ├── MambaSimple_ETTh1.sh
│ │ │ ├── Mamba_ETT_all.sh
│ │ │ ├── Mamba_ETTh1.sh
│ │ │ ├── Mamba_ETTh2.sh
│ │ │ ├── Mamba_ETTm1.sh
│ │ │ ├── Mamba_ETTm2.sh
│ │ │ ├── MultiPatchFormer_ETTh1.sh
│ │ │ ├── MultiPatchFormer_ETTm1.sh
│ │ │ ├── Nonstationary_Transformer_ETTh1.sh
│ │ │ ├── Nonstationary_Transformer_ETTh2.sh
│ │ │ ├── Nonstationary_Transformer_ETTm1.sh
│ │ │ ├── Nonstationary_Transformer_ETTm2.sh
│ │ │ ├── PAttn_ETTh1.sh
│ │ │ ├── PatchTST_ETTh1.sh
│ │ │ ├── PatchTST_ETTh2.sh
│ │ │ ├── PatchTST_ETTm1.sh
│ │ │ ├── PatchTST_ETTm2.sh
│ │ │ ├── Pyraformer_ETTh1.sh
│ │ │ ├── Pyraformer_ETTh2.sh
│ │ │ ├── Pyraformer_ETTm1.sh
│ │ │ ├── Pyraformer_ETTm2.sh
│ │ │ ├── Reformer_ETTh1.sh
│ │ │ ├── SegRNN_ETTh1.sh
│ │ │ ├── SegRNN_ETTh2.sh
│ │ │ ├── SegRNN_ETTm1.sh
│ │ │ ├── SegRNN_ETTm2.sh
│ │ │ ├── TSMixer_ETTh1.sh
│ │ │ ├── TSMixer_ETTh2.sh
│ │ │ ├── TSMixer_ETTm1.sh
│ │ │ ├── TSMixer_ETTm2.sh
│ │ │ ├── TiDE_ETTh1.sh
│ │ │ ├── TimeMixer_ETTh1.sh
│ │ │ ├── TimeMixer_ETTh2.sh
│ │ │ ├── TimeMixer_ETTm1.sh
│ │ │ ├── TimeMixer_ETTm2.sh
│ │ │ ├── TimeXer_ETTh1.sh
│ │ │ ├── TimeXer_ETTh2.sh
│ │ │ ├── TimeXer_ETTm1.sh
│ │ │ ├── TimeXer_ETTm2.sh
│ │ │ ├── TimesNet_ETTh1.sh
│ │ │ ├── TimesNet_ETTh2.sh
│ │ │ ├── TimesNet_ETTm1.sh
│ │ │ ├── TimesNet_ETTm2.sh
│ │ │ ├── Transformer_ETTh1.sh
│ │ │ ├── Transformer_ETTh2.sh
│ │ │ ├── Transformer_ETTm1.sh
│ │ │ ├── Transformer_ETTm2.sh
│ │ │ ├── WPMixer_ETTh1.sh
│ │ │ ├── WPMixer_ETTh2.sh
│ │ │ ├── WPMixer_ETTm1.sh
│ │ │ ├── WPMixer_ETTm2.sh
│ │ │ └── iTransformer_ETTh2.sh
│ │ ├── Exchange_script/
│ │ │ ├── Autoformer.sh
│ │ │ ├── Crossformer.sh
│ │ │ ├── FiLM.sh
│ │ │ ├── Koopa.sh
│ │ │ ├── MICN.sh
│ │ │ ├── Mamba.sh
│ │ │ ├── Nonstationary_Transformer.sh
│ │ │ ├── PatchTST.sh
│ │ │ ├── Pyraformer.sh
│ │ │ ├── TimesNet.sh
│ │ │ └── Transformer.sh
│ │ ├── ILI_script/
│ │ │ ├── Autoformer.sh
│ │ │ ├── Crossformer.sh
│ │ │ ├── FiLM.sh
│ │ │ ├── Koopa.sh
│ │ │ ├── MICN.sh
│ │ │ ├── Nonstationary_Transformer.sh
│ │ │ ├── PatchTST.sh
│ │ │ ├── TimesNet.sh
│ │ │ └── Transformer.sh
│ │ ├── Mamba_all.sh
│ │ ├── Traffic_script/
│ │ │ ├── Autoformer.sh
│ │ │ ├── Crossformer.sh
│ │ │ ├── FiLM.sh
│ │ │ ├── Koopa.sh
│ │ │ ├── MICN.sh
│ │ │ ├── Mamba.sh
│ │ │ ├── MultiPatchFormer.sh
│ │ │ ├── Nonstationary_Transformer.sh
│ │ │ ├── PatchTST.sh
│ │ │ ├── Pyraformer.sh
│ │ │ ├── SegRNN.sh
│ │ │ ├── TSMixer.sh
│ │ │ ├── TimeMixer.sh
│ │ │ ├── TimeXer.sh
│ │ │ ├── TimesNet.sh
│ │ │ ├── Transformer.sh
│ │ │ ├── WPMixer.sh
│ │ │ └── iTransformer.sh
│ │ └── Weather_script/
│ │ ├── Autoformer.sh
│ │ ├── Crossformer.sh
│ │ ├── FiLM.sh
│ │ ├── MICN.sh
│ │ ├── Mamba.sh
│ │ ├── MultiPatchFormer.sh
│ │ ├── Nonstationary_Transformer.sh
│ │ ├── PatchTST.sh
│ │ ├── Pyraformer.sh
│ │ ├── SegRNN.sh
│ │ ├── TSMixer.sh
│ │ ├── TimeMixer.sh
│ │ ├── TimeXer.sh
│ │ ├── TimesNet.sh
│ │ ├── Transformer.sh
│ │ ├── WPMixer.sh
│ │ └── iTransformer.sh
│ └── short_term_forecast/
│ ├── Autoformer_M4.sh
│ ├── Crossformer_M4.sh
│ ├── DLinear_M4.sh
│ ├── ETSformer_M4.sh
│ ├── FEDformer_M4.sh
│ ├── FiLM_M4.sh
│ ├── Informer_M4.sh
│ ├── LightTS_M4.sh
│ ├── MICN_M4.sh
│ ├── Mamba_M4.sh
│ ├── Nonstationary_Transformer_M4.sh
│ ├── Pyraformer_M4.sh
│ ├── Reformer_M4.sh
│ ├── TSMixer_M4.sh
│ ├── TimeMixer_M4.sh
│ ├── TimesNet_M4.sh
│ ├── Transformer_M4.sh
│ └── iTransformer_M4.sh
├── tutorial/
│ └── TimesNet_tutorial.ipynb
└── utils/
├── ADFtest.py
├── __init__.py
├── augmentation.py
├── dtw.py
├── dtw_metric.py
├── losses.py
├── m4_summary.py
├── masking.py
├── metrics.py
├── print_args.py
├── timefeatures.py
└── tools.py
SYMBOL INDEX (983 symbols across 79 files)
FILE: data_provider/data_factory.py
function data_provider (line 22) | def data_provider(args, flag):
FILE: data_provider/data_loader.py
class Dataset_ETT_hour (line 21) | class Dataset_ETT_hour(Dataset):
method __init__ (line 22) | def __init__(self, args, root_path, flag='train', size=None,
method __read_data__ (line 51) | def __read_data__(self):
method __getitem__ (line 101) | def __getitem__(self, index):
method __len__ (line 114) | def __len__(self):
method inverse_transform (line 117) | def inverse_transform(self, data):
class Dataset_ETT_minute (line 121) | class Dataset_ETT_minute(Dataset):
method __init__ (line 122) | def __init__(self, args, root_path, flag='train', size=None,
method __read_data__ (line 151) | def __read_data__(self):
method __getitem__ (line 203) | def __getitem__(self, index):
method __len__ (line 216) | def __len__(self):
method inverse_transform (line 219) | def inverse_transform(self, data):
class Dataset_Custom (line 223) | class Dataset_Custom(Dataset):
method __init__ (line 224) | def __init__(self, args, root_path, flag='train', size=None,
method __read_data__ (line 253) | def __read_data__(self):
method __getitem__ (line 313) | def __getitem__(self, index):
method __len__ (line 326) | def __len__(self):
method inverse_transform (line 329) | def inverse_transform(self, data):
class Dataset_M4 (line 333) | class Dataset_M4(Dataset):
method __init__ (line 334) | def __init__(self, args, root_path, flag='pred', size=None,
method __read_data__ (line 358) | def __read_data__(self):
method __getitem__ (line 370) | def __getitem__(self, index):
method __len__ (line 390) | def __len__(self):
method inverse_transform (line 393) | def inverse_transform(self, data):
method last_insample_window (line 396) | def last_insample_window(self):
class PSMSegLoader (line 412) | class PSMSegLoader(Dataset):
method __init__ (line 413) | def __init__(self, args, root_path, win_size, step=1, flag="train"):
method __len__ (line 449) | def __len__(self):
method __getitem__ (line 459) | def __getitem__(self, index):
class MSLSegLoader (line 474) | class MSLSegLoader(Dataset):
method __init__ (line 475) | def __init__(self, args, root_path, win_size, step=1, flag="train"):
method __len__ (line 512) | def __len__(self):
method __getitem__ (line 522) | def __getitem__(self, index):
class SMAPSegLoader (line 537) | class SMAPSegLoader(Dataset):
method __init__ (line 538) | def __init__(self, args, root_path, win_size, step=1, flag="train"):
method __len__ (line 576) | def __len__(self):
method __getitem__ (line 587) | def __getitem__(self, index):
class SMDSegLoader (line 602) | class SMDSegLoader(Dataset):
method __init__ (line 603) | def __init__(self, args, root_path, win_size, step=100, flag="train"):
method __len__ (line 637) | def __len__(self):
method __getitem__ (line 647) | def __getitem__(self, index):
class SWATSegLoader (line 662) | class SWATSegLoader(Dataset):
method __init__ (line 663) | def __init__(self, args, root_path, win_size, step=1, flag="train"):
method __len__ (line 693) | def __len__(self):
method __getitem__ (line 706) | def __getitem__(self, index):
class UEAloader (line 721) | class UEAloader(Dataset):
method __init__ (line 738) | def __init__(self, args, root_path, file_list=None, limit_size=None, f...
method _resolve_ts_path (line 762) | def _resolve_ts_path(self, root_path, dataset_name, flag):
method load_all (line 770) | def load_all(self, root_path, file_list=None, flag=None):
method load_single (line 788) | def load_single(self, filepath):
method instance_norm (line 824) | def instance_norm(self, case):
method __getitem__ (line 834) | def __getitem__(self, ind):
method __len__ (line 849) | def __len__(self):
FILE: data_provider/m4.py
function _ensure_m4_triplet (line 37) | def _ensure_m4_triplet(root_dir="./dataset/m4", repo_id=HUGGINGFACE_REPO):
function url_file_name (line 57) | def url_file_name(url: str) -> str:
function download (line 67) | def download(url: str, file_path: str) -> None:
class M4Dataset (line 96) | class M4Dataset:
method load (line 104) | def load(training: bool = True, dataset_file: str = '../dataset/m4') -...
class M4Meta (line 125) | class M4Meta:
function load_m4_info (line 155) | def load_m4_info() -> pd.DataFrame:
FILE: data_provider/uea.py
function collate_fn (line 7) | def collate_fn(data, max_len=None):
function padding_mask (line 45) | def padding_mask(lengths, max_len=None):
class Normalizer (line 58) | class Normalizer(object):
method __init__ (line 63) | def __init__(self, norm_type='standardization', mean=None, std=None, m...
method normalize (line 78) | def normalize(self, df):
function interpolate_missing (line 110) | def interpolate_missing(y):
function subsample (line 119) | def subsample(y, limit=256, factor=2):
FILE: exp/exp_anomaly_detection.py
class Exp_Anomaly_Detection (line 20) | class Exp_Anomaly_Detection(Exp_Basic):
method __init__ (line 21) | def __init__(self, args):
method _build_model (line 24) | def _build_model(self):
method _get_data (line 31) | def _get_data(self, flag):
method _select_optimizer (line 35) | def _select_optimizer(self):
method _select_criterion (line 39) | def _select_criterion(self):
method vali (line 43) | def vali(self, vali_data, vali_loader, criterion):
method train (line 63) | def train(self, setting):
method test (line 128) | def test(self, setting, test=0):
FILE: exp/exp_basic.py
class Exp_Basic (line 10) | class Exp_Basic(object):
method __init__ (line 11) | def __init__(self, args):
method _scan_models_directory (line 25) | def _scan_models_directory(self):
method _build_model (line 48) | def _build_model(self):
method _acquire_device (line 52) | def _acquire_device(self):
method _get_data (line 66) | def _get_data(self):
method vali (line 69) | def vali(self):
method train (line 72) | def train(self):
method test (line 75) | def test(self):
class LazyModelDict (line 79) | class LazyModelDict(dict):
method __init__ (line 83) | def __init__(self, model_map):
method __getitem__ (line 87) | def __getitem__(self, key):
FILE: exp/exp_classification.py
class Exp_Classification (line 16) | class Exp_Classification(Exp_Basic):
method __init__ (line 17) | def __init__(self, args):
method _build_model (line 20) | def _build_model(self):
method _get_data (line 34) | def _get_data(self, flag):
method _select_optimizer (line 38) | def _select_optimizer(self):
method _select_criterion (line 43) | def _select_criterion(self):
method vali (line 47) | def vali(self, vali_data, vali_loader, criterion):
method train (line 79) | def train(self, setting):
method test (line 145) | def test(self, setting, test=0):
FILE: exp/exp_imputation.py
class Exp_Imputation (line 16) | class Exp_Imputation(Exp_Basic):
method __init__ (line 17) | def __init__(self, args):
method _build_model (line 20) | def _build_model(self):
method _get_data (line 27) | def _get_data(self, flag):
method _select_optimizer (line 31) | def _select_optimizer(self):
method _select_criterion (line 35) | def _select_criterion(self):
method vali (line 39) | def vali(self, vali_data, vali_loader, criterion):
method train (line 78) | def train(self, setting):
method test (line 156) | def test(self, setting, test=0):
FILE: exp/exp_long_term_forecasting.py
class Exp_Long_Term_Forecast (line 18) | class Exp_Long_Term_Forecast(Exp_Basic):
method __init__ (line 19) | def __init__(self, args):
method _build_model (line 22) | def _build_model(self):
method _get_data (line 29) | def _get_data(self, flag):
method _select_optimizer (line 33) | def _select_optimizer(self):
method _select_criterion (line 37) | def _select_criterion(self):
method vali (line 42) | def vali(self, vali_data, vali_loader, criterion):
method train (line 76) | def train(self, setting):
method test (line 168) | def test(self, setting, test=0):
FILE: exp/exp_short_term_forecasting.py
class Exp_Short_Term_Forecast (line 19) | class Exp_Short_Term_Forecast(Exp_Basic):
method __init__ (line 20) | def __init__(self, args):
method _build_model (line 23) | def _build_model(self):
method _get_data (line 35) | def _get_data(self, flag):
method _select_optimizer (line 39) | def _select_optimizer(self):
method _select_criterion (line 43) | def _select_criterion(self, loss_name='MSE'):
method train (line 53) | def train(self, setting):
method vali (line 129) | def vali(self, train_loader, vali_loader, criterion):
method test (line 160) | def test(self, setting, test=0):
FILE: exp/exp_zero_shot_forecasting.py
class Exp_Zero_Shot_Forecast (line 18) | class Exp_Zero_Shot_Forecast(Exp_Basic):
method __init__ (line 19) | def __init__(self, args):
method _build_model (line 22) | def _build_model(self):
method _get_data (line 29) | def _get_data(self, flag):
method _select_optimizer (line 33) | def _select_optimizer(self):
method _select_criterion (line 37) | def _select_criterion(self):
method test (line 41) | def test(self, setting, test=0):
FILE: layers/AutoCorrelation.py
class AutoCorrelation (line 11) | class AutoCorrelation(nn.Module):
method __init__ (line 19) | def __init__(self, mask_flag=True, factor=1, scale=None, attention_dro...
method time_delay_agg_training (line 27) | def time_delay_agg_training(self, values, corr):
method time_delay_agg_inference (line 51) | def time_delay_agg_inference(self, values, corr):
method time_delay_agg_full (line 78) | def time_delay_agg_full(self, values, corr):
method forward (line 102) | def forward(self, queries, keys, values, attn_mask):
class AutoCorrelationLayer (line 131) | class AutoCorrelationLayer(nn.Module):
method __init__ (line 132) | def __init__(self, correlation, d_model, n_heads, d_keys=None,
method forward (line 146) | def forward(self, queries, keys, values, attn_mask):
FILE: layers/Autoformer_EncDec.py
class my_Layernorm (line 6) | class my_Layernorm(nn.Module):
method __init__ (line 11) | def __init__(self, channels):
method forward (line 15) | def forward(self, x):
class moving_avg (line 21) | class moving_avg(nn.Module):
method __init__ (line 26) | def __init__(self, kernel_size, stride):
method forward (line 31) | def forward(self, x):
class series_decomp (line 41) | class series_decomp(nn.Module):
method __init__ (line 46) | def __init__(self, kernel_size):
method forward (line 50) | def forward(self, x):
class series_decomp_multi (line 56) | class series_decomp_multi(nn.Module):
method __init__ (line 61) | def __init__(self, kernel_size):
method forward (line 66) | def forward(self, x):
class EncoderLayer (line 79) | class EncoderLayer(nn.Module):
method __init__ (line 84) | def __init__(self, attention, d_model, d_ff=None, moving_avg=25, dropo...
method forward (line 95) | def forward(self, x, attn_mask=None):
class Encoder (line 109) | class Encoder(nn.Module):
method __init__ (line 114) | def __init__(self, attn_layers, conv_layers=None, norm_layer=None):
method forward (line 120) | def forward(self, x, attn_mask=None):
class DecoderLayer (line 140) | class DecoderLayer(nn.Module):
method __init__ (line 145) | def __init__(self, self_attention, cross_attention, d_model, c_out, d_...
method forward (line 161) | def forward(self, x, cross, x_mask=None, cross_mask=None):
class Decoder (line 182) | class Decoder(nn.Module):
method __init__ (line 187) | def __init__(self, layers, norm_layer=None, projection=None):
method forward (line 193) | def forward(self, x, cross, x_mask=None, cross_mask=None, trend=None):
FILE: layers/Conv_Blocks.py
class Inception_Block_V1 (line 5) | class Inception_Block_V1(nn.Module):
method __init__ (line 6) | def __init__(self, in_channels, out_channels, num_kernels=6, init_weig...
method _initialize_weights (line 18) | def _initialize_weights(self):
method forward (line 25) | def forward(self, x):
class Inception_Block_V2 (line 33) | class Inception_Block_V2(nn.Module):
method __init__ (line 34) | def __init__(self, in_channels, out_channels, num_kernels=6, init_weig...
method _initialize_weights (line 48) | def _initialize_weights(self):
method forward (line 55) | def forward(self, x):
FILE: layers/Crossformer_EncDec.py
class SegMerging (line 7) | class SegMerging(nn.Module):
method __init__ (line 8) | def __init__(self, d_model, win_size, norm_layer=nn.LayerNorm):
method forward (line 15) | def forward(self, x):
class scale_block (line 33) | class scale_block(nn.Module):
method __init__ (line 34) | def __init__(self, configs, win_size, d_model, n_heads, d_ff, depth, d...
method forward (line 49) | def forward(self, x, attn_mask=None, tau=None, delta=None):
class Encoder (line 61) | class Encoder(nn.Module):
method __init__ (line 62) | def __init__(self, attn_layers):
method forward (line 66) | def forward(self, x):
class DecoderLayer (line 77) | class DecoderLayer(nn.Module):
method __init__ (line 78) | def __init__(self, self_attention, cross_attention, seg_len, d_model, ...
method forward (line 90) | def forward(self, x, cross):
class Decoder (line 109) | class Decoder(nn.Module):
method __init__ (line 110) | def __init__(self, layers):
method forward (line 115) | def forward(self, x, cross):
FILE: layers/DWT_Decomposition.py
class Decomposition (line 18) | class Decomposition(nn.Module):
method __init__ (line 19) | def __init__(self,
method transform (line 66) | def transform(self, x):
method inv_transform (line 74) | def inv_transform(self, yl, yh):
method _dummy_forward (line 81) | def _dummy_forward(self, input_length):
method _init_params (line 90) | def _init_params(self):
method _wavelet_decompose (line 94) | def _wavelet_decompose(self, x):
method _wavelet_reverse_decompose (line 111) | def _wavelet_reverse_decompose(self, yl, yh):
class DWT1DForward (line 137) | class DWT1DForward(nn.Module):
method __init__ (line 151) | def __init__(self, J=1, wave='db1', mode='zero', use_amp=False):
method forward (line 169) | def forward(self, x):
class DWT1DInverse (line 194) | class DWT1DInverse(nn.Module):
method __init__ (line 207) | def __init__(self, wave='db1', mode='zero', use_amp=False):
method forward (line 224) | def forward(self, coeffs):
function roll (line 252) | def roll(x, n, dim, make_even=False):
function mypad (line 271) | def mypad(x, pad, mode='constant', value=0):
function afb1d (line 334) | def afb1d(x, h0, h1, use_amp, mode='zero', dim=-1):
function afb1d_atrous (line 430) | def afb1d_atrous(x, h0, h1, mode='periodic', dim=-1, dilation=1):
function sfb1d (line 481) | def sfb1d(lo, hi, g0, g1, use_amp, mode='zero', dim=-1):
function mode_to_int (line 539) | def mode_to_int(mode):
function int_to_mode (line 558) | def int_to_mode(mode):
class AFB2D (line 577) | class AFB2D(Function):
method forward (line 602) | def forward(ctx, x, h0_row, h1_row, h0_col, h1_col, mode):
method backward (line 616) | def backward(ctx, low, highs):
class AFB1D (line 634) | class AFB1D(Function):
method forward (line 656) | def forward(ctx, x, h0, h1, mode, use_amp):
method backward (line 676) | def backward(ctx, dx0, dx1):
function afb2d (line 696) | def afb2d(x, filts, mode='zero'):
function afb2d_atrous (line 744) | def afb2d_atrous(x, filts, mode='periodization', dilation=1):
function afb2d_nonsep (line 793) | def afb2d_nonsep(x, filts, mode='zero'):
function sfb2d (line 869) | def sfb2d(ll, lh, hl, hh, filts, mode='zero'):
class SFB2D (line 916) | class SFB2D(Function):
method forward (line 941) | def forward(ctx, low, highs, g0_row, g1_row, g0_col, g1_col, mode):
method backward (line 953) | def backward(ctx, dy):
class SFB1D (line 967) | class SFB1D(Function):
method forward (line 989) | def forward(ctx, low, high, g0, g1, mode, use_amp):
method backward (line 1004) | def backward(ctx, dy):
function sfb2d_nonsep (line 1019) | def sfb2d_nonsep(coeffs, filts, mode='zero'):
function prep_filt_afb2d_nonsep (line 1074) | def prep_filt_afb2d_nonsep(h0_col, h1_col, h0_row=None, h1_row=None,
function prep_filt_sfb2d_nonsep (line 1109) | def prep_filt_sfb2d_nonsep(g0_col, g1_col, g0_row=None, g1_row=None,
function prep_filt_sfb2d (line 1143) | def prep_filt_sfb2d(g0_col, g1_col, g0_row=None, g1_row=None, device=None):
function prep_filt_sfb1d (line 1175) | def prep_filt_sfb1d(g0, g1, device=None):
function prep_filt_afb2d (line 1198) | def prep_filt_afb2d(h0_col, h1_col, h0_row=None, h1_row=None, device=None):
function prep_filt_afb1d (line 1229) | def prep_filt_afb1d(h0, h1, device=None):
function reflect (line 1251) | def reflect(x, minx, maxx):
FILE: layers/ETSformer_EncDec.py
class Transform (line 10) | class Transform:
method __init__ (line 11) | def __init__(self, sigma):
method transform (line 15) | def transform(self, x):
method jitter (line 18) | def jitter(self, x):
method scale (line 21) | def scale(self, x):
method shift (line 24) | def shift(self, x):
function conv1d_fft (line 28) | def conv1d_fft(f, g, dim=-1):
class ExponentialSmoothing (line 46) | class ExponentialSmoothing(nn.Module):
method __init__ (line 48) | def __init__(self, dim, nhead, dropout=0.1, aux=False):
method forward (line 56) | def forward(self, values, aux_values=None):
method get_exponential_weight (line 70) | def get_exponential_weight(self, T):
method weight (line 84) | def weight(self):
class Feedforward (line 88) | class Feedforward(nn.Module):
method __init__ (line 89) | def __init__(self, d_model, dim_feedforward, dropout=0.1, activation='...
method forward (line 98) | def forward(self, x):
class GrowthLayer (line 103) | class GrowthLayer(nn.Module):
method __init__ (line 105) | def __init__(self, d_model, nhead, d_head=None, dropout=0.1):
method forward (line 118) | def forward(self, inputs):
class FourierLayer (line 133) | class FourierLayer(nn.Module):
method __init__ (line 135) | def __init__(self, d_model, pred_len, k=None, low_freq=1):
method forward (line 142) | def forward(self, x):
method extrapolate (line 160) | def extrapolate(self, x_freq, f, t):
method topk_freq (line 173) | def topk_freq(self, x_freq):
class LevelLayer (line 182) | class LevelLayer(nn.Module):
method __init__ (line 184) | def __init__(self, d_model, c_out, dropout=0.1):
method forward (line 193) | def forward(self, level, growth, season):
class EncoderLayer (line 205) | class EncoderLayer(nn.Module):
method __init__ (line 207) | def __init__(self, d_model, nhead, c_out, seq_len, pred_len, k, dim_fe...
method forward (line 230) | def forward(self, res, level, attn_mask=None):
method _growth_block (line 240) | def _growth_block(self, x):
method _season_block (line 244) | def _season_block(self, x):
class Encoder (line 249) | class Encoder(nn.Module):
method __init__ (line 251) | def __init__(self, layers):
method forward (line 255) | def forward(self, res, level, attn_mask=None):
class DampingLayer (line 266) | class DampingLayer(nn.Module):
method __init__ (line 268) | def __init__(self, pred_len, nhead, dropout=0.1):
method forward (line 275) | def forward(self, x):
method damping_factor (line 288) | def damping_factor(self):
class DecoderLayer (line 292) | class DecoderLayer(nn.Module):
method __init__ (line 294) | def __init__(self, d_model, nhead, c_out, pred_len, dropout=0.1):
method forward (line 304) | def forward(self, growth, season):
class Decoder (line 312) | class Decoder(nn.Module):
method __init__ (line 314) | def __init__(self, layers):
method forward (line 324) | def forward(self, growths, seasons):
FILE: layers/Embed.py
class PositionalEmbedding (line 8) | class PositionalEmbedding(nn.Module):
method __init__ (line 9) | def __init__(self, d_model, max_len=5000):
method forward (line 25) | def forward(self, x):
class TokenEmbedding (line 29) | class TokenEmbedding(nn.Module):
method __init__ (line 30) | def __init__(self, c_in, d_model):
method forward (line 40) | def forward(self, x):
class FixedEmbedding (line 45) | class FixedEmbedding(nn.Module):
method __init__ (line 46) | def __init__(self, c_in, d_model):
method forward (line 62) | def forward(self, x):
class TemporalEmbedding (line 66) | class TemporalEmbedding(nn.Module):
method __init__ (line 67) | def __init__(self, d_model, embed_type='fixed', freq='h'):
method forward (line 84) | def forward(self, x):
class TimeFeatureEmbedding (line 96) | class TimeFeatureEmbedding(nn.Module):
method __init__ (line 97) | def __init__(self, d_model, embed_type='timeF', freq='h'):
method forward (line 105) | def forward(self, x):
class DataEmbedding (line 109) | class DataEmbedding(nn.Module):
method __init__ (line 110) | def __init__(self, c_in, d_model, embed_type='fixed', freq='h', dropou...
method forward (line 120) | def forward(self, x, x_mark):
class DataEmbedding_inverted (line 129) | class DataEmbedding_inverted(nn.Module):
method __init__ (line 130) | def __init__(self, c_in, d_model, embed_type='fixed', freq='h', dropou...
method forward (line 135) | def forward(self, x, x_mark):
class DataEmbedding_wo_pos (line 146) | class DataEmbedding_wo_pos(nn.Module):
method __init__ (line 147) | def __init__(self, c_in, d_model, embed_type='fixed', freq='h', dropou...
method forward (line 157) | def forward(self, x, x_mark):
class PatchEmbedding (line 165) | class PatchEmbedding(nn.Module):
method __init__ (line 166) | def __init__(self, d_model, patch_len, stride, padding, dropout):
method forward (line 182) | def forward(self, x):
FILE: layers/FourierCorrelation.py
function get_frequency_modes (line 10) | def get_frequency_modes(seq_len, modes=64, mode_select_method='random'):
class FourierBlock (line 28) | class FourierBlock(nn.Module):
method __init__ (line 29) | def __init__(self, in_channels, out_channels, n_heads, seq_len, modes=...
method compl_mul1d (line 50) | def compl_mul1d(self, order, x, weights):
method forward (line 65) | def forward(self, q, k, v, mask):
class FourierCrossAttention (line 83) | class FourierCrossAttention(nn.Module):
method __init__ (line 84) | def __init__(self, in_channels, out_channels, seq_len_q, seq_len_kv, m...
method compl_mul1d (line 108) | def compl_mul1d(self, order, x, weights):
method forward (line 123) | def forward(self, q, k, v, mask):
FILE: layers/MSGBlock.py
class Predict (line 11) | class Predict(nn.Module):
method __init__ (line 12) | def __init__(self, individual, c_out, seq_len, pred_len, dropout):
method forward (line 28) | def forward(self, x):
class Attention_Block (line 43) | class Attention_Block(nn.Module):
method __init__ (line 44) | def __init__(self, d_model, d_ff=None, n_heads=8, dropout=0.1, activa...
method forward (line 55) | def forward(self, x, attn_mask=None):
class self_attention (line 69) | class self_attention(nn.Module):
method __init__ (line 70) | def __init__(self, attention, d_model ,n_heads):
method forward (line 83) | def forward(self, queries ,keys ,values, attn_mask= None):
class FullAttention (line 102) | class FullAttention(nn.Module):
method __init__ (line 103) | def __init__(self, mask_flag=True, factor=5, scale=None, attention_dro...
method forward (line 110) | def forward(self, queries, keys, values, attn_mask):
class GraphBlock (line 128) | class GraphBlock(nn.Module):
method __init__ (line 129) | def __init__(self, c_out , d_model , conv_channel, skip_channel,
method forward (line 143) | def forward(self, x):
class nconv (line 154) | class nconv(nn.Module):
method __init__ (line 155) | def __init__(self):
method forward (line 158) | def forward(self,x, A):
class linear (line 164) | class linear(nn.Module):
method __init__ (line 165) | def __init__(self,c_in,c_out,bias=True):
method forward (line 169) | def forward(self,x):
class mixprop (line 173) | class mixprop(nn.Module):
method __init__ (line 174) | def __init__(self,c_in,c_out,gdep,dropout,alpha):
method forward (line 182) | def forward(self, x, adj):
class simpleVIT (line 196) | class simpleVIT(nn.Module):
method __init__ (line 197) | def __init__(self, in_channels, emb_size, patch_size=2, depth=1, num_h...
method _initialize_weights (line 216) | def _initialize_weights(self):
method forward (line 223) | def forward(self,x):
class MultiHeadAttention (line 234) | class MultiHeadAttention(nn.Module):
method __init__ (line 235) | def __init__(self, emb_size, num_heads, dropout):
method forward (line 245) | def forward(self, x: Tensor, mask: Tensor = None) -> Tensor:
class FeedForward (line 263) | class FeedForward(nn.Module):
method __init__ (line 264) | def __init__(self, dim, hidden_dim):
method forward (line 272) | def forward(self, x):
FILE: layers/MambaBlock.py
class Mamba_TimeVariant (line 24) | class Mamba_TimeVariant(nn.Module):
method __init__ (line 35) | def __init__(
method forward (line 161) | def forward(self, hidden_states, inference_params=None):
method step (line 273) | def step(self, hidden_states, conv_state, ssm_state):
method allocate_inference_cache (line 349) | def allocate_inference_cache(self, batch_size, max_seqlen, dtype=None,...
method _get_states_from_cache (line 362) | def _get_states_from_cache(self, inference_params, batch_size, initial...
FILE: layers/MultiWaveletCorrelation.py
function legendreDer (line 16) | def legendreDer(k, x):
function phi_ (line 26) | def phi_(phi_c, x, lb=0, ub=1):
function get_phi_psi (line 31) | def get_phi_psi(k, base):
function get_filter (line 140) | def get_filter(base, k):
class MultiWaveletTransform (line 201) | class MultiWaveletTransform(nn.Module):
method __init__ (line 206) | def __init__(self, ich=1, k=8, alpha=16, c=128,
method forward (line 219) | def forward(self, queries, keys, values, attn_mask):
class MultiWaveletCross (line 242) | class MultiWaveletCross(nn.Module):
method __init__ (line 247) | def __init__(self, in_channels, out_channels, seq_len_q, seq_len_kv, m...
method forward (line 301) | def forward(self, q, k, v, mask=None):
method wavelet_transform (line 373) | def wavelet_transform(self, x):
method evenOdd (line 381) | def evenOdd(self, x):
class FourierCrossAttentionW (line 394) | class FourierCrossAttentionW(nn.Module):
method __init__ (line 395) | def __init__(self, in_channels, out_channels, seq_len_q, seq_len_kv, m...
method compl_mul1d (line 404) | def compl_mul1d(self, order, x, weights):
method forward (line 419) | def forward(self, q, k, v, mask):
class sparseKernelFT1d (line 458) | class sparseKernelFT1d(nn.Module):
method __init__ (line 459) | def __init__(self,
method compl_mul1d (line 474) | def compl_mul1d(self, order, x, weights):
method forward (line 489) | def forward(self, x):
class MWT_CZ1d (line 506) | class MWT_CZ1d(nn.Module):
method __init__ (line 507) | def __init__(self,
method forward (line 545) | def forward(self, x):
method wavelet_transform (line 568) | def wavelet_transform(self, x):
method evenOdd (line 576) | def evenOdd(self, x):
FILE: layers/Pyraformer_EncDec.py
function get_mask (line 10) | def get_mask(input_size, window_size, inner_size):
function refer_points (line 50) | def refer_points(all_sizes, window_size):
class RegularMask (line 70) | class RegularMask():
method __init__ (line 71) | def __init__(self, mask):
method mask (line 75) | def mask(self):
class EncoderLayer (line 79) | class EncoderLayer(nn.Module):
method __init__ (line 82) | def __init__(self, d_model, d_inner, n_head, dropout=0.1, normalize_be...
method forward (line 92) | def forward(self, enc_input, slf_attn_mask=None):
class Encoder (line 100) | class Encoder(nn.Module):
method __init__ (line 103) | def __init__(self, configs, window_size, inner_size):
method forward (line 121) | def forward(self, x_enc, x_mark_enc):
class ConvLayer (line 139) | class ConvLayer(nn.Module):
method __init__ (line 140) | def __init__(self, c_in, window_size):
method forward (line 149) | def forward(self, x):
class Bottleneck_Construct (line 156) | class Bottleneck_Construct(nn.Module):
method __init__ (line 159) | def __init__(self, d_model, window_size, d_inner):
method forward (line 176) | def forward(self, enc_input):
class PositionwiseFeedForward (line 191) | class PositionwiseFeedForward(nn.Module):
method __init__ (line 194) | def __init__(self, d_in, d_hid, dropout=0.1, normalize_before=True):
method forward (line 205) | def forward(self, x):
FILE: layers/SelfAttention_Family.py
class DSAttention (line 10) | class DSAttention(nn.Module):
method __init__ (line 13) | def __init__(self, mask_flag=True, factor=5, scale=None, attention_dro...
method forward (line 20) | def forward(self, queries, keys, values, attn_mask, tau=None, delta=No...
class FullAttention (line 48) | class FullAttention(nn.Module):
method __init__ (line 49) | def __init__(self, mask_flag=True, factor=5, scale=None, attention_dro...
method forward (line 56) | def forward(self, queries, keys, values, attn_mask, tau=None, delta=No...
class ProbAttention (line 78) | class ProbAttention(nn.Module):
method __init__ (line 79) | def __init__(self, mask_flag=True, factor=5, scale=None, attention_dro...
method _prob_QK (line 87) | def _prob_QK(self, Q, K, sample_k, n_top): # n_top: c*ln(L_q)
method _get_initial_context (line 113) | def _get_initial_context(self, V, L_Q):
method _update_context (line 126) | def _update_context(self, context_in, V, scores, index, L_Q, attn_mask):
method forward (line 147) | def forward(self, queries, keys, values, attn_mask, tau=None, delta=No...
class AttentionLayer (line 179) | class AttentionLayer(nn.Module):
method __init__ (line 180) | def __init__(self, attention, d_model, n_heads, d_keys=None,
method forward (line 194) | def forward(self, queries, keys, values, attn_mask, tau=None, delta=No...
class ReformerLayer (line 216) | class ReformerLayer(nn.Module):
method __init__ (line 217) | def __init__(self, attention, d_model, n_heads, d_keys=None,
method fit_length (line 229) | def fit_length(self, queries):
method forward (line 239) | def forward(self, queries, keys, values, attn_mask, tau, delta):
class TwoStageAttentionLayer (line 246) | class TwoStageAttentionLayer(nn.Module):
method __init__ (line 252) | def __init__(self, configs,
method forward (line 278) | def forward(self, x, attn_mask=None, tau=None, delta=None):
FILE: layers/StandardNorm.py
class Normalize (line 5) | class Normalize(nn.Module):
method __init__ (line 6) | def __init__(self, num_features: int, eps=1e-5, affine=False, subtract...
method forward (line 21) | def forward(self, x, mode: str):
method _init_params (line 31) | def _init_params(self):
method _get_statistics (line 36) | def _get_statistics(self, x):
method _normalize (line 44) | def _normalize(self, x):
method _denormalize (line 57) | def _denormalize(self, x):
FILE: layers/TimeFilter_layers.py
class GCN (line 7) | class GCN(nn.Module):
method __init__ (line 8) | def __init__(self, dim, n_heads):
method forward (line 13) | def forward(self, adj, x):
function mask_topk_moe (line 26) | def mask_topk_moe(adj, thre, n_vars, masks):
function mask_topk_area (line 56) | def mask_topk_area(adj, n_vars, masks, alpha=0.5):
class mask_moe (line 98) | class mask_moe(nn.Module):
method __init__ (line 99) | def __init__(self, n_vars, top_p=0.5, num_experts=3, in_dim=96):
method cv_squared (line 112) | def cv_squared(self, x):
method cross_entropy (line 118) | def cross_entropy(self, x):
method noisy_top_k_gating (line 124) | def noisy_top_k_gating(self, x, is_training, noise_epsilon=1e-2):
method forward (line 158) | def forward(self, x, masks=None):
function mask_topk (line 190) | def mask_topk(x, alpha=0.5, largest=False):
class GraphLearner (line 200) | class GraphLearner(nn.Module):
method __init__ (line 201) | def __init__(self, dim, n_vars, top_p=0.5, in_dim=96):
method forward (line 209) | def forward(self, x, masks=None, alpha=0.5):
class GraphFilter (line 219) | class GraphFilter(nn.Module):
method __init__ (line 220) | def __init__(self, dim, n_vars, n_heads=4, scale=None, top_p=0.5, drop...
method forward (line 229) | def forward(self, x, masks=None, alpha=0.5):
class GraphBlock (line 241) | class GraphBlock(nn.Module):
method __init__ (line 242) | def __init__(self, dim, n_vars, d_ff=None, n_heads=4, top_p=0.5, dropo...
method forward (line 256) | def forward(self, x, masks=None, alpha=0.5):
class TimeFilter_Backbone (line 264) | class TimeFilter_Backbone(nn.Module):
method __init__ (line 265) | def __init__(self, hidden_dim, n_vars, d_ff=None, n_heads=4, n_blocks=...
method forward (line 276) | def forward(self, x, masks=None, alpha=0.5):
FILE: layers/Transformer_EncDec.py
class ConvLayer (line 6) | class ConvLayer(nn.Module):
method __init__ (line 7) | def __init__(self, c_in):
method forward (line 18) | def forward(self, x):
class EncoderLayer (line 27) | class EncoderLayer(nn.Module):
method __init__ (line 28) | def __init__(self, attention, d_model, d_ff=None, dropout=0.1, activat...
method forward (line 39) | def forward(self, x, attn_mask=None, tau=None, delta=None):
class Encoder (line 54) | class Encoder(nn.Module):
method __init__ (line 55) | def __init__(self, attn_layers, conv_layers=None, norm_layer=None):
method forward (line 61) | def forward(self, x, attn_mask=None, tau=None, delta=None):
class DecoderLayer (line 83) | class DecoderLayer(nn.Module):
method __init__ (line 84) | def __init__(self, self_attention, cross_attention, d_model, d_ff=None,
method forward (line 98) | def forward(self, x, cross, x_mask=None, cross_mask=None, tau=None, de...
class Decoder (line 119) | class Decoder(nn.Module):
method __init__ (line 120) | def __init__(self, layers, norm_layer=None, projection=None):
method forward (line 126) | def forward(self, x, cross, x_mask=None, cross_mask=None, tau=None, de...
FILE: models/Autoformer.py
class Model (line 11) | class Model(nn.Module):
method __init__ (line 18) | def __init__(self, configs):
method forecast (line 88) | def forecast(self, x_enc, x_mark_enc, x_dec, x_mark_dec):
method imputation (line 111) | def imputation(self, x_enc, x_mark_enc, x_dec, x_mark_dec, mask):
method anomaly_detection (line 119) | def anomaly_detection(self, x_enc):
method classification (line 127) | def classification(self, x_enc, x_mark_enc):
method forward (line 143) | def forward(self, x_enc, x_mark_enc, x_dec, x_mark_dec, mask=None):
FILE: models/Chronos.py
class Model (line 9) | class Model(nn.Module):
method __init__ (line 10) | def __init__(self, configs):
method forecast (line 25) | def forecast(self, x_enc, x_mark_enc, x_dec, x_mark_dec):
method forward (line 35) | def forward(self, x_enc, x_mark_enc, x_dec, x_mark_dec, mask=None):
FILE: models/Chronos2.py
class Model (line 9) | class Model(nn.Module):
method __init__ (line 10) | def __init__(self, configs):
method forecast (line 21) | def forecast(self, x_enc, x_mark_enc, x_dec, x_mark_dec):
method forward (line 39) | def forward(self, x_enc, x_mark_enc, x_dec, x_mark_dec, mask=None):
FILE: models/Crossformer.py
class Model (line 14) | class Model(nn.Module):
method __init__ (line 18) | def __init__(self, configs):
method forecast (line 82) | def forecast(self, x_enc, x_mark_enc, x_dec, x_mark_dec):
method imputation (line 94) | def imputation(self, x_enc, x_mark_enc, x_dec, x_mark_dec, mask):
method anomaly_detection (line 106) | def anomaly_detection(self, x_enc):
method classification (line 117) | def classification(self, x_enc, x_mark_enc):
method forward (line 132) | def forward(self, x_enc, x_mark_enc, x_dec, x_mark_dec, mask=None):
FILE: models/DLinear.py
class Model (line 7) | class Model(nn.Module):
method __init__ (line 12) | def __init__(self, configs, individual=False):
method encoder (line 55) | def encoder(self, x):
method forecast (line 75) | def forecast(self, x_enc):
method imputation (line 79) | def imputation(self, x_enc):
method anomaly_detection (line 83) | def anomaly_detection(self, x_enc):
method classification (line 87) | def classification(self, x_enc):
method forward (line 97) | def forward(self, x_enc, x_mark_enc, x_dec, x_mark_dec, mask=None):
FILE: models/ETSformer.py
class Model (line 7) | class Model(nn.Module):
method __init__ (line 12) | def __init__(self, configs):
method forecast (line 55) | def forecast(self, x_enc, x_mark_enc, x_dec, x_mark_dec):
method imputation (line 66) | def imputation(self, x_enc, x_mark_enc, x_dec, x_mark_dec, mask):
method anomaly_detection (line 73) | def anomaly_detection(self, x_enc):
method classification (line 80) | def classification(self, x_enc, x_mark_enc):
method forward (line 97) | def forward(self, x_enc, x_mark_enc, x_dec, x_mark_dec, mask=None):
FILE: models/FEDformer.py
class Model (line 11) | class Model(nn.Module):
method __init__ (line 17) | def __init__(self, configs, version='fourier', mode_select='random', m...
method forecast (line 119) | def forecast(self, x_enc, x_mark_enc, x_dec, x_mark_dec):
method imputation (line 136) | def imputation(self, x_enc, x_mark_enc, x_dec, x_mark_dec, mask):
method anomaly_detection (line 144) | def anomaly_detection(self, x_enc):
method classification (line 152) | def classification(self, x_enc, x_mark_enc):
method forward (line 165) | def forward(self, x_enc, x_mark_enc, x_dec, x_mark_dec, mask=None):
FILE: models/FiLM.py
function transition (line 11) | def transition(N):
class HiPPO_LegT (line 20) | class HiPPO_LegT(nn.Module):
method __init__ (line 21) | def __init__(self, N, dt=1.0, discretization='bilinear'):
method forward (line 41) | def forward(self, inputs):
method reconstruct (line 55) | def reconstruct(self, c):
class SpectralConv1d (line 59) | class SpectralConv1d(nn.Module):
method __init__ (line 60) | def __init__(self, in_channels, out_channels, seq_len, ratio=0.5):
method compl_mul1d (line 77) | def compl_mul1d(self, order, x, weights_real, weights_imag):
method forward (line 81) | def forward(self, x):
class Model (line 91) | class Model(nn.Module):
method __init__ (line 95) | def __init__(self, configs):
method forecast (line 132) | def forecast(self, x_enc, x_mark_enc, x_dec_true, x_mark_dec):
method imputation (line 164) | def imputation(self, x_enc, x_mark_enc, x_dec, x_mark_dec, mask):
method anomaly_detection (line 196) | def anomaly_detection(self, x_enc):
method classification (line 228) | def classification(self, x_enc, x_mark_enc):
method forward (line 255) | def forward(self, x_enc, x_mark_enc, x_dec, x_mark_dec, mask=None):
FILE: models/FreTS.py
class Model (line 7) | class Model(nn.Module):
method __init__ (line 12) | def __init__(self, configs):
method tokenEmb (line 44) | def tokenEmb(self, x):
method MLP_temporal (line 53) | def MLP_temporal(self, x, B, N, L):
method MLP_channel (line 61) | def MLP_channel(self, x, B, N, L):
method FreMLP (line 75) | def FreMLP(self, B, nd, dimension, x, r, i, rb, ib):
method forecast (line 98) | def forecast(self, x_enc):
method forward (line 113) | def forward(self, x_enc, x_mark_enc, x_dec, x_mark_dec):
FILE: models/Informer.py
class Model (line 9) | class Model(nn.Module):
method __init__ (line 15) | def __init__(self, configs):
method long_forecast (line 77) | def long_forecast(self, x_enc, x_mark_enc, x_dec, x_mark_dec):
method short_forecast (line 86) | def short_forecast(self, x_enc, x_mark_enc, x_dec, x_mark_dec):
method imputation (line 102) | def imputation(self, x_enc, x_mark_enc, x_dec, x_mark_dec, mask):
method anomaly_detection (line 110) | def anomaly_detection(self, x_enc):
method classification (line 118) | def classification(self, x_enc, x_mark_enc):
method forward (line 131) | def forward(self, x_enc, x_mark_enc, x_dec, x_mark_dec, mask=None):
FILE: models/KANAD.py
class KANADModel (line 7) | class KANADModel(nn.Module):
method __init__ (line 8) | def __init__(self, window: int, order: int, *args, **kwargs) -> None:
method forward (line 28) | def forward(self, x: torch.Tensor, return_last: bool = False, *args, *...
method _create_custom_periodic_cosine (line 52) | def _create_custom_periodic_cosine(self, window: int, period) -> torch...
class Model (line 62) | class Model(nn.Module):
method __init__ (line 63) | def __init__(self, configs):
method anomaly_detection (line 74) | def anomaly_detection(self, x_enc):
method forward (line 83) | def forward(self, x_enc, x_mark_enc, x_dec, x_mark_dec, mask=None):
FILE: models/Koopa.py
class FourierFilter (line 8) | class FourierFilter(nn.Module):
method __init__ (line 12) | def __init__(self, mask_spectrum):
method forward (line 16) | def forward(self, x):
class MLP (line 26) | class MLP(nn.Module):
method __init__ (line 30) | def __init__(self,
method forward (line 59) | def forward(self, x):
class KPLayer (line 66) | class KPLayer(nn.Module):
method __init__ (line 70) | def __init__(self):
method one_step_forward (line 75) | def one_step_forward(self, z, return_rec=False, return_K=False):
method forward (line 93) | def forward(self, z, pred_len=1):
class KPLayerApprox (line 104) | class KPLayerApprox(nn.Module):
method __init__ (line 108) | def __init__(self):
method forward (line 114) | def forward(self, z, pred_len=1):
class TimeVarKP (line 151) | class TimeVarKP(nn.Module):
method __init__ (line 156) | def __init__(self,
method forward (line 180) | def forward(self, x):
class TimeInvKP (line 203) | class TimeInvKP(nn.Module):
method __init__ (line 208) | def __init__(self,
method forward (line 226) | def forward(self, x):
class Model (line 237) | class Model(nn.Module):
method __init__ (line 241) | def __init__(self, configs, dynamic_dim=128, hidden_dim=64, hidden_lay...
method _get_mask_spectrum (line 298) | def _get_mask_spectrum(self, configs):
method forecast (line 310) | def forecast(self, x_enc):
method forward (line 334) | def forward(self, x_enc, x_mark_enc, x_dec, x_mark_dec):
FILE: models/LightTS.py
class IEBlock (line 6) | class IEBlock(nn.Module):
method __init__ (line 7) | def __init__(self, input_dim, hid_dim, output_dim, num_node):
method _build (line 17) | def _build(self):
method forward (line 29) | def forward(self, x):
class Model (line 39) | class Model(nn.Module):
method __init__ (line 44) | def __init__(self, configs, chunk_size=24):
method _build (line 74) | def _build(self):
method encoder (line 102) | def encoder(self, x):
method forecast (line 135) | def forecast(self, x_enc, x_mark_enc, x_dec, x_mark_dec):
method imputation (line 138) | def imputation(self, x_enc, x_mark_enc, x_dec, x_mark_dec, mask):
method anomaly_detection (line 141) | def anomaly_detection(self, x_enc):
method classification (line 144) | def classification(self, x_enc, x_mark_enc):
method forward (line 152) | def forward(self, x_enc, x_mark_enc, x_dec, x_mark_dec, mask=None):
FILE: models/MICN.py
class MIC (line 8) | class MIC(nn.Module):
method __init__ (line 13) | def __init__(self, feature_size=512, n_heads=8, dropout=0.05, decomp_k...
method conv_trans_conv (line 48) | def conv_trans_conv(self, input, conv1d, conv1d_trans, isometric):
method forward (line 69) | def forward(self, src):
class SeasonalPrediction (line 90) | class SeasonalPrediction(nn.Module):
method __init__ (line 91) | def __init__(self, embedding_size=512, n_heads=8, dropout=0.05, d_laye...
method forward (line 102) | def forward(self, dec):
class Model (line 108) | class Model(nn.Module):
method __init__ (line 112) | def __init__(self, configs, conv_kernel=[12, 16]):
method forecast (line 159) | def forecast(self, x_enc, x_mark_enc, x_dec, x_mark_dec):
method imputation (line 172) | def imputation(self, x_enc, x_mark_enc, x_dec, x_mark_dec, mask):
method anomaly_detection (line 182) | def anomaly_detection(self, x_enc):
method classification (line 192) | def classification(self, x_enc, x_mark_enc):
method forward (line 208) | def forward(self, x_enc, x_mark_enc, x_dec, x_mark_dec, mask=None):
FILE: models/MSGNet.py
function FFT_for_Period (line 11) | def FFT_for_Period(x, k=2):
class ScaleGraphBlock (line 22) | class ScaleGraphBlock(nn.Module):
method __init__ (line 23) | def __init__(self, configs):
method forward (line 41) | def forward(self, x):
class Model (line 81) | class Model(nn.Module):
method __init__ (line 82) | def __init__(self, configs):
method forecast (line 118) | def forecast(self, x_enc, x_mark_enc, x_dec, x_mark_dec, mask=None):
method imputation (line 146) | def imputation(self, x_enc, x_mark_enc, x_dec, x_mark_dec, mask=None):
method anomaly_detection (line 176) | def anomaly_detection(self, x_enc):
method classification (line 207) | def classification(self, x_enc, x_mark_enc):
method forward (line 231) | def forward(self, x_enc, x_mark_enc, x_dec, x_mark_dec, mask=None):
FILE: models/Mamba.py
class Model (line 11) | class Model(nn.Module):
method __init__ (line 13) | def __init__(self, configs):
method forecast (line 32) | def forecast(self, x_enc, x_mark_enc):
method forward (line 45) | def forward(self, x_enc, x_mark_enc, x_dec, x_mark_dec, mask=None):
FILE: models/MambaSimple.py
class Model (line 11) | class Model(nn.Module):
method __init__ (line 18) | def __init__(self, configs):
method forecast (line 33) | def forecast(self, x_enc, x_mark_enc):
method forward (line 49) | def forward(self, x_enc, x_mark_enc, x_dec, x_mark_dec, mask=None):
class ResidualBlock (line 55) | class ResidualBlock(nn.Module):
method __init__ (line 56) | def __init__(self, configs, d_inner, dt_rank):
method forward (line 62) | def forward(self, x):
class MambaBlock (line 66) | class MambaBlock(nn.Module):
method __init__ (line 67) | def __init__(self, configs, d_inner, dt_rank):
method forward (line 95) | def forward(self, x):
method ssm (line 117) | def ssm(self, x):
method selective_scan (line 134) | def selective_scan(self, u, delta, A, B, C, D):
class RMSNorm (line 154) | class RMSNorm(nn.Module):
method __init__ (line 155) | def __init__(self, d_model, eps=1e-5):
method forward (line 160) | def forward(self, x):
FILE: models/MambaSingleLayer.py
class TokenEmbedding_cls (line 7) | class TokenEmbedding_cls(nn.Module):
method __init__ (line 10) | def __init__(self, c_in, d_model, d_kernel=3):
method forward (line 20) | def forward(self, x):
class DataEmbedding_cls (line 25) | class DataEmbedding_cls(nn.Module):
method __init__ (line 29) | def __init__(self, c_in, d_model, embed_type='fixed', freq='h', dropou...
method forward (line 35) | def forward(self, x):
class Model (line 41) | class Model(nn.Module):
method __init__ (line 47) | def __init__(self, configs):
method forward (line 100) | def forward(self, x_enc, x_mark_enc, x_dec=None, x_mark_dec=None, mask...
FILE: models/Moirai.py
class Model (line 12) | class Model(nn.Module):
method __init__ (line 13) | def __init__(self, configs):
method forecast (line 34) | def forecast(self, x_enc, x_mark_enc, x_dec, x_mark_dec):
method forward (line 44) | def forward(self, x_enc, x_mark_enc, x_dec, x_mark_dec, mask=None):
FILE: models/MultiPatchFormer.py
class FeedForward (line 9) | class FeedForward(nn.Module):
method __init__ (line 10) | def __init__(self, d_model: int, d_hidden: int = 512):
method forward (line 17) | def forward(self, x):
class Encoder (line 25) | class Encoder(nn.Module):
method __init__ (line 26) | def __init__(
method forward (line 52) | def forward(self, x):
class Model (line 74) | class Model(nn.Module):
method __init__ (line 75) | def __init__(self, configs):
method forecast (line 217) | def forecast(self, x_enc, x_mark_enc, x_dec, x_mark_dec):
method forward (line 346) | def forward(self, x_enc, x_mark_enc, x_dec, x_mark_dec, mask=None):
FILE: models/Nonstationary_Transformer.py
class Projector (line 9) | class Projector(nn.Module):
method __init__ (line 15) | def __init__(self, enc_in, seq_len, hidden_dims, hidden_layers, output...
method forward (line 29) | def forward(self, x, stats):
class Model (line 42) | class Model(nn.Module):
method __init__ (line 47) | def __init__(self, configs):
method forecast (line 113) | def forecast(self, x_enc, x_mark_enc, x_dec, x_mark_dec):
method imputation (line 140) | def imputation(self, x_enc, x_mark_enc, x_dec, x_mark_dec, mask):
method anomaly_detection (line 166) | def anomaly_detection(self, x_enc):
method classification (line 189) | def classification(self, x_enc, x_mark_enc):
method forward (line 217) | def forward(self, x_enc, x_mark_enc, x_dec, x_mark_dec, mask=None):
FILE: models/PAttn.py
class Model (line 8) | class Model(nn.Module):
method __init__ (line 12) | def __init__(self, configs, patch_len=16, stride=8):
method forward (line 40) | def forward(self, x_enc, x_mark_enc, x_dec, x_mark_dec):
FILE: models/PatchTST.py
class Transpose (line 7) | class Transpose(nn.Module):
method __init__ (line 8) | def __init__(self, *dims, contiguous=False):
method forward (line 11) | def forward(self, x):
class FlattenHead (line 16) | class FlattenHead(nn.Module):
method __init__ (line 17) | def __init__(self, n_vars, nf, target_window, head_dropout=0):
method forward (line 24) | def forward(self, x): # x: [bs x nvars x d_model x patch_num]
class Model (line 31) | class Model(nn.Module):
method __init__ (line 36) | def __init__(self, configs, patch_len=16, stride=8):
method forecast (line 82) | def forecast(self, x_enc, x_mark_enc, x_dec, x_mark_dec):
method imputation (line 115) | def imputation(self, x_enc, x_mark_enc, x_dec, x_mark_dec, mask):
method anomaly_detection (line 151) | def anomaly_detection(self, x_enc):
method classification (line 184) | def classification(self, x_enc, x_mark_enc):
method forward (line 213) | def forward(self, x_enc, x_mark_enc, x_dec, x_mark_dec, mask=None):
FILE: models/Pyraformer.py
class Model (line 6) | class Model(nn.Module):
method __init__ (line 12) | def __init__(self, configs, window_size=[4,4], inner_size=5):
method long_forecast (line 38) | def long_forecast(self, x_enc, x_mark_enc, x_dec, x_mark_dec, mask=None):
method short_forecast (line 44) | def short_forecast(self, x_enc, x_mark_enc, x_dec, x_mark_dec, mask=No...
method imputation (line 58) | def imputation(self, x_enc, x_mark_enc, x_dec, x_mark_dec, mask):
method anomaly_detection (line 63) | def anomaly_detection(self, x_enc, x_mark_enc):
method classification (line 68) | def classification(self, x_enc, x_mark_enc):
method forward (line 84) | def forward(self, x_enc, x_mark_enc, x_dec, x_mark_dec, mask=None):
FILE: models/Reformer.py
class Model (line 9) | class Model(nn.Module):
method __init__ (line 15) | def __init__(self, configs, bucket_size=4, n_hashes=4):
method long_forecast (line 51) | def long_forecast(self, x_enc, x_mark_enc, x_dec, x_mark_dec):
method short_forecast (line 64) | def short_forecast(self, x_enc, x_mark_enc, x_dec, x_mark_dec):
method imputation (line 84) | def imputation(self, x_enc, x_mark_enc):
method anomaly_detection (line 92) | def anomaly_detection(self, x_enc):
method classification (line 100) | def classification(self, x_enc, x_mark_enc):
method forward (line 116) | def forward(self, x_enc, x_mark_enc, x_dec, x_mark_dec, mask=None):
FILE: models/SCINet.py
class Splitting (line 6) | class Splitting(nn.Module):
method __init__ (line 7) | def __init__(self):
method even (line 10) | def even(self, x):
method odd (line 13) | def odd(self, x):
method forward (line 16) | def forward(self, x):
class CausalConvBlock (line 21) | class CausalConvBlock(nn.Module):
method __init__ (line 22) | def __init__(self, d_model, kernel_size=5, dropout=0.0):
method forward (line 38) | def forward(self, x):
class SCIBlock (line 42) | class SCIBlock(nn.Module):
method __init__ (line 43) | def __init__(self, d_model, kernel_size=5, dropout=0.0):
method forward (line 48) | def forward(self, x):
class SCINet (line 62) | class SCINet(nn.Module):
method __init__ (line 63) | def __init__(self, d_model, current_level=3, kernel_size=5, dropout=0.0):
method forward (line 72) | def forward(self, x):
method zip_up_the_pants (line 86) | def zip_up_the_pants(self, even, odd):
class Model (line 102) | class Model(nn.Module):
method __init__ (line 103) | def __init__(self, configs):
method forward (line 138) | def forward(self, x_enc, x_mark_enc, x_dec, x_mark_dec, mask=None):
method forecast (line 145) | def forecast(self, x_enc, x_mark_enc, x_dec, x_mark_dec):
method get_position_encoding (line 179) | def get_position_encoding(self, x):
FILE: models/SegRNN.py
class Model (line 7) | class Model(nn.Module):
method __init__ (line 12) | def __init__(self, configs):
method encoder (line 52) | def encoder(self, x):
method forecast (line 84) | def forecast(self, x_enc):
method imputation (line 88) | def imputation(self, x_enc):
method anomaly_detection (line 92) | def anomaly_detection(self, x_enc):
method classification (line 96) | def classification(self, x_enc):
method forward (line 106) | def forward(self, x_enc, x_mark_enc, x_dec, x_mark_dec, mask=None):
FILE: models/Sundial.py
class Model (line 8) | class Model(nn.Module):
method __init__ (line 9) | def __init__(self, configs):
method forecast (line 20) | def forecast(self, x_enc, x_mark_enc, x_dec, x_mark_dec):
method forward (line 29) | def forward(self, x_enc, x_mark_enc, x_dec, x_mark_dec, mask=None):
FILE: models/TSMixer.py
class ResBlock (line 4) | class ResBlock(nn.Module):
method __init__ (line 5) | def __init__(self, configs):
method forward (line 22) | def forward(self, x):
class Model (line 30) | class Model(nn.Module):
method __init__ (line 31) | def __init__(self, configs):
method forecast (line 40) | def forecast(self, x_enc, x_mark_enc, x_dec, x_mark_dec, mask=None):
method forward (line 49) | def forward(self, x_enc, x_mark_enc, x_dec, x_mark_dec, mask=None):
FILE: models/TemporalFusionTransformer.py
function get_known_len (line 20) | def get_known_len(embed_type, freq):
class TFTTemporalEmbedding (line 32) | class TFTTemporalEmbedding(TemporalEmbedding):
method __init__ (line 33) | def __init__(self, d_model, embed_type='fixed', freq='h'):
method forward (line 36) | def forward(self, x):
class TFTTimeFeatureEmbedding (line 50) | class TFTTimeFeatureEmbedding(nn.Module):
method __init__ (line 51) | def __init__(self, d_model, embed_type='timeF', freq='h'):
method forward (line 56) | def forward(self, x):
class TFTEmbedding (line 60) | class TFTEmbedding(nn.Module):
method __init__ (line 61) | def __init__(self, configs):
method forward (line 75) | def forward(self, x_enc, x_mark_enc, x_dec, x_mark_dec):
class GLU (line 92) | class GLU(nn.Module):
method __init__ (line 93) | def __init__(self, input_size, output_size):
method forward (line 99) | def forward(self, x):
class GateAddNorm (line 105) | class GateAddNorm(nn.Module):
method __init__ (line 106) | def __init__(self, input_size, output_size):
method forward (line 112) | def forward(self, x, skip_a):
class GRN (line 118) | class GRN(nn.Module):
method __init__ (line 119) | def __init__(self, input_size, output_size, hidden_size=None, context_...
method forward (line 129) | def forward(self, a: Tensor, c: Optional[Tensor] = None):
class VariableSelectionNetwork (line 140) | class VariableSelectionNetwork(nn.Module):
method __init__ (line 141) | def __init__(self, d_model, variable_num, dropout=0.0):
method forward (line 146) | def forward(self, x: Tensor, context: Optional[Tensor] = None):
class StaticCovariateEncoder (line 161) | class StaticCovariateEncoder(nn.Module):
method __init__ (line 162) | def __init__(self, d_model, static_len, dropout=0.0):
method forward (line 167) | def forward(self, static_input):
class InterpretableMultiHeadAttention (line 176) | class InterpretableMultiHeadAttention(nn.Module):
method __init__ (line 177) | def __init__(self, configs):
method forward (line 189) | def forward(self, x):
class TemporalFusionDecoder (line 210) | class TemporalFusionDecoder(nn.Module):
method __init__ (line 211) | def __init__(self, configs):
method forward (line 225) | def forward(self, history_input, future_input, c_c, c_h, c_e):
class Model (line 254) | class Model(nn.Module):
method __init__ (line 255) | def __init__(self, configs):
method forecast (line 274) | def forecast(self, x_enc, x_mark_enc, x_dec, x_mark_dec):
method forward (line 304) | def forward(self, x_enc, x_mark_enc, x_dec, x_mark_dec):
FILE: models/TiDE.py
class LayerNorm (line 6) | class LayerNorm(nn.Module):
method __init__ (line 9) | def __init__(self, ndim, bias):
method forward (line 14) | def forward(self, input):
class ResBlock (line 19) | class ResBlock(nn.Module):
method __init__ (line 20) | def __init__(self, input_dim, hidden_dim, output_dim, dropout=0.1, bia...
method forward (line 30) | def forward(self, x):
class Model (line 42) | class Model(nn.Module):
method __init__ (line 46) | def __init__(self, configs, bias=True, feature_encode_dim=2):
method forecast (line 88) | def forecast(self, x_enc, x_mark_enc, x_dec, batch_y_mark):
method imputation (line 106) | def imputation(self, x_enc, x_mark_enc, x_dec, batch_y_mark, mask):
method forward (line 124) | def forward(self, x_enc, x_mark_enc, x_dec, batch_y_mark, mask=None):
FILE: models/TiRex.py
class Model (line 9) | class Model(nn.Module):
method __init__ (line 10) | def __init__(self, configs):
method forecast (line 21) | def forecast(self, x_enc, x_mark_enc, x_dec, x_mark_dec):
method forward (line 38) | def forward(self, x_enc, x_mark_enc, x_dec, x_mark_dec, mask=None):
FILE: models/TimeFilter.py
class PatchEmbed (line 11) | class PatchEmbed(nn.Module):
method __init__ (line 12) | def __init__(self, dim, patch_len, stride=None, pos=True):
method forward (line 22) | def forward(self, x):
class Model (line 32) | class Model(nn.Module):
method __init__ (line 33) | def __init__(self, configs):
method _get_mask (line 75) | def _get_mask(self, device):
method forecast (line 90) | def forecast(self, x, masks, x_dec, x_mark_dec):
method imputation (line 109) | def imputation(self, x, x_mark_enc, x_dec, x_mark_dec, mask):
method classification (line 128) | def classification(self, x, x_mark_enc):
method anomaly_detection (line 143) | def anomaly_detection(self, x):
method forward (line 163) | def forward(self, x_enc, x_mark_enc, x_dec, x_mark_dec, mask=None):
FILE: models/TimeMixer.py
class DFT_series_decomp (line 9) | class DFT_series_decomp(nn.Module):
method __init__ (line 14) | def __init__(self, top_k: int = 5):
method forward (line 18) | def forward(self, x):
class MultiScaleSeasonMixing (line 29) | class MultiScaleSeasonMixing(nn.Module):
method __init__ (line 34) | def __init__(self, configs):
method forward (line 55) | def forward(self, season_list):
class MultiScaleTrendMixing (line 73) | class MultiScaleTrendMixing(nn.Module):
method __init__ (line 78) | def __init__(self, configs):
method forward (line 97) | def forward(self, trend_list):
class PastDecomposableMixing (line 118) | class PastDecomposableMixing(nn.Module):
method __init__ (line 119) | def __init__(self, configs):
method forward (line 155) | def forward(self, x_list):
class Model (line 187) | class Model(nn.Module):
method __init__ (line 189) | def __init__(self, configs):
method out_projection (line 269) | def out_projection(self, dec_out, i, out_res):
method pre_enc (line 277) | def pre_enc(self, x_list):
method __multi_scale_process_inputs (line 289) | def __multi_scale_process_inputs(self, x_enc, x_mark_enc):
method forecast (line 329) | def forecast(self, x_enc, x_mark_enc, x_dec, x_mark_dec):
method future_multi_mixing (line 378) | def future_multi_mixing(self, B, enc_out_list, x_list):
method classification (line 398) | def classification(self, x_enc, x_mark_enc):
method anomaly_detection (line 424) | def anomaly_detection(self, x_enc):
method imputation (line 453) | def imputation(self, x_enc, x_mark_enc, mask):
method forward (line 502) | def forward(self, x_enc, x_mark_enc, x_dec, x_mark_dec, mask=None):
FILE: models/TimeMoE.py
class Model (line 8) | class Model(nn.Module):
method __init__ (line 9) | def __init__(self, configs):
method forecast (line 20) | def forecast(self, x_enc, x_mark_enc, x_dec, x_mark_dec):
method forward (line 38) | def forward(self, x_enc, x_mark_enc, x_dec, x_mark_dec, mask=None):
FILE: models/TimeXer.py
class FlattenHead (line 9) | class FlattenHead(nn.Module):
method __init__ (line 10) | def __init__(self, n_vars, nf, target_window, head_dropout=0):
method forward (line 17) | def forward(self, x): # x: [bs x nvars x d_model x patch_num]
class EnEmbedding (line 24) | class EnEmbedding(nn.Module):
method __init__ (line 25) | def __init__(self, n_vars, d_model, patch_len, dropout):
method forward (line 36) | def forward(self, x):
class Encoder (line 51) | class Encoder(nn.Module):
method __init__ (line 52) | def __init__(self, layers, norm_layer=None, projection=None):
method forward (line 58) | def forward(self, x, cross, x_mask=None, cross_mask=None, tau=None, de...
class EncoderLayer (line 70) | class EncoderLayer(nn.Module):
method __init__ (line 71) | def __init__(self, self_attention, cross_attention, d_model, d_ff=None,
method forward (line 85) | def forward(self, x, cross, x_mask=None, cross_mask=None, tau=None, de...
class Model (line 114) | class Model(nn.Module):
method __init__ (line 116) | def __init__(self, configs):
method forecast (line 157) | def forecast(self, x_enc, x_mark_enc, x_dec, x_mark_dec):
method forecast_multi (line 187) | def forecast_multi(self, x_enc, x_mark_enc, x_dec, x_mark_dec):
method forward (line 216) | def forward(self, x_enc, x_mark_enc, x_dec, x_mark_dec, mask=None):
FILE: models/TimesFM.py
class Model (line 9) | class Model(nn.Module):
method __init__ (line 10) | def __init__(self, configs):
method forecast (line 34) | def forecast(self, x_enc, x_mark_enc, x_dec, x_mark_dec):
method forward (line 58) | def forward(self, x_enc, x_mark_enc, x_dec, x_mark_dec, mask=None):
FILE: models/TimesNet.py
function FFT_for_Period (line 9) | def FFT_for_Period(x, k=2):
class TimesBlock (line 21) | class TimesBlock(nn.Module):
method __init__ (line 22) | def __init__(self, configs):
method forward (line 36) | def forward(self, x):
class Model (line 71) | class Model(nn.Module):
method __init__ (line 76) | def __init__(self, configs):
method forecast (line 103) | def forecast(self, x_enc, x_mark_enc, x_dec, x_mark_dec):
method imputation (line 130) | def imputation(self, x_enc, x_mark_enc, x_dec, x_mark_dec, mask):
method anomaly_detection (line 158) | def anomaly_detection(self, x_enc):
method classification (line 183) | def classification(self, x_enc, x_mark_enc):
method forward (line 201) | def forward(self, x_enc, x_mark_enc, x_dec, x_mark_dec, mask=None):
FILE: models/Transformer.py
class Model (line 10) | class Model(nn.Module):
method __init__ (line 17) | def __init__(self, configs):
method forecast (line 73) | def forecast(self, x_enc, x_mark_enc, x_dec, x_mark_dec):
method imputation (line 82) | def imputation(self, x_enc, x_mark_enc, x_dec, x_mark_dec, mask):
method anomaly_detection (line 90) | def anomaly_detection(self, x_enc):
method classification (line 98) | def classification(self, x_enc, x_mark_enc):
method forward (line 111) | def forward(self, x_enc, x_mark_enc, x_dec, x_mark_dec, mask=None):
FILE: models/WPMixer.py
class TokenMixer (line 15) | class TokenMixer(nn.Module):
method __init__ (line 16) | def __init__(self, input_seq=[], batch_size=[], channel=[], pred_seq=[...
method forward (line 33) | def forward(self, x):
class Mixer (line 40) | class Mixer(nn.Module):
method __init__ (line 41) | def __init__(self,
method forward (line 72) | def forward(self, x):
class ResolutionBranch (line 92) | class ResolutionBranch(nn.Module):
method __init__ (line 93) | def __init__(self,
method forward (line 142) | def forward(self, x):
method do_patching (line 165) | def do_patching(self, x):
class WPMixerCore (line 173) | class WPMixerCore(nn.Module):
method __init__ (line 174) | def __init__(self,
method forward (line 240) | def forward(self, xL):
class Model (line 272) | class Model(nn.Module):
method __init__ (line 273) | def __init__(self, args, tfactor=5, dfactor=5, wavelet='db2', level=1,...
method forecast (line 294) | def forecast(self, x_enc, x_mark_enc, x_dec, batch_y_mark):
method forward (line 309) | def forward(self, x_enc, x_mark_enc, x_dec, x_mark_dec, mask=None):
FILE: models/iTransformer.py
class Model (line 10) | class Model(nn.Module):
method __init__ (line 15) | def __init__(self, configs):
method forecast (line 50) | def forecast(self, x_enc, x_mark_enc, x_dec, x_mark_dec):
method imputation (line 69) | def imputation(self, x_enc, x_mark_enc, x_dec, x_mark_dec, mask):
method anomaly_detection (line 88) | def anomaly_detection(self, x_enc):
method classification (line 107) | def classification(self, x_enc, x_mark_enc):
method forward (line 119) | def forward(self, x_enc, x_mark_enc, x_dec, x_mark_dec, mask=None):
FILE: utils/ADFtest.py
function calculate_ADF (line 7) | def calculate_ADF(root_path,data_path):
function calculate_target_ADF (line 20) | def calculate_target_ADF(root_path,data_path,target='OT'):
function archADF (line 33) | def archADF(root_path, data_path):
FILE: utils/augmentation.py
function jitter (line 4) | def jitter(x, sigma=0.03):
function scaling (line 9) | def scaling(x, sigma=0.1):
function rotation (line 14) | def rotation(x):
function permutation (line 21) | def permutation(x, max_segments=5, seg_mode="equal"):
function magnitude_warp (line 46) | def magnitude_warp(x, sigma=0.2, knot=4):
function time_warp (line 59) | def time_warp(x, sigma=0.2, knot=4):
function window_slice (line 74) | def window_slice(x, reduce_ratio=0.9):
function window_warp (line 88) | def window_warp(x, window_ratio=0.1, scales=[0.5, 2.]):
function spawner (line 107) | def spawner(x, labels, sigma=0.05, verbose=0):
function wdba (line 145) | def wdba(x, labels, batch_size=6, slope_constraint="symmetric", use_wind...
function random_guided_warp (line 207) | def random_guided_warp(x, labels, slope_constraint="symmetric", use_wind...
function random_guided_warp_shape (line 247) | def random_guided_warp_shape(x, labels, slope_constraint="symmetric", us...
function discriminative_guided_warp (line 250) | def discriminative_guided_warp(x, labels, batch_size=6, slope_constraint...
function discriminative_guided_warp_shape (line 328) | def discriminative_guided_warp_shape(x, labels, batch_size=6, slope_cons...
function run_augmentation (line 332) | def run_augmentation(x, y, args):
function run_augmentation_single (line 350) | def run_augmentation_single(x, y, args):
function augment (line 386) | def augment(x, y, args):
FILE: utils/dtw.py
function _traceback (line 12) | def _traceback(DTW, slope_constraint):
function dtw (line 50) | def dtw(prototype, sample, return_flag = RETURN_VALUE, slope_constraint=...
function _cummulative_matrix (line 79) | def _cummulative_matrix(cost, slope_constraint, window):
function shape_dtw (line 103) | def shape_dtw(prototype, sample, return_flag = RETURN_VALUE, slope_const...
function draw_graph2d (line 149) | def draw_graph2d(cost, DTW, path, prototype, sample):
function draw_graph1d (line 186) | def draw_graph1d(cost, DTW, path, prototype, sample):
FILE: utils/dtw_metric.py
function dtw (line 6) | def dtw(x, y, dist, warp=1, w=inf, s=1.0):
function accelerated_dtw (line 58) | def accelerated_dtw(x, y, dist, warp=1):
function _traceback (line 100) | def _traceback(D):
FILE: utils/losses.py
function divide_no_nan (line 25) | def divide_no_nan(a, b):
class mape_loss (line 35) | class mape_loss(nn.Module):
method __init__ (line 36) | def __init__(self):
method forward (line 39) | def forward(self, insample: t.Tensor, freq: int,
class smape_loss (line 53) | class smape_loss(nn.Module):
method __init__ (line 54) | def __init__(self):
method forward (line 57) | def forward(self, insample: t.Tensor, freq: int,
class mase_loss (line 71) | class mase_loss(nn.Module):
method __init__ (line 72) | def __init__(self):
method forward (line 75) | def forward(self, insample: t.Tensor, freq: int,
FILE: utils/m4_summary.py
function group_values (line 28) | def group_values(values, groups, group_name):
function mase (line 32) | def mase(forecast, insample, outsample, frequency):
function smape_2 (line 36) | def smape_2(forecast, target):
function mape (line 43) | def mape(forecast, target):
class M4Summary (line 50) | class M4Summary:
method __init__ (line 51) | def __init__(self, file_path, root_path):
method evaluate (line 57) | def evaluate(self):
method summarize_groups (line 113) | def summarize_groups(self, scores):
FILE: utils/masking.py
class TriangularCausalMask (line 4) | class TriangularCausalMask():
method __init__ (line 5) | def __init__(self, B, L, device="cpu"):
method mask (line 11) | def mask(self):
class ProbMask (line 15) | class ProbMask():
method __init__ (line 16) | def __init__(self, B, H, L, index, scores, device="cpu"):
method mask (line 25) | def mask(self):
FILE: utils/metrics.py
function RSE (line 4) | def RSE(pred, true):
function CORR (line 8) | def CORR(pred, true):
function MAE (line 14) | def MAE(pred, true):
function MSE (line 18) | def MSE(pred, true):
function RMSE (line 22) | def RMSE(pred, true):
function MAPE (line 26) | def MAPE(pred, true):
function MSPE (line 30) | def MSPE(pred, true):
function metric (line 34) | def metric(pred, true):
FILE: utils/print_args.py
function print_args (line 1) | def print_args(args):
FILE: utils/timefeatures.py
class TimeFeature (line 23) | class TimeFeature:
method __init__ (line 24) | def __init__(self):
method __call__ (line 27) | def __call__(self, index: pd.DatetimeIndex) -> np.ndarray:
method __repr__ (line 30) | def __repr__(self):
class SecondOfMinute (line 34) | class SecondOfMinute(TimeFeature):
method __call__ (line 37) | def __call__(self, index: pd.DatetimeIndex) -> np.ndarray:
class MinuteOfHour (line 41) | class MinuteOfHour(TimeFeature):
method __call__ (line 44) | def __call__(self, index: pd.DatetimeIndex) -> np.ndarray:
class HourOfDay (line 48) | class HourOfDay(TimeFeature):
method __call__ (line 51) | def __call__(self, index: pd.DatetimeIndex) -> np.ndarray:
class DayOfWeek (line 55) | class DayOfWeek(TimeFeature):
method __call__ (line 58) | def __call__(self, index: pd.DatetimeIndex) -> np.ndarray:
class DayOfMonth (line 62) | class DayOfMonth(TimeFeature):
method __call__ (line 65) | def __call__(self, index: pd.DatetimeIndex) -> np.ndarray:
class DayOfYear (line 69) | class DayOfYear(TimeFeature):
method __call__ (line 72) | def __call__(self, index: pd.DatetimeIndex) -> np.ndarray:
class MonthOfYear (line 76) | class MonthOfYear(TimeFeature):
method __call__ (line 79) | def __call__(self, index: pd.DatetimeIndex) -> np.ndarray:
class WeekOfYear (line 83) | class WeekOfYear(TimeFeature):
method __call__ (line 86) | def __call__(self, index: pd.DatetimeIndex) -> np.ndarray:
function time_features_from_frequency_str (line 90) | def time_features_from_frequency_str(freq_str: str) -> List[TimeFeature]:
function time_features (line 147) | def time_features(dates, freq='h'):
FILE: utils/tools.py
function adjust_learning_rate (line 12) | def adjust_learning_rate(optimizer, epoch, args):
class EarlyStopping (line 32) | class EarlyStopping:
method __init__ (line 33) | def __init__(self, patience=7, verbose=False, delta=0):
method __call__ (line 42) | def __call__(self, val_loss, model, path):
method save_checkpoint (line 57) | def save_checkpoint(self, val_loss, model, path):
class dotdict (line 64) | class dotdict(dict):
class StandardScaler (line 71) | class StandardScaler():
method __init__ (line 72) | def __init__(self, mean, std):
method transform (line 76) | def transform(self, data):
method inverse_transform (line 79) | def inverse_transform(self, data):
function visual (line 83) | def visual(true, preds=None, name='./pic/test.pdf'):
function adjustment (line 95) | def adjustment(gt, pred):
function cal_accuracy (line 119) | def cal_accuracy(y_pred, y_true):
Condensed preview — 363 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (1,387K chars).
[
{
"path": ".gitignore",
"chars": 2576,
"preview": "# Byte-compiled / optimized / DLL files\n__pycache__/\n*.py[cod]\n*$py.class\n\n# C extensions\n*.so\n\n# Distribution / packagi"
},
{
"path": "CONTRIBUTING.md",
"chars": 1496,
"preview": "## Instructions for Contributing to TSlib\n\nSincerely thanks to all the researchers who want to use or contribute to TSli"
},
{
"path": "Dockerfile",
"chars": 814,
"preview": "# syntax=docker/dockerfile:1.4\n\nFROM pytorch/pytorch:2.5.1-cuda12.1-cudnn9-devel AS tslib\n\nWORKDIR /workspace\n\nARG http_"
},
{
"path": "LICENSE",
"chars": 1084,
"preview": "MIT License\n\nCopyright (c) 2021 THUML @ Tsinghua University\n\nPermission is hereby granted, free of charge, to any person"
},
{
"path": "README.md",
"chars": 29785,
"preview": "# Time Series Library (TSLib)\nTSLib is an open-source library for deep learning researchers, especially for deep time se"
},
{
"path": "README_zh.md",
"chars": 22690,
"preview": "# 时间序列库(TSLib)\nTSLib 是一个面向深度学习研究者的开源库,特别适用于深度时间序列分析。\n\n> **English README**:[README.md](./README.md)\n\n我们提供了一个整洁的代码库,用于评测先"
},
{
"path": "data_provider/__init__.py",
"chars": 1,
"preview": "\n"
},
{
"path": "data_provider/data_factory.py",
"chars": 2631,
"preview": "from data_provider.data_loader import Dataset_ETT_hour, Dataset_ETT_minute, Dataset_Custom, Dataset_M4, PSMSegLoader, \\\n"
},
{
"path": "data_provider/data_loader.py",
"chars": 36433,
"preview": "import os\nimport numpy as np\nimport pandas as pd\nimport glob\nimport re\nimport torch\nfrom torch.utils.data import Dataset"
},
{
"path": "data_provider/m4.py",
"chars": 5259,
"preview": "# This source code is provided for the purposes of scientific reproducibility\n# under the following limited license from"
},
{
"path": "data_provider/uea.py",
"chars": 5036,
"preview": "import os\nimport numpy as np\nimport pandas as pd\nimport torch\n\n\ndef collate_fn(data, max_len=None):\n \"\"\"Build mini-ba"
},
{
"path": "docker-compose.yml",
"chars": 809,
"preview": "services:\n dev_tslib:\n image: tslib\n build:\n context: .\n target: tslib\n # args:\n # http_pro"
},
{
"path": "exp/__init__.py",
"chars": 0,
"preview": ""
},
{
"path": "exp/exp_anomaly_detection.py",
"chars": 7805,
"preview": "from data_provider.data_factory import data_provider\nfrom exp.exp_basic import Exp_Basic\nfrom utils.tools import EarlySt"
},
{
"path": "exp/exp_basic.py",
"chars": 3547,
"preview": "import os\nimport torch\nimport importlib\nimport pkgutil \n\n# Just put your model files under models/ folder\n# e.g., model"
},
{
"path": "exp/exp_classification.py",
"chars": 7456,
"preview": "from data_provider.data_factory import data_provider\nfrom exp.exp_basic import Exp_Basic\nfrom utils.tools import EarlySt"
},
{
"path": "exp/exp_imputation.py",
"chars": 8631,
"preview": "from data_provider.data_factory import data_provider\nfrom exp.exp_basic import Exp_Basic\nfrom utils.tools import EarlySt"
},
{
"path": "exp/exp_long_term_forecasting.py",
"chars": 11442,
"preview": "from data_provider.data_factory import data_provider\nfrom exp.exp_basic import Exp_Basic\nfrom utils.tools import EarlySt"
},
{
"path": "exp/exp_short_term_forecasting.py",
"chars": 10325,
"preview": "from data_provider.data_factory import data_provider\nfrom data_provider.m4 import M4Meta\nfrom exp.exp_basic import Exp_B"
},
{
"path": "exp/exp_zero_shot_forecasting.py",
"chars": 5787,
"preview": "from data_provider.data_factory import data_provider\nfrom exp.exp_basic import Exp_Basic\nfrom utils.tools import EarlySt"
},
{
"path": "layers/AutoCorrelation.py",
"chars": 6462,
"preview": "import torch\nimport torch.nn as nn\nimport torch.nn.functional as F\nimport matplotlib.pyplot as plt\nimport numpy as np\nim"
},
{
"path": "layers/Autoformer_EncDec.py",
"chars": 6831,
"preview": "import torch\nimport torch.nn as nn\nimport torch.nn.functional as F\n\n\nclass my_Layernorm(nn.Module):\n \"\"\"\n Special "
},
{
"path": "layers/Conv_Blocks.py",
"chars": 2376,
"preview": "import torch\nimport torch.nn as nn\n\n\nclass Inception_Block_V1(nn.Module):\n def __init__(self, in_channels, out_channe"
},
{
"path": "layers/Crossformer_EncDec.py",
"chars": 4333,
"preview": "import torch\nimport torch.nn as nn\nfrom einops import rearrange, repeat\nfrom layers.SelfAttention_Family import TwoStage"
},
{
"path": "layers/DWT_Decomposition.py",
"chars": 46759,
"preview": "# -*- coding: utf-8 -*-\n\"\"\"\nCreated on Sun Jan 5\n@author: Murad\nSISLab, USF\nmmurad@usf.edu\nhttps://github.com/Secure-an"
},
{
"path": "layers/ETSformer_EncDec.py",
"chars": 11433,
"preview": "import torch\nimport torch.nn as nn\nimport torch.nn.functional as F\nimport torch.fft as fft\nfrom einops import rearrange,"
},
{
"path": "layers/Embed.py",
"chars": 7012,
"preview": "import torch\nimport torch.nn as nn\nimport torch.nn.functional as F\nfrom torch.nn.utils import weight_norm\nimport math\n\n\n"
},
{
"path": "layers/FourierCorrelation.py",
"chars": 7523,
"preview": "# coding=utf-8\n# author=maziqing\n# email=maziqing.mzq@alibaba-inc.com\n\nimport numpy as np\nimport torch\nimport torch.nn a"
},
{
"path": "layers/MSGBlock.py",
"chars": 9954,
"preview": "from math import sqrt\nimport numpy as np\nimport torch.nn as nn\nimport torch.nn.functional as F\nimport torch\nfrom torch i"
},
{
"path": "layers/MambaBlock.py",
"chars": 18260,
"preview": "import math\n\nimport torch\nimport torch.nn as nn\nimport torch.nn.functional as F\n\nfrom einops import rearrange, repeat\n\nf"
},
{
"path": "layers/MultiWaveletCorrelation.py",
"chars": 23039,
"preview": "import torch\nimport numpy as np\nimport torch.nn as nn\nimport torch.nn.functional as F\nfrom torch import Tensor\nfrom typi"
},
{
"path": "layers/Pyraformer_EncDec.py",
"chars": 7433,
"preview": "import torch\nimport torch.nn as nn\nimport torch.nn.functional as F\nfrom torch.nn.modules.linear import Linear\nfrom layer"
},
{
"path": "layers/SelfAttention_Family.py",
"chars": 12001,
"preview": "import torch\nimport torch.nn as nn\nimport numpy as np\nfrom math import sqrt\nfrom utils.masking import TriangularCausalMa"
},
{
"path": "layers/StandardNorm.py",
"chars": 2184,
"preview": "import torch\nimport torch.nn as nn\n\n\nclass Normalize(nn.Module):\n def __init__(self, num_features: int, eps=1e-5, aff"
},
{
"path": "layers/TimeFilter_layers.py",
"chars": 10046,
"preview": "import torch\nimport torch.nn as nn\nimport torch.nn.functional as F\nfrom torch.distributions.normal import Normal\n\n\nclass"
},
{
"path": "layers/Transformer_EncDec.py",
"chars": 4929,
"preview": "import torch\nimport torch.nn as nn\nimport torch.nn.functional as F\n\n\nclass ConvLayer(nn.Module):\n def __init__(self, "
},
{
"path": "layers/__init__.py",
"chars": 0,
"preview": ""
},
{
"path": "models/Autoformer.py",
"chars": 6815,
"preview": "import torch\nimport torch.nn as nn\nimport torch.nn.functional as F\nfrom layers.Embed import DataEmbedding, DataEmbedding"
},
{
"path": "models/Chronos.py",
"chars": 1420,
"preview": "import torch\nfrom torch import nn\nfrom layers.Transformer_EncDec import Encoder, EncoderLayer\nfrom layers.SelfAttention_"
},
{
"path": "models/Chronos2.py",
"chars": 1759,
"preview": "import torch\nfrom torch import nn\nfrom layers.Transformer_EncDec import Encoder, EncoderLayer\nfrom layers.SelfAttention_"
},
{
"path": "models/Crossformer.py",
"chars": 6363,
"preview": "import torch\nimport torch.nn as nn\nimport torch.nn.functional as F\nfrom einops import rearrange, repeat\nfrom layers.Cros"
},
{
"path": "models/DLinear.py",
"chars": 4501,
"preview": "import torch\nimport torch.nn as nn\nimport torch.nn.functional as F\nfrom layers.Autoformer_EncDec import series_decomp\n\n\n"
},
{
"path": "models/ETSformer.py",
"chars": 4599,
"preview": "import torch\nimport torch.nn as nn\nfrom layers.Embed import DataEmbedding\nfrom layers.ETSformer_EncDec import EncoderLay"
},
{
"path": "models/FEDformer.py",
"chars": 8587,
"preview": "import torch\nimport torch.nn as nn\nimport torch.nn.functional as F\nfrom layers.Embed import DataEmbedding\nfrom layers.Au"
},
{
"path": "models/FiLM.py",
"chars": 11567,
"preview": "import torch\nimport torch.nn as nn\nimport torch.nn.functional as F\nimport numpy as np\nfrom scipy import signal\nfrom scip"
},
{
"path": "models/FreTS.py",
"chars": 4630,
"preview": "import torch\nimport torch.nn as nn\nimport torch.nn.functional as F\nimport numpy as np\n\n\nclass Model(nn.Module):\n \"\"\"\n"
},
{
"path": "models/Informer.py",
"chars": 6395,
"preview": "import torch\nimport torch.nn as nn\nimport torch.nn.functional as F\nfrom layers.Transformer_EncDec import Decoder, Decode"
},
{
"path": "models/KANAD.py",
"chars": 3832,
"preview": "import numpy as np\nimport torch\nimport torch.nn as nn\nfrom einops import rearrange\n\n\nclass KANADModel(nn.Module):\n de"
},
{
"path": "models/Koopa.py",
"chars": 13374,
"preview": "import math\nimport torch\nimport torch.nn as nn\nfrom data_provider.data_factory import data_provider\n\n\n\nclass FourierFilt"
},
{
"path": "models/LightTS.py",
"chars": 5622,
"preview": "import torch\nimport torch.nn as nn\nimport torch.nn.functional as F\n\n\nclass IEBlock(nn.Module):\n def __init__(self, in"
},
{
"path": "models/MICN.py",
"chars": 9946,
"preview": "import torch\nimport torch.nn as nn\nfrom layers.Embed import DataEmbedding\nfrom layers.Autoformer_EncDec import series_de"
},
{
"path": "models/MSGNet.py",
"chars": 9560,
"preview": "import numpy as np\n# import pywt\nimport torch\nimport torch.nn as nn\nimport torch.nn.functional as F\nimport torch.fft\nfro"
},
{
"path": "models/Mamba.py",
"chars": 1590,
"preview": "import math\n\nimport torch\nimport torch.nn as nn\nimport torch.nn.functional as F\n\nfrom mamba_ssm import Mamba\n\nfrom layer"
},
{
"path": "models/MambaSimple.py",
"chars": 5501,
"preview": "import math\n\nimport torch\nimport torch.nn as nn\nimport torch.nn.functional as F\nfrom einops import rearrange, repeat, ei"
},
{
"path": "models/MambaSingleLayer.py",
"chars": 5326,
"preview": "import torch.nn as nn\n\nfrom layers.Embed import PositionalEmbedding\nfrom layers.MambaBlock import Mamba_TimeVariant\n\n\ncl"
},
{
"path": "models/Moirai.py",
"chars": 1791,
"preview": "import numpy as np\nimport torch\nfrom torch import nn\nfrom layers.Transformer_EncDec import Encoder, EncoderLayer\nfrom la"
},
{
"path": "models/MultiPatchFormer.py",
"chars": 12067,
"preview": "import torch\nimport torch.nn as nn\nimport math\nfrom einops import rearrange\n\nfrom layers.SelfAttention_Family import Att"
},
{
"path": "models/Nonstationary_Transformer.py",
"chars": 10251,
"preview": "import torch\nimport torch.nn as nn\nfrom layers.Transformer_EncDec import Decoder, DecoderLayer, Encoder, EncoderLayer\nfr"
},
{
"path": "models/PAttn.py",
"chars": 2500,
"preview": "import torch\nimport torch.nn as nn\nfrom layers.Transformer_EncDec import Encoder, EncoderLayer\nfrom layers.SelfAttention"
},
{
"path": "models/PatchTST.py",
"chars": 9071,
"preview": "import torch\nfrom torch import nn\nfrom layers.Transformer_EncDec import Encoder, EncoderLayer\nfrom layers.SelfAttention_"
},
{
"path": "models/Pyraformer.py",
"chars": 4215,
"preview": "import torch\nimport torch.nn as nn\nfrom layers.Pyraformer_EncDec import Encoder\n\n\nclass Model(nn.Module):\n \"\"\" \n P"
},
{
"path": "models/Reformer.py",
"chars": 5090,
"preview": "import torch\nimport torch.nn as nn\nimport torch.nn.functional as F\nfrom layers.Transformer_EncDec import Encoder, Encode"
},
{
"path": "models/SCINet.py",
"chars": 7357,
"preview": "import torch\nimport torch.nn as nn\nimport torch.nn.functional as F\nimport math\n\nclass Splitting(nn.Module):\n def __in"
},
{
"path": "models/SegRNN.py",
"chars": 4215,
"preview": "import torch\nimport torch.nn as nn\nimport torch.nn.functional as F\nfrom layers.Autoformer_EncDec import series_decomp\n\n\n"
},
{
"path": "models/Sundial.py",
"chars": 1309,
"preview": "import torch\nfrom torch import nn\nfrom layers.Transformer_EncDec import Encoder, EncoderLayer\nfrom layers.SelfAttention_"
},
{
"path": "models/TSMixer.py",
"chars": 1814,
"preview": "import torch.nn as nn\n\n\nclass ResBlock(nn.Module):\n def __init__(self, configs):\n super(ResBlock, self).__init"
},
{
"path": "models/TemporalFusionTransformer.py",
"chars": 14027,
"preview": "import torch\nimport torch.nn as nn\nimport torch.nn.functional as F\nfrom layers.Embed import DataEmbedding, TemporalEmbed"
},
{
"path": "models/TiDE.py",
"chars": 7222,
"preview": "import torch\nimport torch.nn as nn\nimport torch.nn.functional as F\n\n\nclass LayerNorm(nn.Module):\n \"\"\" LayerNorm but w"
},
{
"path": "models/TiRex.py",
"chars": 1643,
"preview": "import torch\nfrom torch import nn\nfrom layers.Transformer_EncDec import Encoder, EncoderLayer\nfrom layers.SelfAttention_"
},
{
"path": "models/TimeFilter.py",
"chars": 6769,
"preview": "import torch\nimport torch.nn as nn\nimport torch.nn.functional as F\nimport math\n\nfrom layers.Embed import PositionalEmbed"
},
{
"path": "models/TimeMixer.py",
"chars": 20056,
"preview": "import torch\nimport torch.nn as nn\nimport torch.nn.functional as F\nfrom layers.Autoformer_EncDec import series_decomp\nfr"
},
{
"path": "models/TimeMoE.py",
"chars": 1720,
"preview": "import torch\nfrom torch import nn\nfrom layers.Transformer_EncDec import Encoder, EncoderLayer\nfrom layers.SelfAttention_"
},
{
"path": "models/TimeXer.py",
"chars": 9019,
"preview": "import torch\nimport torch.nn as nn\nimport torch.nn.functional as F\nfrom layers.SelfAttention_Family import FullAttention"
},
{
"path": "models/TimesFM.py",
"chars": 2187,
"preview": "import torch\nfrom torch import nn\nfrom layers.Transformer_EncDec import Encoder, EncoderLayer\nfrom layers.SelfAttention_"
},
{
"path": "models/TimesNet.py",
"chars": 8735,
"preview": "import torch\nimport torch.nn as nn\nimport torch.nn.functional as F\nimport torch.fft\nfrom layers.Embed import DataEmbeddi"
},
{
"path": "models/Transformer.py",
"chars": 5561,
"preview": "import torch\nimport torch.nn as nn\nimport torch.nn.functional as F\nfrom layers.Transformer_EncDec import Decoder, Decode"
},
{
"path": "models/WPMixer.py",
"chars": 13212,
"preview": "# -*- coding: utf-8 -*-\n\"\"\"\nCreated on Sun Jan 5 16:10:01 2025\n@author: Murad\nSISLab, USF\nmmurad@usf.edu\nhttps://github"
},
{
"path": "models/__init__.py",
"chars": 5,
"preview": "pass "
},
{
"path": "models/iTransformer.py",
"chars": 5735,
"preview": "import torch\nimport torch.nn as nn\nimport torch.nn.functional as F\nfrom layers.Transformer_EncDec import Encoder, Encode"
},
{
"path": "requirements.txt",
"chars": 502,
"preview": "einops==0.8.1\nlocal-attention==1.11.2\nreformer-pytorch==1.4.4\n\nnumpy==2.1.2\nscipy==1.16.3\nscikit-learn==1.7.2\npandas==2."
},
{
"path": "run.py",
"chars": 16328,
"preview": "import argparse\nimport os\nimport torch\nimport torch.backends\nfrom utils.print_args import print_args\nimport random\nimpor"
},
{
"path": "scripts/anomaly_detection/MSL/Autoformer.sh",
"chars": 386,
"preview": "export CUDA_VISIBLE_DEVICES=0\n\npython -u run.py \\\n --task_name anomaly_detection \\\n --is_training 1 \\\n --root_path ./"
},
{
"path": "scripts/anomaly_detection/MSL/Crossformer.sh",
"chars": 387,
"preview": "export CUDA_VISIBLE_DEVICES=0\n\npython -u run.py \\\n --task_name anomaly_detection \\\n --is_training 1 \\\n --root_path ./"
},
{
"path": "scripts/anomaly_detection/MSL/DLinear.sh",
"chars": 385,
"preview": "export CUDA_VISIBLE_DEVICES=0\n\npython -u run.py \\\n --task_name anomaly_detection \\\n --is_training 1 \\\n --root_path ./"
},
{
"path": "scripts/anomaly_detection/MSL/ETSformer.sh",
"chars": 404,
"preview": "export CUDA_VISIBLE_DEVICES=0\n\npython -u run.py \\\n --task_name anomaly_detection \\\n --is_training 1 \\\n --root_path ./"
},
{
"path": "scripts/anomaly_detection/MSL/FEDformer.sh",
"chars": 385,
"preview": "export CUDA_VISIBLE_DEVICES=0\n\npython -u run.py \\\n --task_name anomaly_detection \\\n --is_training 1 \\\n --root_path ./"
},
{
"path": "scripts/anomaly_detection/MSL/FiLM.sh",
"chars": 381,
"preview": "export CUDA_VISIBLE_DEVICES=6\n\npython -u run.py \\\n --task_name anomaly_detection \\\n --is_training 1 \\\n --root_path ./"
},
{
"path": "scripts/anomaly_detection/MSL/Informer.sh",
"chars": 384,
"preview": "export CUDA_VISIBLE_DEVICES=0\n\npython -u run.py \\\n --task_name anomaly_detection \\\n --is_training 1 \\\n --root_path ./"
},
{
"path": "scripts/anomaly_detection/MSL/KANAD.sh",
"chars": 392,
"preview": "export CUDA_VISIBLE_DEVICES=0\n\npython -u run.py \\\n --task_name anomaly_detection \\\n --is_training 1 \\\n --root_path ./"
},
{
"path": "scripts/anomaly_detection/MSL/LightTS.sh",
"chars": 383,
"preview": "export CUDA_VISIBLE_DEVICES=0\n\npython -u run.py \\\n --task_name anomaly_detection \\\n --is_training 1 \\\n --root_path ./"
},
{
"path": "scripts/anomaly_detection/MSL/MICN.sh",
"chars": 380,
"preview": "export CUDA_VISIBLE_DEVICES=1\n\npython -u run.py \\\n --task_name anomaly_detection \\\n --is_training 1 \\\n --root_path ./"
},
{
"path": "scripts/anomaly_detection/MSL/Pyraformer.sh",
"chars": 386,
"preview": "export CUDA_VISIBLE_DEVICES=0\n\npython -u run.py \\\n --task_name anomaly_detection \\\n --is_training 1 \\\n --root_path ./"
},
{
"path": "scripts/anomaly_detection/MSL/Reformer.sh",
"chars": 384,
"preview": "export CUDA_VISIBLE_DEVICES=0\n\npython -u run.py \\\n --task_name anomaly_detection \\\n --is_training 1 \\\n --root_path ./"
},
{
"path": "scripts/anomaly_detection/MSL/TimesNet.sh",
"chars": 394,
"preview": "export CUDA_VISIBLE_DEVICES=2\n\npython -u run.py \\\n --task_name anomaly_detection \\\n --is_training 1 \\\n --root_path ./"
},
{
"path": "scripts/anomaly_detection/MSL/Transformer.sh",
"chars": 387,
"preview": "export CUDA_VISIBLE_DEVICES=1\n\npython -u run.py \\\n --task_name anomaly_detection \\\n --is_training 1 \\\n --root_path ./"
},
{
"path": "scripts/anomaly_detection/MSL/iTransformer.sh",
"chars": 388,
"preview": "export CUDA_VISIBLE_DEVICES=0\n\npython -u run.py \\\n --task_name anomaly_detection \\\n --is_training 1 \\\n --root_path ./"
},
{
"path": "scripts/anomaly_detection/PSM/Autoformer.sh",
"chars": 385,
"preview": "export CUDA_VISIBLE_DEVICES=6\n\npython -u run.py \\\n --task_name anomaly_detection \\\n --is_training 1 \\\n --root_path ./"
},
{
"path": "scripts/anomaly_detection/PSM/DLinear.sh",
"chars": 384,
"preview": "export CUDA_VISIBLE_DEVICES=6\n\npython -u run.py \\\n --task_name anomaly_detection \\\n --is_training 1 \\\n --root_path ./"
},
{
"path": "scripts/anomaly_detection/PSM/KANAD.sh",
"chars": 392,
"preview": "export CUDA_VISIBLE_DEVICES=0\n\npython -u run.py \\\n --task_name anomaly_detection \\\n --is_training 1 \\\n --root_path ./"
},
{
"path": "scripts/anomaly_detection/PSM/TimesNet.sh",
"chars": 395,
"preview": "export CUDA_VISIBLE_DEVICES=6\n\npython -u run.py \\\n --task_name anomaly_detection \\\n --is_training 1 \\\n --root_path ./"
},
{
"path": "scripts/anomaly_detection/PSM/Transformer.sh",
"chars": 386,
"preview": "export CUDA_VISIBLE_DEVICES=6\n\npython -u run.py \\\n --task_name anomaly_detection \\\n --is_training 1 \\\n --root_path ./"
},
{
"path": "scripts/anomaly_detection/SMAP/Autoformer.sh",
"chars": 388,
"preview": "export CUDA_VISIBLE_DEVICES=7\n\npython -u run.py \\\n --task_name anomaly_detection \\\n --is_training 1 \\\n --root_path ./"
},
{
"path": "scripts/anomaly_detection/SMAP/KANAD.sh",
"chars": 395,
"preview": "export CUDA_VISIBLE_DEVICES=0\n\npython -u run.py \\\n --task_name anomaly_detection \\\n --is_training 1 \\\n --root_path ./"
},
{
"path": "scripts/anomaly_detection/SMAP/TimesNet.sh",
"chars": 400,
"preview": "export CUDA_VISIBLE_DEVICES=0\n\npython -u run.py \\\n --task_name anomaly_detection \\\n --is_training 1 \\\n --root_path ./"
},
{
"path": "scripts/anomaly_detection/SMAP/Transformer.sh",
"chars": 389,
"preview": "export CUDA_VISIBLE_DEVICES=7\n\npython -u run.py \\\n --task_name anomaly_detection \\\n --is_training 1 \\\n --root_path ./"
},
{
"path": "scripts/anomaly_detection/SMD/Autoformer.sh",
"chars": 388,
"preview": "export CUDA_VISIBLE_DEVICES=2\n\npython -u run.py \\\n --task_name anomaly_detection \\\n --is_training 1 \\\n --root_path ./"
},
{
"path": "scripts/anomaly_detection/SMD/KANAD.sh",
"chars": 394,
"preview": "export CUDA_VISIBLE_DEVICES=0\n\npython -u run.py \\\n --task_name anomaly_detection \\\n --is_training 1 \\\n --root_path ./"
},
{
"path": "scripts/anomaly_detection/SMD/TimesNet.sh",
"chars": 398,
"preview": "export CUDA_VISIBLE_DEVICES=2\n\npython -u run.py \\\n --task_name anomaly_detection \\\n --is_training 1 \\\n --root_path ./"
},
{
"path": "scripts/anomaly_detection/SMD/Transformer.sh",
"chars": 389,
"preview": "export CUDA_VISIBLE_DEVICES=2\n\npython -u run.py \\\n --task_name anomaly_detection \\\n --is_training 1 \\\n --root_path ./"
},
{
"path": "scripts/anomaly_detection/SWAT/Autoformer.sh",
"chars": 402,
"preview": "export CUDA_VISIBLE_DEVICES=1\n\npython -u run.py \\\n --task_name anomaly_detection \\\n --is_training 1 \\\n --root_path ./"
},
{
"path": "scripts/anomaly_detection/SWAT/KANAD.sh",
"chars": 395,
"preview": "export CUDA_VISIBLE_DEVICES=0\n\npython -u run.py \\\n --task_name anomaly_detection \\\n --is_training 1 \\\n --root_path ./"
},
{
"path": "scripts/anomaly_detection/SWAT/TimesNet.sh",
"chars": 2977,
"preview": "export CUDA_VISIBLE_DEVICES=1\n\npython -u run.py \\\n --task_name anomaly_detection \\\n --is_training 1 \\\n --root_path ./"
},
{
"path": "scripts/anomaly_detection/SWAT/Transformer.sh",
"chars": 403,
"preview": "export CUDA_VISIBLE_DEVICES=1\n\npython -u run.py \\\n --task_name anomaly_detection \\\n --is_training 1 \\\n --root_path ./"
},
{
"path": "scripts/classification/Autoformer.sh",
"chars": 3657,
"preview": "export CUDA_VISIBLE_DEVICES=5\n\nmodel_name=Autoformer\n\npython -u run.py \\\n --task_name classification \\\n --is_training "
},
{
"path": "scripts/classification/Crossformer.sh",
"chars": 3658,
"preview": "export CUDA_VISIBLE_DEVICES=3\n\nmodel_name=Crossformer\n\npython -u run.py \\\n --task_name classification \\\n --is_training"
},
{
"path": "scripts/classification/DLinear.sh",
"chars": 3654,
"preview": "export CUDA_VISIBLE_DEVICES=5\n\nmodel_name=DLinear\n\npython -u run.py \\\n --task_name classification \\\n --is_training 1 \\"
},
{
"path": "scripts/classification/ETSformer.sh",
"chars": 3826,
"preview": "export CUDA_VISIBLE_DEVICES=5\n\nmodel_name=ETSformer\n\npython -u run.py \\\n --task_name classification \\\n --is_training 1"
},
{
"path": "scripts/classification/FEDformer.sh",
"chars": 3656,
"preview": "export CUDA_VISIBLE_DEVICES=5\n\nmodel_name=FEDformer\n\npython -u run.py \\\n --task_name classification \\\n --is_training 1"
},
{
"path": "scripts/classification/FiLM.sh",
"chars": 3690,
"preview": "export CUDA_VISIBLE_DEVICES=7\n\nmodel_name=FiLM\n\npython -u run.py \\\n --task_name classification \\\n --is_training 1 \\\n "
},
{
"path": "scripts/classification/Informer.sh",
"chars": 3655,
"preview": "export CUDA_VISIBLE_DEVICES=5\n\nmodel_name=Informer\n\npython -u run.py \\\n --task_name classification \\\n --is_training 1 "
},
{
"path": "scripts/classification/LightTS.sh",
"chars": 3654,
"preview": "export CUDA_VISIBLE_DEVICES=5\n\nmodel_name=LightTS\n\npython -u run.py \\\n --task_name classification \\\n --is_training 1 \\"
},
{
"path": "scripts/classification/MICN.sh",
"chars": 3665,
"preview": "export CUDA_VISIBLE_DEVICES=7\n\nmodel_name=MICN\n\npython -u run.py \\\n --task_name classification \\\n --is_training 1 \\\n "
},
{
"path": "scripts/classification/MambaSL.out",
"chars": 69532,
"preview": "Using GPU\nArgs in experiment:\n\u001b[1mBasic Config\u001b[0m\n Task Name: classification Is Training: 0 "
},
{
"path": "scripts/classification/MambaSL.sh",
"chars": 3196,
"preview": "# This script is for reproducing the MambaSL classification results on the 30 UEA datasets.\n\n# Download checkpoints \n# "
},
{
"path": "scripts/classification/PatchTST.sh",
"chars": 3655,
"preview": "export CUDA_VISIBLE_DEVICES=3\n\nmodel_name=PatchTST\n\npython -u run.py \\\n --task_name classification \\\n --is_training 1 "
},
{
"path": "scripts/classification/Pyraformer.sh",
"chars": 3647,
"preview": "export CUDA_VISIBLE_DEVICES=5\n\nmodel_name=Pyraformer\n\npython -u run.py \\\n --task_name classification \\\n --is_training "
},
{
"path": "scripts/classification/Reformer.sh",
"chars": 3655,
"preview": "export CUDA_VISIBLE_DEVICES=5\n\nmodel_name=Reformer\n\npython -u run.py \\\n --task_name classification \\\n --is_training 1 "
},
{
"path": "scripts/classification/TimesNet.sh",
"chars": 3560,
"preview": "export CUDA_VISIBLE_DEVICES=3\n\npython -u run.py \\\n --task_name classification \\\n --is_training 1 \\\n --root_path ./dat"
},
{
"path": "scripts/classification/Transformer.sh",
"chars": 3658,
"preview": "export CUDA_VISIBLE_DEVICES=4\n\nmodel_name=Transformer\n\npython -u run.py \\\n --task_name classification \\\n --is_training"
},
{
"path": "scripts/classification/iTransformer.sh",
"chars": 3810,
"preview": "export CUDA_VISIBLE_DEVICES=0\n\nmodel_name=iTransformer\n\npython -u run.py \\\n --task_name classification \\\n --is_trainin"
},
{
"path": "scripts/exogenous_forecast/ECL/TimeXer.sh",
"chars": 1720,
"preview": "export CUDA_VISIBLE_DEVICES=1\n\nmodel_name=TimeXer\ndes='Timexer-MS'\n\n\npython -u run.py \\\n --task_name long_term_forecast"
},
{
"path": "scripts/exogenous_forecast/EPF/TimeXer.sh",
"chars": 2117,
"preview": "export CUDA_VISIBLE_DEVICES=0\n\nmodel_name=TimeXer\ndes='Timexer-MS'\npatch_len=24\n\n\npython -u run.py \\\n --is_training 1 \\"
},
{
"path": "scripts/exogenous_forecast/ETTh1/TimeXer.sh",
"chars": 1766,
"preview": "export CUDA_VISIBLE_DEVICES=1\n\nmodel_name=TimeXer\ndes='Timexer-MS'\n\npython -u run.py \\\n --task_name long_term_forecast "
},
{
"path": "scripts/exogenous_forecast/ETTh2/TimeXer.sh",
"chars": 1782,
"preview": "export CUDA_VISIBLE_DEVICES=3\n\nmodel_name=TimeXer\ndes='Timexer-MS'\n\npython -u run.py \\\n --task_name long_term_forecast "
},
{
"path": "scripts/exogenous_forecast/ETTm1/TimeXer.sh",
"chars": 1744,
"preview": "export CUDA_VISIBLE_DEVICES=2\n\nmodel_name=TimeXer\ndes='Timexer-MS'\n\npython -u run.py \\\n --task_name long_term_forecast "
},
{
"path": "scripts/exogenous_forecast/ETTm2/TimeXer.sh",
"chars": 1742,
"preview": "export CUDA_VISIBLE_DEVICES=2\n\nmodel_name=TimeXer\ndes='Timexer-MS'\n\npython -u run.py \\\n --task_name long_term_forecast "
},
{
"path": "scripts/exogenous_forecast/Traffic/TimeXer.sh",
"chars": 1842,
"preview": "export CUDA_VISIBLE_DEVICES=0\n\nmodel_name=TimeXer\ndes='Timexer-MS'\n\npython -u run.py \\\n --task_name long_term_forecast "
},
{
"path": "scripts/exogenous_forecast/Weather/TimeXer.sh",
"chars": 1685,
"preview": "export CUDA_VISIBLE_DEVICES=3\n\nmodel_name=TimeXer\ndes='Timexer-MS'\n\n\npython -u run.py \\\n --task_name long_term_forecast"
},
{
"path": "scripts/imputation/ECL_script/Autoformer.sh",
"chars": 2123,
"preview": "export CUDA_VISIBLE_DEVICES=0\n\nmodel_name=Autoformer\n\npython -u run.py \\\n --task_name imputation \\\n --is_training 1 \\\n"
},
{
"path": "scripts/imputation/ECL_script/DLinear.sh",
"chars": 2100,
"preview": "export CUDA_VISIBLE_DEVICES=0\n\nmodel_name=DLinear\n\npython -u run.py \\\n --task_name imputation \\\n --is_training 1 \\\n -"
},
{
"path": "scripts/imputation/ECL_script/ETSformer.sh",
"chars": 2122,
"preview": "export CUDA_VISIBLE_DEVICES=0\n\nmodel_name=ETSformer\n\npython -u run.py \\\n --task_name imputation \\\n --is_training 1 \\\n "
},
{
"path": "scripts/imputation/ECL_script/FEDformer.sh",
"chars": 2122,
"preview": "export CUDA_VISIBLE_DEVICES=0\n\nmodel_name=FEDformer\n\npython -u run.py \\\n --task_name imputation \\\n --is_training 1 \\\n "
},
{
"path": "scripts/imputation/ECL_script/Informer.sh",
"chars": 2121,
"preview": "export CUDA_VISIBLE_DEVICES=0\n\nmodel_name=Informer\n\npython -u run.py \\\n --task_name imputation \\\n --is_training 1 \\\n "
},
{
"path": "scripts/imputation/ECL_script/LightTS.sh",
"chars": 2124,
"preview": "export CUDA_VISIBLE_DEVICES=0\n\nmodel_name=LightTS\n\npython -u run.py \\\n --task_name imputation \\\n --is_training 1 \\\n -"
},
{
"path": "scripts/imputation/ECL_script/Pyraformer.sh",
"chars": 2123,
"preview": "export CUDA_VISIBLE_DEVICES=0\n\nmodel_name=Pyraformer\n\npython -u run.py \\\n --task_name imputation \\\n --is_training 1 \\\n"
},
{
"path": "scripts/imputation/ECL_script/Reformer.sh",
"chars": 2121,
"preview": "export CUDA_VISIBLE_DEVICES=0\n\nmodel_name=Reformer\n\npython -u run.py \\\n --task_name imputation \\\n --is_training 1 \\\n "
},
{
"path": "scripts/imputation/ECL_script/TimesNet.sh",
"chars": 2113,
"preview": "export CUDA_VISIBLE_DEVICES=7\n\nmodel_name=TimesNet\n\npython -u run.py \\\n --task_name imputation \\\n --is_training 1 \\\n "
},
{
"path": "scripts/imputation/ECL_script/Transformer.sh",
"chars": 2124,
"preview": "export CUDA_VISIBLE_DEVICES=0\n\nmodel_name=Transformer\n\npython -u run.py \\\n --task_name imputation \\\n --is_training 1 \\"
},
{
"path": "scripts/imputation/ECL_script/iTransformer.sh",
"chars": 2125,
"preview": "export CUDA_VISIBLE_DEVICES=0\n\nmodel_name=iTransformer\n\npython -u run.py \\\n --task_name imputation \\\n --is_training 1 "
},
{
"path": "scripts/imputation/ETT_script/Autoformer_ETTh1.sh",
"chars": 2071,
"preview": "export CUDA_VISIBLE_DEVICES=0\n\nmodel_name=Autoformer\n\npython -u run.py \\\n --task_name imputation \\\n --is_training 1 \\\n"
},
{
"path": "scripts/imputation/ETT_script/Autoformer_ETTh2.sh",
"chars": 2071,
"preview": "export CUDA_VISIBLE_DEVICES=0\n\nmodel_name=Autoformer\n\npython -u run.py \\\n --task_name imputation \\\n --is_training 1 \\\n"
},
{
"path": "scripts/imputation/ETT_script/Autoformer_ETTm1.sh",
"chars": 2071,
"preview": "export CUDA_VISIBLE_DEVICES=0\n\nmodel_name=Autoformer\n\npython -u run.py \\\n --task_name imputation \\\n --is_training 1 \\\n"
},
{
"path": "scripts/imputation/ETT_script/Autoformer_ETTm2.sh",
"chars": 2071,
"preview": "export CUDA_VISIBLE_DEVICES=0\n\nmodel_name=Autoformer\n\npython -u run.py \\\n --task_name imputation \\\n --is_training 1 \\\n"
},
{
"path": "scripts/imputation/ETT_script/Crossformer_ETTh1.sh",
"chars": 2064,
"preview": "export CUDA_VISIBLE_DEVICES=0\n\nmodel_name=Crossformer\n\npython -u run.py \\\n --task_name imputation \\\n --is_training 1 \\"
},
{
"path": "scripts/imputation/ETT_script/DLinear_ETTh1.sh",
"chars": 2072,
"preview": "export CUDA_VISIBLE_DEVICES=0\n\nmodel_name=DLinear\n\npython -u run.py \\\n --task_name imputation \\\n --is_training 1 \\\n -"
},
{
"path": "scripts/imputation/ETT_script/FiLM_ETTh1.sh",
"chars": 2061,
"preview": "export CUDA_VISIBLE_DEVICES=6\n\nmodel_name=FiLM\n\npython -u run.py \\\n --task_name imputation \\\n --is_training 1 \\\n --ro"
},
{
"path": "scripts/imputation/ETT_script/MICN_ETTh1.sh",
"chars": 2153,
"preview": "export CUDA_VISIBLE_DEVICES=0\n\nmodel_name=MICN\n\npython -u run.py \\\n --task_name imputation \\\n --is_training 1 \\\n --ro"
},
{
"path": "scripts/imputation/ETT_script/Nonstationary_Transformer_ETTh1.sh",
"chars": 2294,
"preview": "export CUDA_VISIBLE_DEVICES=0\n\nmodel_name=Nonstationary_Transformer\n\npython -u run.py \\\n --task_name imputation \\\n --i"
},
{
"path": "scripts/imputation/ETT_script/TiDE_ETTh1.sh",
"chars": 2059,
"preview": "export CUDA_VISIBLE_DEVICES=0\n\nmodel_name=TiDE\n\npython -u run.py \\\n --task_name imputation \\\n --is_training 1 \\\n --ro"
},
{
"path": "scripts/imputation/ETT_script/TimesNet_ETTh1.sh",
"chars": 2061,
"preview": "export CUDA_VISIBLE_DEVICES=0\n\nmodel_name=TimesNet\n\npython -u run.py \\\n --task_name imputation \\\n --is_training 1 \\\n "
},
{
"path": "scripts/imputation/ETT_script/TimesNet_ETTh2.sh",
"chars": 2061,
"preview": "export CUDA_VISIBLE_DEVICES=1\n\nmodel_name=TimesNet\n\npython -u run.py \\\n --task_name imputation \\\n --is_training 1 \\\n "
},
{
"path": "scripts/imputation/ETT_script/TimesNet_ETTm1.sh",
"chars": 2061,
"preview": "export CUDA_VISIBLE_DEVICES=2\n\nmodel_name=TimesNet\n\npython -u run.py \\\n --task_name imputation \\\n --is_training 1 \\\n "
},
{
"path": "scripts/imputation/ETT_script/TimesNet_ETTm2.sh",
"chars": 2061,
"preview": "export CUDA_VISIBLE_DEVICES=5\n\nmodel_name=TimesNet\n\npython -u run.py \\\n --task_name imputation \\\n --is_training 1 \\\n "
},
{
"path": "scripts/imputation/ETT_script/Transformer_ETTh1.sh",
"chars": 2072,
"preview": "export CUDA_VISIBLE_DEVICES=0\n\nmodel_name=Transformer\n\npython -u run.py \\\n --task_name imputation \\\n --is_training 1 \\"
},
{
"path": "scripts/imputation/ETT_script/Transformer_ETTh2.sh",
"chars": 2072,
"preview": "export CUDA_VISIBLE_DEVICES=0\n\nmodel_name=Transformer\n\npython -u run.py \\\n --task_name imputation \\\n --is_training 1 \\"
},
{
"path": "scripts/imputation/ETT_script/Transformer_ETTm1.sh",
"chars": 2072,
"preview": "export CUDA_VISIBLE_DEVICES=0\n\nmodel_name=Transformer\n\npython -u run.py \\\n --task_name imputation \\\n --is_training 1 \\"
},
{
"path": "scripts/imputation/ETT_script/Transformer_ETTm2.sh",
"chars": 2072,
"preview": "export CUDA_VISIBLE_DEVICES=0\n\nmodel_name=Transformer\n\npython -u run.py \\\n --task_name imputation \\\n --is_training 1 \\"
},
{
"path": "scripts/imputation/ETT_script/iTransformer_ETTh2.sh",
"chars": 2073,
"preview": "export CUDA_VISIBLE_DEVICES=0\n\nmodel_name=iTransformer\n\npython -u run.py \\\n --task_name imputation \\\n --is_training 1 "
},
{
"path": "scripts/imputation/Weather_script/Autoformer.sh",
"chars": 2095,
"preview": "export CUDA_VISIBLE_DEVICES=0\n\nmodel_name=Autoformer\n\npython -u run.py \\\n --task_name imputation \\\n --is_training 1 \\\n"
},
{
"path": "scripts/imputation/Weather_script/TimesNet.sh",
"chars": 2085,
"preview": "export CUDA_VISIBLE_DEVICES=6\n\nmodel_name=TimesNet\n\npython -u run.py \\\n --task_name imputation \\\n --is_training 1 \\\n "
},
{
"path": "scripts/imputation/Weather_script/Transformer.sh",
"chars": 2096,
"preview": "export CUDA_VISIBLE_DEVICES=0\n\nmodel_name=Transformer\n\npython -u run.py \\\n --task_name imputation \\\n --is_training 1 \\"
},
{
"path": "scripts/long_term_forecast/AugmentSample/Classification/PatchTST.sh",
"chars": 641,
"preview": "export CUDA_VISIBLE_DEVICES=0\n\nmodel_name=PatchTST\n\nfor aug in jitter scaling permutation magwarp timewarp windowslice w"
},
{
"path": "scripts/long_term_forecast/AugmentSample/Forecasting/PatchTST.sh",
"chars": 732,
"preview": "export CUDA_VISIBLE_DEVICES=0\n\nmodel_name=PatchTST\nfor aug in jitter scaling permutation magwarp timewarp windowslice wi"
},
{
"path": "scripts/long_term_forecast/AugmentSample/ReadMe.md",
"chars": 2605,
"preview": "# Augmentation Feature Roadbook\n\nHi there! For those who are interested in testing \naugmentation techniques in `Time-Ser"
},
{
"path": "scripts/long_term_forecast/ECL_script/Autoformer.sh",
"chars": 1694,
"preview": "export CUDA_VISIBLE_DEVICES=1\n\nmodel_name=Autoformer\n\npython -u run.py \\\n --task_name long_term_forecast \\\n --is_train"
},
{
"path": "scripts/long_term_forecast/ECL_script/Crossformer.sh",
"chars": 1963,
"preview": "export CUDA_VISIBLE_DEVICES=7\n\nmodel_name=Crossformer\n\npython -u run.py \\\n --task_name long_term_forecast \\\n --is_trai"
},
{
"path": "scripts/long_term_forecast/ECL_script/DLinear.sh",
"chars": 1691,
"preview": "export CUDA_VISIBLE_DEVICES=1\n\nmodel_name=DLinear\n\npython -u run.py \\\n --task_name long_term_forecast \\\n --is_training"
},
{
"path": "scripts/long_term_forecast/ECL_script/ETSformer.sh",
"chars": 1693,
"preview": "export CUDA_VISIBLE_DEVICES=1\n\nmodel_name=ETSformer\n\npython -u run.py \\\n --task_name long_term_forecast \\\n --is_traini"
},
{
"path": "scripts/long_term_forecast/ECL_script/FEDformer.sh",
"chars": 1694,
"preview": "export CUDA_VISIBLE_DEVICES=1\n\nmodel_name=FEDformer\n\npython -u run.py \\\n --task_name long_term_forecast \\\n --is_traini"
},
{
"path": "scripts/long_term_forecast/ECL_script/FiLM.sh",
"chars": 1768,
"preview": "export CUDA_VISIBLE_DEVICES=3\n\nmodel_name=FiLM\n\npython -u run.py \\\n --task_name long_term_forecast \\\n --is_training 1 "
},
{
"path": "scripts/long_term_forecast/ECL_script/Informer.sh",
"chars": 1692,
"preview": "export CUDA_VISIBLE_DEVICES=1\n\nmodel_name=Informer\n\npython -u run.py \\\n --task_name long_term_forecast \\\n --is_trainin"
},
{
"path": "scripts/long_term_forecast/ECL_script/Koopa.sh",
"chars": 1721,
"preview": "export CUDA_VISIBLE_DEVICES=1\n\nmodel_name=Koopa\n\npython -u run.py \\\n --task_name long_term_forecast \\\n --is_training 1"
},
{
"path": "scripts/long_term_forecast/ECL_script/LightTS.sh",
"chars": 1691,
"preview": "export CUDA_VISIBLE_DEVICES=1\n\nmodel_name=LightTS\n\npython -u run.py \\\n --task_name long_term_forecast \\\n --is_training"
},
{
"path": "scripts/long_term_forecast/ECL_script/MICN.sh",
"chars": 1876,
"preview": "export CUDA_VISIBLE_DEVICES=4\n\nmodel_name=MICN\n\npython -u run.py \\\n --task_name long_term_forecast \\\n --is_training 1 "
},
{
"path": "scripts/long_term_forecast/ECL_script/Mamba.sh",
"chars": 555,
"preview": "model_name=Mamba\n\nfor pred_len in 96 192 336 720\n# for pred_len in 336 720\ndo\n\npython -u run.py \\\n --task_name long_ter"
},
{
"path": "scripts/long_term_forecast/ECL_script/MultiPatchFormer.sh",
"chars": 1878,
"preview": "export CUDA_VISIBLE_DEVICES=0\n\nmodel_name=MultiPatchFormer\n\npython -u run.py \\\n --task_name long_term_forecast \\\n --is"
},
{
"path": "scripts/long_term_forecast/ECL_script/Nonstationary_Transformer.sh",
"chars": 1994,
"preview": "export CUDA_VISIBLE_DEVICES=0\n\nmodel_name=Nonstationary_Transformer\n\npython -u run.py \\\n --task_name long_term_forecast"
},
{
"path": "scripts/long_term_forecast/ECL_script/PatchTST.sh",
"chars": 1772,
"preview": "export CUDA_VISIBLE_DEVICES=6\n\nmodel_name=PatchTST\n\npython -u run.py \\\n --task_name long_term_forecast \\\n --is_trainin"
},
{
"path": "scripts/long_term_forecast/ECL_script/Pyraformer.sh",
"chars": 1694,
"preview": "export CUDA_VISIBLE_DEVICES=1\n\nmodel_name=Pyraformer\n\npython -u run.py \\\n --task_name long_term_forecast \\\n --is_train"
},
{
"path": "scripts/long_term_forecast/ECL_script/Reformer.sh",
"chars": 1692,
"preview": "export CUDA_VISIBLE_DEVICES=1\n\nmodel_name=Reformer\n\npython -u run.py \\\n --task_name long_term_forecast \\\n --is_trainin"
},
{
"path": "scripts/long_term_forecast/ECL_script/SegRNN.sh",
"chars": 513,
"preview": "export CUDA_VISIBLE_DEVICES=0\n\nmodel_name=SegRNN\n\nseq_len=96\nfor pred_len in 96 192 336 720\ndo\npython -u run.py \\\n --ta"
},
{
"path": "scripts/long_term_forecast/ECL_script/TSMixer.sh",
"chars": 1849,
"preview": "\nmodel_name=TSMixer\n\npython -u run.py \\\n --task_name long_term_forecast \\\n --is_training 1 \\\n --root_path ./dataset/e"
},
{
"path": "scripts/long_term_forecast/ECL_script/TimeMixer.sh",
"chars": 3091,
"preview": "#export CUDA_VISIBLE_DEVICES=0\n\nmodel_name=TimeMixer\n\nseq_len=96\ne_layers=3\ndown_sampling_layers=3\ndown_sampling_window="
},
{
"path": "scripts/long_term_forecast/ECL_script/TimeXer.sh",
"chars": 1715,
"preview": "export CUDA_VISIBLE_DEVICES=0\n\nmodel_name=TimeXer\n\npython -u run.py \\\n --task_name long_term_forecast \\\n --is_training"
},
{
"path": "scripts/long_term_forecast/ECL_script/TimesNet.sh",
"chars": 1880,
"preview": "export CUDA_VISIBLE_DEVICES=4\n\nmodel_name=TimesNet\n\npython -u run.py \\\n --task_name long_term_forecast \\\n --is_trainin"
},
{
"path": "scripts/long_term_forecast/ECL_script/Transformer.sh",
"chars": 1671,
"preview": "export CUDA_VISIBLE_DEVICES=2\n\nmodel_name=Transformer\n\npython -u run.py \\\n --task_name long_term_forecast \\\n --is_trai"
},
{
"path": "scripts/long_term_forecast/ECL_script/WPMixer.sh",
"chars": 1246,
"preview": "\nexport CUDA_VISIBLE_DEVICES=0\n\n# Model name\nmodel_name=WPMixer\n\n# Datasets and prediction lengths\ndataset=electricity\ns"
},
{
"path": "scripts/long_term_forecast/ECL_script/iTransformer.sh",
"chars": 2018,
"preview": "export CUDA_VISIBLE_DEVICES=0\n\nmodel_name=iTransformer\n\npython -u run.py \\\n --task_name long_term_forecast \\\n --is_tra"
},
{
"path": "scripts/long_term_forecast/ETT_script/Autoformer_ETTh1.sh",
"chars": 1642,
"preview": "export CUDA_VISIBLE_DEVICES=2\n\nmodel_name=Autoformer\n\npython -u run.py \\\n --task_name long_term_forecast \\\n --is_train"
},
{
"path": "scripts/long_term_forecast/ETT_script/Autoformer_ETTh2.sh",
"chars": 1642,
"preview": "export CUDA_VISIBLE_DEVICES=2\n\nmodel_name=Autoformer\n\npython -u run.py \\\n --task_name long_term_forecast \\\n --is_train"
}
]
// ... and 163 more files (download for full content)
About this extraction
This page contains the full source code of the thuml/Time-Series-Library GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 363 files (1.2 MB), approximately 392.1k tokens, and a symbol index with 983 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.