$ show salesforce/Merlion
Merlion is a mature Python library for time series intelligence, specializing in anomaly detection and forecasting. It provides a comprehensive, modular ecosystem including model zoo (classical, tree-based, deep learning, ensemble, AutoML), composable transforms, post-processing chains, evaluation frameworks, and a Dash-based interactive dashboard. The architecture follows a clean layered design: data loading via `ts_datasets`, core `TimeSeries` abstraction, `ModelBase` hierarchy with config-driven instantiation, invertible transforms, and pluggable post-rules. It integrates with Spark for distributed inference and provides benchmarks against standard datasets (NAB, M4, UCR). Though primarily a library (application), it includes research-oriented components such as state-of-the-art transformer architectures (Autoformer, Informer) and Bayesian change point detection, making it a hybrid tool suitable for both production and research.
The LLM identified 7 files worth highlighting for reuse:
Provides the `TimeSeries` and `UnivariateTimeSeries` classes, the core data abstraction for the entire library. Supports sophisticated alignment modes (FixedReference, FixedGranularity, OuterJoin, InnerJoin), resampling, windowing, bisection, and arithmetic operations. Handles missing values and aggregation policies. This is a standalone, well-tested module that could be extracted and reused in any time series project requiring robust alignment and manipulation of time-indexed data.
Implements `RollingWindowDataset`, a flexible PyTorch-style dataset for creating sliding windows from time series. Supports train/validation/test splits, exogenous variable inclusion, timestamp encoding, and configurable stride. The pattern is generic and can be repurposed for any sequence modeling task beyond this library, demonstrating clean design with minimal dependencies (only numpy and torch).
Implements a family of Bayesian conjugate prior distributions: Beta-Bernoulli, Normal-InverseGamma, and Multivariate Normal-InverseWishart, along with Bayesian linear regression. These enable online learning and probabilistic inference with closed-form updates. The module is mathematically rigorous, self-contained (no internal Merlion imports), and directly reusable for any probabilistic modeling task that requires sequential belief updates.
Converts datetime objects into numerical features for forecasting models. Supports multiple time granularities (seconds to years), cyclical encoding (sin/cos for hour, day, month), and configurable subsets. The logic is encapsulated in `TimeFeaturesBase` and concrete implementations like `TimeFeatureFromSeries`. This module is dependency-light (pandas/numpy) and can be extracted as a standalone feature engineering utility for any time series project.
Provides abstract base classes `TransformBase` and `InvertibleTransformBase` defining a consistent interface for trainable, invertible data transformations. Supports chaining via `TransformSequence` and stacking via `TransformStack`. The composability and inversion pattern (essential for forecast uncertainty propagation) is a reusable architectural pattern applicable to any ML pipeline requiring pre/post processing with undo capability.
Defines `TimeSeriesDatasetBase` and `TimeSeriesDataset` abstract classes for loading benchmark time series datasets with a consistent API. Each dataset provides metadata (train/test splits, anomaly labels, frequency) and returns (data, metadata) tuples. This standardized interface enables drop-in replacement of datasets in benchmarks and is extensible to custom data sources. The pattern is reusable for any project that needs structured dataset loaders.
Implements `IStat`, `ExponentialMovingAverage`, and `RecencyWeightedVariance` for incremental (streaming) statistical estimation of mean, variance, and autocovariance without storing all data. This is critical for online learning in time series models (e.g., MSES). The implementation is numerically stable (Welford algorithm), self-contained, and directly usable in any streaming context requiring efficient online statistics.