Datasets:
Formats:
json
Languages:
English
Size:
< 1K
Tags:
time-series
time-series-decomposition
benchmark
component-recovery
symbolic-regression
icml-2026
License:
File size: 2,868 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 | """Utility helpers for decomposition methods."""
from __future__ import annotations
from typing import Any, Dict, List, Optional
def extract_primary_period(meta: Optional[Dict[str, Any]]) -> Optional[float]:
"""
Inspect ``series['meta']`` for the first available primary period.
"""
if not isinstance(meta, dict):
return None
cycles = meta.get("cycles")
if not isinstance(cycles, list):
return None
for entry in cycles:
if not isinstance(entry, dict):
continue
params = entry.get("params", {})
if not isinstance(params, dict):
continue
period = params.get("period")
if period is not None:
try:
return float(period)
except (TypeError, ValueError):
continue
periods = params.get("periods")
if periods:
try:
return float(periods[0])
except (TypeError, ValueError, IndexError):
continue
return None
def extract_periods_from_meta(
meta: Optional[Dict[str, Any]],
fallback: Optional[float] = None,
) -> List[int]:
"""
Extract a list of integer seasonal periods from metadata.
"""
periods: List[int] = []
if isinstance(meta, dict):
cycles = meta.get("cycles")
if isinstance(cycles, list):
for entry in cycles:
if not isinstance(entry, dict):
continue
params = entry.get("params", {})
if not isinstance(params, dict):
continue
period = params.get("period")
if period:
try:
p_int = int(round(float(period)))
if p_int >= 2:
periods.append(p_int)
except (TypeError, ValueError):
pass
multi = params.get("periods")
if multi:
for val in multi:
try:
p_int = int(round(float(val)))
if p_int >= 2:
periods.append(p_int)
except (TypeError, ValueError):
continue
if not periods and fallback:
try:
p_int = int(round(float(fallback)))
if p_int >= 2:
periods.append(p_int)
except (TypeError, ValueError):
pass
# remove duplicates while preserving order
seen = set()
unique_periods: List[int] = []
for p in periods:
if p not in seen:
seen.add(p)
unique_periods.append(p)
return unique_periods
|