pyharbinger 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pyharbinger-0.1.0/.gitignore +223 -0
- pyharbinger-0.1.0/LICENSE +21 -0
- pyharbinger-0.1.0/PKG-INFO +123 -0
- pyharbinger-0.1.0/README.md +87 -0
- pyharbinger-0.1.0/pyproject.toml +65 -0
- pyharbinger-0.1.0/src/pyharbinger/__init__.py +63 -0
- pyharbinger-0.1.0/src/pyharbinger/anomaly.py +238 -0
- pyharbinger-0.1.0/src/pyharbinger/changepoint.py +260 -0
- pyharbinger-0.1.0/src/pyharbinger/clustering.py +84 -0
- pyharbinger-0.1.0/src/pyharbinger/data/examples_anomalies.csv +3713 -0
- pyharbinger-0.1.0/src/pyharbinger/data/examples_changepoints.csv +2304 -0
- pyharbinger-0.1.0/src/pyharbinger/datasets.py +64 -0
- pyharbinger-0.1.0/src/pyharbinger/evaluation.py +188 -0
- pyharbinger-0.1.0/src/pyharbinger/harbinger.py +123 -0
- pyharbinger-0.1.0/src/pyharbinger/utils.py +297 -0
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[codz]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
share/python-wheels/
|
|
24
|
+
*.egg-info/
|
|
25
|
+
.installed.cfg
|
|
26
|
+
*.egg
|
|
27
|
+
MANIFEST
|
|
28
|
+
|
|
29
|
+
# PyInstaller
|
|
30
|
+
# Usually these files are written by a python script from a template
|
|
31
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
32
|
+
*.manifest
|
|
33
|
+
*.spec
|
|
34
|
+
|
|
35
|
+
# Installer logs
|
|
36
|
+
pip-log.txt
|
|
37
|
+
pip-delete-this-directory.txt
|
|
38
|
+
|
|
39
|
+
# Unit test / coverage reports
|
|
40
|
+
htmlcov/
|
|
41
|
+
.tox/
|
|
42
|
+
.nox/
|
|
43
|
+
.coverage
|
|
44
|
+
.coverage.*
|
|
45
|
+
.cache
|
|
46
|
+
nosetests.xml
|
|
47
|
+
coverage.xml
|
|
48
|
+
*.cover
|
|
49
|
+
*.py.cover
|
|
50
|
+
*.lcov
|
|
51
|
+
.hypothesis/
|
|
52
|
+
.pytest_cache/
|
|
53
|
+
cover/
|
|
54
|
+
|
|
55
|
+
# Translations
|
|
56
|
+
*.mo
|
|
57
|
+
*.pot
|
|
58
|
+
|
|
59
|
+
# Django stuff:
|
|
60
|
+
*.log
|
|
61
|
+
local_settings.py
|
|
62
|
+
db.sqlite3
|
|
63
|
+
db.sqlite3-journal
|
|
64
|
+
|
|
65
|
+
# Flask stuff:
|
|
66
|
+
instance/
|
|
67
|
+
.webassets-cache
|
|
68
|
+
|
|
69
|
+
# Scrapy stuff:
|
|
70
|
+
.scrapy
|
|
71
|
+
|
|
72
|
+
# Sphinx documentation
|
|
73
|
+
docs/_build/
|
|
74
|
+
|
|
75
|
+
# PyBuilder
|
|
76
|
+
.pybuilder/
|
|
77
|
+
target/
|
|
78
|
+
|
|
79
|
+
# Jupyter Notebook
|
|
80
|
+
.ipynb_checkpoints
|
|
81
|
+
|
|
82
|
+
# IPython
|
|
83
|
+
profile_default/
|
|
84
|
+
ipython_config.py
|
|
85
|
+
|
|
86
|
+
# pyenv
|
|
87
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
88
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
89
|
+
# .python-version
|
|
90
|
+
|
|
91
|
+
# pipenv
|
|
92
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
93
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
94
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
95
|
+
# install all needed dependencies.
|
|
96
|
+
# Pipfile.lock
|
|
97
|
+
|
|
98
|
+
# uv
|
|
99
|
+
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
|
|
100
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
101
|
+
# commonly ignored for libraries.
|
|
102
|
+
# uv.lock
|
|
103
|
+
|
|
104
|
+
# poetry
|
|
105
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
106
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
107
|
+
# commonly ignored for libraries.
|
|
108
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
109
|
+
# poetry.lock
|
|
110
|
+
# poetry.toml
|
|
111
|
+
|
|
112
|
+
# pdm
|
|
113
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
114
|
+
# pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
|
|
115
|
+
# https://pdm-project.org/en/latest/usage/project/#working-with-version-control
|
|
116
|
+
# pdm.lock
|
|
117
|
+
# pdm.toml
|
|
118
|
+
.pdm-python
|
|
119
|
+
.pdm-build/
|
|
120
|
+
|
|
121
|
+
# pixi
|
|
122
|
+
# Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
|
|
123
|
+
# pixi.lock
|
|
124
|
+
# Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
|
|
125
|
+
# in the .venv directory. It is recommended not to include this directory in version control.
|
|
126
|
+
.pixi/*
|
|
127
|
+
!.pixi/config.toml
|
|
128
|
+
|
|
129
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
130
|
+
__pypackages__/
|
|
131
|
+
|
|
132
|
+
# Celery stuff
|
|
133
|
+
celerybeat-schedule*
|
|
134
|
+
celerybeat.pid
|
|
135
|
+
|
|
136
|
+
# Redis
|
|
137
|
+
*.rdb
|
|
138
|
+
*.aof
|
|
139
|
+
*.pid
|
|
140
|
+
|
|
141
|
+
# RabbitMQ
|
|
142
|
+
mnesia/
|
|
143
|
+
rabbitmq/
|
|
144
|
+
rabbitmq-data/
|
|
145
|
+
|
|
146
|
+
# ActiveMQ
|
|
147
|
+
activemq-data/
|
|
148
|
+
|
|
149
|
+
# SageMath parsed files
|
|
150
|
+
*.sage.py
|
|
151
|
+
|
|
152
|
+
# Environments
|
|
153
|
+
.env
|
|
154
|
+
.envrc
|
|
155
|
+
.venv
|
|
156
|
+
env/
|
|
157
|
+
venv/
|
|
158
|
+
ENV/
|
|
159
|
+
env.bak/
|
|
160
|
+
venv.bak/
|
|
161
|
+
|
|
162
|
+
# Conda environments
|
|
163
|
+
conda-meta/
|
|
164
|
+
|
|
165
|
+
# Spyder project settings
|
|
166
|
+
.spyderproject
|
|
167
|
+
.spyproject
|
|
168
|
+
|
|
169
|
+
# Rope project settings
|
|
170
|
+
.ropeproject
|
|
171
|
+
|
|
172
|
+
# mkdocs/Zensical documentation
|
|
173
|
+
/site
|
|
174
|
+
|
|
175
|
+
# mypy
|
|
176
|
+
.mypy_cache/
|
|
177
|
+
.dmypy.json
|
|
178
|
+
dmypy.json
|
|
179
|
+
|
|
180
|
+
# Pyre type checker
|
|
181
|
+
.pyre/
|
|
182
|
+
|
|
183
|
+
# pytype static type analyzer
|
|
184
|
+
.pytype/
|
|
185
|
+
|
|
186
|
+
# Cython debug symbols
|
|
187
|
+
cython_debug/
|
|
188
|
+
|
|
189
|
+
# PyCharm
|
|
190
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
191
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
192
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
193
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
194
|
+
# .idea/
|
|
195
|
+
|
|
196
|
+
# Abstra
|
|
197
|
+
# Abstra is an AI-powered process automation framework.
|
|
198
|
+
# Ignore directories containing user credentials, local state, and settings.
|
|
199
|
+
# Learn more at https://abstra.io/docs
|
|
200
|
+
.abstra/
|
|
201
|
+
|
|
202
|
+
# Visual Studio Code
|
|
203
|
+
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore that
|
|
204
|
+
# can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
|
|
205
|
+
# and can be added to the global gitignore or merged into this file. However, if you prefer, you
|
|
206
|
+
# could uncomment the following to ignore the entire vscode folder
|
|
207
|
+
# .vscode/
|
|
208
|
+
# Temporary file for partial code execution
|
|
209
|
+
tempCodeRunnerFile.py
|
|
210
|
+
|
|
211
|
+
# Ruff stuff:
|
|
212
|
+
.ruff_cache/
|
|
213
|
+
|
|
214
|
+
# PyPI configuration file
|
|
215
|
+
.pypirc
|
|
216
|
+
|
|
217
|
+
# Marimo
|
|
218
|
+
marimo/_static/
|
|
219
|
+
marimo/_lsp/
|
|
220
|
+
__marimo__/
|
|
221
|
+
|
|
222
|
+
# Streamlit
|
|
223
|
+
.streamlit/secrets.toml
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Data Analytics Lab
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: pyharbinger
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A unified time series event detection framework (Python port of the R harbinger framework)
|
|
5
|
+
Project-URL: Homepage, https://github.com/cefet-rj-dal/pyharbinger
|
|
6
|
+
Project-URL: Repository, https://github.com/cefet-rj-dal/pyharbinger
|
|
7
|
+
Project-URL: Bug Tracker, https://github.com/cefet-rj-dal/pyharbinger/issues
|
|
8
|
+
Author-email: Eduardo Ogasawara <eogasawara@ieee.org>
|
|
9
|
+
License: MIT
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: anomaly detection,change point,event detection,experiment line,scikit-learn,time series
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Intended Audience :: Science/Research
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
17
|
+
Requires-Python: >=3.9
|
|
18
|
+
Requires-Dist: numpy>=1.23
|
|
19
|
+
Requires-Dist: pandas>=1.5
|
|
20
|
+
Requires-Dist: pydaltoolbox>=0.1.0
|
|
21
|
+
Requires-Dist: pytspredit>=0.1.0
|
|
22
|
+
Requires-Dist: ruptures>=1.0
|
|
23
|
+
Requires-Dist: scikit-learn>=1.2
|
|
24
|
+
Requires-Dist: scipy>=1.9
|
|
25
|
+
Provides-Extra: dev
|
|
26
|
+
Requires-Dist: build; extra == 'dev'
|
|
27
|
+
Requires-Dist: pytest>=7; extra == 'dev'
|
|
28
|
+
Requires-Dist: ruff>=0.1; extra == 'dev'
|
|
29
|
+
Requires-Dist: twine; extra == 'dev'
|
|
30
|
+
Provides-Extra: docs
|
|
31
|
+
Requires-Dist: ipykernel>=6; extra == 'docs'
|
|
32
|
+
Requires-Dist: jupytext>=1.16; extra == 'docs'
|
|
33
|
+
Requires-Dist: nbclient>=0.9; extra == 'docs'
|
|
34
|
+
Requires-Dist: nbconvert>=7; extra == 'docs'
|
|
35
|
+
Description-Content-Type: text/markdown
|
|
36
|
+
|
|
37
|
+
# pyharbinger
|
|
38
|
+
|
|
39
|
+
Python port of the R [harbinger](https://github.com/cefet-rj-dal/harbinger) — a **framework
|
|
40
|
+
for time series event detection** (anomalies, change points, and motifs/discords), built on
|
|
41
|
+
the DAL Toolbox *Experiment Line*.
|
|
42
|
+
|
|
43
|
+
`pyharbinger` unifies many detection methods under one interface (`fit` → `detect` →
|
|
44
|
+
`evaluate`) and a common evaluation protocol, so different detectors can be compared fairly —
|
|
45
|
+
reusing classic libraries (scikit-learn, numpy, pandas, scipy, ruptures) through thin
|
|
46
|
+
adapters.
|
|
47
|
+
|
|
48
|
+
It is the capstone of the DAL Python family:
|
|
49
|
+
|
|
50
|
+
- Builds on **[pydaltoolbox](https://github.com/cefet-rj-dal/pydaltoolbox)** (foundation) and
|
|
51
|
+
**[pytspredit](https://github.com/cefet-rj-dal/pytspredit)** (time series prediction) — its
|
|
52
|
+
regressors power the forecasting-based anomaly detectors.
|
|
53
|
+
|
|
54
|
+
## Installation
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
pip install pyharbinger
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Quickstart
|
|
61
|
+
|
|
62
|
+
```python
|
|
63
|
+
from pyharbinger import HanrFft, HarEval, datasets
|
|
64
|
+
|
|
65
|
+
# a labeled example series (one injected anomaly)
|
|
66
|
+
dataset = datasets.examples_anomalies()["simple"]
|
|
67
|
+
serie, event = dataset["serie"], dataset["event"]
|
|
68
|
+
|
|
69
|
+
# fit -> detect -> evaluate
|
|
70
|
+
model = HanrFft().fit(serie)
|
|
71
|
+
detection = model.detect(serie)
|
|
72
|
+
print(detection[detection["event"]])
|
|
73
|
+
|
|
74
|
+
metrics = model.evaluate(detection, event)
|
|
75
|
+
print(metrics["confMatrix"])
|
|
76
|
+
print("F1:", metrics["F1"])
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## What's included (v1)
|
|
80
|
+
|
|
81
|
+
Every detector extends `Harbinger` and returns a detection table with columns
|
|
82
|
+
`idx` / `event` / `type` (`"anomaly"`, `"changepoint"`, `"discord"` or `""`).
|
|
83
|
+
|
|
84
|
+
| Group | Classes |
|
|
85
|
+
|---|---|
|
|
86
|
+
| **Core** | `Harbinger` (base contract), deviation / filter / candidate-selection utilities |
|
|
87
|
+
| **Evaluation** | `HarEval` (hard), `HarEvalSoft` (SoftED, soft matching via the Hungarian algorithm) |
|
|
88
|
+
| **Anomaly** | `HanrMl` (forecasting residuals, wraps a pytspredit regressor), `HanrFft`, `HanrHistogram`, `HanrFbiad` |
|
|
89
|
+
| **Change point** | `HcpAmoc`, `HcpBinseg`, `HcpPelt` (via `ruptures`), `HcpKswin`, `HcpPageHinkley` |
|
|
90
|
+
| **Clustering** | `HanctKmeans` (anomalies / discords) |
|
|
91
|
+
| **Datasets** | `datasets.examples_anomalies()`, `datasets.examples_changepoints()` |
|
|
92
|
+
|
|
93
|
+
### Deferred to a future release (0.2.0 / Block B)
|
|
94
|
+
|
|
95
|
+
ML-classification detector (`hanc_ml`), motif/discord via matrix profile
|
|
96
|
+
(`hdis_mp`/`hmo_mp`), ARIMA/GARCH/EMD/wavelet anomaly detectors, DTW clustering,
|
|
97
|
+
SAX representations, ensembles, streaming/online runners, and plotting helpers.
|
|
98
|
+
|
|
99
|
+
## Faithfulness to R
|
|
100
|
+
|
|
101
|
+
The port is validated against the R package on the same data at every step.
|
|
102
|
+
Deterministic components match R to numerical precision (deviation measures,
|
|
103
|
+
filters, candidate selection, hard/soft evaluation, FFT/histogram/FBIAD
|
|
104
|
+
detectors, `HanrMl` with a deterministic regressor, `HanctKmeans` centroids
|
|
105
|
+
count, and `HcpPageHinkley`). Where the backend or RNG differs, the tolerance is
|
|
106
|
+
documented:
|
|
107
|
+
|
|
108
|
+
- `HanrMl` with a rank-reduced ELM (`nhid < input_size`, `purelin`) depends on
|
|
109
|
+
the hidden-weight RNG.
|
|
110
|
+
- `HanctKmeans` and `HcpKswin` depend on initialization / random-subsample RNG.
|
|
111
|
+
- `HcpAmoc`/`HcpBinseg`/`HcpPelt` use `ruptures` (Gaussian cost); R uses
|
|
112
|
+
`changepoint::cpt.meanvar` with the MBIC penalty, so agreement is approximate.
|
|
113
|
+
|
|
114
|
+
## Related DAL projects
|
|
115
|
+
|
|
116
|
+
- [pydaltoolbox](https://github.com/cefet-rj-dal/pydaltoolbox) — foundation (Python)
|
|
117
|
+
- [pytspredit](https://github.com/cefet-rj-dal/pytspredit) — time series prediction (Python)
|
|
118
|
+
- [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
|
|
119
|
+
- [Data Analytics Lab](https://eic.cefet-rj.br/~dal/)
|
|
120
|
+
|
|
121
|
+
## License
|
|
122
|
+
|
|
123
|
+
MIT
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# pyharbinger
|
|
2
|
+
|
|
3
|
+
Python port of the R [harbinger](https://github.com/cefet-rj-dal/harbinger) — a **framework
|
|
4
|
+
for time series event detection** (anomalies, change points, and motifs/discords), built on
|
|
5
|
+
the DAL Toolbox *Experiment Line*.
|
|
6
|
+
|
|
7
|
+
`pyharbinger` unifies many detection methods under one interface (`fit` → `detect` →
|
|
8
|
+
`evaluate`) and a common evaluation protocol, so different detectors can be compared fairly —
|
|
9
|
+
reusing classic libraries (scikit-learn, numpy, pandas, scipy, ruptures) through thin
|
|
10
|
+
adapters.
|
|
11
|
+
|
|
12
|
+
It is the capstone of the DAL Python family:
|
|
13
|
+
|
|
14
|
+
- Builds on **[pydaltoolbox](https://github.com/cefet-rj-dal/pydaltoolbox)** (foundation) and
|
|
15
|
+
**[pytspredit](https://github.com/cefet-rj-dal/pytspredit)** (time series prediction) — its
|
|
16
|
+
regressors power the forecasting-based anomaly detectors.
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
pip install pyharbinger
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Quickstart
|
|
25
|
+
|
|
26
|
+
```python
|
|
27
|
+
from pyharbinger import HanrFft, HarEval, datasets
|
|
28
|
+
|
|
29
|
+
# a labeled example series (one injected anomaly)
|
|
30
|
+
dataset = datasets.examples_anomalies()["simple"]
|
|
31
|
+
serie, event = dataset["serie"], dataset["event"]
|
|
32
|
+
|
|
33
|
+
# fit -> detect -> evaluate
|
|
34
|
+
model = HanrFft().fit(serie)
|
|
35
|
+
detection = model.detect(serie)
|
|
36
|
+
print(detection[detection["event"]])
|
|
37
|
+
|
|
38
|
+
metrics = model.evaluate(detection, event)
|
|
39
|
+
print(metrics["confMatrix"])
|
|
40
|
+
print("F1:", metrics["F1"])
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## What's included (v1)
|
|
44
|
+
|
|
45
|
+
Every detector extends `Harbinger` and returns a detection table with columns
|
|
46
|
+
`idx` / `event` / `type` (`"anomaly"`, `"changepoint"`, `"discord"` or `""`).
|
|
47
|
+
|
|
48
|
+
| Group | Classes |
|
|
49
|
+
|---|---|
|
|
50
|
+
| **Core** | `Harbinger` (base contract), deviation / filter / candidate-selection utilities |
|
|
51
|
+
| **Evaluation** | `HarEval` (hard), `HarEvalSoft` (SoftED, soft matching via the Hungarian algorithm) |
|
|
52
|
+
| **Anomaly** | `HanrMl` (forecasting residuals, wraps a pytspredit regressor), `HanrFft`, `HanrHistogram`, `HanrFbiad` |
|
|
53
|
+
| **Change point** | `HcpAmoc`, `HcpBinseg`, `HcpPelt` (via `ruptures`), `HcpKswin`, `HcpPageHinkley` |
|
|
54
|
+
| **Clustering** | `HanctKmeans` (anomalies / discords) |
|
|
55
|
+
| **Datasets** | `datasets.examples_anomalies()`, `datasets.examples_changepoints()` |
|
|
56
|
+
|
|
57
|
+
### Deferred to a future release (0.2.0 / Block B)
|
|
58
|
+
|
|
59
|
+
ML-classification detector (`hanc_ml`), motif/discord via matrix profile
|
|
60
|
+
(`hdis_mp`/`hmo_mp`), ARIMA/GARCH/EMD/wavelet anomaly detectors, DTW clustering,
|
|
61
|
+
SAX representations, ensembles, streaming/online runners, and plotting helpers.
|
|
62
|
+
|
|
63
|
+
## Faithfulness to R
|
|
64
|
+
|
|
65
|
+
The port is validated against the R package on the same data at every step.
|
|
66
|
+
Deterministic components match R to numerical precision (deviation measures,
|
|
67
|
+
filters, candidate selection, hard/soft evaluation, FFT/histogram/FBIAD
|
|
68
|
+
detectors, `HanrMl` with a deterministic regressor, `HanctKmeans` centroids
|
|
69
|
+
count, and `HcpPageHinkley`). Where the backend or RNG differs, the tolerance is
|
|
70
|
+
documented:
|
|
71
|
+
|
|
72
|
+
- `HanrMl` with a rank-reduced ELM (`nhid < input_size`, `purelin`) depends on
|
|
73
|
+
the hidden-weight RNG.
|
|
74
|
+
- `HanctKmeans` and `HcpKswin` depend on initialization / random-subsample RNG.
|
|
75
|
+
- `HcpAmoc`/`HcpBinseg`/`HcpPelt` use `ruptures` (Gaussian cost); R uses
|
|
76
|
+
`changepoint::cpt.meanvar` with the MBIC penalty, so agreement is approximate.
|
|
77
|
+
|
|
78
|
+
## Related DAL projects
|
|
79
|
+
|
|
80
|
+
- [pydaltoolbox](https://github.com/cefet-rj-dal/pydaltoolbox) — foundation (Python)
|
|
81
|
+
- [pytspredit](https://github.com/cefet-rj-dal/pytspredit) — time series prediction (Python)
|
|
82
|
+
- [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
|
|
83
|
+
- [Data Analytics Lab](https://eic.cefet-rj.br/~dal/)
|
|
84
|
+
|
|
85
|
+
## License
|
|
86
|
+
|
|
87
|
+
MIT
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "pyharbinger"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "A unified time series event detection framework (Python port of the R harbinger framework)"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.9"
|
|
11
|
+
license = { text = "MIT" }
|
|
12
|
+
authors = [
|
|
13
|
+
{ name = "Eduardo Ogasawara", email = "eogasawara@ieee.org" },
|
|
14
|
+
]
|
|
15
|
+
keywords = [
|
|
16
|
+
"time series",
|
|
17
|
+
"event detection",
|
|
18
|
+
"anomaly detection",
|
|
19
|
+
"change point",
|
|
20
|
+
"experiment line",
|
|
21
|
+
"scikit-learn",
|
|
22
|
+
]
|
|
23
|
+
classifiers = [
|
|
24
|
+
"Development Status :: 3 - Alpha",
|
|
25
|
+
"Intended Audience :: Science/Research",
|
|
26
|
+
"License :: OSI Approved :: MIT License",
|
|
27
|
+
"Programming Language :: Python :: 3",
|
|
28
|
+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
|
|
29
|
+
]
|
|
30
|
+
dependencies = [
|
|
31
|
+
"numpy>=1.23",
|
|
32
|
+
"pandas>=1.5",
|
|
33
|
+
"scikit-learn>=1.2",
|
|
34
|
+
"scipy>=1.9",
|
|
35
|
+
"ruptures>=1.0",
|
|
36
|
+
"pydaltoolbox>=0.1.0",
|
|
37
|
+
"pytspredit>=0.1.0",
|
|
38
|
+
]
|
|
39
|
+
|
|
40
|
+
[project.optional-dependencies]
|
|
41
|
+
dev = ["pytest>=7", "ruff>=0.1", "build", "twine"]
|
|
42
|
+
docs = ["jupytext>=1.16", "nbconvert>=7", "nbclient>=0.9", "ipykernel>=6"]
|
|
43
|
+
|
|
44
|
+
[project.urls]
|
|
45
|
+
Homepage = "https://github.com/cefet-rj-dal/pyharbinger"
|
|
46
|
+
Repository = "https://github.com/cefet-rj-dal/pyharbinger"
|
|
47
|
+
"Bug Tracker" = "https://github.com/cefet-rj-dal/pyharbinger/issues"
|
|
48
|
+
|
|
49
|
+
[tool.hatch.build.targets.wheel]
|
|
50
|
+
packages = ["src/pyharbinger"]
|
|
51
|
+
|
|
52
|
+
# The published source distribution ships only the package and essential metadata.
|
|
53
|
+
# Development-only material (develop/, notebooks/, examples/, tests/, tools/) is kept
|
|
54
|
+
# out of what users install.
|
|
55
|
+
[tool.hatch.build.targets.sdist]
|
|
56
|
+
include = ["src/pyharbinger", "README.md", "LICENSE"]
|
|
57
|
+
exclude = ["develop", "notebooks", "examples", "tests", "tools"]
|
|
58
|
+
|
|
59
|
+
[tool.pytest.ini_options]
|
|
60
|
+
testpaths = ["tests"]
|
|
61
|
+
addopts = "-q"
|
|
62
|
+
|
|
63
|
+
[tool.ruff]
|
|
64
|
+
line-length = 100
|
|
65
|
+
target-version = "py39"
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"""pyharbinger -- A unified time series event detection framework.
|
|
2
|
+
|
|
3
|
+
Python port of the R ``harbinger`` framework, the capstone of the DAL family.
|
|
4
|
+
It builds on ``pydaltoolbox`` (the Experiment Line foundation) and ``pytspredit``
|
|
5
|
+
(time series prediction) to unify many event-detection methods -- anomalies,
|
|
6
|
+
change points, and motifs/discords -- under one interface (``fit`` -> ``detect``
|
|
7
|
+
-> ``evaluate``) and a common evaluation protocol, wrapping numpy / pandas /
|
|
8
|
+
scikit-learn / scipy / ruptures with thin adapters.
|
|
9
|
+
"""
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
from . import datasets, utils
|
|
13
|
+
from .anomaly import HanrFbiad, HanrFft, HanrHistogram, HanrMl
|
|
14
|
+
from .changepoint import HcpAmoc, HcpBinseg, HcpKswin, HcpPageHinkley, HcpPelt
|
|
15
|
+
from .clustering import HanctKmeans
|
|
16
|
+
from .evaluation import HarEval, HarEvalSoft
|
|
17
|
+
from .harbinger import Harbinger
|
|
18
|
+
from .utils import (
|
|
19
|
+
har_candidate_selection_firstgroup,
|
|
20
|
+
har_candidate_selection_highgroup,
|
|
21
|
+
har_candidate_selection_referencedistribution,
|
|
22
|
+
har_deviation_huber,
|
|
23
|
+
har_deviation_l1,
|
|
24
|
+
har_deviation_l2,
|
|
25
|
+
har_filter_boxplot,
|
|
26
|
+
har_filter_gaussian,
|
|
27
|
+
har_filter_grubbs,
|
|
28
|
+
har_filter_mad,
|
|
29
|
+
har_filter_none,
|
|
30
|
+
har_filter_ratio,
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
__version__ = "0.1.0"
|
|
34
|
+
|
|
35
|
+
__all__ = [
|
|
36
|
+
"HanctKmeans",
|
|
37
|
+
"HanrFbiad",
|
|
38
|
+
"HanrFft",
|
|
39
|
+
"HanrHistogram",
|
|
40
|
+
"HanrMl",
|
|
41
|
+
"HarEval",
|
|
42
|
+
"HarEvalSoft",
|
|
43
|
+
"Harbinger",
|
|
44
|
+
"HcpAmoc",
|
|
45
|
+
"HcpBinseg",
|
|
46
|
+
"HcpKswin",
|
|
47
|
+
"HcpPageHinkley",
|
|
48
|
+
"HcpPelt",
|
|
49
|
+
"datasets",
|
|
50
|
+
"har_candidate_selection_firstgroup",
|
|
51
|
+
"har_candidate_selection_highgroup",
|
|
52
|
+
"har_candidate_selection_referencedistribution",
|
|
53
|
+
"har_deviation_huber",
|
|
54
|
+
"har_deviation_l1",
|
|
55
|
+
"har_deviation_l2",
|
|
56
|
+
"har_filter_boxplot",
|
|
57
|
+
"har_filter_gaussian",
|
|
58
|
+
"har_filter_grubbs",
|
|
59
|
+
"har_filter_mad",
|
|
60
|
+
"har_filter_none",
|
|
61
|
+
"har_filter_ratio",
|
|
62
|
+
"utils",
|
|
63
|
+
]
|