Skip to content

Commit

Permalink
✨ Add new modules (#66)
Browse files Browse the repository at this point in the history
* ✨ Add new model

* ✨ Add new images

* ✨ Add new utility function

* ✨ Add new utility function

* ✨ Add new utility function

* 🍎 Adjust default cfg values
  • Loading branch information
TakuyaShintate authored Sep 19, 2021
1 parent b58ce12 commit 2c3445a
Show file tree
Hide file tree
Showing 67 changed files with 7,056 additions and 2,941 deletions.
24 changes: 19 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<img src="img/tsts-logo.png" width="600"/>
</div>

[![pypi](https://img.shields.io/pypi/v/tsts?style=flat)](https://pypi.org/project/tsts/0.4.0/)
[![pypi](https://img.shields.io/pypi/v/tsts?style=flat)](https://pypi.org/project/tsts/0.6.0/)
[![license](https://img.shields.io/github/license/TakuyaShintate/tsts?style=flat)](https://github.com/TakuyaShintate/tsts/blob/main/LICENSE)

([Docs](https://takuyashintate.github.io/tsts/))([Benchmark](https://github.com/TakuyaShintate/tsts/tree/main/benchmark/))
Expand Down Expand Up @@ -61,14 +61,18 @@ Following modules are supported.
</tr>
<tr>
<td>
<li>AR</li>
<li>HistricalInertia</li>
<li>Informer</li>
<li>NBeats</li>
<li>Seq2Seq</li>
</td>
<td>
<li>DILATE</li>
<li>MAE</li>
<li>MAPE</li>
<li>MSE</li>
<li>SmoothMAE</li>
</td>
<td>
<li>MAE</li>
Expand All @@ -78,6 +82,8 @@ Following modules are supported.
</td>
<td>
<li>Adam</li>
<li>AdamW</li>
<li>SAM</li>
<li>SGD</li>
</td>
<td>
Expand Down Expand Up @@ -131,13 +137,16 @@ For inference, it needs to load parameters from a log directory generated in tra
import torch
from tsts.scalers import StandardScaler
from tsts.solvers import TimeSeriesForecaster
from tsts.utils import plot

# Initialize scaler with training dataset
sin_dataset = torch.sin(torch.arange(0.0, 100.0, 0.1))
sin_dataset = sin_dataset.unsqueeze(-1)
X_scaler = StandardScaler()
# NOTE: 0.75 is default training validation dataset ratio (training: 0.75, validation: 0.25)
num_train_samples = int(0.75 * len(sin_dataset))
sin_dataset = sin_dataset[:num_train_samples]

X_scaler = StandardScaler()
X_scaler.fit(sin_dataset)

# Define test dataset
Expand All @@ -150,14 +159,19 @@ forecaster = TimeSeriesForecaster("cfg.yml")
Z = forecaster.predict(X)

# Initialize target to compare prediction with it
y = torch.sin(torch.arange(110.0, 110.8, 0.1)).unsqueeze(1)
y = torch.sin(torch.arange(110.0, 114.8, 0.1)).unsqueeze(1)
y = X_scaler.transform(y)

# Result
print(Z)
print(y)
plot(Z, y, xticks=torch.arange(110.0, 114.8, 0.1))
```

Result:

<div align="center">
<img src="img/result-getting-started.png" width="700"/>
</div>

## Examples

See [Benchmark](https://github.com/TakuyaShintate/tsts/tree/main/benchmark/) for advanced usage.
41 changes: 0 additions & 41 deletions benchmark/dilate/informer_ett_h1.yml

This file was deleted.

45 changes: 0 additions & 45 deletions benchmark/dilate/test_informer_ett_h1.py

This file was deleted.

29 changes: 0 additions & 29 deletions benchmark/dilate/train_informer_ett_h1.py

This file was deleted.

22 changes: 22 additions & 0 deletions benchmark/histricalinertia/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Historical Inertia: A Neglected but Powerful Baseline for Long Sequence Time-series Forecasting

## Citation

```
@article{DBLP:journals/corr/abs-2103-16349,
author = {Yue Cui and
Jiandong Xie and
Kai Zheng},
title = {Historical Inertia: An Ignored but Powerful Baseline for Long Sequence
Time-series Forecasting},
journal = {CoRR},
volume = {abs/2103.16349},
year = {2021},
url = {https://arxiv.org/abs/2103.16349},
eprinttype = {arXiv},
eprint = {2103.16349},
timestamp = {Wed, 07 Apr 2021 15:31:46 +0200},
biburl = {https://dblp.org/rec/journals/corr/abs-2103-16349.bib},
bibsource = {dblp computer science bibliography, https://dblp.org}
}
```
30 changes: 30 additions & 0 deletions benchmark/histricalinertia/hi-ett-h1.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
DEVICE: "cuda:0"

IO:
LOOKBACK: 720
HORIZON: 48

TRAINING:
TRAIN_DATA_SPLIT: "col"
TRAIN_DATA_RATIO: 0.75
NUM_EPOCHS: 1

MODEL:
NAME: "HistricalInertia"

DATASET:
BASE_START_INDEX: 48
NORM_PER_DATASET: False

DATALOADER:
BATCH_SIZE_TRAIN: 32

METRICS:
NAMES: ["MAE", "MSE"]
ARGS: [{}, {}]

SCALER:
NAME: "StandardScaler"

LOGGER:
LOG_DIR: "hi-ett-h1-sam"
45 changes: 45 additions & 0 deletions benchmark/histricalinertia/test_hi_ett_h1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# TODO: Add unnormalized results

import pandas as pd
import torch
from tqdm import tqdm
from tsts.metrics import MAE, MSE
from tsts.scalers import StandardScaler
from tsts.solvers import TimeSeriesForecaster

lookback = 720
horizon = 48
start = 12 * 30 * 24 + 4 * 30 * 24 + lookback
end = 12 * 30 * 24 + 8 * 30 * 24 + lookback - horizon

X = pd.read_csv("/path/to/ETTh1.csv")
X = X[["OT"]]
X = X.values
X = torch.tensor(X, dtype=torch.float32)

solver = TimeSeriesForecaster("./hi-ett-h1.yml")

# Initialize scalers with training dataset
num_train_samples = int(0.75 * (12 * 30 * 24 + 4 * 30 * 24))
X_scaler = StandardScaler()
X_scaler.fit(X[:num_train_samples])
y_scaler = StandardScaler()
y_scaler.fit(X[:num_train_samples])

metric1 = MSE()
metric2 = MAE()

for i in tqdm(range(start, end)):
x = X[i - lookback : i]
y = X[i : i + horizon]
y_mask = torch.ones_like(y)
x = X_scaler.transform(x)
y = y_scaler.transform(y)
Z = solver.predict(x)
metric1.update(Z, y, y_mask)
metric2.update(Z, y, y_mask)

score1 = metric1()
score2 = metric2()
print(f"MSE: {score1}")
print(f"MAE: {score2}")
15 changes: 15 additions & 0 deletions benchmark/histricalinertia/train_hi_ett_h1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import pandas as pd
import torch
from tsts.solvers import TimeSeriesForecaster

start = 0
end = 12 * 30 * 24 + 4 * 30 * 24

X = pd.read_csv("/path/to/ETTh1.csv")
X = X[["OT"]]
X = X.values
X = X[start:end]
X = torch.tensor(X, dtype=torch.float32)

solver = TimeSeriesForecaster("./hi-ett-h1.yml")
solver.fit([X])
2 changes: 1 addition & 1 deletion docs/.buildinfo
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Sphinx build info version 1
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
config: 74b06218c3307010ebd142fcaea93044
config: 293831d798069392d74282626242223e
tags: 645f666f9bcd5a90fca523b33c5a78b7
Binary file modified docs/.doctrees/environment.pickle
Binary file not shown.
Binary file modified docs/.doctrees/index.doctree
Binary file not shown.
Binary file added docs/.doctrees/tutorials/inference.doctree
Binary file not shown.
Binary file modified docs/.doctrees/tutorials/training.doctree
Binary file not shown.
Binary file added docs/_images/inference-scheme.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_images/training-scheme.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion docs/_sources/index.rst.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ Tutorials

.. toctree::
:maxdepth: 1
:caption: Models
:caption: Basic

tutorials/training
tutorials/inference

====
Docs
Expand Down
Loading

0 comments on commit 2c3445a

Please sign in to comment.