mvtsa 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.
- mvtsa-1.0/.gitignore +48 -0
- mvtsa-1.0/CHANGELOG.md +23 -0
- mvtsa-1.0/CITATION.cff +66 -0
- mvtsa-1.0/LICENSE +21 -0
- mvtsa-1.0/PKG-INFO +171 -0
- mvtsa-1.0/README.md +85 -0
- mvtsa-1.0/examples/01_basics/README.rst +2 -0
- mvtsa-1.0/examples/01_basics/plot_01_first_steps.py +51 -0
- mvtsa-1.0/examples/01_basics/plot_02_representations.py +53 -0
- mvtsa-1.0/examples/01_basics/plot_03_pca_models.py +75 -0
- mvtsa-1.0/examples/02_cost_segmentation/README.rst +2 -0
- mvtsa-1.0/examples/02_cost_segmentation/plot_01_costs_and_search.py +87 -0
- mvtsa-1.0/examples/02_cost_segmentation/plot_02_segmentogram.py +45 -0
- mvtsa-1.0/examples/02_cost_segmentation/plot_03_number_of_segments.py +54 -0
- mvtsa-1.0/examples/03_latent_segmentation/README.rst +2 -0
- mvtsa-1.0/examples/03_latent_segmentation/plot_01_pca_t2_q.py +67 -0
- mvtsa-1.0/examples/03_latent_segmentation/plot_02_dynamic_pca.py +91 -0
- mvtsa-1.0/examples/03_latent_segmentation/plot_03_recursive_pca.py +88 -0
- mvtsa-1.0/examples/03_latent_segmentation/plot_04_fuzzy_segmentation.py +52 -0
- mvtsa-1.0/examples/03_latent_segmentation/plot_05_fisher_mma.py +87 -0
- mvtsa-1.0/examples/03_latent_segmentation/plot_06_energy_regression.py +57 -0
- mvtsa-1.0/examples/04_modern_segmentation/README.rst +2 -0
- mvtsa-1.0/examples/04_modern_segmentation/plot_01_bocpd.py +58 -0
- mvtsa-1.0/examples/04_modern_segmentation/plot_02_states.py +77 -0
- mvtsa-1.0/examples/04_modern_segmentation/plot_03_clasp_fluss.py +63 -0
- mvtsa-1.0/examples/04_modern_segmentation/plot_04_predictive.py +58 -0
- mvtsa-1.0/examples/04_modern_segmentation/plot_05_consensus.py +54 -0
- mvtsa-1.0/examples/04_modern_segmentation/plot_06_streaming.py +52 -0
- mvtsa-1.0/examples/05_warping/README.rst +2 -0
- mvtsa-1.0/examples/05_warping/plot_01_dtw_basics.py +79 -0
- mvtsa-1.0/examples/05_warping/plot_02_dtw_variants.py +65 -0
- mvtsa-1.0/examples/05_warping/plot_03_soft_dtw.py +74 -0
- mvtsa-1.0/examples/05_warping/plot_04_diagnostics_learning.py +65 -0
- mvtsa-1.0/examples/06_correlation_warping/README.rst +2 -0
- mvtsa-1.0/examples/06_correlation_warping/plot_01_cbdtw_signatures.py +76 -0
- mvtsa-1.0/examples/06_correlation_warping/plot_02_correlation_sequences.py +62 -0
- mvtsa-1.0/examples/06_correlation_warping/plot_03_dynamic_cbdtw.py +67 -0
- mvtsa-1.0/examples/06_correlation_warping/plot_04_japanese_vowels.py +89 -0
- mvtsa-1.0/examples/06_correlation_warping/plot_05_pla_mdpla.py +80 -0
- mvtsa-1.0/examples/06_correlation_warping/plot_06_mixed_segments.py +81 -0
- mvtsa-1.0/examples/06_correlation_warping/plot_07_episodes.py +63 -0
- mvtsa-1.0/examples/07_clustering/README.rst +2 -0
- mvtsa-1.0/examples/07_clustering/plot_01_partitional.py +56 -0
- mvtsa-1.0/examples/07_clustering/plot_02_hierarchical_maps.py +66 -0
- mvtsa-1.0/examples/07_clustering/plot_03_basic_motions.py +64 -0
- mvtsa-1.0/examples/07_clustering/plot_04_segment_clustering.py +65 -0
- mvtsa-1.0/examples/07_clustering/plot_05_trajectories.py +49 -0
- mvtsa-1.0/examples/08_evaluation/README.rst +2 -0
- mvtsa-1.0/examples/08_evaluation/plot_01_metrics.py +69 -0
- mvtsa-1.0/examples/08_evaluation/plot_02_stability.py +82 -0
- mvtsa-1.0/examples/08_evaluation/plot_03_benchmark.py +72 -0
- mvtsa-1.0/examples/08_evaluation/plot_04_tuning.py +74 -0
- mvtsa-1.0/examples/09_visualization/README.rst +2 -0
- mvtsa-1.0/examples/09_visualization/plot_01_dashboard.py +42 -0
- mvtsa-1.0/examples/09_visualization/plot_02_visibility_graphs.py +75 -0
- mvtsa-1.0/examples/09_visualization/plot_03_recurrence_images.py +68 -0
- mvtsa-1.0/examples/09_visualization/plot_04_warping_maps.py +48 -0
- mvtsa-1.0/examples/10_mlops/README.rst +2 -0
- mvtsa-1.0/examples/10_mlops/plot_01_pipeline_registry.py +72 -0
- mvtsa-1.0/examples/10_mlops/plot_02_drift_monitoring.py +72 -0
- mvtsa-1.0/examples/10_mlops/plot_03_tracking_cards.py +75 -0
- mvtsa-1.0/examples/11_applications/README.rst +2 -0
- mvtsa-1.0/examples/11_applications/plot_01_polymer_grades.py +101 -0
- mvtsa-1.0/examples/11_applications/plot_02_ph_process.py +53 -0
- mvtsa-1.0/examples/11_applications/plot_03_regime_explanation.py +56 -0
- mvtsa-1.0/examples/README.rst +10 -0
- mvtsa-1.0/pyproject.toml +86 -0
- mvtsa-1.0/src/mvtsa/__init__.py +51 -0
- mvtsa-1.0/src/mvtsa/_base.py +348 -0
- mvtsa-1.0/src/mvtsa/_numba.py +46 -0
- mvtsa-1.0/src/mvtsa/cli.py +125 -0
- mvtsa-1.0/src/mvtsa/clustering/__init__.py +15 -0
- mvtsa-1.0/src/mvtsa/clustering/distance_based.py +182 -0
- mvtsa-1.0/src/mvtsa/clustering/feature_based.py +215 -0
- mvtsa-1.0/src/mvtsa/clustering/partitional.py +330 -0
- mvtsa-1.0/src/mvtsa/datasets/__init__.py +10 -0
- mvtsa-1.0/src/mvtsa/datasets/_bundled.py +59 -0
- mvtsa-1.0/src/mvtsa/datasets/data/README.md +22 -0
- mvtsa-1.0/src/mvtsa/datasets/data/basicmotions.npz +0 -0
- mvtsa-1.0/src/mvtsa/datasets/data/gunpoint.npz +0 -0
- mvtsa-1.0/src/mvtsa/datasets/data/japanesevowels.npz +0 -0
- mvtsa-1.0/src/mvtsa/datasets/fetch.py +95 -0
- mvtsa-1.0/src/mvtsa/datasets/generators.py +548 -0
- mvtsa-1.0/src/mvtsa/distances.py +161 -0
- mvtsa-1.0/src/mvtsa/evaluation/__init__.py +42 -0
- mvtsa-1.0/src/mvtsa/evaluation/clustering_metrics.py +141 -0
- mvtsa-1.0/src/mvtsa/evaluation/segmentation_metrics.py +143 -0
- mvtsa-1.0/src/mvtsa/evaluation/validation.py +278 -0
- mvtsa-1.0/src/mvtsa/explain.py +158 -0
- mvtsa-1.0/src/mvtsa/io.py +147 -0
- mvtsa-1.0/src/mvtsa/mlops/__init__.py +11 -0
- mvtsa-1.0/src/mvtsa/mlops/config.py +105 -0
- mvtsa-1.0/src/mvtsa/mlops/monitoring.py +229 -0
- mvtsa-1.0/src/mvtsa/mlops/pipeline.py +156 -0
- mvtsa-1.0/src/mvtsa/mlops/registry.py +280 -0
- mvtsa-1.0/src/mvtsa/preprocessing.py +363 -0
- mvtsa-1.0/src/mvtsa/representation/__init__.py +77 -0
- mvtsa-1.0/src/mvtsa/representation/episodes.py +193 -0
- mvtsa-1.0/src/mvtsa/representation/features.py +168 -0
- mvtsa-1.0/src/mvtsa/representation/graphs.py +207 -0
- mvtsa-1.0/src/mvtsa/representation/images.py +107 -0
- mvtsa-1.0/src/mvtsa/representation/matrix_profile.py +107 -0
- mvtsa-1.0/src/mvtsa/representation/pca_models.py +496 -0
- mvtsa-1.0/src/mvtsa/representation/piecewise.py +149 -0
- mvtsa-1.0/src/mvtsa/representation/spd.py +111 -0
- mvtsa-1.0/src/mvtsa/representation/symbolic.py +152 -0
- mvtsa-1.0/src/mvtsa/segmentation/__init__.py +113 -0
- mvtsa-1.0/src/mvtsa/segmentation/bayesian.py +176 -0
- mvtsa-1.0/src/mvtsa/segmentation/consensus.py +95 -0
- mvtsa-1.0/src/mvtsa/segmentation/costs.py +518 -0
- mvtsa-1.0/src/mvtsa/segmentation/fisher.py +294 -0
- mvtsa-1.0/src/mvtsa/segmentation/fuzzy.py +236 -0
- mvtsa-1.0/src/mvtsa/segmentation/hmm.py +219 -0
- mvtsa-1.0/src/mvtsa/segmentation/latent.py +435 -0
- mvtsa-1.0/src/mvtsa/segmentation/neighbors.py +209 -0
- mvtsa-1.0/src/mvtsa/segmentation/online.py +133 -0
- mvtsa-1.0/src/mvtsa/segmentation/predictive.py +183 -0
- mvtsa-1.0/src/mvtsa/segmentation/profiles.py +232 -0
- mvtsa-1.0/src/mvtsa/segmentation/search.py +602 -0
- mvtsa-1.0/src/mvtsa/segmentation/selection.py +176 -0
- mvtsa-1.0/src/mvtsa/segmentation/states.py +279 -0
- mvtsa-1.0/src/mvtsa/simplify.py +192 -0
- mvtsa-1.0/src/mvtsa/viz/__init__.py +50 -0
- mvtsa-1.0/src/mvtsa/viz/_style.py +54 -0
- mvtsa-1.0/src/mvtsa/viz/clustering.py +201 -0
- mvtsa-1.0/src/mvtsa/viz/evaluation.py +144 -0
- mvtsa-1.0/src/mvtsa/viz/representation.py +135 -0
- mvtsa-1.0/src/mvtsa/viz/segmentation.py +189 -0
- mvtsa-1.0/src/mvtsa/viz/series.py +164 -0
- mvtsa-1.0/src/mvtsa/viz/warping.py +135 -0
- mvtsa-1.0/src/mvtsa/warping/__init__.py +54 -0
- mvtsa-1.0/src/mvtsa/warping/_dp.py +330 -0
- mvtsa-1.0/src/mvtsa/warping/alignment.py +161 -0
- mvtsa-1.0/src/mvtsa/warping/averaging.py +106 -0
- mvtsa-1.0/src/mvtsa/warping/diagnostics.py +110 -0
- mvtsa-1.0/src/mvtsa/warping/dtw.py +316 -0
- mvtsa-1.0/src/mvtsa/warping/elastic.py +173 -0
- mvtsa-1.0/src/mvtsa/warping/learning.py +141 -0
- mvtsa-1.0/src/mvtsa/warping/segment_dtw.py +471 -0
- mvtsa-1.0/tests/conftest.py +19 -0
- mvtsa-1.0/tests/test_base_preprocessing.py +80 -0
- mvtsa-1.0/tests/test_clustering.py +62 -0
- mvtsa-1.0/tests/test_evaluation_explain_simplify.py +120 -0
- mvtsa-1.0/tests/test_mlops_io_cli_viz.py +230 -0
- mvtsa-1.0/tests/test_representation.py +151 -0
- mvtsa-1.0/tests/test_segmentation.py +253 -0
- mvtsa-1.0/tests/test_warping.py +225 -0
mvtsa-1.0/.gitignore
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
__pycache__/
|
|
2
|
+
*.pyc
|
|
3
|
+
*.egg-info/
|
|
4
|
+
dist/
|
|
5
|
+
build/
|
|
6
|
+
.pytest_cache/
|
|
7
|
+
.ruff_cache/
|
|
8
|
+
docs/_build/
|
|
9
|
+
docs/auto_examples/
|
|
10
|
+
docs/gen_modules/
|
|
11
|
+
docs/sg_execution_times.rst
|
|
12
|
+
book/figures/
|
|
13
|
+
book/*.aux
|
|
14
|
+
book/*.log
|
|
15
|
+
book/*.out
|
|
16
|
+
book/*.toc
|
|
17
|
+
book/*.bbl
|
|
18
|
+
book/*.bcf
|
|
19
|
+
book/*.blg
|
|
20
|
+
book/*.run.xml
|
|
21
|
+
book/*.idx
|
|
22
|
+
book/*.ilg
|
|
23
|
+
book/*.ind
|
|
24
|
+
book/*.fls
|
|
25
|
+
book/*.fdb_latexmk
|
|
26
|
+
book/*.synctex.gz
|
|
27
|
+
book/main.pdf
|
|
28
|
+
*.ipynb_checkpoints
|
|
29
|
+
book/_check_tmp/
|
|
30
|
+
book/_check.tex
|
|
31
|
+
docs/_build/
|
|
32
|
+
docs/api/generated/
|
|
33
|
+
docs/_build_log.txt
|
|
34
|
+
book/_build/
|
|
35
|
+
.coverage
|
|
36
|
+
book/_build_new/
|
|
37
|
+
book/_check_*.tex
|
|
38
|
+
book/cover/*.aux
|
|
39
|
+
book/cover/*.log
|
|
40
|
+
book/cover/*.fls
|
|
41
|
+
book/cover/*.fdb_latexmk
|
|
42
|
+
book/cover/*.pdf
|
|
43
|
+
book/cover/*.png
|
|
44
|
+
book/cover/logo.svg
|
|
45
|
+
*.blg
|
|
46
|
+
book/_build_epub/
|
|
47
|
+
book/_build_web/
|
|
48
|
+
docs/_gallery_src/
|
mvtsa-1.0/CHANGELOG.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 1.0 (2026-11-29)
|
|
4
|
+
|
|
5
|
+
First public release.
|
|
6
|
+
|
|
7
|
+
* Segmentation: 8 costs × 7 search strategies with a merge hierarchy
|
|
8
|
+
(segmentogram, persistence, relative reduction rate); PCA, dynamic-PCA,
|
|
9
|
+
Krzanowski, recursive-PCA (with retrospective localization), modified
|
|
10
|
+
Gath–Geva fuzzy and Fisher-information segmentation; BOCPD, sticky Gaussian
|
|
11
|
+
HMM, sparse Gaussian states, ClaSP and FLUSS (half-window centred), state,
|
|
12
|
+
predictive, consensus, streaming and CUSUM segmenters; five rules for the
|
|
13
|
+
number of segments.
|
|
14
|
+
* Warping: DTW family with compiled kernels, edit and kernel measures,
|
|
15
|
+
soft-DTW with expected alignments, correlation-based DTW with static and
|
|
16
|
+
dynamic PCA and Riemannian or mixed segment distances, MPLA/SPLA/MDPLA,
|
|
17
|
+
episode alignment, barycenters, diagnostics and learning.
|
|
18
|
+
* Clustering, representations, evaluation, simplification, explanation,
|
|
19
|
+
visualization and model operations (pipelines, registry, tracking, contracts,
|
|
20
|
+
drift monitoring, model cards, command line).
|
|
21
|
+
* Data: generators, pH and MMA reactor simulators, three bundled UEA & UCR
|
|
22
|
+
collections and fetchers.
|
|
23
|
+
* 48 gallery examples; companion book.
|
mvtsa-1.0/CITATION.cff
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
cff-version: 1.2.0
|
|
2
|
+
message: "If you use mvtsa, please cite it as below, together with the original publications of the methods you use."
|
|
3
|
+
type: software
|
|
4
|
+
title: "mvtsa: segmentation, warping and clustering of multivariate time series in Python"
|
|
5
|
+
version: "1.0"
|
|
6
|
+
date-released: 2026-11-29
|
|
7
|
+
license: MIT
|
|
8
|
+
repository-code: "https://github.com/ComplexSystemsIntelligence/mvtsa"
|
|
9
|
+
url: "https://complexsystemsintelligence.github.io/mvtsa"
|
|
10
|
+
authors:
|
|
11
|
+
- family-names: Abonyi
|
|
12
|
+
given-names: János
|
|
13
|
+
affiliation: "University of Pannonia, Veszprém, Hungary"
|
|
14
|
+
orcid: "https://orcid.org/0000-0001-8593-1493"
|
|
15
|
+
keywords:
|
|
16
|
+
- multivariate time series
|
|
17
|
+
- time series segmentation
|
|
18
|
+
- change point detection
|
|
19
|
+
- dynamic time warping
|
|
20
|
+
- time series clustering
|
|
21
|
+
- principal component analysis
|
|
22
|
+
- process data
|
|
23
|
+
references:
|
|
24
|
+
- type: article
|
|
25
|
+
title: "Modified Gath-Geva clustering for fuzzy segmentation of multivariate time-series"
|
|
26
|
+
authors:
|
|
27
|
+
- family-names: Abonyi
|
|
28
|
+
given-names: János
|
|
29
|
+
- family-names: Feil
|
|
30
|
+
given-names: Balázs
|
|
31
|
+
- family-names: Németh
|
|
32
|
+
given-names: Sándor
|
|
33
|
+
- family-names: Árva
|
|
34
|
+
given-names: Péter
|
|
35
|
+
journal: "Fuzzy Sets and Systems"
|
|
36
|
+
volume: 149
|
|
37
|
+
issue: 1
|
|
38
|
+
start: 39
|
|
39
|
+
end: 56
|
|
40
|
+
year: 2005
|
|
41
|
+
- type: article
|
|
42
|
+
title: "Correlation based dynamic time warping of multivariate time series"
|
|
43
|
+
authors:
|
|
44
|
+
- family-names: Bankó
|
|
45
|
+
given-names: Zoltán
|
|
46
|
+
- family-names: Abonyi
|
|
47
|
+
given-names: János
|
|
48
|
+
journal: "Expert Systems with Applications"
|
|
49
|
+
volume: 39
|
|
50
|
+
issue: 17
|
|
51
|
+
start: 12814
|
|
52
|
+
end: 12823
|
|
53
|
+
year: 2012
|
|
54
|
+
doi: 10.1016/j.eswa.2012.05.012
|
|
55
|
+
- type: article
|
|
56
|
+
title: "On-line detection of homogeneous operation ranges by dynamic principal component analysis based time-series segmentation"
|
|
57
|
+
authors:
|
|
58
|
+
- family-names: Dobos
|
|
59
|
+
given-names: László
|
|
60
|
+
- family-names: Abonyi
|
|
61
|
+
given-names: János
|
|
62
|
+
journal: "Chemical Engineering Science"
|
|
63
|
+
volume: 75
|
|
64
|
+
start: 96
|
|
65
|
+
end: 105
|
|
66
|
+
year: 2012
|
mvtsa-1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 János Abonyi
|
|
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.
|
mvtsa-1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: mvtsa
|
|
3
|
+
Version: 1.0
|
|
4
|
+
Summary: Multivariate time series analysis: segmentation (PCA, dynamic PCA, recursive PCA, fuzzy, Fisher-information, cost-based, Bayesian, HMM, self-supervised, consensus), elastic similarity and warping (DTW family, correlation-based DTW, MDPLA, soft-DTW, edit distances, episode alignment), clustering, representations, evaluation, visualization and MLOps tools.
|
|
5
|
+
Project-URL: Homepage, https://github.com/ComplexSystemsIntelligence/mvtsa
|
|
6
|
+
Project-URL: Documentation, https://complexsystemsintelligence.github.io/mvtsa
|
|
7
|
+
Project-URL: Repository, https://github.com/ComplexSystemsIntelligence/mvtsa
|
|
8
|
+
Project-URL: Issues, https://github.com/ComplexSystemsIntelligence/mvtsa/issues
|
|
9
|
+
Project-URL: Changelog, https://github.com/ComplexSystemsIntelligence/mvtsa/blob/main/CHANGELOG.md
|
|
10
|
+
Project-URL: Book (PDF), https://complexsystemsintelligence.github.io/mvtsa/mvtsa-book.pdf
|
|
11
|
+
Author-email: János Abonyi <janos@abonyilab.com>
|
|
12
|
+
License-Expression: MIT
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Keywords: MLOps,change point detection,correlation-based dynamic time warping,dynamic PCA,dynamic time warping,elastic distances,multivariate time series,principal component analysis,process monitoring,segmentation,state detection,time series,time series clustering
|
|
15
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
16
|
+
Classifier: Intended Audience :: Science/Research
|
|
17
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
18
|
+
Classifier: Operating System :: OS Independent
|
|
19
|
+
Classifier: Programming Language :: Python :: 3
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
24
|
+
Classifier: Topic :: Scientific/Engineering
|
|
25
|
+
Classifier: Topic :: Scientific/Engineering :: Information Analysis
|
|
26
|
+
Classifier: Topic :: Scientific/Engineering :: Mathematics
|
|
27
|
+
Requires-Python: >=3.10
|
|
28
|
+
Requires-Dist: matplotlib>=3.7
|
|
29
|
+
Requires-Dist: networkx>=3.0
|
|
30
|
+
Requires-Dist: numpy>=1.24
|
|
31
|
+
Requires-Dist: pandas>=2.0
|
|
32
|
+
Requires-Dist: scikit-learn>=1.3
|
|
33
|
+
Requires-Dist: scipy>=1.11
|
|
34
|
+
Provides-Extra: all
|
|
35
|
+
Requires-Dist: mlflow>=2.8; extra == 'all'
|
|
36
|
+
Requires-Dist: numba>=0.58; extra == 'all'
|
|
37
|
+
Requires-Dist: plotly>=5.15; extra == 'all'
|
|
38
|
+
Requires-Dist: pyyaml>=6.0; extra == 'all'
|
|
39
|
+
Requires-Dist: ruptures>=1.1; extra == 'all'
|
|
40
|
+
Requires-Dist: stumpy>=1.12; extra == 'all'
|
|
41
|
+
Provides-Extra: book
|
|
42
|
+
Requires-Dist: beautifulsoup4>=4.12; extra == 'book'
|
|
43
|
+
Requires-Dist: lxml; extra == 'book'
|
|
44
|
+
Requires-Dist: numba>=0.58; extra == 'book'
|
|
45
|
+
Requires-Dist: pillow; extra == 'book'
|
|
46
|
+
Requires-Dist: pyyaml>=6.0; extra == 'book'
|
|
47
|
+
Provides-Extra: dev
|
|
48
|
+
Requires-Dist: build; extra == 'dev'
|
|
49
|
+
Requires-Dist: myst-parser; extra == 'dev'
|
|
50
|
+
Requires-Dist: numba>=0.58; extra == 'dev'
|
|
51
|
+
Requires-Dist: numpydoc; extra == 'dev'
|
|
52
|
+
Requires-Dist: pydata-sphinx-theme; extra == 'dev'
|
|
53
|
+
Requires-Dist: pytest-cov; extra == 'dev'
|
|
54
|
+
Requires-Dist: pytest>=7; extra == 'dev'
|
|
55
|
+
Requires-Dist: pyyaml>=6.0; extra == 'dev'
|
|
56
|
+
Requires-Dist: ruff; extra == 'dev'
|
|
57
|
+
Requires-Dist: sphinx-copybutton; extra == 'dev'
|
|
58
|
+
Requires-Dist: sphinx-design; extra == 'dev'
|
|
59
|
+
Requires-Dist: sphinx-gallery>=0.15; extra == 'dev'
|
|
60
|
+
Requires-Dist: sphinx>=7; extra == 'dev'
|
|
61
|
+
Requires-Dist: twine; extra == 'dev'
|
|
62
|
+
Provides-Extra: docs
|
|
63
|
+
Requires-Dist: myst-parser; extra == 'docs'
|
|
64
|
+
Requires-Dist: numba>=0.58; extra == 'docs'
|
|
65
|
+
Requires-Dist: numpydoc; extra == 'docs'
|
|
66
|
+
Requires-Dist: pydata-sphinx-theme; extra == 'docs'
|
|
67
|
+
Requires-Dist: sphinx-copybutton; extra == 'docs'
|
|
68
|
+
Requires-Dist: sphinx-design; extra == 'docs'
|
|
69
|
+
Requires-Dist: sphinx-gallery>=0.15; extra == 'docs'
|
|
70
|
+
Requires-Dist: sphinx>=7; extra == 'docs'
|
|
71
|
+
Provides-Extra: fast
|
|
72
|
+
Requires-Dist: numba>=0.58; extra == 'fast'
|
|
73
|
+
Provides-Extra: interactive
|
|
74
|
+
Requires-Dist: plotly>=5.15; extra == 'interactive'
|
|
75
|
+
Provides-Extra: interop
|
|
76
|
+
Requires-Dist: ruptures>=1.1; extra == 'interop'
|
|
77
|
+
Requires-Dist: stumpy>=1.12; extra == 'interop'
|
|
78
|
+
Provides-Extra: mlops
|
|
79
|
+
Requires-Dist: mlflow>=2.8; extra == 'mlops'
|
|
80
|
+
Requires-Dist: pyyaml>=6.0; extra == 'mlops'
|
|
81
|
+
Provides-Extra: test
|
|
82
|
+
Requires-Dist: pytest-cov; extra == 'test'
|
|
83
|
+
Requires-Dist: pytest>=7; extra == 'test'
|
|
84
|
+
Requires-Dist: pyyaml>=6.0; extra == 'test'
|
|
85
|
+
Description-Content-Type: text/markdown
|
|
86
|
+
|
|
87
|
+
<p align="center"><img src="https://raw.githubusercontent.com/ComplexSystemsIntelligence/mvtsa/main/docs/_static/banner.png" alt="mvtsa: segmentation, warping and clustering of multivariate time series"></p>
|
|
88
|
+
|
|
89
|
+
# mvtsa: segmentation, warping and clustering of multivariate time series
|
|
90
|
+
|
|
91
|
+
[](https://github.com/ComplexSystemsIntelligence/mvtsa/actions/workflows/ci.yml)
|
|
92
|
+
[](https://complexsystemsintelligence.github.io/mvtsa)
|
|
93
|
+
[](https://complexsystemsintelligence.github.io/mvtsa/book.html)
|
|
94
|
+
[](https://github.com/ComplexSystemsIntelligence/mvtsa/blob/main/LICENSE)
|
|
95
|
+
|
|
96
|
+
**mvtsa** cuts multivariate time series into homogeneous segments, compares
|
|
97
|
+
series whose time axes do not agree, and groups them. It implements the
|
|
98
|
+
segmentation and warping methods developed by the group of János Abonyi at the
|
|
99
|
+
University of Pannonia over two decades — PCA and dynamic-PCA segmentation, the
|
|
100
|
+
modified Gath–Geva fuzzy segmentation, recursive-PCA on-line segmentation,
|
|
101
|
+
Fisher-information segmentation for experiment design, correlation-based
|
|
102
|
+
dynamic time warping, mixed piecewise-linear measures and episode alignment —
|
|
103
|
+
next to the strongest methods of the field and several new ones, with tools to
|
|
104
|
+
evaluate, validate, explain, simplify and operate the resulting models.
|
|
105
|
+
|
|
106
|
+
| Module | Contents |
|
|
107
|
+
|---|---|
|
|
108
|
+
| `mvtsa.segmentation` | costs (L2, L1, Gaussian, linear, AR, kernel, PCA T²/Q, regression) × searches (bottom-up with a merge hierarchy, top-down, sliding window, SWAB, optimal partitioning, PELT, window discrepancy); PCA, dynamic-PCA, Krzanowski and recursive-PCA segmentation; modified Gath–Geva fuzzy segmentation; Fisher-information segmentation; BOCPD; sticky Gaussian HMM; sparse Gaussian states; ClaSP; FLUSS; segment-then-cluster states; predictive homogeneity with any scikit-learn model; consensus; streaming and CUSUM; selection of the number of segments |
|
|
109
|
+
| `mvtsa.warping` | DTW with windows, step patterns, penalties and lower bounds; DTW_I, DDTW, WDTW, ADTW, shapeDTW, FastDTW, subsequence DTW; LCSS, EDR, ERP, TWED, MSM; soft-DTW and its divergence, GAK, SBD; correlation-based DTW (static and dynamic PCA, Riemannian and mixed segment distances); MPLA/SPLA/MDPLA; episode alignment and episode DTW; DBA and soft-DTW barycenters; path statistics, tightness of warping, window learning, elastic ensemble |
|
|
110
|
+
| `mvtsa.clustering` | k-means (Euclidean, DBA, soft-DTW), k-Shape, k-medoids, fuzzy c-medoids, hierarchical, spectral, DBSCAN/HDBSCAN, consensus; feature- and signature-based, segment and trajectory clustering |
|
|
111
|
+
| `mvtsa.representation` | PCA, PPCA, recursive PCA, similarity factors (Krzanowski, λ, Eros), principal angles, SPD geometry; PAA, APCA, PLA, PIP, SAX, ABBA, SFA; triangular episodes; features and path signatures; visibility, six-sigma, ordinal and recurrence networks; recurrence plots, GAF, MTF; matrix and k-NN profiles |
|
|
112
|
+
| `mvtsa.evaluation` | F1 with margin, covering, Hausdorff, annotation error, state ARI/AMI; clustering scores, silhouette, Dunn, partition coefficient; k-NN accuracy, precision–recall curves, mAP; stability, sensitivity, Friedman–Nemenyi, Wilcoxon–Holm; benchmarks and grid search |
|
|
113
|
+
| `mvtsa.simplify`, `mvtsa.explain` | merging short segments, pruning, hierarchy reduction, PLA simplification, compression; variable contributions, segment tables, decision-tree rules of states, regime transition networks |
|
|
114
|
+
| `mvtsa.mlops` | JSON/YAML configurations, analysis pipelines, model files with checksums and data fingerprints, a model registry with stages, experiment tracking (local, optional MLflow), data contracts, drift monitoring, model cards; command line `mvtsa` |
|
|
115
|
+
| `mvtsa.viz` | segmented series, fuzzy memberships, segmentograms, cost curves, PCA statistics and loadings, alignments, cost matrices, alignment uncertainty, prototypes, dendrograms, Sammon and fuzzy Sammon maps, critical-difference diagrams, stability plots, dashboards |
|
|
116
|
+
| `mvtsa.datasets` | generators (piecewise stationary, correlation switching, dynamic switching, recurring regimes, energy, CBF, synthetic control, signatures, motion, correlation and dynamic sequences); pH and MMA polymerization reactor simulators; bundled BasicMotions, JapaneseVowels and GunPoint; UEA & UCR and TSSB fetchers |
|
|
117
|
+
|
|
118
|
+
## Installation
|
|
119
|
+
|
|
120
|
+
```bash
|
|
121
|
+
pip install mvtsa # numpy, scipy, pandas, scikit-learn, matplotlib, networkx
|
|
122
|
+
pip install "mvtsa[fast]" # + numba for the dynamic-programming kernels
|
|
123
|
+
pip install "mvtsa[all]" # + MLflow, YAML, ruptures, stumpy
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## Quick start
|
|
127
|
+
|
|
128
|
+
```python
|
|
129
|
+
import mvtsa as mv
|
|
130
|
+
|
|
131
|
+
# segmentation: four regimes that differ only in their correlation structure
|
|
132
|
+
X, cps, _ = mv.datasets.make_correlation_switching(n_segments=4, length=150)
|
|
133
|
+
seg = mv.segment(X, "pca", n_segments=4, n_components=1) # Q statistic, bottom-up
|
|
134
|
+
print(seg.change_points, cps) # [150 300 450] [150 300 450]
|
|
135
|
+
mv.viz.plot_segmentation(X, seg, truth=cps)
|
|
136
|
+
|
|
137
|
+
# warping: correlation-based DTW of on-line signatures
|
|
138
|
+
C, writer = mv.datasets.make_signatures(n_writers=6, n_per_writer=8)
|
|
139
|
+
D = mv.warping.CBDTW(n_segments=10, n_components=2).fit(C).pairwise()
|
|
140
|
+
print(mv.evaluation.knn_accuracy(D, writer))
|
|
141
|
+
|
|
142
|
+
# clustering on the same distances
|
|
143
|
+
labels = mv.clustering.KMedoids(6, metric="precomputed").fit(D).labels_
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
## Documentation and book
|
|
147
|
+
|
|
148
|
+
* Documentation, gallery of 48 examples and API reference:
|
|
149
|
+
<https://complexsystemsintelligence.github.io/mvtsa>
|
|
150
|
+
* Book *Segmentation, Warping and Clustering of Multivariate Time Series in
|
|
151
|
+
Python* (PDF, EPUB, web), built from the same example scripts:
|
|
152
|
+
<https://complexsystemsintelligence.github.io/mvtsa/book.html>
|
|
153
|
+
|
|
154
|
+
## Citing
|
|
155
|
+
|
|
156
|
+
J. Abonyi, *mvtsa: segmentation, warping and clustering of multivariate time
|
|
157
|
+
series in Python*, version 1.0, 2026 — together with the original publications
|
|
158
|
+
of the methods you use (see `CITATION.cff` and the method lineage page of the
|
|
159
|
+
documentation).
|
|
160
|
+
|
|
161
|
+
## Acknowledgement
|
|
162
|
+
|
|
163
|
+
The research summarized in this package was supported by the National
|
|
164
|
+
Research, Development and Innovation Office of Hungary (NKFIH) through the
|
|
165
|
+
OTKA 143482 project. The package is maintained by the Complex Systems
|
|
166
|
+
Intelligence group ([abonyilab.com](https://www.abonyilab.com)) of the
|
|
167
|
+
University of Pannonia, Veszprém.
|
|
168
|
+
|
|
169
|
+
## License
|
|
170
|
+
|
|
171
|
+
MIT (software); the book is published under CC BY 4.0.
|
mvtsa-1.0/README.md
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
<p align="center"><img src="https://raw.githubusercontent.com/ComplexSystemsIntelligence/mvtsa/main/docs/_static/banner.png" alt="mvtsa: segmentation, warping and clustering of multivariate time series"></p>
|
|
2
|
+
|
|
3
|
+
# mvtsa: segmentation, warping and clustering of multivariate time series
|
|
4
|
+
|
|
5
|
+
[](https://github.com/ComplexSystemsIntelligence/mvtsa/actions/workflows/ci.yml)
|
|
6
|
+
[](https://complexsystemsintelligence.github.io/mvtsa)
|
|
7
|
+
[](https://complexsystemsintelligence.github.io/mvtsa/book.html)
|
|
8
|
+
[](https://github.com/ComplexSystemsIntelligence/mvtsa/blob/main/LICENSE)
|
|
9
|
+
|
|
10
|
+
**mvtsa** cuts multivariate time series into homogeneous segments, compares
|
|
11
|
+
series whose time axes do not agree, and groups them. It implements the
|
|
12
|
+
segmentation and warping methods developed by the group of János Abonyi at the
|
|
13
|
+
University of Pannonia over two decades — PCA and dynamic-PCA segmentation, the
|
|
14
|
+
modified Gath–Geva fuzzy segmentation, recursive-PCA on-line segmentation,
|
|
15
|
+
Fisher-information segmentation for experiment design, correlation-based
|
|
16
|
+
dynamic time warping, mixed piecewise-linear measures and episode alignment —
|
|
17
|
+
next to the strongest methods of the field and several new ones, with tools to
|
|
18
|
+
evaluate, validate, explain, simplify and operate the resulting models.
|
|
19
|
+
|
|
20
|
+
| Module | Contents |
|
|
21
|
+
|---|---|
|
|
22
|
+
| `mvtsa.segmentation` | costs (L2, L1, Gaussian, linear, AR, kernel, PCA T²/Q, regression) × searches (bottom-up with a merge hierarchy, top-down, sliding window, SWAB, optimal partitioning, PELT, window discrepancy); PCA, dynamic-PCA, Krzanowski and recursive-PCA segmentation; modified Gath–Geva fuzzy segmentation; Fisher-information segmentation; BOCPD; sticky Gaussian HMM; sparse Gaussian states; ClaSP; FLUSS; segment-then-cluster states; predictive homogeneity with any scikit-learn model; consensus; streaming and CUSUM; selection of the number of segments |
|
|
23
|
+
| `mvtsa.warping` | DTW with windows, step patterns, penalties and lower bounds; DTW_I, DDTW, WDTW, ADTW, shapeDTW, FastDTW, subsequence DTW; LCSS, EDR, ERP, TWED, MSM; soft-DTW and its divergence, GAK, SBD; correlation-based DTW (static and dynamic PCA, Riemannian and mixed segment distances); MPLA/SPLA/MDPLA; episode alignment and episode DTW; DBA and soft-DTW barycenters; path statistics, tightness of warping, window learning, elastic ensemble |
|
|
24
|
+
| `mvtsa.clustering` | k-means (Euclidean, DBA, soft-DTW), k-Shape, k-medoids, fuzzy c-medoids, hierarchical, spectral, DBSCAN/HDBSCAN, consensus; feature- and signature-based, segment and trajectory clustering |
|
|
25
|
+
| `mvtsa.representation` | PCA, PPCA, recursive PCA, similarity factors (Krzanowski, λ, Eros), principal angles, SPD geometry; PAA, APCA, PLA, PIP, SAX, ABBA, SFA; triangular episodes; features and path signatures; visibility, six-sigma, ordinal and recurrence networks; recurrence plots, GAF, MTF; matrix and k-NN profiles |
|
|
26
|
+
| `mvtsa.evaluation` | F1 with margin, covering, Hausdorff, annotation error, state ARI/AMI; clustering scores, silhouette, Dunn, partition coefficient; k-NN accuracy, precision–recall curves, mAP; stability, sensitivity, Friedman–Nemenyi, Wilcoxon–Holm; benchmarks and grid search |
|
|
27
|
+
| `mvtsa.simplify`, `mvtsa.explain` | merging short segments, pruning, hierarchy reduction, PLA simplification, compression; variable contributions, segment tables, decision-tree rules of states, regime transition networks |
|
|
28
|
+
| `mvtsa.mlops` | JSON/YAML configurations, analysis pipelines, model files with checksums and data fingerprints, a model registry with stages, experiment tracking (local, optional MLflow), data contracts, drift monitoring, model cards; command line `mvtsa` |
|
|
29
|
+
| `mvtsa.viz` | segmented series, fuzzy memberships, segmentograms, cost curves, PCA statistics and loadings, alignments, cost matrices, alignment uncertainty, prototypes, dendrograms, Sammon and fuzzy Sammon maps, critical-difference diagrams, stability plots, dashboards |
|
|
30
|
+
| `mvtsa.datasets` | generators (piecewise stationary, correlation switching, dynamic switching, recurring regimes, energy, CBF, synthetic control, signatures, motion, correlation and dynamic sequences); pH and MMA polymerization reactor simulators; bundled BasicMotions, JapaneseVowels and GunPoint; UEA & UCR and TSSB fetchers |
|
|
31
|
+
|
|
32
|
+
## Installation
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
pip install mvtsa # numpy, scipy, pandas, scikit-learn, matplotlib, networkx
|
|
36
|
+
pip install "mvtsa[fast]" # + numba for the dynamic-programming kernels
|
|
37
|
+
pip install "mvtsa[all]" # + MLflow, YAML, ruptures, stumpy
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Quick start
|
|
41
|
+
|
|
42
|
+
```python
|
|
43
|
+
import mvtsa as mv
|
|
44
|
+
|
|
45
|
+
# segmentation: four regimes that differ only in their correlation structure
|
|
46
|
+
X, cps, _ = mv.datasets.make_correlation_switching(n_segments=4, length=150)
|
|
47
|
+
seg = mv.segment(X, "pca", n_segments=4, n_components=1) # Q statistic, bottom-up
|
|
48
|
+
print(seg.change_points, cps) # [150 300 450] [150 300 450]
|
|
49
|
+
mv.viz.plot_segmentation(X, seg, truth=cps)
|
|
50
|
+
|
|
51
|
+
# warping: correlation-based DTW of on-line signatures
|
|
52
|
+
C, writer = mv.datasets.make_signatures(n_writers=6, n_per_writer=8)
|
|
53
|
+
D = mv.warping.CBDTW(n_segments=10, n_components=2).fit(C).pairwise()
|
|
54
|
+
print(mv.evaluation.knn_accuracy(D, writer))
|
|
55
|
+
|
|
56
|
+
# clustering on the same distances
|
|
57
|
+
labels = mv.clustering.KMedoids(6, metric="precomputed").fit(D).labels_
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Documentation and book
|
|
61
|
+
|
|
62
|
+
* Documentation, gallery of 48 examples and API reference:
|
|
63
|
+
<https://complexsystemsintelligence.github.io/mvtsa>
|
|
64
|
+
* Book *Segmentation, Warping and Clustering of Multivariate Time Series in
|
|
65
|
+
Python* (PDF, EPUB, web), built from the same example scripts:
|
|
66
|
+
<https://complexsystemsintelligence.github.io/mvtsa/book.html>
|
|
67
|
+
|
|
68
|
+
## Citing
|
|
69
|
+
|
|
70
|
+
J. Abonyi, *mvtsa: segmentation, warping and clustering of multivariate time
|
|
71
|
+
series in Python*, version 1.0, 2026 — together with the original publications
|
|
72
|
+
of the methods you use (see `CITATION.cff` and the method lineage page of the
|
|
73
|
+
documentation).
|
|
74
|
+
|
|
75
|
+
## Acknowledgement
|
|
76
|
+
|
|
77
|
+
The research summarized in this package was supported by the National
|
|
78
|
+
Research, Development and Innovation Office of Hungary (NKFIH) through the
|
|
79
|
+
OTKA 143482 project. The package is maintained by the Complex Systems
|
|
80
|
+
Intelligence group ([abonyilab.com](https://www.abonyilab.com)) of the
|
|
81
|
+
University of Pannonia, Veszprém.
|
|
82
|
+
|
|
83
|
+
## License
|
|
84
|
+
|
|
85
|
+
MIT (software); the book is published under CC BY 4.0.
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"""
|
|
2
|
+
First steps: segment, look, evaluate
|
|
3
|
+
====================================
|
|
4
|
+
|
|
5
|
+
A multivariate series of three variables whose correlation structure
|
|
6
|
+
switches three times -- the means and variances stay the same, so no
|
|
7
|
+
variable shows the changes on its own. A PCA-based bottom-up segmentation
|
|
8
|
+
(Abonyi et al., 2005) finds them, and the result is compared with the truth.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
# %%
|
|
12
|
+
# Data and segmentation
|
|
13
|
+
# ---------------------
|
|
14
|
+
import matplotlib.pyplot as plt
|
|
15
|
+
|
|
16
|
+
import mvtsa as mv
|
|
17
|
+
from mvtsa.evaluation import evaluate_segmentation
|
|
18
|
+
|
|
19
|
+
# [snippet:first]
|
|
20
|
+
X, true_cps, states = mv.datasets.make_correlation_switching(
|
|
21
|
+
n_segments=4, length=150, random_state=0
|
|
22
|
+
)
|
|
23
|
+
seg = mv.segment(
|
|
24
|
+
X, "pca", n_segments=4, n_components=1
|
|
25
|
+
) # Q-statistic cost, bottom-up search
|
|
26
|
+
print(seg)
|
|
27
|
+
print(evaluate_segmentation(true_cps, seg, len(X), margin=5))
|
|
28
|
+
# [/snippet:first]
|
|
29
|
+
|
|
30
|
+
# %%
|
|
31
|
+
# The segmented series
|
|
32
|
+
# --------------------
|
|
33
|
+
# Segments are shaded, detected change points are blue lines, the true ones
|
|
34
|
+
# orange marks at the top.
|
|
35
|
+
mv.viz.plot_segmentation(X, seg, truth=true_cps, names=["x1", "x2", "x3"])
|
|
36
|
+
|
|
37
|
+
# %%
|
|
38
|
+
# The same series segmented by the means only
|
|
39
|
+
# -------------------------------------------
|
|
40
|
+
# A piecewise-constant (L2) cost cannot see correlation changes.
|
|
41
|
+
# [snippet:l2]
|
|
42
|
+
seg_l2 = mv.segment(X, "bottomup", cost="l2", n_segments=4)
|
|
43
|
+
print(
|
|
44
|
+
"L2 change points:",
|
|
45
|
+
seg_l2.change_points,
|
|
46
|
+
" PCA change points:",
|
|
47
|
+
seg.change_points,
|
|
48
|
+
)
|
|
49
|
+
# [/snippet:l2]
|
|
50
|
+
mv.viz.plot_segmentation(X, seg_l2, truth=true_cps, names=["x1", "x2", "x3"])
|
|
51
|
+
plt.show()
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Representations: PAA, PLA, SAX, episodes
|
|
3
|
+
========================================
|
|
4
|
+
|
|
5
|
+
Four ways to summarize a noisy signal: piecewise aggregate and piecewise
|
|
6
|
+
linear approximations, the symbolic SAX word and the qualitative episodes
|
|
7
|
+
of trend analysis (Cheung and Stephanopoulos, 1990; Balaskó et al., 2007).
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
import matplotlib.pyplot as plt
|
|
11
|
+
import numpy as np
|
|
12
|
+
|
|
13
|
+
from mvtsa import representation as rp
|
|
14
|
+
from mvtsa import viz
|
|
15
|
+
|
|
16
|
+
rng = np.random.default_rng(1)
|
|
17
|
+
t = np.linspace(0, 4 * np.pi, 400)
|
|
18
|
+
x = np.sin(t) + 0.4 * np.sin(3.1 * t) + 0.05 * rng.normal(size=t.size)
|
|
19
|
+
|
|
20
|
+
# %%
|
|
21
|
+
# Piecewise linear approximation
|
|
22
|
+
# ------------------------------
|
|
23
|
+
# [snippet:pla]
|
|
24
|
+
p = rp.pla(x, n_segments=12)
|
|
25
|
+
print("slope angles (degrees):", np.degrees(p.angles[:, 0]).round(0))
|
|
26
|
+
# [/snippet:pla]
|
|
27
|
+
viz.plot_pla(x, p)
|
|
28
|
+
|
|
29
|
+
# %%
|
|
30
|
+
# SAX
|
|
31
|
+
# ---
|
|
32
|
+
# [snippet:sax]
|
|
33
|
+
print("SAX word:", "".join(rp.sax(x, n_segments=16, alphabet_size=5)))
|
|
34
|
+
# [/snippet:sax]
|
|
35
|
+
viz.plot_sax(x, 16, 5)
|
|
36
|
+
|
|
37
|
+
# %%
|
|
38
|
+
# Qualitative episodes
|
|
39
|
+
# --------------------
|
|
40
|
+
# [snippet:episodes]
|
|
41
|
+
eps = rp.triangular_episodes(x, sigma=6)
|
|
42
|
+
print("episodes:", rp.episode_string(eps))
|
|
43
|
+
# [/snippet:episodes]
|
|
44
|
+
viz.plot_episodes(x, eps, smooth=6)
|
|
45
|
+
|
|
46
|
+
# %%
|
|
47
|
+
# Parameter study: the smoothing of the episodes
|
|
48
|
+
# ----------------------------------------------
|
|
49
|
+
for s in (2, 6, 15, 30):
|
|
50
|
+
print(
|
|
51
|
+
f"sigma={s:2d}:", rp.episode_string(rp.triangular_episodes(x, sigma=s))
|
|
52
|
+
)
|
|
53
|
+
plt.show()
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"""
|
|
2
|
+
PCA models: T², Q and similarity factors
|
|
3
|
+
========================================
|
|
4
|
+
|
|
5
|
+
A PCA model fitted on normal operation describes the correlation of the
|
|
6
|
+
variables; the Hotelling :math:`T^2` statistic measures the variation inside
|
|
7
|
+
the model, the :math:`Q` statistic the distance from it. When the
|
|
8
|
+
correlation structure changes, :math:`Q` exceeds its control limit -- the
|
|
9
|
+
principle behind PCA-based segmentation and monitoring.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
import matplotlib.pyplot as plt
|
|
13
|
+
import numpy as np
|
|
14
|
+
|
|
15
|
+
from mvtsa import viz
|
|
16
|
+
from mvtsa.datasets import make_correlation_switching
|
|
17
|
+
from mvtsa.representation import (
|
|
18
|
+
PCAModel,
|
|
19
|
+
chordal_distance,
|
|
20
|
+
krzanowski_similarity,
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
X, cps, _ = make_correlation_switching(
|
|
24
|
+
n_segments=2, length=300, random_state=3
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
# %%
|
|
28
|
+
# Monitoring statistics of a reference model
|
|
29
|
+
# ------------------------------------------
|
|
30
|
+
# [snippet:model]
|
|
31
|
+
model = PCAModel(n_components=1).fit(X[:300]) # first regime as reference
|
|
32
|
+
t2_lim, q_lim = model.control_limits(alpha=0.01)
|
|
33
|
+
q = model.q_statistic(X)
|
|
34
|
+
print(
|
|
35
|
+
f"Q limit {q_lim:.3f}; exceedance before/after the change: "
|
|
36
|
+
f"{np.mean(q[:300] > q_lim):.2f} / {np.mean(q[300:] > q_lim):.2f}"
|
|
37
|
+
)
|
|
38
|
+
# [/snippet:model]
|
|
39
|
+
viz.plot_pca_statistics(X, model)
|
|
40
|
+
|
|
41
|
+
# %%
|
|
42
|
+
# Comparing PCA models: Krzanowski similarity
|
|
43
|
+
# -------------------------------------------
|
|
44
|
+
# [snippet:similarity]
|
|
45
|
+
m1, m2 = PCAModel(1).fit(X[:300]), PCAModel(1).fit(X[300:])
|
|
46
|
+
print(
|
|
47
|
+
"s_PCA(regime 1, regime 1 half) =",
|
|
48
|
+
round(m1.similarity(PCAModel(1).fit(X[:150])), 3),
|
|
49
|
+
)
|
|
50
|
+
print("s_PCA(regime 1, regime 2) =", round(m1.similarity(m2), 3))
|
|
51
|
+
print(
|
|
52
|
+
"chordal distance =",
|
|
53
|
+
round(chordal_distance(m1.components_, m2.components_), 3),
|
|
54
|
+
)
|
|
55
|
+
# [/snippet:similarity]
|
|
56
|
+
|
|
57
|
+
# %%
|
|
58
|
+
# Parameter study: window length and similarity
|
|
59
|
+
# ---------------------------------------------
|
|
60
|
+
# The similarity of short windows to the reference fluctuates; longer
|
|
61
|
+
# windows estimate the subspace better.
|
|
62
|
+
fig, ax = plt.subplots(figsize=(6, 3))
|
|
63
|
+
for w in (20, 50, 100):
|
|
64
|
+
s = [
|
|
65
|
+
krzanowski_similarity(
|
|
66
|
+
m1.components_, PCAModel(1).fit(X[a : a + w]).components_
|
|
67
|
+
)
|
|
68
|
+
for a in range(0, len(X) - w, 5)
|
|
69
|
+
]
|
|
70
|
+
ax.plot(np.arange(0, len(X) - w, 5) + w, s, label=f"window {w}")
|
|
71
|
+
ax.axvline(300, color="gray", ls=":")
|
|
72
|
+
ax.set_xlabel("window end")
|
|
73
|
+
ax.set_ylabel("Krzanowski similarity")
|
|
74
|
+
ax.legend(frameon=False)
|
|
75
|
+
plt.show()
|