treegraphduals 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.
Files changed (47) hide show
  1. treegraphduals-0.1.0/.gitignore +19 -0
  2. treegraphduals-0.1.0/CHANGELOG.md +64 -0
  3. treegraphduals-0.1.0/CITATION.cff +28 -0
  4. treegraphduals-0.1.0/LICENSE +9 -0
  5. treegraphduals-0.1.0/PKG-INFO +179 -0
  6. treegraphduals-0.1.0/README.md +149 -0
  7. treegraphduals-0.1.0/docs/Makefile +69 -0
  8. treegraphduals-0.1.0/docs/_static/.gitkeep +0 -0
  9. treegraphduals-0.1.0/docs/api/core.rst +9 -0
  10. treegraphduals-0.1.0/docs/api/timeseries.rst +23 -0
  11. treegraphduals-0.1.0/docs/api/visualizations.rst +33 -0
  12. treegraphduals-0.1.0/docs/changelog.md +5 -0
  13. treegraphduals-0.1.0/docs/conf.py +112 -0
  14. treegraphduals-0.1.0/docs/contributing.rst +4 -0
  15. treegraphduals-0.1.0/docs/examples.rst +4 -0
  16. treegraphduals-0.1.0/docs/index.rst +70 -0
  17. treegraphduals-0.1.0/docs/installation.rst +8 -0
  18. treegraphduals-0.1.0/docs/quickstart.rst +4 -0
  19. treegraphduals-0.1.0/docs/testing.rst +45 -0
  20. treegraphduals-0.1.0/docs/tutorial.rst +4 -0
  21. treegraphduals-0.1.0/pyproject.toml +93 -0
  22. treegraphduals-0.1.0/pytest.ini +18 -0
  23. treegraphduals-0.1.0/src/treegraphduals/__init__.py +30 -0
  24. treegraphduals-0.1.0/src/treegraphduals/agents/__init__.py +4 -0
  25. treegraphduals-0.1.0/src/treegraphduals/core/__init__.py +28 -0
  26. treegraphduals-0.1.0/src/treegraphduals/core/base_graph.py +303 -0
  27. treegraphduals-0.1.0/src/treegraphduals/core/binary_tree.py +286 -0
  28. treegraphduals-0.1.0/src/treegraphduals/core/dag.py +84 -0
  29. treegraphduals-0.1.0/src/treegraphduals/core/erdos_renyi.py +36 -0
  30. treegraphduals-0.1.0/src/treegraphduals/core/forest.py +45 -0
  31. treegraphduals-0.1.0/src/treegraphduals/core/galton_watson.py +53 -0
  32. treegraphduals-0.1.0/src/treegraphduals/core/graph.py +28 -0
  33. treegraphduals-0.1.0/src/treegraphduals/core/multigraph.py +23 -0
  34. treegraphduals-0.1.0/src/treegraphduals/core/polytree.py +58 -0
  35. treegraphduals-0.1.0/src/treegraphduals/core/real_tree.py +39 -0
  36. treegraphduals-0.1.0/src/treegraphduals/core/tree.py +1293 -0
  37. treegraphduals-0.1.0/src/treegraphduals/py.typed +0 -0
  38. treegraphduals-0.1.0/src/treegraphduals/timeseries/__init__.py +36 -0
  39. treegraphduals-0.1.0/src/treegraphduals/timeseries/timeseries.py +991 -0
  40. treegraphduals-0.1.0/src/treegraphduals/visualizations/__init__.py +44 -0
  41. treegraphduals-0.1.0/src/treegraphduals/visualizations/plot_combined.py +217 -0
  42. treegraphduals-0.1.0/src/treegraphduals/visualizations/plot_timeseries.py +205 -0
  43. treegraphduals-0.1.0/src/treegraphduals/visualizations/plot_trees.py +751 -0
  44. treegraphduals-0.1.0/tests/test_binary_tree.py +165 -0
  45. treegraphduals-0.1.0/tests/test_timeseries.py +108 -0
  46. treegraphduals-0.1.0/tests/test_tree.py +371 -0
  47. treegraphduals-0.1.0/uv.lock +1383 -0
