File size: 4,667 Bytes
17b7ba4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
154
155
156
157
158
"""Benchmark configuration for TSComp v1.0.0 runbook."""

from __future__ import annotations

from typing import Dict, List, Sequence

BENCHMARK_VERSION = "1.0.0"

SUITES: Dict[str, List[str]] = {
    "core": [
        "trend_only_linear",
        "trend_plus_single_sine",
        "poly_trend_multi_harmonic",
        "logistic_trend_multi_seasonal",
        "rw_trend_freq_drifting_cycle",
        "piecewise_trend_regime_cycle_with_events",
    ],
    "full": [
        "trend_only_linear",
        "trend_plus_single_sine",
        "poly_trend_multi_harmonic",
        "logistic_trend_multi_seasonal",
        "rw_trend_freq_drifting_cycle",
        "piecewise_trend_regime_cycle_with_events",
    ],
}

SCENARIO_TIER: Dict[str, int] = {
    "trend_only_linear": 1,
    "trend_plus_single_sine": 1,
    "poly_trend_multi_harmonic": 2,
    "logistic_trend_multi_seasonal": 2,
    "rw_trend_freq_drifting_cycle": 3,
    "piecewise_trend_regime_cycle_with_events": 3,
}

# Protocol periods for injection (length=512, dt=1.0).
SCENARIO_PERIODS: Dict[str, List[int]] = {
    "trend_only_linear": [50],
    "trend_plus_single_sine": [50],
    "poly_trend_multi_harmonic": [48],
    "logistic_trend_multi_seasonal": [24, 168],
    "rw_trend_freq_drifting_cycle": [50],
    "piecewise_trend_regime_cycle_with_events": [40, 65],
}

CORE_METHODS: List[str] = [
    "stl",
    "mstl",
    "ssa",
    "emd",
    "ceemdan",
    "vmd",
    "wavelet",
]

DEFAULT_METHOD_CONFIGS: Dict[str, Dict[str, object]] = {
    "stl": {"period": None},
    "mstl": {"periods": None},
    "robuststl": {"period": None},
    "ssa": {"window": None, "rank": 10, "primary_period": None},
    "emd": {"primary_period": None},
    "ceemdan": {"primary_period": None},
    "vmd": {
        "K": None,  # v1.1.0: auto-calculated from periods (None triggers dynamic default)
        "alpha": 300.0,  # v1.1.0: reduced from 2000 for better mode separation
        "tau": 0.0,
        "DC": 0,
        "init": 1,
        "tol": 1e-7,
        "seasonal_num_modes": 1,
        "primary_period": None,
    },
    "wavelet": {"wavelet": "db4", "level": None},
    "ma_baseline": {"trend_window": None, "season_period": None},
    "dr_ts_reg": {
        "lambda_T": 5.0,  # v1.1.0: reduced from 100 to prevent over-smoothing
        "lambda_S": 50.0,
        "lambda_R": 0.1,
        "period": None,
    },
    "dr_ts_ae": {
        "model_path": None,
        "latent_dim": 16,
        "hidden_channels": [32, 64],
        "kernel_size": 7,
        "alpha_T": 10.0,
        "alpha_S": 5.0,
        "n_epochs": 50,
        "device": "cpu",
        "cache_model": True,
        # WARNING: ORACLE method - trains on test data
    },
    "sl_lib": {
        "library_size": 500,
        "n_trend_bases": 200,
        "n_seasonal_bases": 300,
        "n_candidates": 100,  # v1.1.0: increased from 50
        "sparsity_lambda": 0.001,  # v1.1.0: reduced from 0.01
        "max_poly_degree": 5,
        "min_period": 4,
        "max_period": 128,
    },
}


def list_suites() -> List[str]:
    return sorted(SUITES.keys())


def get_suite(suite: str) -> List[str]:
    key = suite.strip().lower()
    if key not in SUITES:
        raise ValueError(f"Unknown suite '{suite}'. Available: {list_suites()}")
    return list(SUITES[key])


def normalize_methods(methods: Sequence[str]) -> List[str]:
    return [m.strip().lower() for m in methods if m and m.strip()]


def resolve_methods(methods: str | Sequence[str]) -> List[str]:
    if isinstance(methods, str):
        raw = methods.strip().lower()
        if raw in {"core", "official"}:
            return list(CORE_METHODS)
        if raw in {"all", "full"}:
            return sorted(DEFAULT_METHOD_CONFIGS.keys())
        return normalize_methods(raw.split(","))
    return normalize_methods(methods)


def normalize_periods(periods: Sequence[int], length: int) -> List[int]:
    cleaned: List[int] = []
    max_period = max(2, length // 2)
    for val in periods:
        try:
            p = int(round(float(val)))
        except (TypeError, ValueError):
            continue
        p = max(2, min(p, max_period))
        if p not in cleaned:
            cleaned.append(p)
    return cleaned


def select_primary_period(periods: Sequence[int]) -> int | None:
    for val in periods:
        if val is None:
            continue
        try:
            p = int(round(float(val)))
        except (TypeError, ValueError):
            continue
        if p >= 2:
            return p
    return None