persforest 0.3.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.
- persforest-0.3.0/CMakeLists.txt +50 -0
- persforest-0.3.0/LICENSE +21 -0
- persforest-0.3.0/PKG-INFO +333 -0
- persforest-0.3.0/README.md +288 -0
- persforest-0.3.0/cpp/bindings.cpp +185 -0
- persforest-0.3.0/cpp/cubical.cpp +163 -0
- persforest-0.3.0/cpp/cubical.hpp +37 -0
- persforest-0.3.0/cpp/delaunay.cpp +914 -0
- persforest-0.3.0/cpp/delaunay.hpp +56 -0
- persforest-0.3.0/cpp/engine.cpp +346 -0
- persforest-0.3.0/cpp/engine.hpp +67 -0
- persforest-0.3.0/cpp/simplicial.cpp +162 -0
- persforest-0.3.0/cpp/simplicial.hpp +41 -0
- persforest-0.3.0/cpp/third_party/geogram/Delaunay_psm.cpp +36370 -0
- persforest-0.3.0/cpp/third_party/geogram/Delaunay_psm.h +13251 -0
- persforest-0.3.0/cpp/third_party/geogram/LICENSE +29 -0
- persforest-0.3.0/cpp/third_party/geogram/README.md +44 -0
- persforest-0.3.0/pyproject.toml +96 -0
- persforest-0.3.0/src/persforest/__init__.py +5 -0
- persforest-0.3.0/src/persforest/_forest/__init__.py +0 -0
- persforest-0.3.0/src/persforest/_forest/arrays.py +136 -0
- persforest-0.3.0/src/persforest/_forest/representatives.py +275 -0
- persforest-0.3.0/src/persforest/barcode.py +107 -0
- persforest-0.3.0/src/persforest/chains.py +181 -0
- persforest-0.3.0/src/persforest/filtrations/__init__.py +0 -0
- persforest-0.3.0/src/persforest/filtrations/_interface.py +76 -0
- persforest-0.3.0/src/persforest/filtrations/_validation.py +93 -0
- persforest-0.3.0/src/persforest/filtrations/cubical.py +236 -0
- persforest-0.3.0/src/persforest/filtrations/delaunay.py +149 -0
- persforest-0.3.0/src/persforest/filtrations/simplicial.py +201 -0
- persforest-0.3.0/src/persforest/forest.py +2194 -0
- persforest-0.3.0/src/persforest/geometry/__init__.py +0 -0
- persforest-0.3.0/src/persforest/geometry/cubical.py +140 -0
- persforest-0.3.0/src/persforest/geometry/loops.py +430 -0
- persforest-0.3.0/src/persforest/geometry/planar.py +515 -0
- persforest-0.3.0/src/persforest/geometry/simplicial.py +178 -0
- persforest-0.3.0/src/persforest/landscapes/__init__.py +21 -0
- persforest-0.3.0/src/persforest/landscapes/_validation.py +78 -0
- persforest-0.3.0/src/persforest/landscapes/family.py +187 -0
- persforest-0.3.0/src/persforest/landscapes/functions.py +217 -0
- persforest-0.3.0/src/persforest/landscapes/kernels.py +201 -0
- persforest-0.3.0/src/persforest/landscapes/profiles.py +345 -0
- persforest-0.3.0/src/persforest/measurements/__init__.py +0 -0
- persforest-0.3.0/src/persforest/measurements/additive.py +153 -0
- persforest-0.3.0/src/persforest/measurements/basic.py +319 -0
- persforest-0.3.0/src/persforest/measurements/cubical.py +157 -0
- persforest-0.3.0/src/persforest/measurements/loops.py +370 -0
- persforest-0.3.0/src/persforest/measurements/shape.py +330 -0
- persforest-0.3.0/src/persforest/plotting/__init__.py +0 -0
- persforest-0.3.0/src/persforest/plotting/_cubical_scene.py +268 -0
- persforest-0.3.0/src/persforest/plotting/_dependencies.py +24 -0
- persforest-0.3.0/src/persforest/plotting/_geometry.py +240 -0
- persforest-0.3.0/src/persforest/plotting/_lines.py +146 -0
- persforest-0.3.0/src/persforest/plotting/_routes.py +361 -0
- persforest-0.3.0/src/persforest/plotting/_scene.py +169 -0
- persforest-0.3.0/src/persforest/plotting/_style.py +99 -0
- persforest-0.3.0/src/persforest/plotting/animation/__init__.py +1 -0
- persforest-0.3.0/src/persforest/plotting/animation/_export.py +153 -0
- persforest-0.3.0/src/persforest/plotting/animation/_layout.py +193 -0
- persforest-0.3.0/src/persforest/plotting/animation/_point_cloud.py +90 -0
- persforest-0.3.0/src/persforest/plotting/animation/_timing.py +60 -0
- persforest-0.3.0/src/persforest/plotting/animation/api.py +435 -0
- persforest-0.3.0/src/persforest/plotting/animation/filtration.py +871 -0
- persforest-0.3.0/src/persforest/plotting/animation/measurements.py +230 -0
- persforest-0.3.0/src/persforest/plotting/barcode.py +258 -0
- persforest-0.3.0/src/persforest/plotting/colors.py +112 -0
- persforest-0.3.0/src/persforest/plotting/cubical_mpl.py +793 -0
- persforest-0.3.0/src/persforest/plotting/cubical_plotly.py +440 -0
- persforest-0.3.0/src/persforest/plotting/filtration_mpl.py +927 -0
- persforest-0.3.0/src/persforest/plotting/filtration_plotly.py +720 -0
- persforest-0.3.0/src/persforest/plotting/forest.py +413 -0
- persforest-0.3.0/src/persforest/plotting/interior_mpl.py +803 -0
- persforest-0.3.0/src/persforest/plotting/interior_plotly.py +525 -0
- persforest-0.3.0/src/persforest/plotting/landscapes.py +494 -0
- persforest-0.3.0/src/persforest/plotting/loops.py +95 -0
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
cmake_minimum_required(VERSION 3.18...3.31)
|
|
2
|
+
|
|
3
|
+
project(${SKBUILD_PROJECT_NAME} LANGUAGES CXX)
|
|
4
|
+
|
|
5
|
+
set(CMAKE_CXX_STANDARD 17)
|
|
6
|
+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
7
|
+
set(CMAKE_CXX_EXTENSIONS OFF)
|
|
8
|
+
|
|
9
|
+
find_package(Python 3.11 REQUIRED COMPONENTS Interpreter Development.Module)
|
|
10
|
+
find_package(nanobind CONFIG REQUIRED)
|
|
11
|
+
find_package(Threads REQUIRED)
|
|
12
|
+
|
|
13
|
+
# geogram's Delaunay module, vendored unmodified (BSD-3-Clause; see
|
|
14
|
+
# cpp/third_party/geogram/README.md).
|
|
15
|
+
set(GEOGRAM_DIR cpp/third_party/geogram)
|
|
16
|
+
set(GEOGRAM_SOURCES ${GEOGRAM_DIR}/Delaunay_psm.cpp)
|
|
17
|
+
|
|
18
|
+
# The engine is plain C++17 (cpp/engine.*, cpp/cubical.*, cpp/simplicial.*,
|
|
19
|
+
# cpp/delaunay.*); bindings.cpp is the only file that knows about Python. No
|
|
20
|
+
# fast-math: filtration ties and tolerances rely on exact IEEE comparisons.
|
|
21
|
+
# NOMINSIZE keeps -O3: nanobind's default -Os slows the engine by about 20%.
|
|
22
|
+
nanobind_add_module(_engine NB_STATIC NOMINSIZE cpp/bindings.cpp cpp/engine.cpp cpp/cubical.cpp
|
|
23
|
+
cpp/simplicial.cpp cpp/delaunay.cpp ${GEOGRAM_SOURCES})
|
|
24
|
+
|
|
25
|
+
# GEO_STATIC_LIBS keeps geogram's API macros empty (no dllimport on Windows).
|
|
26
|
+
# The header is a system include so its warnings stay out of our files.
|
|
27
|
+
target_compile_definitions(_engine PRIVATE GEO_STATIC_LIBS)
|
|
28
|
+
# geogram includes <windows.h>; keep its min/max macros and rarely used parts out.
|
|
29
|
+
if(WIN32)
|
|
30
|
+
target_compile_definitions(_engine PRIVATE NOMINMAX WIN32_LEAN_AND_MEAN)
|
|
31
|
+
endif()
|
|
32
|
+
target_include_directories(_engine SYSTEM PRIVATE ${GEOGRAM_DIR})
|
|
33
|
+
target_link_libraries(_engine PRIVATE Threads::Threads)
|
|
34
|
+
|
|
35
|
+
# geogram's exact predicates need separately rounded products: no fused
|
|
36
|
+
# multiply-add contraction in its source or in any file including its header
|
|
37
|
+
# (Clang on arm64 contracts by default). Warnings are silenced for the vendored
|
|
38
|
+
# source only.
|
|
39
|
+
if(MSVC)
|
|
40
|
+
set(GEOGRAM_EXACT_FLAGS /fp:precise)
|
|
41
|
+
set(GEOGRAM_VENDORED_FLAGS /w)
|
|
42
|
+
else()
|
|
43
|
+
set(GEOGRAM_EXACT_FLAGS -ffp-contract=off)
|
|
44
|
+
set(GEOGRAM_VENDORED_FLAGS -w)
|
|
45
|
+
endif()
|
|
46
|
+
set_source_files_properties(${GEOGRAM_SOURCES} PROPERTIES
|
|
47
|
+
COMPILE_OPTIONS "${GEOGRAM_EXACT_FLAGS};${GEOGRAM_VENDORED_FLAGS}")
|
|
48
|
+
set_source_files_properties(cpp/delaunay.cpp PROPERTIES COMPILE_OPTIONS "${GEOGRAM_EXACT_FLAGS}")
|
|
49
|
+
|
|
50
|
+
install(TARGETS _engine LIBRARY DESTINATION persforest)
|
persforest-0.3.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 leonrenkin
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: persforest
|
|
3
|
+
Version: 0.3.0
|
|
4
|
+
Summary: Persistence forests, cycle progression barcodes and measurement landscapes for codimension-one persistent homology.
|
|
5
|
+
Author: Fabian Lenzen
|
|
6
|
+
Author-Email: Leon Renkin <leon.renkin@gmail.com>
|
|
7
|
+
License-Expression: MIT AND BSD-3-Clause
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
License-File: cpp/third_party/geogram/LICENSE
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: Intended Audience :: Science/Research
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
17
|
+
Classifier: Topic :: Scientific/Engineering :: Mathematics
|
|
18
|
+
Project-URL: Repository, https://github.com/leonrenkin/persforest
|
|
19
|
+
Project-URL: Issues, https://github.com/leonrenkin/persforest/issues
|
|
20
|
+
Requires-Python: <3.15,>=3.11
|
|
21
|
+
Requires-Dist: numpy>=1.26
|
|
22
|
+
Provides-Extra: gudhi
|
|
23
|
+
Requires-Dist: gudhi>=3.11; extra == "gudhi"
|
|
24
|
+
Provides-Extra: plot
|
|
25
|
+
Requires-Dist: matplotlib>=3.8; extra == "plot"
|
|
26
|
+
Provides-Extra: plotly
|
|
27
|
+
Requires-Dist: persforest[plot]; extra == "plotly"
|
|
28
|
+
Requires-Dist: plotly>=6.0; extra == "plotly"
|
|
29
|
+
Provides-Extra: notebook
|
|
30
|
+
Requires-Dist: persforest[plotly]; extra == "notebook"
|
|
31
|
+
Requires-Dist: nbformat>=5.10; extra == "notebook"
|
|
32
|
+
Requires-Dist: ipywidgets>=8.1; extra == "notebook"
|
|
33
|
+
Requires-Dist: anywidget>=0.9; extra == "notebook"
|
|
34
|
+
Provides-Extra: examples
|
|
35
|
+
Requires-Dist: persforest[plot]; extra == "examples"
|
|
36
|
+
Requires-Dist: pandas>=2.2; extra == "examples"
|
|
37
|
+
Requires-Dist: scikit-learn>=1.4; extra == "examples"
|
|
38
|
+
Provides-Extra: droplets
|
|
39
|
+
Requires-Dist: persforest[plot]; extra == "droplets"
|
|
40
|
+
Requires-Dist: scipy>=1.11; extra == "droplets"
|
|
41
|
+
Requires-Dist: pillow>=10.0; extra == "droplets"
|
|
42
|
+
Requires-Dist: pandas>=2.2; extra == "droplets"
|
|
43
|
+
Requires-Dist: ipywidgets>=8.1; extra == "droplets"
|
|
44
|
+
Description-Content-Type: text/markdown
|
|
45
|
+
|
|
46
|
+
# Persistence Forests and Measurement Landscapes
|
|
47
|
+
|
|
48
|
+
Implementation accompanying the manuscript on persistent cycle progressions
|
|
49
|
+
and measurement landscapes, available at
|
|
50
|
+
https://doi.org/10.48550/arXiv.2512.09668.
|
|
51
|
+
|
|
52
|
+
## Paper version and citation
|
|
53
|
+
|
|
54
|
+
Release `v0.1.0` is the version of the code used for the results and figures
|
|
55
|
+
in the paper. It is archived on Zenodo; the DOI is shown on the GitHub release
|
|
56
|
+
page. The `main` branch has since been restructured and its API differs, so
|
|
57
|
+
use `v0.1.0` to reproduce the paper:
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
pip install "persforest @ git+https://github.com/leonrenkin/persforest.git@v0.1.0"
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
At `v0.1.0`, the figures are produced by `examples/paper-examples.py` (run from
|
|
64
|
+
inside `examples/`, requires LaTeX), and the tendril regression experiment lives
|
|
65
|
+
in `examples/tendril_regression/`. Citation metadata is in
|
|
66
|
+
[`CITATION.cff`](CITATION.cff).
|
|
67
|
+
|
|
68
|
+
## What this repo provides
|
|
69
|
+
|
|
70
|
+
- `PersistenceForest`: the forest of optimal cycles of a filtration, with its
|
|
71
|
+
barcode and cycle representatives, built by a compiled engine: millions of
|
|
72
|
+
points or pixels take seconds (see [Performance](#performance)). Supports alpha and Delaunay–Čech
|
|
73
|
+
filtrations of point clouds, custom simplicial filtrations, and cubical grids
|
|
74
|
+
(images and volumes).
|
|
75
|
+
- Plots and animations of cycle representatives, barcodes and persistence
|
|
76
|
+
forests (Matplotlib and Plotly).
|
|
77
|
+
- Measurement profiles and landscapes built from cycle measurements such as
|
|
78
|
+
length, enclosed area or volume, circularity and excess curvature.
|
|
79
|
+
- Tutorial notebooks in [`examples/tutorials/`](examples/tutorials/README.md).
|
|
80
|
+
- A droplet segmentation application for 2D microscopy images in
|
|
81
|
+
[`applications/droplet_segmentation/`](applications/droplet_segmentation/README.md).
|
|
82
|
+
|
|
83
|
+
## Installation
|
|
84
|
+
|
|
85
|
+
Requires Python 3.11–3.14. The base installation needs only NumPy; GUDHI and
|
|
86
|
+
plotting dependencies are optional extras.
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
python -m pip install persforest
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Plots and animations need Matplotlib, which the `plot` extra installs:
|
|
93
|
+
`python -m pip install "persforest[plot]"` (the quotes keep shells such as zsh
|
|
94
|
+
from expanding the brackets).
|
|
95
|
+
|
|
96
|
+
Binary wheels are available for Linux (x86_64, aarch64), macOS (Intel and Apple
|
|
97
|
+
silicon, macOS 11 or later) and Windows (x86_64). On other platforms, and when
|
|
98
|
+
installing from a Git checkout, pip compiles a small C++ extension, which needs
|
|
99
|
+
a C++17 compiler (Xcode Command Line Tools on macOS, GCC or Clang on Linux,
|
|
100
|
+
Visual Studio Build Tools on Windows); CMake and the other build tools are
|
|
101
|
+
fetched automatically.
|
|
102
|
+
|
|
103
|
+
| Extra | Adds |
|
|
104
|
+
| --- | --- |
|
|
105
|
+
| `gudhi` | point clouds in four or more dimensions |
|
|
106
|
+
| `plot` | Matplotlib plots and animations |
|
|
107
|
+
| `plotly` | interactive 2D/3D Plotly figures |
|
|
108
|
+
| `notebook` | inline rendering and widgets in Jupyter |
|
|
109
|
+
| `examples` | pandas and scikit-learn for the research scripts |
|
|
110
|
+
| `droplets` | the droplet segmentation application |
|
|
111
|
+
|
|
112
|
+
MP4 export additionally needs `ffmpeg` on `PATH`. Changes between releases,
|
|
113
|
+
including how to upgrade from 0.2.0, are listed in [`CHANGELOG.md`](CHANGELOG.md).
|
|
114
|
+
|
|
115
|
+
For development, use [uv](https://docs.astral.sh/uv/), which installs the
|
|
116
|
+
package editably together with all extras:
|
|
117
|
+
|
|
118
|
+
```bash
|
|
119
|
+
uv sync --all-extras --locked
|
|
120
|
+
uv run python examples/pers_forest_example.py
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
`uv sync` rebuilds the C++ extension when files in `cpp/` or the build
|
|
124
|
+
configuration change.
|
|
125
|
+
|
|
126
|
+
Notebooks are committed without outputs. Enable the Git filter that strips
|
|
127
|
+
them (your working copy keeps its outputs) once per clone:
|
|
128
|
+
|
|
129
|
+
```bash
|
|
130
|
+
git config filter.strip-notebook-outputs.clean "python3 tools/strip_notebook_outputs.py"
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
## Quickstart
|
|
134
|
+
|
|
135
|
+
```python
|
|
136
|
+
import numpy as np
|
|
137
|
+
import matplotlib.pyplot as plt
|
|
138
|
+
from persforest import PersistenceForest
|
|
139
|
+
from persforest.measurements.basic import signed_chain_edge_length
|
|
140
|
+
|
|
141
|
+
rng = np.random.default_rng(0)
|
|
142
|
+
pts = rng.random((300, 2))
|
|
143
|
+
|
|
144
|
+
forest = PersistenceForest(pts) # alpha filtration
|
|
145
|
+
forest.plot_barcode(coloring="forest")
|
|
146
|
+
forest.plot_at_filtration(0.1)
|
|
147
|
+
|
|
148
|
+
family = forest.compute_measurement_landscapes(
|
|
149
|
+
signed_chain_edge_length,
|
|
150
|
+
label="edge-length",
|
|
151
|
+
max_k=5,
|
|
152
|
+
x_grid=np.linspace(0.0, 0.5, 512),
|
|
153
|
+
)
|
|
154
|
+
forest.plot_measurement_landscapes(label="edge-length")
|
|
155
|
+
plt.show()
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
`PersistenceForest` is the public entry point. Other functions are imported
|
|
159
|
+
from their modules, e.g. `persforest.measurements.shape` or
|
|
160
|
+
`persforest.chains.SignedChain`.
|
|
161
|
+
|
|
162
|
+
## Performance
|
|
163
|
+
|
|
164
|
+
Building the forest of a large input takes seconds. The times below run from
|
|
165
|
+
a NumPy array to the complete persistence forest, which holds the barcode and
|
|
166
|
+
the cycle representatives of every bar at every filtration value; single
|
|
167
|
+
representatives are then read from it on demand. Peak memory is that of the
|
|
168
|
+
whole Python process, input included.
|
|
169
|
+
Measured on an Apple M4 Pro (macOS, Python 3.13) in November 2026.
|
|
170
|
+
|
|
171
|
+
**Point clouds** (alpha filtration, uniform random points; median of 3 runs;
|
|
172
|
+
Delaunay–Čech takes about the same time):
|
|
173
|
+
|
|
174
|
+
| Points | 2D time | 2D memory | 3D time | 3D memory |
|
|
175
|
+
| ---: | ---: | ---: | ---: | ---: |
|
|
176
|
+
| 10,000 | 0.01 s | 0.05 GiB | 0.04 s | 0.07 GiB |
|
|
177
|
+
| 100,000 | 0.14 s | 0.14 GiB | 0.36 s | 0.33 GiB |
|
|
178
|
+
| 1,000,000 | 1.7 s | 0.96 GiB | 4.8 s | 3.0 GiB |
|
|
179
|
+
| 3,000,000 | 6.1 s | 2.7 GiB | 17 s | 8.9 GiB |
|
|
180
|
+
| 10,000,000 | 24 s | 9.3 GiB | 63 s¹ | 26 GiB¹ |
|
|
181
|
+
|
|
182
|
+
¹ One run.
|
|
183
|
+
|
|
184
|
+
**Cubical grids** (top-cell filtration; one run per size). Uniform noise is the
|
|
185
|
+
slowest input; smooth images, closer to real data, are 1.4–3× faster:
|
|
186
|
+
|
|
187
|
+
| Grid | Cells | Smooth field | Uniform noise | Memory |
|
|
188
|
+
| --- | ---: | ---: | ---: | ---: |
|
|
189
|
+
| 1024² | 1.0 M | 0.20 s | 0.32 s | 0.4 GiB |
|
|
190
|
+
| 2048² | 4.2 M | 0.86 s | 1.7 s | 1.2–1.4 GiB |
|
|
191
|
+
| 4096² | 16.8 M | 4.2 s | 10 s | 4.6–5.5 GiB |
|
|
192
|
+
| 8192² | 67.1 M | 18 s | 52 s | 18 GiB |
|
|
193
|
+
| 128³ | 2.1 M | 0.47 s | 0.67 s | 0.8 GiB |
|
|
194
|
+
| 256³ | 16.8 M | 5.7 s | 8.7 s | 5.8–6.6 GiB |
|
|
195
|
+
|
|
196
|
+
Memory grows linearly with the input size, so it usually limits the input size
|
|
197
|
+
before time does. The engine is single-threaded; the 3D point-cloud builder
|
|
198
|
+
uses about 1.5 cores. The benchmark harness is in
|
|
199
|
+
[`benchmarks/performance/`](benchmarks/performance/README.md).
|
|
200
|
+
|
|
201
|
+
## Filtrations
|
|
202
|
+
|
|
203
|
+
| Input | Constructor | `filtration_type` |
|
|
204
|
+
| --- | --- | --- |
|
|
205
|
+
| Point cloud | `PersistenceForest.from_points(points)` | `"alpha"` (default), `"delaunay_cech"` |
|
|
206
|
+
| Point cloud + simplices | `PersistenceForest.from_simplicial_filtration(points, filtration)` | `"custom_simplicial"` |
|
|
207
|
+
| Grid values | `PersistenceForest.from_cubical_grid(values)` | `"top_cells"` (default), `"vertices"` |
|
|
208
|
+
|
|
209
|
+
`PersistenceForest(points)` is shorthand for `from_points`. The tracked
|
|
210
|
+
homology has dimension `dim - 1`: H1 of a 2D point cloud or image, H2 of a 3D
|
|
211
|
+
point cloud or volume.
|
|
212
|
+
|
|
213
|
+
- **Alpha and Delaunay–Čech filtrations** of 2D and 3D point clouds are
|
|
214
|
+
computed by persforest's compiled builders on
|
|
215
|
+
[geogram](https://github.com/BrunoLevy/geogram)'s Delaunay triangulation,
|
|
216
|
+
with exact predicates, in radius units. Four or more dimensions use GUDHI
|
|
217
|
+
(the `gudhi` extra); 1D point clouds are not supported.
|
|
218
|
+
Degenerate inputs (grids, cocircular points) are triangulated by symbolic
|
|
219
|
+
perturbation and may give different representatives from earlier versions.
|
|
220
|
+
Of identical points only the first is used. The former `forest.simplex_tree`
|
|
221
|
+
attribute was removed. `forest.filtration` lists the top cells and their
|
|
222
|
+
facets in filtration order.
|
|
223
|
+
- **Custom simplicial filtrations** are `(simplex, value)` pairs with
|
|
224
|
+
nondecreasing values, every face listed before its cofaces. The complex must
|
|
225
|
+
be geometrically embedded and its final complex must be contractible.
|
|
226
|
+
The factory warns that it does not verify these requirements.
|
|
227
|
+
- **Cubical grids** follow GUDHI's conventions (`top_cells`: entries are
|
|
228
|
+
pixels/voxels; `vertices`: lower-star filtration). `spacing` and `origin`
|
|
229
|
+
place the grid in space. In 2D, bars enclose regions brighter than their
|
|
230
|
+
surroundings; use the negative image for dark objects.
|
|
231
|
+
[Tutorial 07](examples/tutorials/07_plotting_cubical_grids.ipynb) shows the
|
|
232
|
+
grid plots.
|
|
233
|
+
|
|
234
|
+
## Representatives and forest structure
|
|
235
|
+
|
|
236
|
+
The forest stores, for each node, only the cells its representative adds or
|
|
237
|
+
removes; representatives are rebuilt on demand from these changes. Get them
|
|
238
|
+
with `forest.iter_bar_cycle_reps(bar)` or `forest.cycle_for_bar_at(bar, value)`.
|
|
239
|
+
A bar's representative changes at `bar.critical_values`; `forest.parent_bar(bar)`
|
|
240
|
+
is the bar it splits off at its birth (None at the root of its tree) and
|
|
241
|
+
`forest.child_bars(bar)` the bars that split off it; `bar.tree_id` names its
|
|
242
|
+
tree. `forest.interior_simplex_activity()`
|
|
243
|
+
returns when each top-dimensional cell lies inside a representative; plot it
|
|
244
|
+
with `forest.plot_interior_simplex_activity()`.
|
|
245
|
+
|
|
246
|
+
## Measurement profiles and landscapes
|
|
247
|
+
|
|
248
|
+
A measurement is a callable `(chain, geometry) -> float`. Ready-made ones are in
|
|
249
|
+
`persforest.measurements` (`basic`, `shape`, `loops`, `cubical`). Shape
|
|
250
|
+
measurements of 2D cycles can be computed on smoothed or taut loops via
|
|
251
|
+
`persforest.measurements.loops` (see
|
|
252
|
+
[tutorial 08](examples/tutorials/08_cycle_shapes_from_loops.ipynb)).
|
|
253
|
+
|
|
254
|
+
`compute_measurement_landscapes` does everything in one call. To reuse the
|
|
255
|
+
measurements, compute the profiles once and build landscapes from them:
|
|
256
|
+
|
|
257
|
+
```python
|
|
258
|
+
from persforest.landscapes import landscapes_from_profiles
|
|
259
|
+
|
|
260
|
+
profiles = forest.compute_measurement_profiles(signed_chain_edge_length, "edge length")
|
|
261
|
+
forest.plot_measurement_profiles(profiles)
|
|
262
|
+
family = landscapes_from_profiles(profiles, x_grid=grid, max_k=5)
|
|
263
|
+
forest.plot_measurement_landscapes(family)
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
Landscapes are sampled on `family.x_grid`; `family.landscapes[k]` is the k-th
|
|
267
|
+
level. Landscapes require nonnegative measurements. Measurements default to
|
|
268
|
+
`signed=False` (opposite simplices cancel before measuring) in every entry
|
|
269
|
+
point, including `animate_barcode_measurement`.
|
|
270
|
+
|
|
271
|
+
### Additive measurements
|
|
272
|
+
|
|
273
|
+
Lengths, areas, volumes and cell counts are sums of fixed per-cell weights.
|
|
274
|
+
Such measurements are `AdditiveMeasurement` objects, and profiles and landscapes
|
|
275
|
+
evaluate them incrementally from the forest's stored diffs instead of
|
|
276
|
+
re-measuring every representative, which is much faster for long-lived cycles
|
|
277
|
+
with large boundaries. The built-ins `signed_chain_volume` (boundary length in 2D,
|
|
278
|
+
area in 3D), `signed_chain_interior_volume`, `cubical_chain_volume` and
|
|
279
|
+
`cubical_chain_interior_volume` are additive. All other measurements, such as
|
|
280
|
+
shape and loop functionals, are evaluated on each representative as before.
|
|
281
|
+
|
|
282
|
+
An `AdditiveMeasurement` is still an ordinary `(chain, geometry) -> float`
|
|
283
|
+
callable. To define one, give a vectorized weight function returning one weight
|
|
284
|
+
per cell and the support it sums over (`"boundary"` or `"interior"`):
|
|
285
|
+
|
|
286
|
+
```python
|
|
287
|
+
import numpy as np
|
|
288
|
+
from persforest.measurements.additive import AdditiveMeasurement
|
|
289
|
+
|
|
290
|
+
edge_count = AdditiveMeasurement(lambda cells, geometry: np.ones(len(cells)), "boundary")
|
|
291
|
+
profiles = forest.compute_measurement_profiles(edge_count, "edge count")
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
Weights must not depend on orientation. Boundary cells are counted once per
|
|
295
|
+
stored orientation, so with the default `signed=False` cells present in both
|
|
296
|
+
orientations cancel.
|
|
297
|
+
|
|
298
|
+
## Tutorials
|
|
299
|
+
|
|
300
|
+
Start with [`examples/tutorials/README.md`](examples/tutorials/README.md):
|
|
301
|
+
|
|
302
|
+
1. Visualizing cycle representatives
|
|
303
|
+
2. Extracting cycle representatives
|
|
304
|
+
3. Animating cycle representatives
|
|
305
|
+
4. Measurement profiles
|
|
306
|
+
5. Measurement landscapes
|
|
307
|
+
6. Plotting persistence forests
|
|
308
|
+
7. Plotting cubical grids
|
|
309
|
+
8. Cycle shapes from loops
|
|
310
|
+
|
|
311
|
+
## Repository layout
|
|
312
|
+
|
|
313
|
+
- `src/persforest/` – the library (`forest.py` is the public facade;
|
|
314
|
+
`filtrations/`, `measurements/`, `landscapes/`, `plotting/` hold the parts).
|
|
315
|
+
- `cpp/` – the compiled engine and the 2D/3D Delaunay filtration builders,
|
|
316
|
+
with geogram's Delaunay module vendored in `cpp/third_party/geogram/`.
|
|
317
|
+
- `examples/` – tutorials, a quickstart script, and point-cloud samplers.
|
|
318
|
+
- `applications/droplet_segmentation/` – droplet segmentation (`dropseg`).
|
|
319
|
+
- `applications/nuclei-boundary-segmentation/` – nuclei from envelope
|
|
320
|
+
stainings (`nucseg`), a separately installed package.
|
|
321
|
+
- `research/` – manuscript figures and the tendril regression experiment.
|
|
322
|
+
- `benchmarks/` – runtime and memory benchmarks.
|
|
323
|
+
- `tests/` – hand-written tests and [agent-written tests](tests/tests-by-agents/README.md).
|
|
324
|
+
|
|
325
|
+
## Tests
|
|
326
|
+
|
|
327
|
+
```bash
|
|
328
|
+
uv sync --all-extras --locked
|
|
329
|
+
MPLBACKEND=Agg uv run --locked python -m unittest discover -s tests -t .
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
CI runs the suite on Python 3.11–3.14 (Linux) and on macOS and Windows, and
|
|
333
|
+
builds and tests the wheels.
|