@@ -0,0 +1,19 @@
1
+ .idea
2
+ .claude/settings.local.json
3
+ __pycache__/
4
+ *.py[cod]
5
+ *.egg-info/
6
+ .pytest_cache/
7
+ .coverage
8
+ coverage.json
9
+ htmlcov/
10
+ docs/_build/
11
+ .venv/
12
+ venv/
13
+ build/
14
+ dist/
15
+ .mypy_cache/
16
+ .ruff_cache/
17
+ .env
18
+ docs/coverage_report.md
19
+ docs/test_results.txt
@@ -0,0 +1,64 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project are documented here.
4
+ Format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
5
+
6
+ ## [Unreleased]
7
+ ### Fixed
8
+ - Docstring tree diagrams rendered mangled: 15 docstrings were not raw strings,
9
+ so a trailing `\` in the ASCII art silently swallowed the following newline
10
+ and joined rows together (`/ \` + `1 2` became `/ 1 2`). The
11
+ art in the source was correct all along. Diagrams are now raw strings inside
12
+ RST literal blocks, and the Horton pruning and Horton-Strahler examples are
13
+ redrawn from what the algorithms actually produce.
14
+ - The Sphinx build is now warning-free (was 84 warnings).
15
+ - Symbolic extrema search (`TimeSeries.from_function(..., preserve_extrema=True)`)
16
+ no longer silently discards critical points:
17
+ - Real roots that sympy returns in complex form (Cardano's formula writes the
18
+ three real roots of a cubic using `I`) were dropped, because the reality test
19
+ was "does `float()` succeed". Reality is now decided by the magnitude of the
20
+ imaginary part, so e.g. `t**4/4 - 2*t**2 + t/3` reports its three extrema
21
+ instead of none.
22
+ - Periodic derivatives only ever produced sympy's principal solutions, so
23
+ `sin(t)` on `[0, 10]` lost its maximum at `5*pi/2`. Critical points are now
24
+ solved over the interval, which enumerates the periodic solutions.
25
+ - `plot_tree_and_harris_path` no longer leaks one matplotlib figure per call
26
+ (pyplot kept every discarded `plot_tree` figure alive), and now draws the tree
27
+ into its left axes instead of a "Tree plot" placeholder.
28
+
29
+ ### Changed
30
+ - README reorganized into what the package computes today versus what is
31
+ planned. Every original bullet is preserved; the previous single list mixed
32
+ 25+ unimplemented features (duals, visibility graphs, merge trees, graph
33
+ metrics) with the 7 that work, and it is the PyPI long description.
34
+
35
+ ### Added
36
+ - `tests/test_timeseries.py`: regression tests for the extrema cases above, the
37
+ numerical fallback path, uniform sampling, and level-set tree construction.
38
+ - Packaging: Hatchling build backend, so the project can be built and published
39
+ (`uv build`). Ships `py.typed`, the MIT license file, README as the long
40
+ description, classifiers, keywords and project URLs.
41
+
42
+ ### Changed
43
+ - **Breaking:** moved `core`, `timeseries`, `visualizations` and `agents` under a
44
+ single `src/treegraphduals/` package. Imports are now
45
+ `from treegraphduals.core import Tree` rather than `from core import Tree`,
46
+ so the library no longer claims generic top-level names.
47
+ - `requires-python` raised to `>=3.12`, matching what CI and Read the Docs test.
48
+ - Test and documentation tooling moved out of runtime dependencies into the `dev`
49
+ and `docs` dependency groups; a plain `pip install treegraphduals` no longer
50
+ pulls in pytest and Sphinx.
51
+ - Doctests now run by default: `testpaths` covers `src` as well as `tests`, so the
52
+ `--doctest-modules` flag in CI is no longer a no-op (62 tests, up from 40).
53
+ - `docs/conf.py` reads the version from package metadata instead of hardcoding it,
54
+ and no longer injects an absolute local path for doctest setup.
55
+ - Replaced a `print` with `warnings.warn` when symbolic differentiation falls back
56
+ to the numerical extrema search.
57
+ - Cleared the Ruff backlog (56 findings): added missing module and magic-method
58
+ docstrings, made ASCII-art docstrings raw so the diagrams render literally,
59
+ replaced implicit `Optional` annotations, narrowed a bare `except`, collapsed
60
+ nested conditionals, sorted `__all__` lists, and dropped dead locals.
61
+
62
+ ## [0.1.0] - 2026-09-18
63
+ ### Added
64
+ - Initial project setup: `uv` packaging, Ruff lint/format, Pyrefly type checking, pytest + Hypothesis + coverage, Sphinx docs on Read the Docs, `CITATION.cff` with Zenodo DOI, pre-commit hooks.
@@ -0,0 +1,28 @@
1
+ cff-version: 1.2.0
2
+ message: "If you use this software in your work, please cite it as below."
3
+ title: "treegraphduals"
4
+ version: "0.1.0"
5
+ date-released: "2026-09-19"
6
+ authors:
7
+ - family-names: "Khan"
8
+ given-names: "Ibraheem"
9
+ orcid: "https://orcid.org/0009-0002-5697-0682"
10
+ url: "https://github.com/pikhan/treegraphduals"
11
+ repository-code: "https://github.com/pikhan/treegraphduals"
12
+ identifiers:
13
+ - type: doi
14
+ value: 10.5281/zenodo.22839827
15
+ description: "The concept DOI representing all versions of this work."
16
+ preferred-citation:
17
+ type: thesis
18
+ thesis-type: "Master's Thesis"
19
+ title: "The Horizontal Tunnelability Graph is Dual to Level Set Trees"
20
+ authors:
21
+ - family-names: "Khan"
22
+ given-names: "Ibraheem"
23
+ orcid: "https://orcid.org/0009-0002-5697-0682"
24
+ institution:
25
+ name: "University of Nevada, Reno"
26
+ year: 2023
27
+ month: 9
28
+ url: "http://hdl.handle.net/11714/10548"
@@ -0,0 +1,9 @@
1
+
2
+
3
+ Copyright 2024, Ibraheem Mehdi Khan
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,179 @@
1
+ Metadata-Version: 2.5
2
+ Name: treegraphduals
3
+ Version: 0.1.0
4
+ Summary: Trees, their duals, graphs, and time series: level-set trees, Harris paths, Horton-Strahler pruning, and horizontal tunnelability graphs.
5
+ Project-URL: Homepage, https://github.com/pikhan/treegraphduals
6
+ Project-URL: Repository, https://github.com/pikhan/treegraphduals
7
+ Project-URL: Documentation, https://treegraphduals.readthedocs.io
8
+ Project-URL: Changelog, https://github.com/pikhan/treegraphduals/blob/main/CHANGELOG.md
9
+ Project-URL: Thesis, http://hdl.handle.net/11714/10548
10
+ Project-URL: Zenodo, https://doi.org/10.5281/zenodo.22839827
11
+ Author-email: Ibraheem Mehdi Khan <polymathykhan@gmail.com>
12
+ License-Expression: MIT
13
+ License-File: LICENSE
14
+ Keywords: duality,graphs,harris paths,horton-strahler,level-set trees,random self-similar trees,time series,trees
15
+ Classifier: Development Status :: 3 - Alpha
16
+ Classifier: Intended Audience :: Science/Research
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Topic :: Scientific/Engineering :: Mathematics
21
+ Classifier: Typing :: Typed
22
+ Requires-Python: >=3.12
23
+ Requires-Dist: igraph>=0.11
24
+ Requires-Dist: matplotlib>=3.8
25
+ Requires-Dist: networkx>=3.2
26
+ Requires-Dist: numpy>=1.26
27
+ Requires-Dist: scipy>=1.11
28
+ Requires-Dist: sympy>=1.12
29
+ Description-Content-Type: text/markdown
30
+
31
+ [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.22839827.svg)](https://doi.org/10.5281/zenodo.22839827)
32
+ [![Docs](https://readthedocs.org/projects/treegraphduals/badge/?version=latest)](https://treegraphduals.readthedocs.io/en/latest/)
33
+
34
+ # treegraphduals
35
+
36
+ This package is an extension of my Master's thesis: [The Horizontal Tunnelability Graph is Dual to Level Set Trees](http://hdl.handle.net/11714/10548).
37
+ I have tried to keep everything as compatible as possible with other popular time series, tree, and graph libraries.
38
+
39
+ This is an early release. The sections below separate what the package computes
40
+ today from what it is being built towards, so you can tell at a glance whether
41
+ the piece you need is ready.
42
+
43
+ ## Install
44
+
45
+ ```bash
46
+ pip install treegraphduals # or: uv add treegraphduals
47
+ ```
48
+
49
+ Requires Python 3.12+.
50
+
51
+ ## Quickstart
52
+
53
+ ```python
54
+ from treegraphduals.core import Tree
55
+ from treegraphduals.timeseries import TimeSeries
56
+
57
+ # Level-set tree of a time series
58
+ ts = TimeSeries.from_array([0, 3, 1, 4, 2, 5, 0])
59
+ tree = ts.to_level_set_tree()
60
+ tree # Tree(n_nodes=6, n_leaves=3, root=0)
61
+ tree.horton_strahler_order_tree() # 2
62
+ tree.max_horton_prunings() # 3
63
+
64
+ # Level-set tree of a symbolic function, using exact critical points
65
+ import sympy as sp
66
+
67
+ t = sp.Symbol("t")
68
+ extrema = TimeSeries.from_function(
69
+ (t - 1) * (t - 3) * (t - 5) * (t - 7), 1, 7, preserve_extrema=True
70
+ )
71
+ extrema.times # [1.0, 1.764, 4.0, 6.236, 7.0]
72
+
73
+ # Hand the result to NetworkX or igraph
74
+ G = tree.to_networkx() # DiGraph with 6 nodes and 5 edges
75
+ ```
76
+
77
+ ## What the package computes today
78
+
79
+ **Time series to trees**
80
+
81
+ - Level Set Trees of Time Series as Alternating Piecewise Linear Excursions with Slopes +/- 1 (Harris Paths)
82
+ - Level Set Trees of Time Series as Alternating Piecewise Linear Excursions of Arbitrary Slope
83
+ - Level Set Trees and Partial Trees of Arbitrary Time Series
84
+ - Level Set Trees of Arbitrary Functions via Sympy, using exact symbolic differentiation
85
+ - Harris Paths of Binary Trees (and Partial Trees)
86
+ - Local extrema detection, minimal excursions, and unit-slope excursions
87
+
88
+ **Trees**
89
+
90
+ - Horton-Strahler Orders of a Binary Tree, and of a tree as a whole
91
+ - Horton Pruning of a Tree, with series reduction, and the pruning count to eliminate a tree
92
+ - Plantedness, leaves, internal nodes, depths, subtree sizes, total length
93
+ - Traversals: depth-first, breadth-first, left-to-right, and edge contours
94
+ - Paths, distances, and ancestry queries between any two nodes
95
+ - Structures: `Tree`, `BinaryTree`, `Forest`, `DAG`, `Polytree`, `Graph`, `Multigraph`, `ErdosRenyi`, `GaltonWatsonTree`, `RealTree`
96
+
97
+ Trees may be weighted or unweighted.
98
+
99
+ **Interoperability** — every structure converts to and from
100
+
101
+ - NetworkX and igraph graphs
102
+ - NumPy adjacency matrices and SciPy sparse matrices
103
+ - Parent arrays, with left/right child information preserved for binary trees
104
+
105
+ This is the intended route to general graph-theoretic quantities for now:
106
+ export to NetworkX or igraph and use their algorithms.
107
+
108
+ **Visualization**
109
+
110
+ - Tree plots with disk (for duality), radial, force-directed, and hierarchical layouts
111
+ - Coloring by Horton-Strahler order, with node and edge annotations
112
+ - Time series, excursion, and extrema plots
113
+ - Trees drawn side by side with their Harris path
114
+
115
+ ## Planned
116
+
117
+ None of the following is implemented yet. They are the roadmap, listed here
118
+ because they are where the package is going, not what it does now.
119
+
120
+ **Duals and visibility graphs**
121
+
122
+ - Duals of Binary Trees (Horizontal Tunnelability Graphs)
123
+ - Duals of Binary Trees w/ Partial Trees
124
+ - Dual of a Graph
125
+ - Horizontal Visibility Graphs of Piecewise Linear Excursions, Arbitrary Time Series, and Arbitrary Functions
126
+ - Horizon Visibility Graphs of Piecewise Linear Excursions, Arbitrary Time Series, and Arbitrary Functions
127
+ - Visibility Graphs of Piecewise Linear Excursions, Arbitrary Time Series, and Arbitrary Functions
128
+
129
+ **Further tree and time series constructions**
130
+
131
+ - Time Series Merge Trees of Arbitrary Time Series and of Arbitrary Functions
132
+ - Chiral Merge Trees of Arbitrary Time Series and of Arbitrary Functions
133
+ - U-shaped Segments of Arbitrary Time Series and of Arbitrary Functions
134
+ - Hurst Exponents
135
+ - Persistence Diagrams/Barcodes
136
+ - Time-varying trees, and hence time-varying duals, with appropriate interpretation on time series
137
+
138
+ **Native graph functionality**
139
+
140
+ The graph classes are intended to become general enough to allow for:
141
+
142
+ - Vertices with or without numerical weights as well as optional labels of arbitrary data type
143
+ - Directed or undirected Edges with or without numerical weights and optional labels of arbitrary data type
144
+ - Easy and efficient recall/computation of other graph representations and important quantities such as
145
+ - Adjacency Matrix, Incidence Matrix, Adjacency List, Laplacian Matrix, Graph Distance Matrix, etc.
146
+ - Graph Traversal Algorithms: DFS and BFS
147
+ - Find Shortest Path, Shortest Path Function, Hamiltonian Path, Topological Sort
148
+ - Find Graph Distances, Find Paths (Edge/Vertex Independent as well), Find Cycles (All, Eulerian, Hamiltonian, Postman, Shortest Tour)
149
+ - Check if two Graphs are Isomorphic
150
+ - Graph Union, Find Maximum Flow, Path Lengths, Mean Path Lengths, etc.
151
+ - Compute Graph Polynomials: Tutte, Chromatic, Flow
152
+ - Check if a Graph is a Subgraph of Another Graph
153
+ - Generate Neighborhood Graphs and Subgraphs from Graphs
154
+ - Get Connected Components of a Graph, k-Core Components, Weakly Connected Components
155
+ - Find Cliques
156
+ - Check if a Graph is a Tree (and if so how k-ary), if it is Acyclic, Bipartite, Planar, Loop Free, Simple, etc.
157
+ - Graph Self-Similarity, Small-World Property, Scale-Invariance
158
+ - Graph Metrics: Vertex and Edge Count, Vertex Degree/In and Out Degrees, Vertex Eccentricity
159
+ - Graph Radius, Graph Diameter, Graph Center, Graph Periphery, Vertex and Edge Connectivity
160
+ - Centrality Measures: Closeness, Betweenness, Edge Betweenness, Degree Centrality, Eigenvector Centrality, Katz Centrality, PageRank Centrality, HITS Centrality, Radiality, Status Centrality
161
+ - Reciprocity and Transitivity Measures: Graph Reciprocity & Global, Local, and Mean Clustering Coefficients
162
+ - Homophily, Assortative Mixing, and Similarity Measures: Assortativity, Vertex Correlation, Mean Neighbor Degree
163
+ - Mean Degree Connectivity, Vertex Dice Similarity, Vertex Jaccard Similarity, Vertex Cosine Similarity
164
+ - Mean Degree, Mean Path Length, Clustering Coefficients, Degree Distributions, Degree Sequences, many many other things
165
+
166
+ ## Documentation
167
+
168
+ Full API documentation, tutorials, and examples: <https://treegraphduals.readthedocs.io>
169
+
170
+ ## Citing
171
+
172
+ If you use this package, please cite it via the DOI above, or see
173
+ [`CITATION.cff`](CITATION.cff). The underlying thesis is
174
+ *The Horizontal Tunnelability Graph is Dual to Level Set Trees*
175
+ (University of Nevada, Reno, 2023).
176
+
177
+ ## License
178
+
179
+ MIT
@@ -0,0 +1,149 @@
1
+ [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.22839827.svg)](https://doi.org/10.5281/zenodo.22839827)
2
+ [![Docs](https://readthedocs.org/projects/treegraphduals/badge/?version=latest)](https://treegraphduals.readthedocs.io/en/latest/)
3
+
4
+ # treegraphduals
5
+
6
+ This package is an extension of my Master's thesis: [The Horizontal Tunnelability Graph is Dual to Level Set Trees](http://hdl.handle.net/11714/10548).
7
+ I have tried to keep everything as compatible as possible with other popular time series, tree, and graph libraries.
8
+
9
+ This is an early release. The sections below separate what the package computes
10
+ today from what it is being built towards, so you can tell at a glance whether
11
+ the piece you need is ready.
12
+
13
+ ## Install
14
+
15
+ ```bash
16
+ pip install treegraphduals # or: uv add treegraphduals
17
+ ```
18
+
19
+ Requires Python 3.12+.
20
+
21
+ ## Quickstart
22
+
23
+ ```python
24
+ from treegraphduals.core import Tree
25
+ from treegraphduals.timeseries import TimeSeries
26
+
27
+ # Level-set tree of a time series
28
+ ts = TimeSeries.from_array([0, 3, 1, 4, 2, 5, 0])
29
+ tree = ts.to_level_set_tree()
30
+ tree # Tree(n_nodes=6, n_leaves=3, root=0)
31
+ tree.horton_strahler_order_tree() # 2
32
+ tree.max_horton_prunings() # 3
33
+
34
+ # Level-set tree of a symbolic function, using exact critical points
35
+ import sympy as sp
36
+
37
+ t = sp.Symbol("t")
38
+ extrema = TimeSeries.from_function(
39
+ (t - 1) * (t - 3) * (t - 5) * (t - 7), 1, 7, preserve_extrema=True
40
+ )
41
+ extrema.times # [1.0, 1.764, 4.0, 6.236, 7.0]
42
+
43
+ # Hand the result to NetworkX or igraph
44
+ G = tree.to_networkx() # DiGraph with 6 nodes and 5 edges
45
+ ```
46
+
47
+ ## What the package computes today
48
+
49
+ **Time series to trees**
50
+
51
+ - Level Set Trees of Time Series as Alternating Piecewise Linear Excursions with Slopes +/- 1 (Harris Paths)
52
+ - Level Set Trees of Time Series as Alternating Piecewise Linear Excursions of Arbitrary Slope
53
+ - Level Set Trees and Partial Trees of Arbitrary Time Series
54
+ - Level Set Trees of Arbitrary Functions via Sympy, using exact symbolic differentiation
55
+ - Harris Paths of Binary Trees (and Partial Trees)
56
+ - Local extrema detection, minimal excursions, and unit-slope excursions
57
+
58
+ **Trees**
59
+
60
+ - Horton-Strahler Orders of a Binary Tree, and of a tree as a whole
61
+ - Horton Pruning of a Tree, with series reduction, and the pruning count to eliminate a tree
62
+ - Plantedness, leaves, internal nodes, depths, subtree sizes, total length
63
+ - Traversals: depth-first, breadth-first, left-to-right, and edge contours
64
+ - Paths, distances, and ancestry queries between any two nodes
65
+ - Structures: `Tree`, `BinaryTree`, `Forest`, `DAG`, `Polytree`, `Graph`, `Multigraph`, `ErdosRenyi`, `GaltonWatsonTree`, `RealTree`
66
+
67
+ Trees may be weighted or unweighted.
68
+
69
+ **Interoperability** — every structure converts to and from
70
+
71
+ - NetworkX and igraph graphs
72
+ - NumPy adjacency matrices and SciPy sparse matrices
73
+ - Parent arrays, with left/right child information preserved for binary trees
74
+
75
+ This is the intended route to general graph-theoretic quantities for now:
76
+ export to NetworkX or igraph and use their algorithms.
77
+
78
+ **Visualization**
79
+
80
+ - Tree plots with disk (for duality), radial, force-directed, and hierarchical layouts
81
+ - Coloring by Horton-Strahler order, with node and edge annotations
82
+ - Time series, excursion, and extrema plots
83
+ - Trees drawn side by side with their Harris path
84
+
85
+ ## Planned
86
+
87
+ None of the following is implemented yet. They are the roadmap, listed here
88
+ because they are where the package is going, not what it does now.
89
+
90
+ **Duals and visibility graphs**
91
+
92
+ - Duals of Binary Trees (Horizontal Tunnelability Graphs)
93
+ - Duals of Binary Trees w/ Partial Trees
94
+ - Dual of a Graph
95
+ - Horizontal Visibility Graphs of Piecewise Linear Excursions, Arbitrary Time Series, and Arbitrary Functions
96
+ - Horizon Visibility Graphs of Piecewise Linear Excursions, Arbitrary Time Series, and Arbitrary Functions
97
+ - Visibility Graphs of Piecewise Linear Excursions, Arbitrary Time Series, and Arbitrary Functions
98
+
99
+ **Further tree and time series constructions**
100
+
101
+ - Time Series Merge Trees of Arbitrary Time Series and of Arbitrary Functions
102
+ - Chiral Merge Trees of Arbitrary Time Series and of Arbitrary Functions
103
+ - U-shaped Segments of Arbitrary Time Series and of Arbitrary Functions
104
+ - Hurst Exponents
105
+ - Persistence Diagrams/Barcodes
106
+ - Time-varying trees, and hence time-varying duals, with appropriate interpretation on time series
107
+
108
+ **Native graph functionality**
109
+
110
+ The graph classes are intended to become general enough to allow for:
111
+
112
+ - Vertices with or without numerical weights as well as optional labels of arbitrary data type
113
+ - Directed or undirected Edges with or without numerical weights and optional labels of arbitrary data type
114
+ - Easy and efficient recall/computation of other graph representations and important quantities such as
115
+ - Adjacency Matrix, Incidence Matrix, Adjacency List, Laplacian Matrix, Graph Distance Matrix, etc.
116
+ - Graph Traversal Algorithms: DFS and BFS
117
+ - Find Shortest Path, Shortest Path Function, Hamiltonian Path, Topological Sort
118
+ - Find Graph Distances, Find Paths (Edge/Vertex Independent as well), Find Cycles (All, Eulerian, Hamiltonian, Postman, Shortest Tour)
119
+ - Check if two Graphs are Isomorphic
120
+ - Graph Union, Find Maximum Flow, Path Lengths, Mean Path Lengths, etc.
121
+ - Compute Graph Polynomials: Tutte, Chromatic, Flow
122
+ - Check if a Graph is a Subgraph of Another Graph
123
+ - Generate Neighborhood Graphs and Subgraphs from Graphs
124
+ - Get Connected Components of a Graph, k-Core Components, Weakly Connected Components
125
+ - Find Cliques
126
+ - Check if a Graph is a Tree (and if so how k-ary), if it is Acyclic, Bipartite, Planar, Loop Free, Simple, etc.
127
+ - Graph Self-Similarity, Small-World Property, Scale-Invariance
128
+ - Graph Metrics: Vertex and Edge Count, Vertex Degree/In and Out Degrees, Vertex Eccentricity
129
+ - Graph Radius, Graph Diameter, Graph Center, Graph Periphery, Vertex and Edge Connectivity
130
+ - Centrality Measures: Closeness, Betweenness, Edge Betweenness, Degree Centrality, Eigenvector Centrality, Katz Centrality, PageRank Centrality, HITS Centrality, Radiality, Status Centrality
131
+ - Reciprocity and Transitivity Measures: Graph Reciprocity & Global, Local, and Mean Clustering Coefficients
132
+ - Homophily, Assortative Mixing, and Similarity Measures: Assortativity, Vertex Correlation, Mean Neighbor Degree
133
+ - Mean Degree Connectivity, Vertex Dice Similarity, Vertex Jaccard Similarity, Vertex Cosine Similarity
134
+ - Mean Degree, Mean Path Length, Clustering Coefficients, Degree Distributions, Degree Sequences, many many other things
135
+
136
+ ## Documentation
137
+
138
+ Full API documentation, tutorials, and examples: <https://treegraphduals.readthedocs.io>
139
+
140
+ ## Citing
141
+
142
+ If you use this package, please cite it via the DOI above, or see
143
+ [`CITATION.cff`](CITATION.cff). The underlying thesis is
144
+ *The Horizontal Tunnelability Graph is Dual to Level Set Trees*
145
+ (University of Nevada, Reno, 2023).
146
+
147
+ ## License
148
+
149
+ MIT
@@ -0,0 +1,69 @@
1
+ # Makefile for Sphinx documentation with integrated testing
2
+
3
+ SPHINXOPTS ?=
4
+ SPHINXBUILD ?= sphinx-build
5
+ SOURCEDIR = .
6
+ BUILDDIR = _build
7
+ PYTEST = pytest
8
+ COVERAGE = coverage
9
+
10
+ .PHONY: help clean html test coverage docs-with-tests
11
+
12
+ help:
13
+ @echo "Please use 'make <target>' where <target> is one of"
14
+ @echo " html Build HTML documentation only"
15
+ @echo " test Run tests only"
16
+ @echo " coverage Run tests with coverage only"
17
+ @echo " docs-with-tests Run tests + coverage + build docs (RECOMMENDED)"
18
+ @echo " clean Remove build artifacts"
19
+
20
+ clean:
21
+ rm -rf $(BUILDDIR)/*
22
+ rm -rf ../htmlcov
23
+ rm -rf ../.coverage
24
+ rm -rf ../.pytest_cache
25
+ rm -f coverage_report.md test_results.txt
26
+
27
+ test:
28
+ @echo "Running pytest..."
29
+ cd .. && $(PYTEST) -v
30
+
31
+ coverage:
32
+ @echo "Running pytest with coverage..."
33
+ cd .. && $(PYTEST) --cov=treegraphduals --cov-report=html --cov-report=term -v
34
+
35
+ docs-with-tests:
36
+ @echo "========================================="
37
+ @echo "Running Tests & Building Documentation"
38
+ @echo "========================================="
39
+ @echo ""
40
+ @echo "Step 1: Running all tests with coverage..."
41
+ cd .. && $(PYTEST) --cov=treegraphduals \
42
+ --cov-report=html \
43
+ --cov-report=term \
44
+ --cov-report=json \
45
+ --cov-report=markdown:docs/coverage_report.md \
46
+ --doctest-modules \
47
+ -v --tb=short | tee docs/test_results.txt
48
+ @echo ""
49
+ @echo "Step 2: Building Sphinx documentation..."
50
+ $(SPHINXBUILD) -b html "$(SOURCEDIR)" "$(BUILDDIR)/html" $(SPHINXOPTS)
51
+ @echo ""
52
+ @echo "Step 3: Copying coverage HTML..."
53
+ @if [ -d "../htmlcov" ]; then \
54
+ cp -r ../htmlcov $(BUILDDIR)/html/; \
55
+ echo "Coverage report copied to _build/html/htmlcov/"; \
56
+ fi
57
+ @echo ""
58
+ @echo "========================================="
59
+ @echo "Done!"
60
+ @echo "Open: $(BUILDDIR)/html/index.html"
61
+ @echo "Coverage: $(BUILDDIR)/html/htmlcov/index.html"
62
+ @echo "========================================="
63
+
64
+ html: clean
65
+ $(SPHINXBUILD) -b html "$(SOURCEDIR)" "$(BUILDDIR)/html" $(SPHINXOPTS)
66
+
67
+ # Catch-all target
68
+ %: Makefile
69
+ @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
File without changes
@@ -0,0 +1,9 @@
1
+ Core Module
2
+ ===========
3
+
4
+ The core module provides the fundamental graph data structures.
5
+
6
+ .. automodule:: treegraphduals.core
7
+ :members:
8
+ :undoc-members:
9
+ :show-inheritance:
@@ -0,0 +1,23 @@
1
+ Time Series Module
2
+ ==================
3
+
4
+ The time series module provides the fundamental time series data structures and tools for manipulation/analysis.
5
+
6
+ .. autoclass:: treegraphduals.timeseries.TimeSeries
7
+ :members:
8
+ :inherited-members:
9
+ :show-inheritance:
10
+
11
+ Conversion Functions
12
+ --------------------
13
+
14
+ .. autofunction:: treegraphduals.timeseries.timeseries_to_tree
15
+
16
+ .. autofunction:: treegraphduals.timeseries.tree_to_timeseries
17
+
18
+ .. autofunction:: treegraphduals.timeseries.tree_to_harris_path
19
+
20
+ Utilities
21
+ ---------
22
+
23
+ .. autofunction:: treegraphduals.timeseries.detect_local_extrema
@@ -0,0 +1,33 @@
1
+ Visualizations Module
2
+ =====================
3
+
4
+ The visualizations module provides the main methods for visualizing trees, graphs, time series, duals, etc.
5
+
6
+ Tree Plotting
7
+ -------------
8
+
9
+ .. autofunction:: treegraphduals.visualizations.plot_tree
10
+
11
+ .. autofunction:: treegraphduals.visualizations.color_by_horton_strahler
12
+
13
+ .. autofunction:: treegraphduals.visualizations.add_node_annotation
14
+
15
+ .. autofunction:: treegraphduals.visualizations.add_edge_annotation
16
+
17
+ Time Series Plotting
18
+ --------------------
19
+
20
+ .. autofunction:: treegraphduals.visualizations.plot_timeseries
21
+
22
+ .. autofunction:: treegraphduals.visualizations.plot_timeseries_with_extrema
23
+
24
+ .. autofunction:: treegraphduals.visualizations.plot_excursion
25
+
26
+ Combined Visualizations
27
+ -----------------------
28
+
29
+ .. autofunction:: treegraphduals.visualizations.plot_tree_and_harris_path
30
+
31
+ .. autofunction:: treegraphduals.visualizations.plot_levelset_overlay
32
+
33
+ .. autofunction:: treegraphduals.visualizations.plot_graph_overlay
@@ -0,0 +1,5 @@
1
+ # Changelog
2
+
3
+ ```{include} ../CHANGELOG.md
4
+ :start-line: 1
5
+ ```