-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_record_baselines.py
More file actions
153 lines (139 loc) · 5.09 KB
/
Copy path_record_baselines.py
File metadata and controls
153 lines (139 loc) · 5.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
"""One-shot script to record baseline values for e2e pipeline tests.
Run: .venv/bin/python _record_baselines.py
"""
import os
import sys
import tempfile
import numpy as np
def _base_config(
identifier_mode,
hpo,
model='lstm',
split_mode='per_entity',
id_integration=None,
**extra,
):
from liulian.config import load_config
if id_integration is None:
id_integration = (
'add_after_patch'
if model == 'patchtst' and identifier_mode == 'embedding'
else 'concat_to_x'
)
cfg = load_config()
cfg.update(
data='swiss-river-1990',
seq_len=10,
pred_len=3,
split_mode=split_mode,
scaler='minmax',
train_split=0.8,
task='forecast',
use_current_x=True,
use_full_history=False,
short_subsequence_method='drop',
gap_mode='split',
max_mask_consecutive=10,
noise_type=None,
include_historical_y='none',
include_historical_predicted_y=False,
identifier_mode=identifier_mode,
id_integration=id_integration,
embedding_size=4,
graph_mode='none',
model=model,
d_model=16,
e_layers=1,
d_layers=1,
label_len=5,
enc_in=None,
individual=False,
moving_avg=25,
embed='none', # Skip temporal embedding (swiss-river has single time feature)
batch_size=16,
max_train_iters=5,
max_eval_iters=5,
train_epochs=1,
learning_rate=0.001,
loss='mse',
metrics='rmse,mae,nse',
patience=5,
lradj='none',
num_workers=0,
show_progress=False,
eval_denorm=True,
wandb_project=None,
dev_run=True,
hpo=hpo,
hpo_num_samples=2 if hpo else 0,
hpo_local_mode=True,
hpo_grace_period=1,
hpo_reduction_factor=2,
hpo_resources_cpu=1,
hpo_resources_gpu=0,
hpo_save_checkpoints=True,
hpo_trim_checkpoints=False,
auto_viz=False,
seed=2026,
quick_test=False,
)
cfg.update(extra)
return cfg
def run_scenario(name, cfg):
from liulian.pipeline import run_experiment
with tempfile.TemporaryDirectory() as tmpdir:
old_cwd = os.getcwd()
os.chdir(tmpdir)
try:
summary = run_experiment(cfg)
finally:
os.chdir(old_cwd)
ft = summary['metrics']['test']
preds = summary['predictions']['preds']
flat = preds.numpy().flatten()[:5].tolist()
return {
'pred_shape': tuple(preds.shape),
'test_mse': ft['mse'],
'test_rmse': ft['rmse'],
'test_mae': ft['mae'],
'test_nse': ft['nse'],
'pred_first5': flat,
}
SCENARIOS = {
# LSTM scenarios
'lstm_single_emb': lambda: _base_config('embedding', False),
'lstm_single_no_emb': lambda: _base_config('none', False),
'lstm_tune_emb': lambda: _base_config('embedding', True),
'lstm_tune_no_emb': lambda: _base_config('none', True),
# DLinear scenarios (no embedding)
'dlinear_single_no_emb': lambda: _base_config('none', False, model='dlinear', split_mode='multi_channel'),
'dlinear_tune_no_emb': lambda: _base_config('none', True, model='dlinear', split_mode='multi_channel'),
# DLinear scenarios (with channel embedding)
'dlinear_single_emb': lambda: _base_config('embedding', False, model='dlinear', split_mode='multi_channel'),
'dlinear_tune_emb': lambda: _base_config('embedding', True, model='dlinear', split_mode='multi_channel'),
# PatchTST scenarios (multi_channel mode)
'patchtst_single_no_emb': lambda: _base_config('none', False, model='patchtst', split_mode='multi_channel'),
'patchtst_single_emb': lambda: _base_config('embedding', False, model='patchtst', split_mode='multi_channel'),
'patchtst_tune_no_emb': lambda: _base_config('none', True, model='patchtst', split_mode='multi_channel'),
'patchtst_tune_emb': lambda: _base_config('embedding', True, model='patchtst', split_mode='multi_channel'),
# Informer scenarios (multi_channel mode)
'informer_single_no_emb': lambda: _base_config('none', False, model='informer', split_mode='multi_channel', factor=3),
'informer_single_emb': lambda: _base_config('embedding', False, model='informer', split_mode='multi_channel', factor=3),
'informer_tune_no_emb': lambda: _base_config('none', True, model='informer', split_mode='multi_channel', factor=3),
'informer_tune_emb': lambda: _base_config('embedding', True, model='informer', split_mode='multi_channel', factor=3),
}
if __name__ == '__main__':
# Run a specific scenario or all
targets = sys.argv[1:] if len(sys.argv) > 1 else list(SCENARIOS.keys())
for name in targets:
if name not in SCENARIOS:
print(f'Unknown scenario: {name}')
continue
print(f'\n{"=" * 60}')
print(f'Running: {name}')
print(f'{"=" * 60}')
cfg = SCENARIOS[name]()
result = run_scenario(name, cfg)
print(f'\nBASELINE for {name}:')
for k, v in result.items():
print(f' {k!r}: {v!r},')