ts-anomaly-detection
Time SeriesTime-Series-Library
Description
Time Series Anomaly Detection: Custom Model Design
Objective
Design and implement a custom deep learning model for unsupervised time series anomaly detection via reconstruction. Your code goes in the Model class in models/Custom.py. Three reference implementations (DLinear, TimesNet, PatchTST) are provided as read-only.
Evaluation
Trained and evaluated on three anomaly detection datasets:
- PSM (25 variables, server machine dataset)
- MSL (55 variables, Mars Science Laboratory)
- SMAP (25 variables, Soil Moisture Active Passive satellite)
All use seq_len=100, anomaly_ratio=1. Metric: F-score (higher is better).
Code
Custom.py
EditableRead-only
1import torch2import torch.nn as nn345class Model(nn.Module):6"""7Custom model for time series anomaly detection.89Forward signature: forward(x_enc, x_mark_enc, x_dec, x_mark_dec, mask=None)10- x_enc: [batch, seq_len, enc_in] — input time series11- x_mark_enc: not used for anomaly detection (None)12- x_dec: not used for anomaly detection (None)13- x_mark_dec: not used for anomaly detection (None)1415Must return: [batch, seq_len, c_out] — reconstructed sequence
Additional context files (read-only):
Time-Series-Library/models/DLinear.pyTime-Series-Library/models/TimesNet.pyTime-Series-Library/models/PatchTST.pyTime-Series-Library/layers/AutoCorrelation.pyTime-Series-Library/layers/Autoformer_EncDec.pyTime-Series-Library/layers/Conv_Blocks.pyTime-Series-Library/layers/Crossformer_EncDec.pyTime-Series-Library/layers/Embed.pyTime-Series-Library/layers/FourierCorrelation.pyTime-Series-Library/layers/SelfAttention_Family.pyTime-Series-Library/layers/StandardNorm.pyTime-Series-Library/layers/Transformer_EncDec.py
Results
| Model | Type | f score PSM ↑ | precision PSM ↑ | recall PSM ↑ | f score MSL ↑ | precision MSL ↑ | recall MSL ↑ | f score SMAP ↑ | precision SMAP ↑ | recall SMAP ↑ |
|---|---|---|---|---|---|---|---|---|---|---|
| dlinear | baseline | 0.966 | 0.987 | 0.947 | 0.819 | 0.897 | 0.753 | 0.673 | 0.899 | 0.538 |
| patchtst | baseline | 0.962 | 0.989 | 0.936 | 0.790 | 0.887 | 0.713 | 0.688 | 0.904 | 0.556 |
| timesnet | baseline | 0.974 | 0.985 | 0.962 | 0.804 | 0.888 | 0.736 | 0.694 | 0.899 | 0.565 |
| timesnet | baseline | 0.974 | 0.985 | 0.963 | 0.818 | 0.895 | 0.753 | 0.694 | 0.901 | 0.565 |
| timesnet | baseline | 0.973 | 0.985 | 0.962 | 0.804 | 0.883 | 0.738 | 0.693 | 0.898 | 0.564 |
| timesnet | baseline | 0.973 | 0.984 | 0.962 | 0.810 | 0.892 | 0.742 | 0.695 | 0.898 | 0.566 |
| anthropic/claude-opus-4.6 | vanilla | 0.937 | 0.982 | 0.897 | 0.775 | 0.877 | 0.694 | 0.671 | 0.899 | 0.535 |
| deepseek-reasoner | vanilla | 0.922 | 0.980 | 0.871 | 0.776 | 0.892 | 0.687 | 0.685 | 0.893 | 0.556 |
| google/gemini-3.1-pro-preview | vanilla | 0.937 | 0.990 | 0.889 | 0.739 | 0.871 | 0.642 | 0.683 | 0.900 | 0.550 |
| gpt-5.4-pro | vanilla | 0.968 | 0.985 | 0.950 | 0.781 | 0.880 | 0.702 | 0.688 | 0.904 | 0.555 |
| openai/gpt-5.4-pro | vanilla | 0.969 | 0.986 | 0.953 | 0.801 | 0.862 | 0.748 | 0.687 | 0.895 | 0.557 |
| qwen/qwen3.6-plus:free | vanilla | 0.933 | 0.982 | 0.888 | 0.317 | 0.636 | 0.211 | 0.685 | 0.900 | 0.553 |
| anthropic/claude-opus-4.6 | agent | 0.964 | 0.986 | 0.943 | 0.791 | 0.885 | 0.716 | 0.673 | 0.896 | 0.538 |
| deepseek-reasoner | agent | 0.928 | 0.993 | 0.872 | 0.790 | 0.894 | 0.707 | 0.684 | 0.894 | 0.554 |
| google/gemini-3.1-pro-preview | agent | 0.954 | 0.986 | 0.923 | 0.734 | 0.863 | 0.639 | 0.675 | 0.902 | 0.539 |
| gpt-5.4-pro | agent | 0.968 | 0.985 | 0.950 | 0.781 | 0.880 | 0.702 | 0.688 | 0.904 | 0.555 |
| openai/gpt-5.4-pro | agent | 0.969 | 0.986 | 0.953 | 0.801 | 0.862 | 0.748 | 0.687 | 0.895 | 0.557 |
| qwen/qwen3.6-plus:free | agent | 0.932 | 0.990 | 0.881 | - | - | - | - | - | - |