Metadata-Version: 2.5
Name: pyharbinger
Version: 1.0.707
Summary: A unified time series event detection framework (Python port of the R harbinger framework)
Project-URL: Homepage, https://github.com/cefet-rj-dal/pyharbinger
Project-URL: Repository, https://github.com/cefet-rj-dal/pyharbinger
Project-URL: Bug Tracker, https://github.com/cefet-rj-dal/pyharbinger/issues
Author: CEFET/RJ
Author-email: Eduardo Ogasawara <eogasawara@ieee.org>, Anthony Heimlich <anthony.heimlich@eic.cefet-rj.br>, Antonio Castro <antonio.castro@eic.cefet-rj.br>, Antonio Mello <antonio.mello@eic.cefet-rj.br>, Diego Carvalho <d.carvalho@ieee.org>, Eduardo Bezerra <ebezerra@cefet-rj.br>, Ellen Paixão <ellen.paixao@eic.cefet-rj.br>, Fernando Fraga <fernando.fraga@eic.cefet-rj.br>, Gabriel Giuliano <gabriel.giuliano@eic.cefet-rj.br>, Heraldo Borges <heraldo.borges@cefet-rj.br>, Igor Andrade <igor.andrade@eic.cefet-rj.br>, Isabele Rocha <isabele.rocha@eic.cefet-rj.br>, Janio Lima <janio.lima@eic.cefet-rj.br>, Jessica Souza <jessica.souza@eic.cefet-rj.br>, Lais Baroni <lais.baronis@eic.cefet-rj.br>, Lucas Tavares <lucas.tavares@eic.cefet-rj.br>, Michel Reis <michel.reis@eic.cefet-rj.br>, Rebecca Salles <rebecca.salles@eic.cefet-rj.br>
Maintainer-email: Eduardo Ogasawara <eogasawara@ieee.org>
License: MIT
License-File: LICENSE
Keywords: anomaly detection,change point,event detection,experiment line,scikit-learn,time series
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Requires-Python: >=3.9
Requires-Dist: matplotlib>=3.5
Requires-Dist: numpy>=1.23
Requires-Dist: pandas>=1.5
Requires-Dist: pydaltoolbox>=0.1.0
Requires-Dist: pytspredit>=0.1.0
Requires-Dist: scikit-learn>=1.2
Requires-Dist: scipy>=1.9
Provides-Extra: dev
Requires-Dist: build; extra == 'dev'
Requires-Dist: pytest>=7; extra == 'dev'
Requires-Dist: ruff>=0.1; extra == 'dev'
Requires-Dist: twine; extra == 'dev'
Provides-Extra: docs
Requires-Dist: ipykernel>=6; extra == 'docs'
Requires-Dist: jupytext>=1.16; extra == 'docs'
Requires-Dist: nbclient>=0.9; extra == 'docs'
Requires-Dist: nbconvert>=7; extra == 'docs'
Description-Content-Type: text/markdown

# pyharbinger

