Skip to main content

Local Global Trend Decomposition for Time Series Analysis

Project description

LGTD: Local–Global Trend Decomposition

Python 3.8+ License: MIT PyPI version

Season-length-free time series decomposition.

LGTD (Local–Global Trend Decomposition) is a principled method for decomposing a univariate time series into trend, seasonal, and residual components without requiring prior specification of seasonal periods. In contrast to classical decomposition techniques—such as STL, X-11, and MSTL—which assume fixed or user-specified seasonal lengths, LGTD automatically identifies and aggregates repeating structures of arbitrary and potentially time-varying scales.


Motivation

Many real-world time series exhibit seasonality that is non-stationary, intermittent, or composed of multiple overlapping cycles. Period-dependent methods are brittle in such settings, as incorrect or misspecified periods can substantially degrade decomposition quality. LGTD is designed to address this limitation by eliminating the need for explicit period selection.

# STL requires an explicit seasonal period
from statsmodels.tsa.seasonal import STL
stl = STL(y, seasonal=24)  # ❌ requires prior knowledge of the period
result = stl.fit()

# LGTD does not require period specification
from lgtd import lgtd
model = lgtd()
result = model.fit_transform(y)  # ✅ accommodates variable and unknown periods

Installation

pip install lgtd

Quick Start

from lgtd import lgtd
import numpy as np

# Synthetic time series with trend and seasonality
t = np.arange(500)
y = 0.05 * t + 10 * np.sin(2 * np.pi * t / 24) + np.random.normal(0, 1, 500)

# Decomposition
model = lgtd()
result = model.fit_transform(y)

# Decomposed components
print("Detected periods:", result.detected_periods)
print("Trend:", result.trend)
print("Seasonal:", result.seasonal)
print("Residual:", result.residual)

Key Properties

  • Season-length-free — No assumption of known or fixed seasonal periods
  • Multiple and time-varying periodicities — Supports overlapping and drifting cycles
  • Adaptive trend modeling — Automatically selects between linear and LOWESS trends
  • Noise robustness — Stable performance under irregular and noisy observations
  • Minimal interface — Simple, scikit-learn–style API

Parameters

model = lgtd(
    window_size=3,            # Local window size for pattern extraction
    error_percentile=50,      # Threshold for seasonal pattern aggregation
    trend_selection='auto',   # {'auto', 'linear', 'lowess'}
    lowess_frac=0.1,          # LOWESS smoothing fraction
    threshold_r2=0.9          # R² threshold for trend selection
)

Refer to the Parameter Guide for detailed tuning guidelines.


Visualization

from lgtd.evaluation.visualization import plot_decomposition

result = model.fit_transform(y)
plot_decomposition(result, title="LGTD Decomposition")

Evaluation Metrics

from lgtd.evaluation.metrics import compute_mse, compute_mae

mse = compute_mse(ground_truth, {
    'trend': result.trend,
    'seasonal': result.seasonal,
    'residual': result.residual
})

Reproducibility

This repository contains a complete experimental pipeline for reproducing the results reported in the accompanying paper. LGTD is evaluated against seven baseline decomposition methods on both synthetic and real-world datasets.

python experiments/scripts/run_synthetic_experiments.py
python experiments/scripts/run_realworld_experiments.py

python experiments/scripts/generate_tables.py
python experiments/scripts/generate_figures.py

See the Experiments Guide for full details.


Documentation


Method Overview

LGTD decomposes a time series ( y_t ) as

[ y_t = T_t + S_t + R_t, ]

where ( T_t ) denotes the global trend, ( S_t ) the aggregated seasonal structure, and ( R_t ) the residual component.

High-level procedure:

  1. Estimate a global trend (linear or LOWESS, selected adaptively)
  2. Remove the estimated trend
  3. Identify local linear patterns using sliding windows
  4. Aggregate consistent patterns into a seasonal component
  5. Compute residuals

See Algorithm Documentation for formal definitions and analysis.


Citation

@article{lgtd2026arxiv,
  title        = {LGTD: Local--Global Trend Decomposition for Season-Length-Free Time Series Analysis},
  author       = {Sophaken, Chotanan and Rattanakornphan, Thanadej and Charoenpoonpanich, Piyanon and Phungtua-eng, Thanapol and Amornbunchornvej, Chainarong},
  journal      = {arXiv preprint},
  year         = {2026},
  eprint       = {2601.04820},
  archivePrefix= {arXiv},
  primaryClass = {cs.DB}
}

License

Released under the MIT License. See LICENSE for details.


Links

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lgtd-0.1.0.tar.gz (16.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lgtd-0.1.0-py3-none-any.whl (15.4 kB view details)

Uploaded Python 3

File details

Details for the file lgtd-0.1.0.tar.gz.

File metadata

  • Download URL: lgtd-0.1.0.tar.gz
  • Upload date:
  • Size: 16.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.12

File hashes

Hashes for lgtd-0.1.0.tar.gz
Algorithm Hash digest
SHA256 8c420edef685c03e9d15e66bfa20e560d62fad8c33cd19189e29d1612b545fad
MD5 8e5acc42eb2cc76898d24ab4ecf092af
BLAKE2b-256 5b0fe392e11d720ec6f67e66047e4d9d70800436cd04fd7ca05fb205dbd9f4a7

See more details on using hashes here.

File details

Details for the file lgtd-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: lgtd-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 15.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.12

File hashes

Hashes for lgtd-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1fb61bb5b4a1f2fab568f96dc84e6d6f4c28aabb2ce81712487d68e9658ae218
MD5 c93c01c7de80d70b6a1aaf2ed01666dc
BLAKE2b-256 88ef273bdcc8aee7295f757b1d864c63d0389fb04d78addbc927f41c2dacabdb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page