Git Product home page Git Product logo

spacetime's Introduction

SpaceTime 🌌⏱️

Code for SpaceTime, a neural net architecture for time series. Named after state-space models for time series forecasting and classification.

Cousin of S4, S4D, DSS, and H3. Descendent of LSSL. Expressive autoregressive modeling + fast flexible decoding (i.e., forecasting) ftw.

Proposed in Effectively Modeling Time Series with Simple Discrete State Spaces, ICLR 2023.

spacetime

Paper links:

Setup

Dependencies

A list of dependencies is provided in environment.yaml. We recommend creating a virtual environment with conda:

conda env create -f environment.yaml
conda activate spacetime

Data

Data for the Informer benchmark can be downloaded from https://github.com/zhouhaoyi/ETDataset. The data exists as CSV files, which should be saved in the directory ./dataloaders/data/informer/, e.g.,

./dataloaders/data/informer/etth/ETTh1.csv
./dataloaders/data/informer/etth/ETTh2.csv
./dataloaders/data/informer/ettm/ETTm1.csv
./dataloaders/data/informer/ettm/ETTm2.csv

Usage

Colab demo

We include an example Colab notebook walking through how to train and forecast a SpaceTime model on financial time series. For fun, we also provide a quick demo on how to power a trading bot with SpaceTime forecasts (probably with some bugs). Feel free to extend it and have fun. None of this is financial advice!

Training scripts

Sample scripts for training models on the Informer benchmark are provided below. For a complete set of arguments, please see ./setup/args.py. For an overview of key command-line arguments, please see the Experiment arguments section below.

# ETTh1 720  
python main.py --dataset etth1 --lag 336 --horizon 720 --embedding_config embedding/repeat --encoder_config encoder/default --decoder_config decoder/default --output_config output/default --n_blocks 1 --kernel_dim 64 --norm_order 1 --batch_size 50 --dropout 0.25 --lr 1e-3 --weight_decay 1e-4 --max_epochs 500 --early_stopping_epochs 20 --data_transform mean --loss informer_rmse --val_metric informer_rmse --criterion_weights 1 1 1 --seed 0 --no_wandb

# ETTh2 720   
python main.py --dataset etth2 --lag 336 --horizon 720 --embedding_config embedding/repeat --encoder_config encoder/default --decoder_config decoder/default --output_config output/default --n_blocks 1 --kernel_dim 64 --norm_order 1 --batch_size 50 --dropout 0.25 --lr 1e-3 --weight_decay 1e-4 --max_epochs 500 --early_stopping_epochs 20 --data_transform mean --loss informer_rmse --val_metric informer_rmse --criterion_weights 1 1 1 --seed 0 --no_wandb

# ETTm1 720  
python main.py --dataset ettm1 --lag 336 --horizon 720 --embedding_config embedding/repeat --encoder_config encoder/default --decoder_config decoder/default --output_config output/default --n_blocks 1 --kernel_dim 64 --norm_order 1 --batch_size 50 --dropout 0.25 --lr 1e-3 --weight_decay 1e-4 --max_epochs 500 --early_stopping_epochs 20 --data_transform mean --loss informer_rmse --val_metric informer_rmse --criterion_weights 1 1 1 --seed 0 --no_wandb

# ETTm2 720  
python main.py --dataset ettm2 --lag 336 --horizon 720 --embedding_config embedding/repeat --encoder_config encoder/default --decoder_config decoder/default --output_config output/default --n_blocks 1 --kernel_dim 64 --norm_order 1 --batch_size 50 --dropout 0.25 --lr 1e-3 --weight_decay 1e-4 --max_epochs 500 --early_stopping_epochs 20 --data_transform mean --loss informer_rmse --val_metric informer_rmse --criterion_weights 1 1 1 --seed 0 --no_wandb

More details

SpaceTime architecture and configs

spacetime_architecture

To build a SpaceTime model, we specify a series of config files responsible for individual model components (determined via the config arguments, e.g., --embedding_config embedding/<config_name>). Default config files are located in ./configs/model. Please find more information on the directory structure via the config paths and descriptions below.