[![PyPI](https://img.shields.io/pypi/v/pyharbinger.svg)](https://pypi.org/project/pyharbinger/)
[![Python versions](https://img.shields.io/pypi/pyversions/pyharbinger.svg)](https://pypi.org/project/pyharbinger/)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/cefet-rj-dal/pyharbinger/blob/main/LICENSE)

Python port of the R [harbinger](https://github.com/cefet-rj-dal/harbinger) — a **framework
for time series event detection** (anomalies, change points, and motifs/discords), built on
the DAL Toolbox *Experiment Line*.

`pyharbinger` unifies many detection methods under one interface (`fit` → `detect` →
`evaluate`) and a common evaluation protocol, so different detectors can be compared fairly —
reusing classic libraries (scikit-learn, numpy, pandas, scipy) through thin adapters and
self-contained native implementations.

It is the capstone of the DAL Python family:

- Builds on **[pydaltoolbox](https://github.com/cefet-rj-dal/pydaltoolbox)** (foundation) and
  **[pytspredit](https://github.com/cefet-rj-dal/pytspredit)** (time series prediction) — its
  regressors power the forecasting-based anomaly detectors.

## Installation

```bash
pip install pyharbinger
```

## Quickstart

```python
from pyharbinger import HanrFft, HarEval, datasets

# a labeled example series (one injected anomaly)
dataset = datasets.examples_anomalies()["simple"]
serie, event = dataset["serie"], dataset["event"]

# fit -> detect -> evaluate
model = HanrFft().fit(serie)
detection = model.detect(serie)
print(detection[detection["event"]])

metrics = model.evaluate(detection, event)
print(metrics["confMatrix"])
print("F1:", metrics["F1"])
```

## What's included

Every detector extends `Harbinger` and returns a detection table with columns
`idx` / `event` / `type` (`"anomaly"`, `"changepoint"`, `"discord"` or `""`).

| Group | Classes |
|---|---|
| **Core** | `Harbinger` (base contract), deviation / filter / candidate-selection utilities |
| **Evaluation** | `HarEval` (hard), `HarEvalSoft` (SoftED, soft matching via the Hungarian algorithm) |
| **Anomaly** | `HanrMl` (forecasting residuals, wraps a pytspredit regressor), `HanrArima` (ARIMA residuals, reuses the DAL ARIMA), `HanrFft`, `HanrFftAmoc`, `HanrFftBinseg`, `HanrFftAmocCusum`, `HanrFftBinsegCusum`, `HanrFftSma` (adaptive FFT-selected moving average), `HanrHistogram`, `HanrFbiad`, `HanrEmd`, `HanrRemd`, `HanrRtad`, `HanrWavelet` (native MODWT, reuses pytspredit), `HanrGarch` |
| **Change point** | `HcpAmoc`, `HcpBinseg`, `HcpPelt`, `HcpKswin`, `HcpPageHinkley`, `HcpCfLr`, `HcpScp`, `HcpJoinpoint`, `HcpChow`, `HcpGft`, `HcpCfArima`, `HcpCfEts`, `HcpGarch`, `HcpBocpd` |
| **Clustering** | `HanctKmeans`, `HanctDtw` (anomalies / discords) |
| **Classification** | `HancMl` (supervised; wraps a pydaltoolbox classifier) |
| **Multivariate** | `HmuPca` (PCA reconstruction error) |
| **Motifs & Discords** | `HmoMp`, `HdisMp` (Matrix Profile), `TransSax` / `TransXsax` (SAX / XSAX encoding), `HmoSax` / `HmoXsax` (motifs), `HdisSax` (discords) |
| **Ensemble** | `HarEnsemble` (majority vote), `HarEnsembleFuzzy` (fuzzy consensus) |
| **Plotting** | `har_plot`, `har_ensemble_plot`, `har_ensemble_plot_models` (matplotlib) |
| **Online / streaming** | `HarOnlineSession` + sources (`HarSourceSimulated`/`HarSourceDataframe`/`HarSourceCallback`/`HarSourceKafka` + collector seam), memory policies, execution strategies; `HarStreamEval` + `har_stream_experiment` |
| **Datasets** | `datasets.examples_anomalies()`, `datasets.examples_changepoints()`, `datasets.examples_motifs()`, `datasets.examples_harbinger()`; benchmark collection via `datasets.benchmark()` / `datasets.loadfulldata()` (Yahoo, gecco, MIT-BIH, NAB, oil_3w, UCR) |

Detectors accept a univariate series or, for the multivariate ones, a
`DataFrame` with one column per variable.

## Guided Tutorial Track

If you are new to `pyharbinger`, start with the guided tutorials in the
[GitHub examples collection](https://github.com/cefet-rj-dal/pyharbinger/blob/main/examples/README.md):

- [Tutorials](https://github.com/cefet-rj-dal/pyharbinger/blob/main/examples/tutorial/README.md) — a
  10-part sequential learning path covering first contact with the package, data inspection,
  plotting, baseline anomaly detection, model-based detection, evaluation, change points,
  smoothing, symbolic encodings, and motif discovery.

## Thematic Example Collections

If you already know the basic `fit` → `detect` → `evaluate` workflow, jump directly to any
thematic example collection on GitHub:

- [General examples](https://github.com/cefet-rj-dal/pyharbinger/blob/main/examples/general/README.md) — orientation datasets, deviation measures, filter criteria, candidate selection, and hard/soft evaluation.
- [Dataset examples](https://github.com/cefet-rj-dal/pyharbinger/blob/main/examples/datasets/README.md) — benchmark archives (Yahoo, NAB, UCR) and domain collections (MIT-BIH, Oil 3W, GECCO).
- [Transformation examples](https://github.com/cefet-rj-dal/pyharbinger/blob/main/examples/transformations/README.md) — moving-average smoothing (`mas`) and symbolic encodings (`TransSax`, `TransXsax`).
- [Anomaly examples](https://github.com/cefet-rj-dal/pyharbinger/blob/main/examples/anomalies/README.md) — baseline, spectral, decomposition, statistical, ML regression, supervised classification, clustering, discord, ensemble, and multivariate anomaly detectors. Deep-learning detectors (`HanAutoencoder`) live in `pydaltoolboxdp`.
- [Change-point examples](https://github.com/cefet-rj-dal/pyharbinger/blob/main/examples/change_point/README.md) — single-break, multiple-break, structural-break, ChangeFinder, volatility, window, BOCPD, ensemble, and streaming drift detectors. Deep-learning `HcpWaypoint` lives in `pydaltoolboxdp`.
- [Motif examples](https://github.com/cefet-rj-dal/pyharbinger/blob/main/examples/motifs/README.md) — Matrix Profile (`HmoMp`, `HdisMp`) and symbolic (`HmoSax`, `HmoXsax`, `HdisSax`) motif and discord discovery.
- [Online examples](https://github.com/cefet-rj-dal/pyharbinger/blob/main/examples/online/README.md) — streaming sources, online sessions, memory policies, execution strategies, stream evaluation, experiment grids, and the dependency-free Kafka collector seam.
- [Custom examples](https://github.com/cefet-rj-dal/pyharbinger/blob/main/examples/custom/README.md) — extending `pyharbinger` with custom transformations, anomaly/sequence/change-point/motif detectors, and custom evaluators.

## Main Capabilities

- **Unified abstractions** for event detectors, transformations, ensembles, evaluators, online sessions, and data sources.
- **Anomaly detection** through statistical, spectral, decomposition, residual, machine-learning, supervised classification, clustering, discord, ensemble, and multivariate approaches.
- **Change-point detection** through single-break, multiple-break, structural-break, probabilistic (BOCPD), volatility (GARCH), ChangeFinder, window, ensemble, and streaming/online approaches.
- **Motif and discord discovery** using Matrix Profile and symbolic (SAX / XSAX) representations.
- **Time series transformations** including moving-average smoothing (`mas`), SAX, and extended SAX (`TransSax`, `TransXsax`).
- **Evaluation and visualization** with hard (`HarEval`) and soft (`HarEvalSoft` / SoftED) evaluation protocols, plotting utilities (`har_plot`, `har_ensemble_plot`), and reproducible streaming experiments (`HarOnlineSession`, `HarStreamEval`).

## Related DAL projects

- [pydaltoolbox](https://github.com/cefet-rj-dal/pydaltoolbox) — foundation (Python)
- [pytspredit](https://github.com/cefet-rj-dal/pytspredit) — time series prediction (Python)
- [daltoolbox](https://github.com/cefet-rj-dal/daltoolbox) / [tspredit](https://github.com/cefet-rj-dal/tspredit) / [harbinger](https://github.com/cefet-rj-dal/harbinger) — R originals
- [Data Analytics Lab](https://eic.cefet-rj.br/~dal/)

## License

MIT
