Skip to main content

pyharbinger

PyPI Python versions License: MIT

Python port of the R 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, ruptures) through thin adapters.

It is the capstone of the DAL Python family:

  • Builds on pydaltoolbox (foundation) and pytspredit (time series prediction) — its regressors power the forecasting-based anomaly detectors.

Installation

pip install pyharbinger

On Python 3.14, ruptures 1.1.x has no prebuilt wheel yet; install with pip install --prefer-binary pyharbinger so pip uses the pure-Python ruptures 1.0.6 wheel. Python 3.9–3.13 install directly.

Quickstart

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), HanrFft, HanrFftAmoc, HanrFftBinseg, HanrFftAmocCusum, HanrFftBinsegCusum, HanrHistogram, HanrFbiad
Change point HcpAmoc, HcpBinseg, HcpPelt (via ruptures), HcpKswin, HcpPageHinkley, HcpCfLr, HcpScp, HcpJoinpoint, HcpChow, HcpGft (native structural change), HcpCfArima, HcpCfEts (ChangeFinder, native forecast replacement)
Clustering HanctKmeans (anomalies / discords)
Classification HancMl (supervised; wraps a pydaltoolbox classifier)
Multivariate HmuPca (PCA reconstruction error)
Datasets datasets.examples_anomalies(), datasets.examples_changepoints()

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

Roadmap

Later releases expand coverage toward feature parity with R in two cycles. The low-dependency cycle adds the FFT-hybrid anomaly detectors, the extended change-point family (ChangeFinder, Chow, GFT, join-point, BOCPD, ...), native SAX motif/discord, ensembles, plotting, and the streaming runners. The heavy-dependency cycle then adds — each behind an optional extra — matrix profile (stumpy), GARCH (arch), EMD (EMD-signal), wavelets (PyWavelets), DTW clustering, and the autoencoder detectors (deep-learning backend). See develop/planejamento.md for the full plan.

Faithfulness to R

The port is validated against the R package on the same data at every step. Deterministic components match R to numerical precision (deviation measures, filters, candidate selection, hard/soft evaluation, FFT/histogram/FBIAD detectors, HanrMl with a deterministic regressor, HanctKmeans centroids count, and HcpPageHinkley). Where the backend or RNG differs, the tolerance is documented:

  • HanrMl with a rank-reduced ELM (nhid < input_size, purelin) depends on the hidden-weight RNG.
  • HanctKmeans and HcpKswin depend on initialization / random-subsample RNG.
  • HcpAmoc/HcpBinseg/HcpPelt use ruptures (Gaussian cost); R uses changepoint::cpt.meanvar with the MBIC penalty, so agreement is approximate.
  • HancMl detections match R (e.g. the hanc_ml k-NN example flags the same positions), but class probabilities can differ because scikit-learn and R's class::knn break ties differently.
  • HmuPca matches R exactly (same events and residuals) after fixing a latent degeneracy in R's hmu_pca, which kept all principal components; both now reconstruct from a reduced set (90% variance by default, capped at n_features - 1).
  • HcpCfLr, HcpScp and the FFT-hybrid anomaly detectors match R exactly on the example series. HcpJoinpoint matches R on well-conditioned series; on a perfectly piecewise-linear series its segment residuals collapse to round-off, so the exact break positions are numerically ill-conditioned (the dominant change point is still recovered).
  • HcpChow and HcpGft are native re-implementations of R's strucchange backend (Bai & Perron dynamic program + a reverse-engineered Gaussian BIC). HcpGft matches R exactly on the well-conditioned series and HcpChow on 6 of 7; the remaining simple (ramp) and sinusoidal cases are ties with an identical fit objective, not disagreements.
  • HcpCfArima and HcpCfEts are native re-implementations of R's forecast backend (auto.arima / ets): the models are fitted with statsmodels, but the order/model selection is ours. HcpCfEts matches R ets() exactly on all example series. HcpCfArima matches R's integration order d on all series and matches detections exactly on the well-conditioned ones (simple, complex); elsewhere the (p, q) stepwise selection diverges from forecast (statsmodels full-ML AICc vs forecast's CSS/ML approximation and stepwise path), so detections overlap substantially but are not identical — the documented tolerance for forecast's auto-selection.

License

MIT

Metadata

Release files for pyharbinger 0.4.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyharbinger 0.4.2
File Size Uploaded Provenance Actions
pyharbinger-0.4.2.tar.gz 98.0 kB Without provenance Details for pyharbinger-0.4.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pyharbinger 0.4.2
File Interpreter ABI Platform Actions
pyharbinger-0.4.2-py3-none-any.whl Python 3 none any Details for pyharbinger-0.4.2-py3-none-any.whl

Total release size: 198.0 kB

Release files / pyharbinger-0.4.2.tar.gz

Download URL pyharbinger-0.4.2.tar.gz
Size 98.0 kB
Tags Source
SHA-256 checksum
How to use checksums
4ace37d5cce0ec1ede2c098489ad5ad44bc36b147d39bdc29a15d67ccade6f64
BLAKE2b-256 checksum
How to use checksums
c5726d3f7cfebf01008a725b35e8c4486f6f448d93d5666b1f4ed7d5693e56ec
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.0

Release files / pyharbinger-0.4.2-py3-none-any.whl

Download URL pyharbinger-0.4.2-py3-none-any.whl
Size 100.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
81c1f6264e15f5af439a6d623206c34f3400ad484f10c332465f7777886a3ebb
BLAKE2b-256 checksum
How to use checksums
d78ed6d2b0c92a8838bd2c5dd89d950b8b90efd055eeaddab09de8a228eccae6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.0

Security for pyharbinger 0.4.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page