Config Path (./configs/model/) Description
embedding/ Configs for the input layer, which maps from the input sample dimension (1 for univariate data) to the model dimension (hidden-layer width).
encoder/ Configs for the encoder blocks ("SpaceTime layers" in the paper). - Each config specifies the configs behind the preprocessing, open-loop, and closed-loop SSMs, the MLPs, and the skip connections in each block.
decoder/ Configs for the decoder block. Same organization as encoder/
ssm/ Configs for open-loop (convolutional view) SSMs used in the encoder blocks. - Also contains subdirectories for preprocessing and closed-loop SSMs.
ssm/preprocess/ Configs for the preprocessing SSMs (e.g., differencing, moving average residual) used in the encoder blocks.
ssm/closed_loop/ Configs for the closed-loop (recurrent view) SSMs used in the decoder block.
mlp/ Configs for MLPs (FFNs) used in each block.
output/ Configs for the output layer, which maps from the model dimension to the target dimension.

Command-line arguments

Argument Description
--dataset The dataset name
--lag Input sequence length, i.e., number of historical time-steps or lag terms taken as input to the model
--horizon Output sequence length, i.e., number of future time-steps or horizon terms to predict
--embedding_config Config file for model embedding layer
--encoder_config Config file for model encoder blocks ("SpaceTime Layers" in the paper)
--decoder_config Config file for model decoder blocks ("SpaceTime Layers" in the paper)
--output_config Config file for model output layer
--n_blocks Number of blocks (SpaceTime layers) in the model encoder. Overrides default specified in --encoder_config file
--kernel_dim Dimension of SSM kernel used in each block. Overrides default specified in SSM config file (see section on SpaceTime Architecture for more details)
--norm_order Normalization order applied to A, B and C / K matrices when computing SSM outputs
--early_stopping_epochs Number of epochs to wait before early stopping. Training stops after validation metric (specified in --val_metric) does not improve after this many epochs.
--data_transform Transformation applied to lag terms before being used as model inputs. We reverse this transformation for the predictions. Defaults to subtracting the mean over inputs.
--criterion_weights List of 3 values that specify relative weight of loss components. Given --criterion_weights w0 w1 w2, w0 weights loss over horizon term model outputs, w1 weights loss over lag term model outputs, w2 weights loss over lag term closed-loop outputs (last-layer next-time-step inputs). Please see ./train/step/informer.py for additional details.
--no_wandb If included, does not use Weights & Biases (wandb) to log experiment metrics (default logs to wandb)
--no_cuda If included, does not use GPU for training and inference (default uses one GPU if available)

Citation

If you use our code or found our work valuable, please cite:

@article{,
  title={Effectively Modeling Time Series with Simple Discrete State Spaces},
  author={Zhang, Michael, and Saab, Khaled and Poli, Michael and Dao, Tri and Goel, Karan and R{\'e}, Christopher},
  journal={International Conference on Learning Representations},
  year={2023},
}

spacetime's People

Contributors

mzio avatar khaledsaab avatar

Stargazers

Charles I Niswander II avatar zhaohao avatar  avatar Kuk Jin Kim avatar Horace GUY avatar Haijie Wu avatar  avatar  avatar Charles Shi avatar ChenTianhao avatar Carlos A. Segura Diaz De Leon avatar  avatar 乐正子春 avatar Thinh D. NGO avatar Abner avatar Haibao Yu avatar  avatar Shashank Yadav avatar LKAMING avatar Erin avatar  avatar Jinseong Park avatar Tongyi Liang avatar  avatar Federico Celi avatar fri tol avatar  avatar Pulak Gautam avatar Kevin Lim avatar Detravious Jamari Brinkley avatar oblivious avatar DebugWorld avatar  avatar  avatar Halu avatar Longhao Wang avatar Roi Mallo avatar  avatar patricksha avatar  avatar Sanat Sharma avatar yyhscg avatar Simon Polichinel von der Maase, Ph.D avatar  avatar  avatar  avatar Jonathan avatar  avatar Nikita avatar Eugene Zatepyakin avatar Charles Foster avatar  avatar LZH avatar Tijin Yan avatar Dustin T Hughes avatar imadcat avatar Adrien Petralia avatar Hyeonggeun Yun avatar Zhihui Xie avatar Yuan Kaixin avatar Syakir Omar avatar PtrMan avatar  avatar Aistis Raulinaitis avatar Jonas Verhellen avatar  avatar Alex Wang avatar drdaliang avatar Gurumurthi V Ramanan avatar Josh Mize avatar Shida Wang avatar Gürsu Gülcü avatar  avatar Yasuo Kabe avatar Xiaohui Yang avatar Xiaochen Zheng avatar Jinming Wu avatar Matsumoto Kazutaka avatar Krzysztof Joachimiak avatar darimaru avatar  avatar  avatar Wesley Wilson avatar DP avatar Richard Kelley avatar xmzzyo avatar George De Ath avatar  avatar iMad avatar  avatar Kevin Gustavo M. Q. avatar  avatar Tian-Yu Zhao avatar Alper avatar  avatar Unai Sainz de la Maza avatar Jeffrey Fetzer avatar Zhiwei ZHANG avatar Arleigh Chang avatar Nils avatar

Watchers

Jason Alan Fries avatar Mike Cafarella avatar Nimit Sohoni avatar James Cloos avatar Alex Ratner avatar  avatar pixor avatar Jian Zhang avatar  avatar Henry Ehrenberg avatar Albert Gu avatar Karan Goel avatar  avatar Detravious Jamari Brinkley avatar  avatar

spacetime's Issues

companion_krylov not used

Hello,

This work is super cool! One question I have is that the code in companion_krylov.py seems to more closely match what's written in the paper (Algorithm 1). However, it looks like companion.py does not use it. It instead uses the much simpler krylov.py.

Is there a particular reason for this or am I misunderstanding the code paths?

Experiment Setup broken

Hey Everyone,

when I ran the experiments for the univariate ETTh1.csv everything worked properly and I also did some tests with my own data.

Oddly when I want to train multivariate data with python main.py --dataset etth1 --features M --lag 336 --horizon 720 --embedding_config embedding/repeat --encoder_config encoder/default --decoder_config decoder/default --output_config output/default --n_blocks 1 --kernel_dim 64 --norm_order 1 --batch_size 50 --dropout 0.25 --lr 1e-3 --weight_decay 1e-4 --max_epochs 500 --early_stopping_epochs 20 --data_transform mean --loss informer_rmse --val_metric informer_rmse --criterion_weights 1 1 1 --seed 0 --no_wandb it breaks with the following error:

Traceback (most recent call last):
  File "/home/i53/student/j_bach/Documents/spacetime/main.py", line 178, in <module>
    main()
  File "/home/i53/student/j_bach/Documents/spacetime/main.py", line 141, in main
    model = train_model(model, optimizer, scheduler, dataloaders_by_split,
  File "/home/i53/student/j_bach/Documents/spacetime/train/train.py", line 61, in train_model
    _, metrics, y, hopefully_context = run_epoch(model, dataloaders_by_split, optimizer, scheduler,
  File "/home/i53/student/j_bach/Documents/spacetime/train/epoch.py", line 26, in run_epoch
    model, _metrics, y, x = shared_step(model, dataloader, optimizer, scheduler,
  File "/home/i53/student/j_bach/Documents/spacetime/train/step/informer.py", line 71, in shared_step
    y_pred, z_pred = model(u)
  File "/home/temp_store/j_bach/miniconda3/envs/spacetime/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1501, in _call_impl
    return forward_call(*args, **kwargs)
  File "/home/i53/student/j_bach/Documents/spacetime/model/network.py", line 96, in forward
    z = self.encoder(z)
  File "/home/temp_store/j_bach/miniconda3/envs/spacetime/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1501, in _call_impl
    return forward_call(*args, **kwargs)
  File "/home/i53/student/j_bach/Documents/spacetime/model/block.py", line 88, in forward
    return self.blocks(x)
  File "/home/temp_store/j_bach/miniconda3/envs/spacetime/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1501, in _call_impl
    return forward_call(*args, **kwargs)
  File "/home/temp_store/j_bach/miniconda3/envs/spacetime/lib/python3.9/site-packages/torch/nn/modules/container.py", line 217, in forward
    input = module(input)
  File "/home/temp_store/j_bach/miniconda3/envs/spacetime/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1501, in _call_impl
    return forward_call(*args, **kwargs)
  File "/home/i53/student/j_bach/Documents/spacetime/model/block.py", line 42, in forward
    y = self.mlp(y)
  File "/home/temp_store/j_bach/miniconda3/envs/spacetime/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1501, in _call_impl
    return forward_call(*args, **kwargs)
  File "/home/i53/student/j_bach/Documents/spacetime/model/mlp.py", line 114, in forward
    x = self.layers(x) + x
RuntimeError: The size of tensor a (128) must match the size of tensor b (896) at non-singleton dimension 2

Can anyone confirm they have the same problem or even better a fix?

Best regards

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.