visibgraph 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.
- visibgraph-1.0/.gitignore +48 -0
- visibgraph-1.0/CHANGELOG.md +14 -0
- visibgraph-1.0/CITATION.cff +64 -0
- visibgraph-1.0/LICENSE +21 -0
- visibgraph-1.0/PKG-INFO +181 -0
- visibgraph-1.0/README.md +92 -0
- visibgraph-1.0/examples/01_basics/README.rst +2 -0
- visibgraph-1.0/examples/01_basics/plot_01_first_steps.py +64 -0
- visibgraph-1.0/examples/01_basics/plot_02_algorithms.py +79 -0
- visibgraph-1.0/examples/01_basics/plot_03_exact_results.py +68 -0
- visibgraph-1.0/examples/01_basics/plot_04_time_and_windows.py +60 -0
- visibgraph-1.0/examples/01_basics/plot_05_import_export.py +50 -0
- visibgraph-1.0/examples/02_family/README.rst +2 -0
- visibgraph-1.0/examples/02_family/plot_01_directed_weighted.py +61 -0
- visibgraph-1.0/examples/02_family/plot_02_penetrable.py +62 -0
- visibgraph-1.0/examples/02_family/plot_03_parametric.py +56 -0
- visibgraph-1.0/examples/02_family/plot_04_difference_dual.py +51 -0
- visibgraph-1.0/examples/02_family/plot_05_multiplex.py +58 -0
- visibgraph-1.0/examples/02_family/plot_06_image.py +51 -0
- visibgraph-1.0/examples/02_family/plot_07_other_networks.py +59 -0
- visibgraph-1.0/examples/03_measures/README.rst +2 -0
- visibgraph-1.0/examples/03_measures/plot_01_chaos_vs_noise.py +52 -0
- visibgraph-1.0/examples/03_measures/plot_02_hurst.py +47 -0
- visibgraph-1.0/examples/03_measures/plot_03_irreversibility.py +50 -0
- visibgraph-1.0/examples/03_measures/plot_04_motifs.py +41 -0
- visibgraph-1.0/examples/03_measures/plot_05_features.py +58 -0
- visibgraph-1.0/examples/03_measures/plot_06_series_distance.py +53 -0
- visibgraph-1.0/examples/04_spc/README.rst +2 -0
- visibgraph-1.0/examples/04_spc/plot_01_labelled_hvg.py +61 -0
- visibgraph-1.0/examples/04_spc/plot_02_run_rules.py +65 -0
- visibgraph-1.0/examples/04_spc/plot_03_zone_ladders.py +53 -0
- visibgraph-1.0/examples/04_spc/plot_04_label_enrichment.py +60 -0
- visibgraph-1.0/examples/04_spc/plot_05_run_lengths.py +54 -0
- visibgraph-1.0/examples/04_spc/plot_06_benchmark.py +71 -0
- visibgraph-1.0/examples/04_spc/plot_07_reproduction.py +137 -0
- visibgraph-1.0/examples/04_spc/plot_08_monitoring.py +86 -0
- visibgraph-1.0/examples/05_segmentation/README.rst +2 -0
- visibgraph-1.0/examples/05_segmentation/plot_01_window_features.py +44 -0
- visibgraph-1.0/examples/05_segmentation/plot_02_divergence.py +46 -0
- visibgraph-1.0/examples/05_segmentation/plot_03_modularity_dp.py +69 -0
- visibgraph-1.0/examples/05_segmentation/plot_04_comparison.py +69 -0
- visibgraph-1.0/examples/05_segmentation/plot_05_scalogram.py +38 -0
- visibgraph-1.0/examples/05_segmentation/plot_06_nile.py +44 -0
- visibgraph-1.0/examples/06_visualization/README.rst +2 -0
- visibgraph-1.0/examples/06_visualization/plot_01_sight_lines.py +42 -0
- visibgraph-1.0/examples/06_visualization/plot_02_arcs_and_matrices.py +40 -0
- visibgraph-1.0/examples/06_visualization/plot_03_horizons_and_barriers.py +43 -0
- visibgraph-1.0/examples/06_visualization/plot_04_networks.py +36 -0
- visibgraph-1.0/examples/06_visualization/plot_05_dashboard.py +27 -0
- visibgraph-1.0/examples/06_visualization/plot_06_interactive.py +39 -0
- visibgraph-1.0/examples/07_applications/README.rst +2 -0
- visibgraph-1.0/examples/07_applications/plot_01_bifurcation.py +56 -0
- visibgraph-1.0/examples/07_applications/plot_02_tennessee_eastman.py +89 -0
- visibgraph-1.0/examples/07_applications/plot_03_sklearn_pipeline.py +56 -0
- visibgraph-1.0/examples/README.rst +10 -0
- visibgraph-1.0/pyproject.toml +84 -0
- visibgraph-1.0/src/visibgraph/__init__.py +136 -0
- visibgraph-1.0/src/visibgraph/accessor.py +64 -0
- visibgraph-1.0/src/visibgraph/construct/__init__.py +43 -0
- visibgraph-1.0/src/visibgraph/construct/horizontal.py +110 -0
- visibgraph-1.0/src/visibgraph/construct/multivariate.py +180 -0
- visibgraph-1.0/src/visibgraph/construct/natural.py +162 -0
- visibgraph-1.0/src/visibgraph/construct/penetrable.py +172 -0
- visibgraph-1.0/src/visibgraph/construct/spatial.py +145 -0
- visibgraph-1.0/src/visibgraph/construct/variants.py +152 -0
- visibgraph-1.0/src/visibgraph/construct/windows.py +128 -0
- visibgraph-1.0/src/visibgraph/core.py +441 -0
- visibgraph-1.0/src/visibgraph/datasets/__init__.py +49 -0
- visibgraph-1.0/src/visibgraph/datasets/_bundled.py +78 -0
- visibgraph-1.0/src/visibgraph/datasets/benchmark.py +229 -0
- visibgraph-1.0/src/visibgraph/datasets/data/README.md +35 -0
- visibgraph-1.0/src/visibgraph/datasets/data/lynx.csv +115 -0
- visibgraph-1.0/src/visibgraph/datasets/data/nile.csv +101 -0
- visibgraph-1.0/src/visibgraph/datasets/data/sunspots.csv +290 -0
- visibgraph-1.0/src/visibgraph/datasets/data/tep_d00.csv.gz +0 -0
- visibgraph-1.0/src/visibgraph/datasets/data/tep_d00_te.csv.gz +0 -0
- visibgraph-1.0/src/visibgraph/datasets/data/tep_d01_te.csv.gz +0 -0
- visibgraph-1.0/src/visibgraph/datasets/data/tep_d04_te.csv.gz +0 -0
- visibgraph-1.0/src/visibgraph/datasets/data/tep_d05_te.csv.gz +0 -0
- visibgraph-1.0/src/visibgraph/datasets/data/tep_d06_te.csv.gz +0 -0
- visibgraph-1.0/src/visibgraph/datasets/data/tep_d11_te.csv.gz +0 -0
- visibgraph-1.0/src/visibgraph/datasets/generators.py +216 -0
- visibgraph-1.0/src/visibgraph/interactive.py +84 -0
- visibgraph-1.0/src/visibgraph/io.py +153 -0
- visibgraph-1.0/src/visibgraph/labelled.py +263 -0
- visibgraph-1.0/src/visibgraph/measures.py +586 -0
- visibgraph-1.0/src/visibgraph/ml.py +179 -0
- visibgraph-1.0/src/visibgraph/networks.py +142 -0
- visibgraph-1.0/src/visibgraph/segment.py +642 -0
- visibgraph-1.0/src/visibgraph/spc.py +267 -0
- visibgraph-1.0/src/visibgraph/surrogates.py +147 -0
- visibgraph-1.0/src/visibgraph/symbolic.py +226 -0
- visibgraph-1.0/src/visibgraph/viz/__init__.py +62 -0
- visibgraph-1.0/src/visibgraph/viz/_style.py +92 -0
- visibgraph-1.0/src/visibgraph/viz/arcs.py +175 -0
- visibgraph-1.0/src/visibgraph/viz/distributions.py +202 -0
- visibgraph-1.0/src/visibgraph/viz/graphs.py +175 -0
- visibgraph-1.0/src/visibgraph/viz/multi.py +84 -0
- visibgraph-1.0/src/visibgraph/viz/series.py +223 -0
- visibgraph-1.0/tests/conftest.py +3 -0
- visibgraph-1.0/tests/test_construct.py +132 -0
- visibgraph-1.0/tests/test_measures.py +89 -0
- visibgraph-1.0/tests/test_segment_viz_io.py +124 -0
- visibgraph-1.0/tests/test_spc.py +84 -0
|
@@ -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/
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 1.0 (2026-11-29) — first release
|
|
4
|
+
|
|
5
|
+
* The SPC-labelled visibility graphs of Ferenczi, Kummer and Abonyi (Scientific Reports 16: 17774, 2026): eight SPC zones with a frozen Phase-I baseline, direction-aware Western Electric rules and the reference detector of the paper, zone-labelled natural and horizontal visibility graphs, state transition networks, zone-aggregated graphs and the structural features of the study. The data generator of the paper is ported line by line (`load_six_sigma_benchmark`) and reproduces the published data set value for value.
|
|
6
|
+
* The visibility graph family: natural (divide and conquer, with a scan and a brute-force reference), horizontal (O(N) stack), directed and weighted graphs with ten edge weights, limited penetrable graphs (LPVG, LPHVG), parametric graphs, difference graphs, bottom and dual-perspective graphs, sliding-window graphs and an online horizontal visibility graph, multiplex graphs of multivariate series and image visibility graphs (IHVG4/8). All builders are checked against the definitions by brute force and against `ts2vg`.
|
|
7
|
+
* Measures: exact iid references (HVG, DHVG, LPHVG, periodic mean degree), exponential fits with a safe lower cut-off (a cut-off of 2 returns ln(3/2) for every aperiodic series — proved in the book), discrete power-law fits, the Hurst exponent, time irreversibility, sequential motifs with their iid probabilities, global and node features, horizons, cut profiles, graph distances; shuffle, phase, IAAFT and block surrogates with rank tests.
|
|
8
|
+
* New for labelled graphs: zone-to-zone visibility and transition features, visibility enrichment against the exact permutation expectation, the zone ladder view, the Nelson rules, and the link between visibility spans and the run lengths and ARL of control charts.
|
|
9
|
+
* Segmentation: window features with PELT and binary segmentation, divergence profiles, an exact dynamic program for optimal contiguous modularity with configuration, span and spatial null models and a surrogate stopping rule, community segmentation, the visibility scalogram and segmentation scores.
|
|
10
|
+
* Other series networks for comparison: ordinal partition networks, quantile graphs, recurrence networks.
|
|
11
|
+
* Static views (`visibgraph.viz`): sight lines, arc diagrams, adjacency and label matrices, horizon and barrier profiles, control charts, zone ladders, graph and network layouts, degree distributions, motif profiles, feature timelines, divergence and modularity profiles, segmentations, scalograms, multiplex views, degree images and a dashboard; plotly twins (`visibgraph.interactive`).
|
|
12
|
+
* Interoperability: pandas Series input and the `series.vg` accessor; NetworkX, igraph and ts2vg; GraphML, GEXF, GML, Pajek, node-link JSON and CSV; the `VisibilityFeatures` scikit-learn transformer and the `WERuleClassifier`; tables ready for `ruptures`.
|
|
13
|
+
* Data sets: the six-sigma benchmark, the Tennessee Eastman process (faults 0, 1, 4, 5, 6, 11), the Nile, lynx and sunspot series; generators of white noise, AR(1), logistic and Hénon maps, the Lorenz flow, fractional Gaussian noise and motion, periodic, regime-switching and control-chart pattern series.
|
|
14
|
+
* 41 gallery examples, Sphinx documentation and the companion book (PDF, EPUB and web edition) *Visibility Graphs of Time Series in Python*.
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
cff-version: 1.2.0
|
|
2
|
+
message: "If you use visibgraph, please cite it as below, together with the original publications of the methods you use."
|
|
3
|
+
type: software
|
|
4
|
+
title: "visibgraph: visibility graphs of time series in Python"
|
|
5
|
+
version: "1.0"
|
|
6
|
+
date-released: 2026-11-29
|
|
7
|
+
license: MIT
|
|
8
|
+
repository-code: "https://github.com/ComplexSystemsIntelligence/visibgraph"
|
|
9
|
+
url: "https://complexsystemsintelligence.github.io/visibgraph"
|
|
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
|
+
- family-names: Ferenczi
|
|
16
|
+
given-names: Martin
|
|
17
|
+
affiliation: "University of Pannonia, Veszprém, Hungary"
|
|
18
|
+
- family-names: Kummer
|
|
19
|
+
given-names: Alex
|
|
20
|
+
affiliation: "University of Pannonia, Veszprém, Hungary"
|
|
21
|
+
keywords:
|
|
22
|
+
- visibility graph
|
|
23
|
+
- horizontal visibility graph
|
|
24
|
+
- time series analysis
|
|
25
|
+
- complex networks
|
|
26
|
+
- statistical process control
|
|
27
|
+
- Western Electric rules
|
|
28
|
+
- segmentation
|
|
29
|
+
- visualization
|
|
30
|
+
references:
|
|
31
|
+
- type: article
|
|
32
|
+
title: "Six-sigma approach-based visibility graphs"
|
|
33
|
+
authors:
|
|
34
|
+
- family-names: Ferenczi
|
|
35
|
+
given-names: Martin
|
|
36
|
+
- family-names: Kummer
|
|
37
|
+
given-names: Alex
|
|
38
|
+
- family-names: Abonyi
|
|
39
|
+
given-names: János
|
|
40
|
+
journal: "Scientific Reports"
|
|
41
|
+
volume: 16
|
|
42
|
+
start: 17774
|
|
43
|
+
year: 2026
|
|
44
|
+
doi: 10.1038/s41598-026-48718-6
|
|
45
|
+
- type: article
|
|
46
|
+
title: "From time series to complex networks: The visibility graph"
|
|
47
|
+
authors:
|
|
48
|
+
- family-names: Lacasa
|
|
49
|
+
given-names: Lucas
|
|
50
|
+
- family-names: Luque
|
|
51
|
+
given-names: Bartolo
|
|
52
|
+
- family-names: Ballesteros
|
|
53
|
+
given-names: Fernando
|
|
54
|
+
- family-names: Luque
|
|
55
|
+
given-names: Jordi
|
|
56
|
+
- family-names: Nuño
|
|
57
|
+
given-names: Juan Carlos
|
|
58
|
+
journal: "Proceedings of the National Academy of Sciences"
|
|
59
|
+
volume: 105
|
|
60
|
+
issue: 13
|
|
61
|
+
start: 4972
|
|
62
|
+
end: 4975
|
|
63
|
+
year: 2008
|
|
64
|
+
doi: 10.1073/pnas.0709247105
|
visibgraph-1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 János Abonyi, Martin Ferenczi, Alex Kummer
|
|
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.
|
visibgraph-1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: visibgraph
|
|
3
|
+
Version: 1.0
|
|
4
|
+
Summary: Visibility graphs of time series: construction of the whole visibility graph family, exact reference results, measures, SPC-labelled graphs (Western Electric and Nelson rules), segmentation (including exact contiguous modularity), and visualization, with interoperability to networkx, igraph, pandas and scikit-learn.
|
|
5
|
+
Project-URL: Homepage, https://github.com/ComplexSystemsIntelligence/visibgraph
|
|
6
|
+
Project-URL: Documentation, https://complexsystemsintelligence.github.io/visibgraph
|
|
7
|
+
Project-URL: Repository, https://github.com/ComplexSystemsIntelligence/visibgraph
|
|
8
|
+
Project-URL: Issues, https://github.com/ComplexSystemsIntelligence/visibgraph/issues
|
|
9
|
+
Project-URL: Changelog, https://github.com/ComplexSystemsIntelligence/visibgraph/blob/main/CHANGELOG.md
|
|
10
|
+
Project-URL: Book (PDF), https://complexsystemsintelligence.github.io/visibgraph/visibgraph-book.pdf
|
|
11
|
+
Author: Martin Ferenczi, Alex Kummer
|
|
12
|
+
Author-email: János Abonyi <janos@abonyilab.com>
|
|
13
|
+
License-Expression: MIT
|
|
14
|
+
License-File: LICENSE
|
|
15
|
+
Keywords: Western Electric rules,change point detection,complex networks,horizontal visibility graph,nonlinear time series analysis,segmentation,statistical process control,time series,visibility graph,visualization
|
|
16
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
17
|
+
Classifier: Intended Audience :: Science/Research
|
|
18
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
19
|
+
Classifier: Operating System :: OS Independent
|
|
20
|
+
Classifier: Programming Language :: Python :: 3
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
25
|
+
Classifier: Topic :: Scientific/Engineering
|
|
26
|
+
Classifier: Topic :: Scientific/Engineering :: Information Analysis
|
|
27
|
+
Classifier: Topic :: Scientific/Engineering :: Visualization
|
|
28
|
+
Requires-Python: >=3.10
|
|
29
|
+
Requires-Dist: matplotlib>=3.7
|
|
30
|
+
Requires-Dist: networkx>=3.0
|
|
31
|
+
Requires-Dist: numpy>=1.24
|
|
32
|
+
Requires-Dist: pandas>=2.0
|
|
33
|
+
Requires-Dist: scipy>=1.11
|
|
34
|
+
Provides-Extra: all
|
|
35
|
+
Requires-Dist: igraph>=0.11; extra == 'all'
|
|
36
|
+
Requires-Dist: plotly>=5.15; extra == 'all'
|
|
37
|
+
Requires-Dist: ruptures>=1.1; extra == 'all'
|
|
38
|
+
Requires-Dist: scikit-learn>=1.3; extra == 'all'
|
|
39
|
+
Requires-Dist: ts2vg>=1.2; extra == 'all'
|
|
40
|
+
Provides-Extra: book
|
|
41
|
+
Requires-Dist: beautifulsoup4>=4.12; extra == 'book'
|
|
42
|
+
Requires-Dist: igraph>=0.11; extra == 'book'
|
|
43
|
+
Requires-Dist: lxml; extra == 'book'
|
|
44
|
+
Requires-Dist: pillow; extra == 'book'
|
|
45
|
+
Requires-Dist: plotly>=5.15; extra == 'book'
|
|
46
|
+
Requires-Dist: scikit-learn>=1.3; extra == 'book'
|
|
47
|
+
Requires-Dist: ts2vg>=1.2; extra == 'book'
|
|
48
|
+
Provides-Extra: dev
|
|
49
|
+
Requires-Dist: build; extra == 'dev'
|
|
50
|
+
Requires-Dist: igraph>=0.11; extra == 'dev'
|
|
51
|
+
Requires-Dist: myst-parser; extra == 'dev'
|
|
52
|
+
Requires-Dist: numpydoc; extra == 'dev'
|
|
53
|
+
Requires-Dist: plotly>=5.15; extra == 'dev'
|
|
54
|
+
Requires-Dist: pydata-sphinx-theme; extra == 'dev'
|
|
55
|
+
Requires-Dist: pytest-cov; extra == 'dev'
|
|
56
|
+
Requires-Dist: pytest>=7; extra == 'dev'
|
|
57
|
+
Requires-Dist: ruff; extra == 'dev'
|
|
58
|
+
Requires-Dist: ruptures>=1.1; extra == 'dev'
|
|
59
|
+
Requires-Dist: scikit-learn>=1.3; extra == 'dev'
|
|
60
|
+
Requires-Dist: sphinx-copybutton; extra == 'dev'
|
|
61
|
+
Requires-Dist: sphinx-design; extra == 'dev'
|
|
62
|
+
Requires-Dist: sphinx-gallery>=0.15; extra == 'dev'
|
|
63
|
+
Requires-Dist: sphinx>=7; extra == 'dev'
|
|
64
|
+
Requires-Dist: ts2vg>=1.2; extra == 'dev'
|
|
65
|
+
Requires-Dist: twine; extra == 'dev'
|
|
66
|
+
Provides-Extra: docs
|
|
67
|
+
Requires-Dist: myst-parser; extra == 'docs'
|
|
68
|
+
Requires-Dist: numpydoc; extra == 'docs'
|
|
69
|
+
Requires-Dist: plotly>=5.15; extra == 'docs'
|
|
70
|
+
Requires-Dist: pydata-sphinx-theme; extra == 'docs'
|
|
71
|
+
Requires-Dist: scikit-learn>=1.3; extra == 'docs'
|
|
72
|
+
Requires-Dist: sphinx-copybutton; extra == 'docs'
|
|
73
|
+
Requires-Dist: sphinx-design; extra == 'docs'
|
|
74
|
+
Requires-Dist: sphinx-gallery>=0.15; extra == 'docs'
|
|
75
|
+
Requires-Dist: sphinx>=7; extra == 'docs'
|
|
76
|
+
Provides-Extra: interactive
|
|
77
|
+
Requires-Dist: plotly>=5.15; extra == 'interactive'
|
|
78
|
+
Provides-Extra: interop
|
|
79
|
+
Requires-Dist: igraph>=0.11; extra == 'interop'
|
|
80
|
+
Requires-Dist: ruptures>=1.1; extra == 'interop'
|
|
81
|
+
Requires-Dist: ts2vg>=1.2; extra == 'interop'
|
|
82
|
+
Provides-Extra: ml
|
|
83
|
+
Requires-Dist: scikit-learn>=1.3; extra == 'ml'
|
|
84
|
+
Provides-Extra: test
|
|
85
|
+
Requires-Dist: pytest-cov; extra == 'test'
|
|
86
|
+
Requires-Dist: pytest>=7; extra == 'test'
|
|
87
|
+
Requires-Dist: scikit-learn>=1.3; extra == 'test'
|
|
88
|
+
Description-Content-Type: text/markdown
|
|
89
|
+
|
|
90
|
+
<p align="center"><img src="https://raw.githubusercontent.com/ComplexSystemsIntelligence/visibgraph/main/docs/_static/banner.png" alt="visibgraph: visibility graphs of time series in Python"></p>
|
|
91
|
+
|
|
92
|
+
# visibgraph: visibility graphs of time series in Python
|
|
93
|
+
|
|
94
|
+
[](https://github.com/ComplexSystemsIntelligence/visibgraph/actions/workflows/ci.yml)
|
|
95
|
+
[](https://complexsystemsintelligence.github.io/visibgraph)
|
|
96
|
+
[](https://complexsystemsintelligence.github.io/visibgraph/book.html)
|
|
97
|
+
[](https://github.com/ComplexSystemsIntelligence/visibgraph/blob/main/LICENSE)
|
|
98
|
+
|
|
99
|
+
**visibgraph** turns time series into networks and reads the dynamics off them. A
|
|
100
|
+
visibility graph links two observations when the straight line between them
|
|
101
|
+
passes above everything in between (Lacasa et al., PNAS 2008); its degrees,
|
|
102
|
+
motifs, spans and communities then describe the series. The package builds the
|
|
103
|
+
whole visibility graph family, compares the graphs with exact reference results,
|
|
104
|
+
labels them with the zones of statistical process control as proposed by
|
|
105
|
+
Ferenczi, Kummer and Abonyi
|
|
106
|
+
([Scientific Reports 16: 17774, 2026](https://doi.org/10.1038/s41598-026-48718-6)),
|
|
107
|
+
segments series through them and draws them. Several methods are new: the exact
|
|
108
|
+
contiguous-modularity segmentation with a surrogate stopping rule, visibility
|
|
109
|
+
enrichment of labelled graphs, the zone ladder, the visibility scalogram, and the
|
|
110
|
+
link between visibility spans and the average run length of control charts.
|
|
111
|
+
|
|
112
|
+
| Module | Contents |
|
|
113
|
+
|---|---|
|
|
114
|
+
| `visibgraph.core` | `VisibilityGraph`: degrees (past and future), spans, edge weights, windows (hereditary property), set operations, Laplacian, node and edge tables |
|
|
115
|
+
| `visibgraph.construct` | natural (divide and conquer, O(N log N) on average), horizontal (O(N) stack), directed, weighted, limited penetrable (LPVG, LPHVG), parametric, difference, bottom and dual-perspective, sliding-window, online, multiplex and image visibility graphs |
|
|
116
|
+
| `visibgraph.measures` | exact iid references (HVG, DHVG, LPHVG, periodic), exponential and power-law fits with safe defaults, Hurst exponent, irreversibility, sequential motifs, global and node features, horizons, cut profiles, graph distances |
|
|
117
|
+
| `visibgraph.symbolic`, `visibgraph.spc`, `visibgraph.labelled` | frozen Phase-I baselines, eight SPC zones, SAX, ordinal patterns; Western Electric and Nelson rules, the reference classifier, ARL; zone-to-zone visibility, state transition networks, label-aggregated graphs, label enrichment |
|
|
118
|
+
| `visibgraph.segment` | window features with PELT and binary segmentation, divergence profiles, exact contiguous modularity (configuration, span and spatial null models), community segmentation, visibility scalograms, segmentation scores |
|
|
119
|
+
| `visibgraph.networks`, `visibgraph.surrogates` | ordinal partition networks, quantile graphs, recurrence networks; shuffle, phase, IAAFT and block surrogates with rank tests |
|
|
120
|
+
| `visibgraph.viz`, `visibgraph.interactive` | sight lines, arc diagrams, adjacency and label matrices, horizon and barrier profiles, control charts, zone ladders, networks, degree distributions, motif profiles, feature timelines, divergence and modularity profiles, scalograms, multiplex views, dashboards; plotly twins |
|
|
121
|
+
| `visibgraph.ml`, `visibgraph.io`, `visibgraph.accessor` | scikit-learn transformer and rule classifier; NetworkX, igraph, ts2vg, GraphML, GEXF, GML, Pajek, JSON, CSV; the `series.vg` pandas accessor |
|
|
122
|
+
| `visibgraph.datasets` | the six-sigma benchmark of the paper (bit-exact port), Tennessee Eastman, Nile, lynx, sunspots; generators of maps, flows, AR, fractional Gaussian noise and motion, periodic, regime-switching and control-chart series |
|
|
123
|
+
|
|
124
|
+
## Installation
|
|
125
|
+
|
|
126
|
+
```bash
|
|
127
|
+
pip install visibgraph
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
Python ≥ 3.10; depends on numpy, scipy, networkx, pandas and matplotlib.
|
|
131
|
+
`pip install "visibgraph[all]"` adds plotly, igraph, ts2vg, ruptures and scikit-learn.
|
|
132
|
+
|
|
133
|
+
## Quick start
|
|
134
|
+
|
|
135
|
+
```python
|
|
136
|
+
import visibgraph as vg
|
|
137
|
+
from visibgraph.viz import plot_visibility, plot_zone_ladder
|
|
138
|
+
|
|
139
|
+
y = vg.datasets.ar1(500, phi=0.6, random_state=1)
|
|
140
|
+
G = vg.hvg(y) # horizontal visibility graph in O(N)
|
|
141
|
+
vg.exponential_fit(G.degree()) # lambda against ln(3/2) of iid noise
|
|
142
|
+
vg.irreversibility(G) # time asymmetry of the series
|
|
143
|
+
|
|
144
|
+
bench = vg.datasets.load_six_sigma_benchmark() # the benchmark of the paper
|
|
145
|
+
y, base = bench.X[1500], bench.baseline(1500) # frozen Phase-I baseline
|
|
146
|
+
G = vg.nvg(y, labels=vg.spc_zones(y, base)) # zone-labelled natural visibility graph
|
|
147
|
+
vg.western_electric(y, base) # rule, direction, start, end
|
|
148
|
+
plot_visibility(G); plot_zone_ladder(G) # sight lines; visibility between zones
|
|
149
|
+
|
|
150
|
+
y, truth = vg.datasets.regime_switching(random_state=0)
|
|
151
|
+
vg.modularity_segmentation(vg.nvg(y)).boundaries # exact contiguous-modularity segmentation
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
## Documentation and book
|
|
155
|
+
|
|
156
|
+
* Documentation, gallery of 41 runnable examples and API reference:
|
|
157
|
+
<https://complexsystemsintelligence.github.io/visibgraph>
|
|
158
|
+
* The companion book, *Visibility Graphs of Time Series in Python: The visibgraph
|
|
159
|
+
toolbox* (CC BY 4.0): [PDF](https://complexsystemsintelligence.github.io/visibgraph/visibgraph-book.pdf),
|
|
160
|
+
[EPUB](https://complexsystemsintelligence.github.io/visibgraph/visibgraph-book.epub),
|
|
161
|
+
[web edition](https://complexsystemsintelligence.github.io/visibgraph/book/index.html)
|
|
162
|
+
|
|
163
|
+
## Citing
|
|
164
|
+
|
|
165
|
+
Please cite the toolbox and the original paper (see `CITATION.cff`):
|
|
166
|
+
|
|
167
|
+
> J. Abonyi, M. Ferenczi, A. Kummer, *visibgraph: visibility graphs of time series in Python*, version 1.0, 2026.
|
|
168
|
+
>
|
|
169
|
+
> M. Ferenczi, A. Kummer, J. Abonyi, Six-sigma approach-based visibility graphs, *Scientific Reports* 16 (2026) 17774, doi:10.1038/s41598-026-48718-6.
|
|
170
|
+
|
|
171
|
+
## Acknowledgments
|
|
172
|
+
|
|
173
|
+
Developed at the University of Pannonia, Veszprém, by the
|
|
174
|
+
[Complex Systems Intelligence](https://complexsystemsintelligence.github.io) group
|
|
175
|
+
([abonyilab.com](https://www.abonyilab.com)). The research was supported by the
|
|
176
|
+
National Research, Development and Innovation Office of Hungary (NKFIH) through the
|
|
177
|
+
OTKA 143482 project.
|
|
178
|
+
|
|
179
|
+
## License
|
|
180
|
+
|
|
181
|
+
MIT for the software; CC BY 4.0 for the book.
|
visibgraph-1.0/README.md
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
<p align="center"><img src="https://raw.githubusercontent.com/ComplexSystemsIntelligence/visibgraph/main/docs/_static/banner.png" alt="visibgraph: visibility graphs of time series in Python"></p>
|
|
2
|
+
|
|
3
|
+
# visibgraph: visibility graphs of time series in Python
|
|
4
|
+
|
|
5
|
+
[](https://github.com/ComplexSystemsIntelligence/visibgraph/actions/workflows/ci.yml)
|
|
6
|
+
[](https://complexsystemsintelligence.github.io/visibgraph)
|
|
7
|
+
[](https://complexsystemsintelligence.github.io/visibgraph/book.html)
|
|
8
|
+
[](https://github.com/ComplexSystemsIntelligence/visibgraph/blob/main/LICENSE)
|
|
9
|
+
|
|
10
|
+
**visibgraph** turns time series into networks and reads the dynamics off them. A
|
|
11
|
+
visibility graph links two observations when the straight line between them
|
|
12
|
+
passes above everything in between (Lacasa et al., PNAS 2008); its degrees,
|
|
13
|
+
motifs, spans and communities then describe the series. The package builds the
|
|
14
|
+
whole visibility graph family, compares the graphs with exact reference results,
|
|
15
|
+
labels them with the zones of statistical process control as proposed by
|
|
16
|
+
Ferenczi, Kummer and Abonyi
|
|
17
|
+
([Scientific Reports 16: 17774, 2026](https://doi.org/10.1038/s41598-026-48718-6)),
|
|
18
|
+
segments series through them and draws them. Several methods are new: the exact
|
|
19
|
+
contiguous-modularity segmentation with a surrogate stopping rule, visibility
|
|
20
|
+
enrichment of labelled graphs, the zone ladder, the visibility scalogram, and the
|
|
21
|
+
link between visibility spans and the average run length of control charts.
|
|
22
|
+
|
|
23
|
+
| Module | Contents |
|
|
24
|
+
|---|---|
|
|
25
|
+
| `visibgraph.core` | `VisibilityGraph`: degrees (past and future), spans, edge weights, windows (hereditary property), set operations, Laplacian, node and edge tables |
|
|
26
|
+
| `visibgraph.construct` | natural (divide and conquer, O(N log N) on average), horizontal (O(N) stack), directed, weighted, limited penetrable (LPVG, LPHVG), parametric, difference, bottom and dual-perspective, sliding-window, online, multiplex and image visibility graphs |
|
|
27
|
+
| `visibgraph.measures` | exact iid references (HVG, DHVG, LPHVG, periodic), exponential and power-law fits with safe defaults, Hurst exponent, irreversibility, sequential motifs, global and node features, horizons, cut profiles, graph distances |
|
|
28
|
+
| `visibgraph.symbolic`, `visibgraph.spc`, `visibgraph.labelled` | frozen Phase-I baselines, eight SPC zones, SAX, ordinal patterns; Western Electric and Nelson rules, the reference classifier, ARL; zone-to-zone visibility, state transition networks, label-aggregated graphs, label enrichment |
|
|
29
|
+
| `visibgraph.segment` | window features with PELT and binary segmentation, divergence profiles, exact contiguous modularity (configuration, span and spatial null models), community segmentation, visibility scalograms, segmentation scores |
|
|
30
|
+
| `visibgraph.networks`, `visibgraph.surrogates` | ordinal partition networks, quantile graphs, recurrence networks; shuffle, phase, IAAFT and block surrogates with rank tests |
|
|
31
|
+
| `visibgraph.viz`, `visibgraph.interactive` | sight lines, arc diagrams, adjacency and label matrices, horizon and barrier profiles, control charts, zone ladders, networks, degree distributions, motif profiles, feature timelines, divergence and modularity profiles, scalograms, multiplex views, dashboards; plotly twins |
|
|
32
|
+
| `visibgraph.ml`, `visibgraph.io`, `visibgraph.accessor` | scikit-learn transformer and rule classifier; NetworkX, igraph, ts2vg, GraphML, GEXF, GML, Pajek, JSON, CSV; the `series.vg` pandas accessor |
|
|
33
|
+
| `visibgraph.datasets` | the six-sigma benchmark of the paper (bit-exact port), Tennessee Eastman, Nile, lynx, sunspots; generators of maps, flows, AR, fractional Gaussian noise and motion, periodic, regime-switching and control-chart series |
|
|
34
|
+
|
|
35
|
+
## Installation
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
pip install visibgraph
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Python ≥ 3.10; depends on numpy, scipy, networkx, pandas and matplotlib.
|
|
42
|
+
`pip install "visibgraph[all]"` adds plotly, igraph, ts2vg, ruptures and scikit-learn.
|
|
43
|
+
|
|
44
|
+
## Quick start
|
|
45
|
+
|
|
46
|
+
```python
|
|
47
|
+
import visibgraph as vg
|
|
48
|
+
from visibgraph.viz import plot_visibility, plot_zone_ladder
|
|
49
|
+
|
|
50
|
+
y = vg.datasets.ar1(500, phi=0.6, random_state=1)
|
|
51
|
+
G = vg.hvg(y) # horizontal visibility graph in O(N)
|
|
52
|
+
vg.exponential_fit(G.degree()) # lambda against ln(3/2) of iid noise
|
|
53
|
+
vg.irreversibility(G) # time asymmetry of the series
|
|
54
|
+
|
|
55
|
+
bench = vg.datasets.load_six_sigma_benchmark() # the benchmark of the paper
|
|
56
|
+
y, base = bench.X[1500], bench.baseline(1500) # frozen Phase-I baseline
|
|
57
|
+
G = vg.nvg(y, labels=vg.spc_zones(y, base)) # zone-labelled natural visibility graph
|
|
58
|
+
vg.western_electric(y, base) # rule, direction, start, end
|
|
59
|
+
plot_visibility(G); plot_zone_ladder(G) # sight lines; visibility between zones
|
|
60
|
+
|
|
61
|
+
y, truth = vg.datasets.regime_switching(random_state=0)
|
|
62
|
+
vg.modularity_segmentation(vg.nvg(y)).boundaries # exact contiguous-modularity segmentation
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Documentation and book
|
|
66
|
+
|
|
67
|
+
* Documentation, gallery of 41 runnable examples and API reference:
|
|
68
|
+
<https://complexsystemsintelligence.github.io/visibgraph>
|
|
69
|
+
* The companion book, *Visibility Graphs of Time Series in Python: The visibgraph
|
|
70
|
+
toolbox* (CC BY 4.0): [PDF](https://complexsystemsintelligence.github.io/visibgraph/visibgraph-book.pdf),
|
|
71
|
+
[EPUB](https://complexsystemsintelligence.github.io/visibgraph/visibgraph-book.epub),
|
|
72
|
+
[web edition](https://complexsystemsintelligence.github.io/visibgraph/book/index.html)
|
|
73
|
+
|
|
74
|
+
## Citing
|
|
75
|
+
|
|
76
|
+
Please cite the toolbox and the original paper (see `CITATION.cff`):
|
|
77
|
+
|
|
78
|
+
> J. Abonyi, M. Ferenczi, A. Kummer, *visibgraph: visibility graphs of time series in Python*, version 1.0, 2026.
|
|
79
|
+
>
|
|
80
|
+
> M. Ferenczi, A. Kummer, J. Abonyi, Six-sigma approach-based visibility graphs, *Scientific Reports* 16 (2026) 17774, doi:10.1038/s41598-026-48718-6.
|
|
81
|
+
|
|
82
|
+
## Acknowledgments
|
|
83
|
+
|
|
84
|
+
Developed at the University of Pannonia, Veszprém, by the
|
|
85
|
+
[Complex Systems Intelligence](https://complexsystemsintelligence.github.io) group
|
|
86
|
+
([abonyilab.com](https://www.abonyilab.com)). The research was supported by the
|
|
87
|
+
National Research, Development and Innovation Office of Hungary (NKFIH) through the
|
|
88
|
+
OTKA 143482 project.
|
|
89
|
+
|
|
90
|
+
## License
|
|
91
|
+
|
|
92
|
+
MIT for the software; CC BY 4.0 for the book.
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"""
|
|
2
|
+
First steps: natural and horizontal visibility
|
|
3
|
+
===============================================
|
|
4
|
+
|
|
5
|
+
A visibility graph has one node per observation. In the *natural* visibility
|
|
6
|
+
graph (NVG) two observations are linked if the straight line between their
|
|
7
|
+
tops passes above every observation in between; in the *horizontal* visibility
|
|
8
|
+
graph (HVG) the line must be horizontal, so every intermediate observation must
|
|
9
|
+
be lower than both. The HVG is a subgraph of the NVG. Both graphs always contain
|
|
10
|
+
the path of consecutive observations, so they are connected.
|
|
11
|
+
|
|
12
|
+
The highlighted observation (the highest one) sees far in both graphs: peaks
|
|
13
|
+
become hubs.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
import matplotlib.pyplot as plt
|
|
17
|
+
import numpy as np
|
|
18
|
+
|
|
19
|
+
import visibgraph as vg
|
|
20
|
+
from visibgraph import viz
|
|
21
|
+
|
|
22
|
+
# %%
|
|
23
|
+
# Building the two graphs
|
|
24
|
+
# -----------------------
|
|
25
|
+
# [snippet:build]
|
|
26
|
+
y = np.array([0.8, 2.1, 1.2, 3.4, 0.9, 1.7, 2.8, 0.6, 1.5, 2.4, 1.1, 3.0, 1.9, 0.7, 2.2])
|
|
27
|
+
G = vg.nvg(y) # natural visibility graph
|
|
28
|
+
H = vg.hvg(y) # horizontal visibility graph
|
|
29
|
+
print(G, H, sep="\n")
|
|
30
|
+
print("degrees NVG:", G.degree())
|
|
31
|
+
print("degrees HVG:", H.degree())
|
|
32
|
+
print("HVG is a subgraph of the NVG:", H.difference(G).n_edges == 0)
|
|
33
|
+
# [/snippet:build]
|
|
34
|
+
|
|
35
|
+
fig, axes = plt.subplots(1, 2, figsize=(11, 3.4))
|
|
36
|
+
viz.plot_visibility(G, ax=axes[0], highlight=3, title="Natural visibility (NVG)")
|
|
37
|
+
viz.plot_visibility(H, ax=axes[1], highlight=3, title="Horizontal visibility (HVG)")
|
|
38
|
+
fig.tight_layout()
|
|
39
|
+
|
|
40
|
+
# %%
|
|
41
|
+
# The graphs as networks
|
|
42
|
+
# ----------------------
|
|
43
|
+
# The same graphs drawn as networks (Kamada–Kawai layout), coloured by time
|
|
44
|
+
# and sized by degree. ``G.to_networkx()`` returns a NetworkX graph with the
|
|
45
|
+
# time, value and degree of every node and the span of every edge.
|
|
46
|
+
# [snippet:networkx]
|
|
47
|
+
nxG = G.to_networkx(weights=("span", "slope"))
|
|
48
|
+
print(nxG.nodes[3], list(nxG.edges(data=True))[:2])
|
|
49
|
+
print(G.edge_frame().head())
|
|
50
|
+
# [/snippet:networkx]
|
|
51
|
+
fig, axes = plt.subplots(1, 2, figsize=(9, 4))
|
|
52
|
+
viz.plot_graph(G, ax=axes[0], with_labels=True, title="NVG")
|
|
53
|
+
viz.plot_graph(H, ax=axes[1], with_labels=True, title="HVG")
|
|
54
|
+
fig.tight_layout()
|
|
55
|
+
|
|
56
|
+
# %%
|
|
57
|
+
# Parameter study: how the series shapes the graph
|
|
58
|
+
# ------------------------------------------------
|
|
59
|
+
# A monotone series makes every observation see only its neighbours in the
|
|
60
|
+
# HVG but all observations in the NVG of a convex series; random noise lies in
|
|
61
|
+
# between. The mean degree summarizes this.
|
|
62
|
+
cases = {"increasing": np.arange(15.0), "convex": (np.arange(15.0) - 7) ** 2, "noise": np.random.default_rng(1).normal(size=15)}
|
|
63
|
+
for name, s in cases.items():
|
|
64
|
+
print(f"{name:10s} NVG mean degree {vg.nvg(s).degree().mean():5.2f} HVG mean degree {vg.hvg(s).degree().mean():5.2f}")
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Algorithms and their cost
|
|
3
|
+
=========================
|
|
4
|
+
|
|
5
|
+
The natural visibility graph is computed by divide and conquer (Lan et al.,
|
|
6
|
+
2015): the maximum of a segment blocks every line of sight across it, so after
|
|
7
|
+
the visible neighbours of the maximum have been found the two halves are
|
|
8
|
+
independent. The average cost is :math:`O(N\\log N)`, the worst case (a
|
|
9
|
+
monotone series) :math:`O(N^2)`. A vectorized scan from every node and the
|
|
10
|
+
brute-force check of the definition are available for comparison. The
|
|
11
|
+
horizontal visibility graph needs a single pass with a stack, :math:`O(N)`.
|
|
12
|
+
|
|
13
|
+
The figure shows the measured running times; the dashed lines are slopes 1 and 2
|
|
14
|
+
on the log–log scale.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
import time
|
|
18
|
+
|
|
19
|
+
import matplotlib.pyplot as plt
|
|
20
|
+
import numpy as np
|
|
21
|
+
|
|
22
|
+
import visibgraph as vg
|
|
23
|
+
from visibgraph.viz._style import BRAND, GREEN, VERM, despine
|
|
24
|
+
|
|
25
|
+
# %%
|
|
26
|
+
# The three NVG algorithms give identical graphs
|
|
27
|
+
# ----------------------------------------------
|
|
28
|
+
# [snippet:methods]
|
|
29
|
+
y = np.random.default_rng(0).normal(size=300)
|
|
30
|
+
edges = {m: vg.nvg(y, method=m).edges for m in ("dc", "scan", "naive")}
|
|
31
|
+
print({m: e.shape[0] for m, e in edges.items()},
|
|
32
|
+
"identical:", all(np.array_equal(edges["dc"], e) for e in edges.values()))
|
|
33
|
+
# [/snippet:methods]
|
|
34
|
+
|
|
35
|
+
# %%
|
|
36
|
+
# Running time against the length of the series
|
|
37
|
+
# ---------------------------------------------
|
|
38
|
+
rng = np.random.default_rng(1)
|
|
39
|
+
sizes = [500, 1000, 2000, 4000, 8000, 16000, 32000]
|
|
40
|
+
res = {"NVG divide & conquer": [], "NVG scan": [], "HVG stack": [], "NVG d&c, random walk": []}
|
|
41
|
+
for n in sizes:
|
|
42
|
+
y = rng.normal(size=n)
|
|
43
|
+
w = np.cumsum(rng.normal(size=n))
|
|
44
|
+
for name, f in (("NVG divide & conquer", lambda y=y: vg.nvg(y, method="dc")),
|
|
45
|
+
("NVG scan", lambda y=y: vg.nvg(y, method="scan")),
|
|
46
|
+
("HVG stack", lambda y=y: vg.hvg(y)),
|
|
47
|
+
("NVG d&c, random walk", lambda w=w: vg.nvg(w, method="dc"))):
|
|
48
|
+
if name == "NVG scan" and n > 16000:
|
|
49
|
+
res[name].append(np.nan)
|
|
50
|
+
continue
|
|
51
|
+
t0 = time.perf_counter()
|
|
52
|
+
f()
|
|
53
|
+
res[name].append(time.perf_counter() - t0)
|
|
54
|
+
|
|
55
|
+
fig, ax = plt.subplots(figsize=(5.6, 4))
|
|
56
|
+
for (name, ts), c in zip(res.items(), [BRAND, VERM, GREEN, "#CC79A7"]):
|
|
57
|
+
ax.loglog(sizes, ts, "o-", color=c, label=name, ms=4)
|
|
58
|
+
x = np.array(sizes, float)
|
|
59
|
+
ax.loglog(x, 2e-6 * x, "--", color="gray", lw=0.8)
|
|
60
|
+
ax.loglog(x, 2e-9 * x**2, ":", color="gray", lw=0.8)
|
|
61
|
+
ax.set_xlabel("length of the series $N$")
|
|
62
|
+
ax.set_ylabel("seconds")
|
|
63
|
+
ax.legend(frameon=False, fontsize=8)
|
|
64
|
+
despine(ax)
|
|
65
|
+
ax.set_title("Construction time", fontsize=10, loc="left")
|
|
66
|
+
fig.tight_layout()
|
|
67
|
+
|
|
68
|
+
# %%
|
|
69
|
+
# Parameter study: worst case of divide and conquer
|
|
70
|
+
# -------------------------------------------------
|
|
71
|
+
# A monotone series is the worst case: the maximum is always at the end and the
|
|
72
|
+
# recursion degenerates into a scan. Long series of this kind are better
|
|
73
|
+
# handled with a limited horizon ``max_span``, which keeps only edges up to a
|
|
74
|
+
# given temporal length.
|
|
75
|
+
y = np.sort(np.random.default_rng(2).normal(size=4000))
|
|
76
|
+
for ms in (None, 200, 50):
|
|
77
|
+
t0 = time.perf_counter()
|
|
78
|
+
G = vg.nvg(y, max_span=ms)
|
|
79
|
+
print(f"max_span={ms}: {G.n_edges} edges in {time.perf_counter() - t0:.3f} s")
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Exact results for uncorrelated and periodic series
|
|
3
|
+
===================================================
|
|
4
|
+
|
|
5
|
+
The horizontal visibility graph of a series of independent, identically
|
|
6
|
+
distributed continuous values has the degree distribution
|
|
7
|
+
|
|
8
|
+
.. math:: P(k)=\\tfrac13\\bigl(\\tfrac23\\bigr)^{k-2},\\qquad k\\ge 2,
|
|
9
|
+
|
|
10
|
+
whatever the distribution of the values (Luque et al., 2009): only the order of
|
|
11
|
+
the values matters, and every order is equally likely. Its mean degree is 4. The
|
|
12
|
+
directed graph splits the degree into links to the past and to the future, each
|
|
13
|
+
distributed as :math:`P(k)=2^{-k}` (Lacasa et al., 2012). A periodic series of
|
|
14
|
+
period :math:`T` has mean degree :math:`4(1-1/(2T))` (Núñez et al., 2012). These
|
|
15
|
+
results are the reference against which a real series is read.
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
import matplotlib.pyplot as plt
|
|
19
|
+
import numpy as np
|
|
20
|
+
|
|
21
|
+
import visibgraph as vg
|
|
22
|
+
from visibgraph import measures as M
|
|
23
|
+
from visibgraph import viz
|
|
24
|
+
from visibgraph.viz._style import BRAND, INK, VERM, despine
|
|
25
|
+
|
|
26
|
+
# %%
|
|
27
|
+
# Universality: three distributions, one degree distribution
|
|
28
|
+
# ----------------------------------------------------------
|
|
29
|
+
# [snippet:universal]
|
|
30
|
+
graphs = {d: vg.hvg(vg.datasets.white_noise(100_000, d, random_state=1)) for d in ("normal", "uniform", "exponential")}
|
|
31
|
+
for d, G in graphs.items():
|
|
32
|
+
print(f"{d:12s} mean degree {G.degree().mean():.4f} lambda {M.exponential_fit(G)['lambda']:.4f}")
|
|
33
|
+
# [/snippet:universal]
|
|
34
|
+
fig, axes = plt.subplots(1, 2, figsize=(10, 3.6))
|
|
35
|
+
viz.plot_degree_distribution(graphs, ax=axes[0], title="HVG of i.i.d. series")
|
|
36
|
+
|
|
37
|
+
# %%
|
|
38
|
+
# Links to the past and to the future
|
|
39
|
+
# -----------------------------------
|
|
40
|
+
G = vg.hvg(vg.datasets.white_noise(100_000, random_state=2), directed=True)
|
|
41
|
+
for which, c in (("in", BRAND), ("out", VERM)):
|
|
42
|
+
k, p = M.degree_distribution(G, which, kmax=12)
|
|
43
|
+
axes[1].semilogy(k[1:], p[1:], "o", color=c, label=f"{which}-degree", ms=4)
|
|
44
|
+
kk = np.arange(1, 13)
|
|
45
|
+
axes[1].semilogy(kk, M.dhvg_iid_distribution(kk), "--", color=INK, lw=1, label="$2^{-k}$")
|
|
46
|
+
axes[1].set_xlabel("degree $k$")
|
|
47
|
+
axes[1].legend(frameon=False, fontsize=8)
|
|
48
|
+
despine(axes[1])
|
|
49
|
+
axes[1].set_title("Directed HVG of an i.i.d. series", fontsize=10, loc="left")
|
|
50
|
+
fig.tight_layout()
|
|
51
|
+
|
|
52
|
+
# %%
|
|
53
|
+
# Parameter study: the period of a periodic series
|
|
54
|
+
# ------------------------------------------------
|
|
55
|
+
# [snippet:periodic]
|
|
56
|
+
periods = np.arange(1, 21)
|
|
57
|
+
kbar = [vg.hvg(vg.datasets.periodic(20_000, T, random_state=T)).degree().mean() for T in periods]
|
|
58
|
+
# [/snippet:periodic]
|
|
59
|
+
fig, ax = plt.subplots(figsize=(5.2, 3.4))
|
|
60
|
+
ax.plot(periods, [M.periodic_mean_degree(T) for T in periods], "-", color=INK, lw=1, label=r"$4(1-\frac{1}{2T})$")
|
|
61
|
+
ax.plot(periods, kbar, "o", color=VERM, ms=4, label="measured")
|
|
62
|
+
ax.axhline(4, color="gray", lw=0.6, ls=":")
|
|
63
|
+
ax.set_xlabel("period $T$")
|
|
64
|
+
ax.set_ylabel("mean degree")
|
|
65
|
+
ax.legend(frameon=False)
|
|
66
|
+
despine(ax)
|
|
67
|
+
ax.set_title("Mean degree of periodic series", fontsize=10, loc="left")
|
|
68
|
+
fig.tight_layout()
|