multipers 2.7.0b8__cp315-cp315-win_amd64.whl
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.
- multipers/_2pac_interface.cp315-win_amd64.pyd +0 -0
- multipers/__init__.py +51 -0
- multipers/_aida_interface.cp315-win_amd64.pyd +0 -0
- multipers/_core_delaunay_nanobind.cp315-win_amd64.pyd +0 -0
- multipers/_deg_rips_interface.cp315-win_amd64.pyd +0 -0
- multipers/_end_curves_interface.cp315-win_amd64.pyd +0 -0
- multipers/_function_delaunay_interface.cp315-win_amd64.pyd +0 -0
- multipers/_function_rips_nanobind.cp315-win_amd64.pyd +0 -0
- multipers/_graphcode_interface.cp315-win_amd64.pyd +0 -0
- multipers/_grid_helper_nanobind.cp315-win_amd64.pyd +0 -0
- multipers/_hera_interface.cp315-win_amd64.pyd +0 -0
- multipers/_mcbif_nanobind.cp315-win_amd64.pyd +0 -0
- multipers/_mma_nanobind.cp315-win_amd64.pyd +0 -0
- multipers/_mpfree_interface.cp315-win_amd64.pyd +0 -0
- multipers/_multi_critical_interface.cp315-win_amd64.pyd +0 -0
- multipers/_muphasa_interface.cp315-win_amd64.pyd +0 -0
- multipers/_persistence_algebra_interface.cp315-win_amd64.pyd +0 -0
- multipers/_rhomboid_tiling_interface.cp315-win_amd64.pyd +0 -0
- multipers/_signed_measure_meta.py +489 -0
- multipers/_simplex_tree_multi_nanobind.cp315-win_amd64.pyd +0 -0
- multipers/_simplextree_algorithms.py +26 -0
- multipers/_skyscraper_interface.cp315-win_amd64.pyd +0 -0
- multipers/_slicer_algorithms.py +185 -0
- multipers/_slicer_meta.py +167 -0
- multipers/_slicer_nanobind.cp315-win_amd64.pyd +0 -0
- multipers/array_api/__init__.py +175 -0
- multipers/array_api/jax.py +334 -0
- multipers/array_api/numpy.py +365 -0
- multipers/array_api/torch.py +394 -0
- multipers/data/MOL2.py +505 -0
- multipers/data/UCR.py +18 -0
- multipers/data/__init__.py +1 -0
- multipers/data/graphs.py +466 -0
- multipers/data/immuno_regions.py +27 -0
- multipers/data/minimal_presentation_to_st_bf.py +0 -0
- multipers/data/pytorch2simplextree.py +91 -0
- multipers/data/shape3d.py +101 -0
- multipers/data/synthetic.py +113 -0
- multipers/distances.py +1730 -0
- multipers/filtrations/__init__.py +25 -0
- multipers/filtrations/density.py +727 -0
- multipers/filtrations/filtrations.py +1432 -0
- multipers/function_rips.py +33 -0
- multipers/grids.py +766 -0
- multipers/invariants/__init__.py +779 -0
- multipers/invariants/_utils.py +41 -0
- multipers/invariants/end_curves.py +469 -0
- multipers/invariants/landscapes.py +388 -0
- multipers/invariants/projected_barcode.py +140 -0
- multipers/invariants/skyscraper.py +551 -0
- multipers/libgcc_s_seh-1.dll +0 -0
- multipers/libgmp-10.dll +0 -0
- multipers/libmpfr-6.dll +0 -0
- multipers/logs.py +297 -0
- multipers/ml/__init__.py +0 -0
- multipers/ml/accuracies.py +90 -0
- multipers/ml/filtered_complex.py +529 -0
- multipers/ml/invariants_with_persistable.py +79 -0
- multipers/ml/kernels.py +199 -0
- multipers/ml/mma.py +782 -0
- multipers/ml/one.py +471 -0
- multipers/ml/point_clouds.py +21 -0
- multipers/ml/signed_measures.py +1734 -0
- multipers/ml/sliced_wasserstein.py +286 -0
- multipers/ml/tools.py +113 -0
- multipers/mma_structures.py +1 -0
- multipers/multiparameter_edge_collapse.py +41 -0
- multipers/multiparameter_module_approximation.py +961 -0
- multipers/multipers_core.dll +0 -0
- multipers/multipers_core.lib +0 -0
- multipers/ops.py +870 -0
- multipers/pickle.py +89 -0
- multipers/plots.py +961 -0
- multipers/point_measure.py +421 -0
- multipers/simplex_tree_multi.py +738 -0
- multipers/slicer.py +992 -0
- multipers/tbb12.dll +0 -0
- multipers/tests/__init__.py +73 -0
- multipers-2.7.0b8.dist-info/METADATA +154 -0
- multipers-2.7.0b8.dist-info/RECORD +84 -0
- multipers-2.7.0b8.dist-info/WHEEL +5 -0
- multipers-2.7.0b8.dist-info/licenses/LICENSE +674 -0
- multipers-2.7.0b8.dist-info/licenses/THIRD_PARTY_NOTICES.md +89 -0
- multipers-2.7.0b8.dist-info/licenses/licenses/LGPL-3.0-or-later.txt +165 -0
|
Binary file
|
multipers/__init__.py
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
from importlib import import_module as _import_module
|
|
2
|
+
from importlib.metadata import version as _version
|
|
3
|
+
import sys
|
|
4
|
+
|
|
5
|
+
__version__ = _version("multipers")
|
|
6
|
+
# Doc
|
|
7
|
+
from . import (
|
|
8
|
+
filtrations,
|
|
9
|
+
grids,
|
|
10
|
+
logs,
|
|
11
|
+
multiparameter_module_approximation,
|
|
12
|
+
simplex_tree_multi,
|
|
13
|
+
slicer,
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
if sys.platform != "win32":
|
|
17
|
+
from . import ops
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
# Shortcuts
|
|
21
|
+
from ._slicer_meta import Slicer
|
|
22
|
+
from .multiparameter_module_approximation import module_approximation
|
|
23
|
+
from .simplex_tree_multi import SimplexTreeMulti
|
|
24
|
+
from ._signed_measure_meta import signed_measure
|
|
25
|
+
|
|
26
|
+
__all__ = [
|
|
27
|
+
"data",
|
|
28
|
+
"filtrations",
|
|
29
|
+
"grids",
|
|
30
|
+
"invariants",
|
|
31
|
+
"logs",
|
|
32
|
+
"multiparameter_module_approximation",
|
|
33
|
+
"plots",
|
|
34
|
+
"simplex_tree_multi",
|
|
35
|
+
"slicer",
|
|
36
|
+
"signed_measure",
|
|
37
|
+
"Slicer",
|
|
38
|
+
"module_approximation",
|
|
39
|
+
"SimplexTreeMulti",
|
|
40
|
+
]
|
|
41
|
+
|
|
42
|
+
if sys.platform != "win32":
|
|
43
|
+
__all__.append("ops")
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def __getattr__(name):
|
|
47
|
+
if name in {"data", "invariants", "plots"}:
|
|
48
|
+
module = _import_module(f".{name}", __name__)
|
|
49
|
+
globals()[name] = module
|
|
50
|
+
return module
|
|
51
|
+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,489 @@
|
|
|
1
|
+
from collections.abc import Iterable, Sequence
|
|
2
|
+
from typing import Optional, Union
|
|
3
|
+
|
|
4
|
+
import numpy as np
|
|
5
|
+
import time
|
|
6
|
+
|
|
7
|
+
from multipers.array_api import api_from_tensors
|
|
8
|
+
from multipers.grids import compute_grid, evaluate_in_grid, sms_in_grid
|
|
9
|
+
from multipers.point_measure import clean_sms, zero_out_sms
|
|
10
|
+
from multipers.simplex_tree_multi import (
|
|
11
|
+
SimplexTreeMulti_type,
|
|
12
|
+
_available_strategies,
|
|
13
|
+
is_simplextree_multi,
|
|
14
|
+
)
|
|
15
|
+
from multipers.slicer import (
|
|
16
|
+
Slicer_type,
|
|
17
|
+
_hilbert_signed_measure,
|
|
18
|
+
_rank_from_slicer,
|
|
19
|
+
_signed_measure_from_slicer,
|
|
20
|
+
is_slicer,
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def signed_measure(
|
|
25
|
+
filtered_complex: Union[SimplexTreeMulti_type, Slicer_type],
|
|
26
|
+
degree: Optional[int] = None,
|
|
27
|
+
degrees: Sequence[int | None] = [],
|
|
28
|
+
mass_default=None,
|
|
29
|
+
grid_strategy: _available_strategies = "exact",
|
|
30
|
+
invariant: Optional[str] = None,
|
|
31
|
+
plot: bool = False,
|
|
32
|
+
verbose: bool = False,
|
|
33
|
+
n_jobs: int = -1,
|
|
34
|
+
expand_collapse: bool = False,
|
|
35
|
+
backend: Optional[str] = None, # deprecated
|
|
36
|
+
grid: Optional[Iterable] = None,
|
|
37
|
+
coordinate_measure: bool = False,
|
|
38
|
+
num_collapses: int = 0, # TODO : deprecate
|
|
39
|
+
clean: Optional[bool] = None,
|
|
40
|
+
vineyard: bool = False,
|
|
41
|
+
grid_conversion: Optional[Iterable] = None,
|
|
42
|
+
ignore_infinite_filtration_values: bool = True,
|
|
43
|
+
mobius: str = "auto",
|
|
44
|
+
**infer_grid_kwargs,
|
|
45
|
+
) -> list[tuple[np.ndarray, np.ndarray]]:
|
|
46
|
+
r"""
|
|
47
|
+
Computes the signed measures given by the decomposition of the hilbert
|
|
48
|
+
function or the euler characteristic, or the rank invariant.
|
|
49
|
+
|
|
50
|
+
Parameters
|
|
51
|
+
----------
|
|
52
|
+
- filtered_complex: given by a simplextree or a slicer.
|
|
53
|
+
- degree:int|None / degrees:list[int] the degrees to compute.
|
|
54
|
+
None represents the euler characteristic.
|
|
55
|
+
- mass_default: Either None, or 'auto' or 'inf', or array-like of floats.
|
|
56
|
+
Where to put the default mass to get a zero-mass measure.
|
|
57
|
+
This corresponds to zero-out the filtered complex outside of $\{ x\in \mathbb R^n \mid x\le `mass_default`\}$
|
|
58
|
+
- invariant: The invariant to use, either "hilbert", "rank", or "euler".
|
|
59
|
+
- plot:bool, plots the computed measures if true.
|
|
60
|
+
- n_jobs:int, number of jobs. Defaults to #cpu.
|
|
61
|
+
- verbose:bool, prints c++ logs.
|
|
62
|
+
- expand_collapse: when computing Hilbert from a simplextree, expand the
|
|
63
|
+
copied complex up to max(degrees) + 1 before conversion to a slicer.
|
|
64
|
+
- backend:str reduces first the filtered complex using some external backend `backend`,
|
|
65
|
+
see ``backend`` in :func:`multipers.ops.minimal_presentation`.
|
|
66
|
+
- grid: If given, the computations will be done on the restriction of the filtered complex to this grid.
|
|
67
|
+
It can also be used for auto-differentiation, i.e., if the grid is a list of pytorch tensors,
|
|
68
|
+
then the output measure will be pytorch-differentiable.
|
|
69
|
+
- grid_strategy: If not squeezed yet, and no grid is given,
|
|
70
|
+
the strategy to coarsen the grid; see ``strategy`` in :func:`multipers.grids.compute_grid`.
|
|
71
|
+
- coordinate_measure: bool, if True, compute the signed measure as a coordinates given in grid.
|
|
72
|
+
- num_collapses: int, if `filtered_complex` is a simplextree, does some collapses if possible.
|
|
73
|
+
- clean: if True, reduces the measure. It is not necessary in general.
|
|
74
|
+
- ignore_infinite_filtration_values: Backend optimization.
|
|
75
|
+
- mobius: "auto", "sparse" or "dense" for rank and Hilbert signed
|
|
76
|
+
measures. "auto" keeps sparse rank and chooses sparse Hilbert only when
|
|
77
|
+
the grid shape predicts fewer slice computations. "sparse" applies
|
|
78
|
+
Möbius inversion online and avoids materializing the dense tensor when
|
|
79
|
+
supported. "dense" uses the previous dense path.
|
|
80
|
+
|
|
81
|
+
Output
|
|
82
|
+
------
|
|
83
|
+
|
|
84
|
+
`[signed_measure_of_degree for degree in degrees]`
|
|
85
|
+
with `signed_measure_of_degree` of the form `(dirac location, dirac weights)`.
|
|
86
|
+
|
|
87
|
+
References
|
|
88
|
+
----------
|
|
89
|
+
Loiseaux, Carrière, Botnan, Oudot, and Scoccola, "Stable Vectorization of
|
|
90
|
+
Multiparameter Persistent Homology using Signed Barcodes as Measures",
|
|
91
|
+
Advances in Neural Information Processing Systems, 2023.
|
|
92
|
+
|
|
93
|
+
Scoccola, Setlur, Loiseaux, Carrière, and Oudot, "Differentiability and
|
|
94
|
+
Optimization of Multiparameter Persistent Homology", Proceedings of the
|
|
95
|
+
41st International Conference on Machine Learning, PMLR 235:43986-44011,
|
|
96
|
+
2024.
|
|
97
|
+
|
|
98
|
+
Notes on computational backends
|
|
99
|
+
-------------------------------
|
|
100
|
+
There are several backends for each of these computations.
|
|
101
|
+
The backend for computations used can be displayed with `verbose=True`, use it!
|
|
102
|
+
Also note that if `backend` is given, then the input will be converted to a slicer.
|
|
103
|
+
- Euler: is always computed by summing the weights of the simplices
|
|
104
|
+
- Hilbert: is computed by computing persistence on slices, and a Möbius inversion,
|
|
105
|
+
unless the detected input is a minimal free resolution (i.e., `filtered_complex.is_minres`),
|
|
106
|
+
which in that case, doesn't need any computation.
|
|
107
|
+
- If the input is a simplextree, it is converted to a slicer first.
|
|
108
|
+
- If the input is a slicer then
|
|
109
|
+
- If the input is vineyard-capable, then slices are computed via vineyards updates.
|
|
110
|
+
It is slower in general, but faster if single threaded.
|
|
111
|
+
In particular, it is usually faster to use this backend if you want to compute the
|
|
112
|
+
signed measure of multiple datasets in a parallel context.
|
|
113
|
+
- Otherwise, slices are computed in parallel.
|
|
114
|
+
It is usually faster to use this backend if not in a parallel context.
|
|
115
|
+
- Rank: Same as Hilbert.
|
|
116
|
+
"""
|
|
117
|
+
if backend is not None:
|
|
118
|
+
raise ValueError(
|
|
119
|
+
"backend is deprecated. reduce the complex before this function."
|
|
120
|
+
)
|
|
121
|
+
if mobius not in {"auto", "sparse", "dense"}:
|
|
122
|
+
raise ValueError(
|
|
123
|
+
f"Invalid mobius={mobius!r}. Expected 'auto', 'sparse', or 'dense'."
|
|
124
|
+
)
|
|
125
|
+
if num_collapses > 0:
|
|
126
|
+
raise ValueError(
|
|
127
|
+
"num_collapses is deprecated. reduce the complex before this function."
|
|
128
|
+
)
|
|
129
|
+
## TODO : add timings in verbose
|
|
130
|
+
if grid_conversion is not None:
|
|
131
|
+
grid = tuple(f for f in grid_conversion)
|
|
132
|
+
raise DeprecationWarning(
|
|
133
|
+
"""
|
|
134
|
+
Parameter `grid_conversion` is deprecated. Use `grid` instead.
|
|
135
|
+
Most of the time there is no conversion anymore.
|
|
136
|
+
"""
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
degrees = [] if degrees is None else list(degrees)
|
|
140
|
+
if (
|
|
141
|
+
degree is None
|
|
142
|
+
and len(degrees) == 0
|
|
143
|
+
and is_slicer(filtered_complex)
|
|
144
|
+
and filtered_complex.is_minpres
|
|
145
|
+
and invariant is not None
|
|
146
|
+
):
|
|
147
|
+
degree = filtered_complex.minpres_degree
|
|
148
|
+
if degree is not None or len(degrees) == 0:
|
|
149
|
+
degrees.append(degree)
|
|
150
|
+
if (
|
|
151
|
+
is_slicer(filtered_complex)
|
|
152
|
+
and filtered_complex.is_minpres
|
|
153
|
+
and invariant is not None
|
|
154
|
+
and None not in degrees
|
|
155
|
+
and not np.array_equal(
|
|
156
|
+
np.asarray(degrees, dtype=int).reshape(-1),
|
|
157
|
+
np.asarray([filtered_complex.minpres_degree], dtype=int),
|
|
158
|
+
)
|
|
159
|
+
):
|
|
160
|
+
raise ValueError(
|
|
161
|
+
"Cannot change degree of an already minimal-presentation slicer."
|
|
162
|
+
)
|
|
163
|
+
if None in degrees:
|
|
164
|
+
if len(degrees) != 1:
|
|
165
|
+
raise ValueError(
|
|
166
|
+
f"Can only compute one invariant at the time. Got {degrees=}, {invariant=}."
|
|
167
|
+
)
|
|
168
|
+
if invariant is not None and ("hilbert" in invariant or "rank" in invariant):
|
|
169
|
+
raise ValueError(
|
|
170
|
+
f"Hilbert and Rank cannot compute `None` degree. got {degrees=}, {invariant=}."
|
|
171
|
+
)
|
|
172
|
+
invariant = "euler"
|
|
173
|
+
if clean is None:
|
|
174
|
+
clean = True if None in degrees else False
|
|
175
|
+
|
|
176
|
+
valid_invariants = {
|
|
177
|
+
"hilbert",
|
|
178
|
+
"rank_invariant",
|
|
179
|
+
"euler",
|
|
180
|
+
"rank",
|
|
181
|
+
"euler_characteristic",
|
|
182
|
+
"hilbert_function",
|
|
183
|
+
"rectangle",
|
|
184
|
+
"hook",
|
|
185
|
+
}
|
|
186
|
+
if invariant is not None and invariant not in valid_invariants:
|
|
187
|
+
raise ValueError(
|
|
188
|
+
f"Invalid invariant {invariant!r}. Expected one of {sorted(valid_invariants)}."
|
|
189
|
+
)
|
|
190
|
+
|
|
191
|
+
num_parameters = filtered_complex.num_parameters
|
|
192
|
+
retained_grid = filtered_complex.filtration_grid
|
|
193
|
+
if num_parameters == 0 and retained_grid is not None:
|
|
194
|
+
num_parameters = len(retained_grid)
|
|
195
|
+
if plot and num_parameters != 2:
|
|
196
|
+
raise ValueError(f"Can only plot 2d measures. Got {num_parameters=}.")
|
|
197
|
+
|
|
198
|
+
if grid is None:
|
|
199
|
+
if retained_grid is not None and len(filtered_complex) == 0:
|
|
200
|
+
grid = retained_grid
|
|
201
|
+
elif not filtered_complex.is_squeezed:
|
|
202
|
+
grid = compute_grid(
|
|
203
|
+
filtered_complex, strategy=grid_strategy, **infer_grid_kwargs
|
|
204
|
+
)
|
|
205
|
+
else:
|
|
206
|
+
grid = filtered_complex.filtration_grid
|
|
207
|
+
else:
|
|
208
|
+
grid = tuple(grid)
|
|
209
|
+
if num_parameters == 0 and len(filtered_complex) == 0:
|
|
210
|
+
# An empty `Slicer()` has no parameters; the explicit grid gives the measure width.
|
|
211
|
+
num_parameters = len(grid)
|
|
212
|
+
|
|
213
|
+
if num_parameters != len(grid):
|
|
214
|
+
raise ValueError(
|
|
215
|
+
"Number of parameter do not coincide. "
|
|
216
|
+
f"Got (grid) {len(grid)} and (filtered complex) {num_parameters}."
|
|
217
|
+
)
|
|
218
|
+
|
|
219
|
+
if mass_default is None:
|
|
220
|
+
pass
|
|
221
|
+
elif isinstance(mass_default, str):
|
|
222
|
+
if mass_default == "auto" and len(filtered_complex) == 0:
|
|
223
|
+
# A zero measure has no mass boundary and needs no grid extrema.
|
|
224
|
+
mass_default = None
|
|
225
|
+
elif mass_default == "auto":
|
|
226
|
+
api = api_from_tensors(*grid)
|
|
227
|
+
mass_default = api.asnumpy(
|
|
228
|
+
api.stack([1.1 * api.max(f) - 0.1 * api.min(f) for f in grid])
|
|
229
|
+
)
|
|
230
|
+
elif mass_default == "inf":
|
|
231
|
+
mass_default = np.array([np.inf] * num_parameters)
|
|
232
|
+
else:
|
|
233
|
+
raise NotImplementedError
|
|
234
|
+
else:
|
|
235
|
+
mass_default = np.asarray(mass_default)
|
|
236
|
+
if mass_default.ndim != 1 or mass_default.shape[0] != num_parameters:
|
|
237
|
+
raise ValueError(
|
|
238
|
+
"`mass_default` must be a 1D array with one value per parameter. "
|
|
239
|
+
f"Got shape {mass_default.shape} for {num_parameters} parameters."
|
|
240
|
+
)
|
|
241
|
+
|
|
242
|
+
if len(filtered_complex) == 0:
|
|
243
|
+
rank_measure = invariant is not None and (
|
|
244
|
+
"rank" in invariant or "hook" in invariant or "rectangle" in invariant
|
|
245
|
+
)
|
|
246
|
+
width = num_parameters * (2 if rank_measure else 1)
|
|
247
|
+
sms = [
|
|
248
|
+
(
|
|
249
|
+
np.empty((0, width), dtype=filtered_complex.dtype),
|
|
250
|
+
np.empty(0, dtype=int),
|
|
251
|
+
)
|
|
252
|
+
for _ in degrees
|
|
253
|
+
]
|
|
254
|
+
if len(grid) and not coordinate_measure:
|
|
255
|
+
decode_grid = tuple(grid) * (2 if rank_measure else 1)
|
|
256
|
+
sms = tuple(
|
|
257
|
+
(
|
|
258
|
+
evaluate_in_grid(np.asarray(points, dtype=np.int64), decode_grid),
|
|
259
|
+
weights,
|
|
260
|
+
)
|
|
261
|
+
for points, weights in sms
|
|
262
|
+
)
|
|
263
|
+
return sms
|
|
264
|
+
|
|
265
|
+
if not filtered_complex.is_squeezed:
|
|
266
|
+
if verbose:
|
|
267
|
+
print("Coarsening complex...", end="", flush=True)
|
|
268
|
+
t0 = time.time()
|
|
269
|
+
filtered_complex_ = filtered_complex.grid_squeeze(grid)
|
|
270
|
+
|
|
271
|
+
if verbose:
|
|
272
|
+
print(f"Done. ({time.time() - t0:.3f}s)")
|
|
273
|
+
else:
|
|
274
|
+
filtered_complex_ = filtered_complex.copy()
|
|
275
|
+
|
|
276
|
+
# assert filtered_complex_.is_squeezed
|
|
277
|
+
if None not in degrees:
|
|
278
|
+
if is_slicer(filtered_complex_) and filtered_complex_.is_minres:
|
|
279
|
+
pass
|
|
280
|
+
else:
|
|
281
|
+
max_degree = np.max(degrees) + 1
|
|
282
|
+
if verbose:
|
|
283
|
+
print(f"Pruning simplicies up to {max_degree}...", end="", flush=True)
|
|
284
|
+
t0 = time.time()
|
|
285
|
+
if filtered_complex_.dimension > max_degree:
|
|
286
|
+
filtered_complex_.prune_above_dimension(max_degree)
|
|
287
|
+
if verbose:
|
|
288
|
+
print(f"Done. ({time.time() - t0:.3f}s)")
|
|
289
|
+
|
|
290
|
+
fix_mass_default = mass_default is not None
|
|
291
|
+
if is_slicer(filtered_complex_):
|
|
292
|
+
if verbose:
|
|
293
|
+
print("Input is a slicer.")
|
|
294
|
+
if backend is not None and not filtered_complex_.is_minpres:
|
|
295
|
+
raise ValueError("giving a backend to this function is deprecated")
|
|
296
|
+
else: # No backend
|
|
297
|
+
if invariant is not None and (
|
|
298
|
+
"rank" in invariant or "hook" in invariant or "rectangle" in invariant
|
|
299
|
+
):
|
|
300
|
+
degrees = np.asarray(degrees, dtype=int)
|
|
301
|
+
if verbose:
|
|
302
|
+
print("Computing rank...", end="", flush=True)
|
|
303
|
+
t0 = time.time()
|
|
304
|
+
sms = _rank_from_slicer(
|
|
305
|
+
filtered_complex_,
|
|
306
|
+
degrees=degrees,
|
|
307
|
+
n_jobs=n_jobs,
|
|
308
|
+
zero_pad=fix_mass_default,
|
|
309
|
+
# grid_shape=tuple(len(g) for g in grid),
|
|
310
|
+
ignore_inf=ignore_infinite_filtration_values,
|
|
311
|
+
verbose=verbose,
|
|
312
|
+
mobius=mobius,
|
|
313
|
+
)
|
|
314
|
+
fix_mass_default = False
|
|
315
|
+
if verbose:
|
|
316
|
+
print(f"Done. ({time.time() - t0:.3f}s)")
|
|
317
|
+
elif filtered_complex_.is_minres:
|
|
318
|
+
if verbose:
|
|
319
|
+
print(
|
|
320
|
+
"Minimal-resolution slicer. Retrieving measure from it...",
|
|
321
|
+
end="",
|
|
322
|
+
flush=True,
|
|
323
|
+
)
|
|
324
|
+
t0 = time.time()
|
|
325
|
+
sms = [
|
|
326
|
+
_signed_measure_from_slicer(
|
|
327
|
+
filtered_complex_,
|
|
328
|
+
shift=(
|
|
329
|
+
filtered_complex_.minpres_degree & 1 if d is None else d & 1
|
|
330
|
+
),
|
|
331
|
+
)[0]
|
|
332
|
+
for d in degrees
|
|
333
|
+
]
|
|
334
|
+
if verbose:
|
|
335
|
+
print(f"Done. ({time.time() - t0:.3f}s)")
|
|
336
|
+
elif (invariant is None or "euler" in invariant) and (
|
|
337
|
+
len(degrees) == 1 and degrees[0] is None
|
|
338
|
+
):
|
|
339
|
+
if verbose:
|
|
340
|
+
print("Retrieving measure from slicer...", end="", flush=True)
|
|
341
|
+
t0 = time.time()
|
|
342
|
+
sms = _signed_measure_from_slicer(
|
|
343
|
+
filtered_complex_,
|
|
344
|
+
shift=0, # no minpres
|
|
345
|
+
)
|
|
346
|
+
if verbose:
|
|
347
|
+
print(f"Done. ({time.time() - t0:.3f}s)")
|
|
348
|
+
else:
|
|
349
|
+
if verbose:
|
|
350
|
+
print("Computing Hilbert function...", end="", flush=True)
|
|
351
|
+
t0 = time.time()
|
|
352
|
+
sms = _hilbert_signed_measure(
|
|
353
|
+
filtered_complex_,
|
|
354
|
+
degrees=degrees,
|
|
355
|
+
zero_pad=False,
|
|
356
|
+
n_jobs=n_jobs,
|
|
357
|
+
verbose=verbose,
|
|
358
|
+
ignore_inf=ignore_infinite_filtration_values,
|
|
359
|
+
mobius=mobius,
|
|
360
|
+
)
|
|
361
|
+
fix_mass_default = mass_default is not None
|
|
362
|
+
if verbose:
|
|
363
|
+
print(f"Done. ({time.time() - t0:.3f}s)")
|
|
364
|
+
|
|
365
|
+
elif is_simplextree_multi(filtered_complex_):
|
|
366
|
+
if verbose:
|
|
367
|
+
print("Input is a simplextree.")
|
|
368
|
+
## we still have a simplextree here
|
|
369
|
+
if invariant in ["rank_invariant", "rank", "hook", "rectangle"]:
|
|
370
|
+
if verbose:
|
|
371
|
+
print("Computing rank invariant...", end="", flush=True)
|
|
372
|
+
t0 = time.time()
|
|
373
|
+
|
|
374
|
+
if coordinate_measure:
|
|
375
|
+
raise NotImplementedError("coordinate_measure is not implemented")
|
|
376
|
+
from multipers import Slicer
|
|
377
|
+
|
|
378
|
+
slicer = Slicer(filtered_complex_, dtype=filtered_complex_.dtype)
|
|
379
|
+
sms = _rank_from_slicer(
|
|
380
|
+
slicer,
|
|
381
|
+
degrees=np.asarray(degrees, dtype=int),
|
|
382
|
+
n_jobs=n_jobs,
|
|
383
|
+
zero_pad=fix_mass_default,
|
|
384
|
+
ignore_inf=ignore_infinite_filtration_values,
|
|
385
|
+
verbose=verbose,
|
|
386
|
+
mobius=mobius,
|
|
387
|
+
)
|
|
388
|
+
fix_mass_default = False
|
|
389
|
+
if verbose:
|
|
390
|
+
print(f"Done. ({time.time() - t0:.3f}s)")
|
|
391
|
+
elif len(degrees) == 1 and degrees[0] is None:
|
|
392
|
+
if verbose:
|
|
393
|
+
print("Computing Euler Characteristic...", end="", flush=True)
|
|
394
|
+
t0 = time.time()
|
|
395
|
+
if invariant is not None and invariant not in [
|
|
396
|
+
"euler",
|
|
397
|
+
"euler_characteristic",
|
|
398
|
+
]:
|
|
399
|
+
raise ValueError("Provide a degree to compute hilbert function.")
|
|
400
|
+
# assert not coordinate_measure, "Not implemented"
|
|
401
|
+
from multipers.simplex_tree_multi import _euler_signed_measure
|
|
402
|
+
|
|
403
|
+
sms = [
|
|
404
|
+
_euler_signed_measure(
|
|
405
|
+
filtered_complex_,
|
|
406
|
+
mass_default=mass_default,
|
|
407
|
+
verbose=verbose,
|
|
408
|
+
)
|
|
409
|
+
]
|
|
410
|
+
fix_mass_default = False
|
|
411
|
+
if verbose:
|
|
412
|
+
print(f"Done. ({time.time() - t0:.3f}s)")
|
|
413
|
+
else:
|
|
414
|
+
if verbose:
|
|
415
|
+
print("Computing Hilbert Function...", end="", flush=True)
|
|
416
|
+
t0 = time.time()
|
|
417
|
+
if invariant is not None and invariant not in [
|
|
418
|
+
"hilbert",
|
|
419
|
+
"hilbert_function",
|
|
420
|
+
]:
|
|
421
|
+
raise ValueError("Found homological degrees for euler computation.")
|
|
422
|
+
|
|
423
|
+
if expand_collapse:
|
|
424
|
+
filtered_complex_.expansion(int(np.max(degrees)) + 1)
|
|
425
|
+
from multipers import Slicer
|
|
426
|
+
|
|
427
|
+
sms = _hilbert_signed_measure(
|
|
428
|
+
Slicer(filtered_complex_, dtype=filtered_complex_.dtype),
|
|
429
|
+
degrees=degrees,
|
|
430
|
+
zero_pad=False,
|
|
431
|
+
verbose=verbose,
|
|
432
|
+
n_jobs=n_jobs,
|
|
433
|
+
ignore_inf=ignore_infinite_filtration_values,
|
|
434
|
+
mobius=mobius,
|
|
435
|
+
)
|
|
436
|
+
fix_mass_default = mass_default is not None
|
|
437
|
+
if verbose:
|
|
438
|
+
print(f"Done. ({time.time() - t0:.3f}s)")
|
|
439
|
+
else:
|
|
440
|
+
raise ValueError("Filtered complex has to be a SimplexTree or a Slicer.")
|
|
441
|
+
|
|
442
|
+
if grid is not None and not coordinate_measure:
|
|
443
|
+
if verbose:
|
|
444
|
+
print("Pushing back the measure to the grid...", end="", flush=True)
|
|
445
|
+
t0 = time.time()
|
|
446
|
+
sms = sms_in_grid(
|
|
447
|
+
sms,
|
|
448
|
+
grid=grid,
|
|
449
|
+
mass_default=mass_default,
|
|
450
|
+
# num_parameters=num_parameters,
|
|
451
|
+
)
|
|
452
|
+
if verbose:
|
|
453
|
+
print(f"Done. ({time.time() - t0:.3f}s)")
|
|
454
|
+
|
|
455
|
+
if fix_mass_default:
|
|
456
|
+
# TODO : some methods need to use this, this could be optimized
|
|
457
|
+
if verbose:
|
|
458
|
+
print("Seems that fixing mass default is necessary...", end="", flush=True)
|
|
459
|
+
t0 = time.time()
|
|
460
|
+
sms = zero_out_sms(sms, mass_default=mass_default)
|
|
461
|
+
if verbose:
|
|
462
|
+
print(f"Done. ({time.time() - t0:.3f}s)")
|
|
463
|
+
|
|
464
|
+
if clean:
|
|
465
|
+
if verbose:
|
|
466
|
+
print("Cleaning measure...", end="", flush=True)
|
|
467
|
+
t0 = time.time()
|
|
468
|
+
sms = clean_sms(sms)
|
|
469
|
+
if verbose:
|
|
470
|
+
print(f"Done. ({time.time() - t0:.3f}s)")
|
|
471
|
+
|
|
472
|
+
if invariant == "hook":
|
|
473
|
+
if verbose:
|
|
474
|
+
print(
|
|
475
|
+
"Converting rank decomposition to hook decomposition...",
|
|
476
|
+
end="",
|
|
477
|
+
flush=True,
|
|
478
|
+
)
|
|
479
|
+
t0 = time.time()
|
|
480
|
+
from multipers.point_measure import rectangle_to_hook_minimal_signed_barcode
|
|
481
|
+
|
|
482
|
+
sms = [rectangle_to_hook_minimal_signed_barcode(pts, w) for pts, w in sms]
|
|
483
|
+
if verbose:
|
|
484
|
+
print(f"Done. ({time.time() - t0:.3f}s)")
|
|
485
|
+
if plot:
|
|
486
|
+
from multipers.plots import plot_signed_measures
|
|
487
|
+
|
|
488
|
+
plot_signed_measures(sms, alpha=1 if invariant == "hook" else None)
|
|
489
|
+
return sms
|
|
Binary file
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import numpy as np
|
|
4
|
+
|
|
5
|
+
from multipers import _simplex_tree_multi_nanobind as _nb
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def _euler_signed_measure(simplextree, mass_default=None, verbose=False):
|
|
9
|
+
if not simplextree.is_squeezed:
|
|
10
|
+
raise ValueError("Squeeze grid first.")
|
|
11
|
+
zero_pad = mass_default is not None
|
|
12
|
+
grid_shape = np.array([len(f) for f in simplextree.filtration_grid], dtype=np.int32)
|
|
13
|
+
if mass_default is not None:
|
|
14
|
+
mass_default = np.asarray(mass_default)
|
|
15
|
+
assert (
|
|
16
|
+
mass_default.ndim == 1
|
|
17
|
+
and mass_default.shape[0] == simplextree.num_parameters
|
|
18
|
+
)
|
|
19
|
+
if zero_pad:
|
|
20
|
+
grid_shape = grid_shape + 1
|
|
21
|
+
pts, weights = _nb._compute_euler_signed_measure(
|
|
22
|
+
simplextree, grid_shape.tolist(), zero_pad, verbose
|
|
23
|
+
)
|
|
24
|
+
return np.asarray(pts, dtype=np.int32).reshape(
|
|
25
|
+
-1, simplextree.num_parameters
|
|
26
|
+
), np.asarray(weights, dtype=np.int32)
|
|
Binary file
|