multipers 2.4.0b1__cp312-cp312-macosx_11_0_arm64.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/.dylibs/libboost_timer.dylib +0 -0
- multipers/.dylibs/libc++.1.0.dylib +0 -0
- multipers/.dylibs/libtbb.12.17.dylib +0 -0
- multipers/__init__.py +33 -0
- multipers/_signed_measure_meta.py +426 -0
- multipers/_slicer_meta.py +231 -0
- multipers/array_api/__init__.py +62 -0
- multipers/array_api/numpy.py +124 -0
- multipers/array_api/torch.py +133 -0
- multipers/data/MOL2.py +458 -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 +202 -0
- multipers/filtration_conversions.pxd +736 -0
- multipers/filtration_conversions.pxd.tp +226 -0
- multipers/filtrations/__init__.py +21 -0
- multipers/filtrations/density.py +529 -0
- multipers/filtrations/filtrations.py +480 -0
- multipers/filtrations.pxd +534 -0
- multipers/filtrations.pxd.tp +332 -0
- multipers/function_rips.cpython-312-darwin.so +0 -0
- multipers/function_rips.pyx +104 -0
- multipers/grids.cpython-312-darwin.so +0 -0
- multipers/grids.pyx +538 -0
- multipers/gudhi/Persistence_slices_interface.h +213 -0
- multipers/gudhi/Simplex_tree_interface.h +274 -0
- multipers/gudhi/Simplex_tree_multi_interface.h +648 -0
- multipers/gudhi/gudhi/Bitmap_cubical_complex.h +450 -0
- multipers/gudhi/gudhi/Bitmap_cubical_complex_base.h +1070 -0
- multipers/gudhi/gudhi/Bitmap_cubical_complex_periodic_boundary_conditions_base.h +579 -0
- multipers/gudhi/gudhi/Debug_utils.h +52 -0
- multipers/gudhi/gudhi/Degree_rips_bifiltration.h +2307 -0
- multipers/gudhi/gudhi/Dynamic_multi_parameter_filtration.h +2524 -0
- multipers/gudhi/gudhi/Fields/Multi_field.h +453 -0
- multipers/gudhi/gudhi/Fields/Multi_field_operators.h +460 -0
- multipers/gudhi/gudhi/Fields/Multi_field_shared.h +444 -0
- multipers/gudhi/gudhi/Fields/Multi_field_small.h +584 -0
- multipers/gudhi/gudhi/Fields/Multi_field_small_operators.h +490 -0
- multipers/gudhi/gudhi/Fields/Multi_field_small_shared.h +580 -0
- multipers/gudhi/gudhi/Fields/Z2_field.h +391 -0
- multipers/gudhi/gudhi/Fields/Z2_field_operators.h +389 -0
- multipers/gudhi/gudhi/Fields/Zp_field.h +493 -0
- multipers/gudhi/gudhi/Fields/Zp_field_operators.h +384 -0
- multipers/gudhi/gudhi/Fields/Zp_field_shared.h +492 -0
- multipers/gudhi/gudhi/Flag_complex_edge_collapser.h +337 -0
- multipers/gudhi/gudhi/Matrix.h +2200 -0
- multipers/gudhi/gudhi/Multi_filtration/Multi_parameter_generator.h +1712 -0
- multipers/gudhi/gudhi/Multi_filtration/multi_filtration_conversions.h +237 -0
- multipers/gudhi/gudhi/Multi_filtration/multi_filtration_utils.h +225 -0
- multipers/gudhi/gudhi/Multi_parameter_filtered_complex.h +485 -0
- multipers/gudhi/gudhi/Multi_parameter_filtration.h +2643 -0
- multipers/gudhi/gudhi/Multi_persistence/Box.h +233 -0
- multipers/gudhi/gudhi/Multi_persistence/Line.h +309 -0
- multipers/gudhi/gudhi/Multi_persistence/Multi_parameter_filtered_complex_pcoh_interface.h +268 -0
- multipers/gudhi/gudhi/Multi_persistence/Persistence_interface_cohomology.h +159 -0
- multipers/gudhi/gudhi/Multi_persistence/Persistence_interface_matrix.h +463 -0
- multipers/gudhi/gudhi/Multi_persistence/Point.h +853 -0
- multipers/gudhi/gudhi/Off_reader.h +173 -0
- multipers/gudhi/gudhi/Persistence_matrix/Base_matrix.h +834 -0
- multipers/gudhi/gudhi/Persistence_matrix/Base_matrix_with_column_compression.h +838 -0
- multipers/gudhi/gudhi/Persistence_matrix/Boundary_matrix.h +833 -0
- multipers/gudhi/gudhi/Persistence_matrix/Chain_matrix.h +1367 -0
- multipers/gudhi/gudhi/Persistence_matrix/Id_to_index_overlay.h +1157 -0
- multipers/gudhi/gudhi/Persistence_matrix/Position_to_index_overlay.h +869 -0
- multipers/gudhi/gudhi/Persistence_matrix/RU_matrix.h +905 -0
- multipers/gudhi/gudhi/Persistence_matrix/allocators/entry_constructors.h +122 -0
- multipers/gudhi/gudhi/Persistence_matrix/base_pairing.h +260 -0
- multipers/gudhi/gudhi/Persistence_matrix/base_swap.h +288 -0
- multipers/gudhi/gudhi/Persistence_matrix/chain_pairing.h +170 -0
- multipers/gudhi/gudhi/Persistence_matrix/chain_rep_cycles.h +247 -0
- multipers/gudhi/gudhi/Persistence_matrix/chain_vine_swap.h +571 -0
- multipers/gudhi/gudhi/Persistence_matrix/columns/chain_column_extra_properties.h +182 -0
- multipers/gudhi/gudhi/Persistence_matrix/columns/column_dimension_holder.h +130 -0
- multipers/gudhi/gudhi/Persistence_matrix/columns/column_utilities.h +235 -0
- multipers/gudhi/gudhi/Persistence_matrix/columns/entry_types.h +312 -0
- multipers/gudhi/gudhi/Persistence_matrix/columns/heap_column.h +1092 -0
- multipers/gudhi/gudhi/Persistence_matrix/columns/intrusive_list_column.h +923 -0
- multipers/gudhi/gudhi/Persistence_matrix/columns/intrusive_set_column.h +914 -0
- multipers/gudhi/gudhi/Persistence_matrix/columns/list_column.h +930 -0
- multipers/gudhi/gudhi/Persistence_matrix/columns/naive_vector_column.h +1071 -0
- multipers/gudhi/gudhi/Persistence_matrix/columns/row_access.h +203 -0
- multipers/gudhi/gudhi/Persistence_matrix/columns/set_column.h +886 -0
- multipers/gudhi/gudhi/Persistence_matrix/columns/unordered_set_column.h +984 -0
- multipers/gudhi/gudhi/Persistence_matrix/columns/vector_column.h +1213 -0
- multipers/gudhi/gudhi/Persistence_matrix/index_mapper.h +58 -0
- multipers/gudhi/gudhi/Persistence_matrix/matrix_dimension_holders.h +227 -0
- multipers/gudhi/gudhi/Persistence_matrix/matrix_row_access.h +200 -0
- multipers/gudhi/gudhi/Persistence_matrix/ru_pairing.h +166 -0
- multipers/gudhi/gudhi/Persistence_matrix/ru_rep_cycles.h +319 -0
- multipers/gudhi/gudhi/Persistence_matrix/ru_vine_swap.h +562 -0
- multipers/gudhi/gudhi/Persistence_on_a_line.h +152 -0
- multipers/gudhi/gudhi/Persistence_on_rectangle.h +617 -0
- multipers/gudhi/gudhi/Persistent_cohomology/Field_Zp.h +118 -0
- multipers/gudhi/gudhi/Persistent_cohomology/Multi_field.h +173 -0
- multipers/gudhi/gudhi/Persistent_cohomology/Persistent_cohomology_column.h +128 -0
- multipers/gudhi/gudhi/Persistent_cohomology.h +769 -0
- multipers/gudhi/gudhi/Points_off_io.h +171 -0
- multipers/gudhi/gudhi/Projective_cover_kernel.h +379 -0
- multipers/gudhi/gudhi/Simple_object_pool.h +69 -0
- multipers/gudhi/gudhi/Simplex_tree/Simplex_tree_iterators.h +559 -0
- multipers/gudhi/gudhi/Simplex_tree/Simplex_tree_node_explicit_storage.h +83 -0
- multipers/gudhi/gudhi/Simplex_tree/Simplex_tree_siblings.h +121 -0
- multipers/gudhi/gudhi/Simplex_tree/Simplex_tree_star_simplex_iterators.h +277 -0
- multipers/gudhi/gudhi/Simplex_tree/filtration_value_utils.h +155 -0
- multipers/gudhi/gudhi/Simplex_tree/hooks_simplex_base.h +62 -0
- multipers/gudhi/gudhi/Simplex_tree/indexing_tag.h +27 -0
- multipers/gudhi/gudhi/Simplex_tree/serialization_utils.h +60 -0
- multipers/gudhi/gudhi/Simplex_tree/simplex_tree_options.h +105 -0
- multipers/gudhi/gudhi/Simplex_tree.h +3170 -0
- multipers/gudhi/gudhi/Slicer.h +848 -0
- multipers/gudhi/gudhi/Thread_safe_slicer.h +393 -0
- multipers/gudhi/gudhi/distance_functions.h +62 -0
- multipers/gudhi/gudhi/graph_simplicial_complex.h +104 -0
- multipers/gudhi/gudhi/multi_simplex_tree_helpers.h +147 -0
- multipers/gudhi/gudhi/persistence_interval.h +263 -0
- multipers/gudhi/gudhi/persistence_matrix_options.h +188 -0
- multipers/gudhi/gudhi/reader_utils.h +367 -0
- multipers/gudhi/gudhi/simple_mdspan.h +484 -0
- multipers/gudhi/gudhi/slicer_helpers.h +779 -0
- multipers/gudhi/tmp_h0_pers/mma_interface_h0.h +223 -0
- multipers/gudhi/tmp_h0_pers/naive_merge_tree.h +536 -0
- multipers/io.cpython-312-darwin.so +0 -0
- multipers/io.pyx +472 -0
- multipers/ml/__init__.py +0 -0
- multipers/ml/accuracies.py +90 -0
- multipers/ml/invariants_with_persistable.py +79 -0
- multipers/ml/kernels.py +176 -0
- multipers/ml/mma.py +713 -0
- multipers/ml/one.py +472 -0
- multipers/ml/point_clouds.py +352 -0
- multipers/ml/signed_measures.py +1667 -0
- multipers/ml/sliced_wasserstein.py +461 -0
- multipers/ml/tools.py +113 -0
- multipers/mma_structures.cpython-312-darwin.so +0 -0
- multipers/mma_structures.pxd +134 -0
- multipers/mma_structures.pyx +1483 -0
- multipers/mma_structures.pyx.tp +1126 -0
- multipers/multi_parameter_rank_invariant/diff_helpers.h +85 -0
- multipers/multi_parameter_rank_invariant/euler_characteristic.h +95 -0
- multipers/multi_parameter_rank_invariant/function_rips.h +317 -0
- multipers/multi_parameter_rank_invariant/hilbert_function.h +761 -0
- multipers/multi_parameter_rank_invariant/persistence_slices.h +149 -0
- multipers/multi_parameter_rank_invariant/rank_invariant.h +350 -0
- multipers/multiparameter_edge_collapse.py +41 -0
- multipers/multiparameter_module_approximation/approximation.h +2541 -0
- multipers/multiparameter_module_approximation/debug.h +107 -0
- multipers/multiparameter_module_approximation/format_python-cpp.h +292 -0
- multipers/multiparameter_module_approximation/utilities.h +428 -0
- multipers/multiparameter_module_approximation.cpython-312-darwin.so +0 -0
- multipers/multiparameter_module_approximation.pyx +286 -0
- multipers/ops.cpython-312-darwin.so +0 -0
- multipers/ops.pyx +231 -0
- multipers/pickle.py +89 -0
- multipers/plots.py +550 -0
- multipers/point_measure.cpython-312-darwin.so +0 -0
- multipers/point_measure.pyx +409 -0
- multipers/simplex_tree_multi.cpython-312-darwin.so +0 -0
- multipers/simplex_tree_multi.pxd +136 -0
- multipers/simplex_tree_multi.pyx +11719 -0
- multipers/simplex_tree_multi.pyx.tp +2102 -0
- multipers/slicer.cpython-312-darwin.so +0 -0
- multipers/slicer.pxd +2097 -0
- multipers/slicer.pxd.tp +263 -0
- multipers/slicer.pyx +13042 -0
- multipers/slicer.pyx.tp +1259 -0
- multipers/tensor/tensor.h +672 -0
- multipers/tensor.pxd +13 -0
- multipers/test.pyx +44 -0
- multipers/tests/__init__.py +70 -0
- multipers/torch/__init__.py +1 -0
- multipers/torch/diff_grids.py +240 -0
- multipers/torch/rips_density.py +310 -0
- multipers/vector_interface.pxd +46 -0
- multipers-2.4.0b1.dist-info/METADATA +131 -0
- multipers-2.4.0b1.dist-info/RECORD +184 -0
- multipers-2.4.0b1.dist-info/WHEEL +6 -0
- multipers-2.4.0b1.dist-info/licenses/LICENSE +21 -0
- multipers-2.4.0b1.dist-info/top_level.txt +1 -0
|
Binary file
|
|
Binary file
|
|
Binary file
|
multipers/__init__.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
from importlib.metadata import version as _version
|
|
2
|
+
|
|
3
|
+
__version__ = _version("multipers")
|
|
4
|
+
# Doc
|
|
5
|
+
from multipers import (
|
|
6
|
+
data,
|
|
7
|
+
filtrations,
|
|
8
|
+
grids,
|
|
9
|
+
io,
|
|
10
|
+
multiparameter_module_approximation,
|
|
11
|
+
simplex_tree_multi,
|
|
12
|
+
slicer,
|
|
13
|
+
)
|
|
14
|
+
from multipers._signed_measure_meta import signed_measure
|
|
15
|
+
|
|
16
|
+
# Shortcuts
|
|
17
|
+
from multipers._slicer_meta import Slicer
|
|
18
|
+
from multipers.multiparameter_module_approximation import module_approximation
|
|
19
|
+
from multipers.simplex_tree_multi import SimplexTreeMulti
|
|
20
|
+
|
|
21
|
+
__all__ = [
|
|
22
|
+
"data",
|
|
23
|
+
"filtrations",
|
|
24
|
+
"grids",
|
|
25
|
+
"io",
|
|
26
|
+
"multiparameter_module_approximation",
|
|
27
|
+
"simplex_tree_multi",
|
|
28
|
+
"slicer",
|
|
29
|
+
"signed_measure",
|
|
30
|
+
"Slicer",
|
|
31
|
+
"module_approximation",
|
|
32
|
+
"SimplexTreeMulti",
|
|
33
|
+
]
|
|
@@ -0,0 +1,426 @@
|
|
|
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.grids import compute_grid, sms_in_grid
|
|
8
|
+
from multipers.plots import plot_signed_measures
|
|
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
|
+
is_slicer,
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def signed_measure(
|
|
24
|
+
filtered_complex: Union[SimplexTreeMulti_type, Slicer_type],
|
|
25
|
+
degree: Optional[int] = None,
|
|
26
|
+
degrees: Sequence[int | None] = [],
|
|
27
|
+
mass_default=None,
|
|
28
|
+
grid_strategy: _available_strategies = "exact",
|
|
29
|
+
invariant: Optional[str] = None,
|
|
30
|
+
plot: bool = False,
|
|
31
|
+
verbose: bool = False,
|
|
32
|
+
n_jobs: int = -1,
|
|
33
|
+
expand_collapse: bool = False,
|
|
34
|
+
backend: Optional[str] = None, # deprecated
|
|
35
|
+
grid: Optional[Iterable] = None,
|
|
36
|
+
coordinate_measure: bool = False,
|
|
37
|
+
num_collapses: int = 0, # TODO : deprecate
|
|
38
|
+
clean: Optional[bool] = None,
|
|
39
|
+
vineyard: bool = False,
|
|
40
|
+
grid_conversion: Optional[Iterable] = None,
|
|
41
|
+
ignore_infinite_filtration_values: bool = True,
|
|
42
|
+
**infer_grid_kwargs,
|
|
43
|
+
) -> list[tuple[np.ndarray, np.ndarray]]:
|
|
44
|
+
r"""
|
|
45
|
+
Computes the signed measures given by the decomposition of the hilbert
|
|
46
|
+
function or the euler characteristic, or the rank invariant.
|
|
47
|
+
|
|
48
|
+
Input
|
|
49
|
+
-----
|
|
50
|
+
- filtered_complex: given by a simplextree or a slicer.
|
|
51
|
+
- degree:int|None / degrees:list[int] the degrees to compute.
|
|
52
|
+
None represents the euler characteristic.
|
|
53
|
+
- mass_default: Either None, or 'auto' or 'inf', or array-like of floats.
|
|
54
|
+
Where to put the default mass to get a zero-mass measure.
|
|
55
|
+
This corresponds to zero-out the filtered complex outside of $\{ x\in \mathbb R^n \mid x\le `mass_default`\}$
|
|
56
|
+
- invariant: The invariant to use, either "hilbert", "rank", or "euler".
|
|
57
|
+
- plot:bool, plots the computed measures if true.
|
|
58
|
+
- n_jobs:int, number of jobs. Defaults to #cpu.
|
|
59
|
+
- verbose:bool, prints c++ logs.
|
|
60
|
+
- expand_collapse: when the input is a simplextree,
|
|
61
|
+
only expands the complex when computing 1-dimensional slices.
|
|
62
|
+
Meant to reduce memory footprint at some computational expense.
|
|
63
|
+
- backend:str reduces first the filtered complex using an external library `backend`,
|
|
64
|
+
see ``backend`` in :func:`multipers.io.reduce_complex`.
|
|
65
|
+
- grid: If given, the computations will be done on the restriction of the filtered complex to this grid.
|
|
66
|
+
It can also be used for auto-differentiation, i.e., if the grid is a list of pytorch tensors,
|
|
67
|
+
then the output measure will be pytorch-differentiable.
|
|
68
|
+
- grid_strategy: If not squeezed yet, and no grid is given,
|
|
69
|
+
the strategy to coarsen the grid; see ``strategy`` in :func:`multipers.grids.compute_grid`.
|
|
70
|
+
- coordinate_measure: bool, if True, compute the signed measure as a coordinates given in grid.
|
|
71
|
+
- num_collapses: int, if `filtered_complex` is a simplextree, does some collapses if possible.
|
|
72
|
+
- clean: if True, reduces the measure. It is not necessary in general.
|
|
73
|
+
- ignore_infinite_filtration_values: Backend optimization.
|
|
74
|
+
|
|
75
|
+
Output
|
|
76
|
+
------
|
|
77
|
+
|
|
78
|
+
`[signed_measure_of_degree for degree in degrees]`
|
|
79
|
+
with `signed_measure_of_degree` of the form `(dirac location, dirac weights)`.
|
|
80
|
+
|
|
81
|
+
Notes on computational backends
|
|
82
|
+
-------------------------------
|
|
83
|
+
There are several backends for each of these computations.
|
|
84
|
+
The backend for computations used can be displayed with `verbose=True`, use it!
|
|
85
|
+
Also note that if `backend` is given, then the input will be converted to a slicer.
|
|
86
|
+
- Euler: is always computed by summing the weights of the simplices
|
|
87
|
+
- Hilbert: is computed by computing persistence on slices, and a Möbius inversion,
|
|
88
|
+
unless the detected input is a minimal presentation (i.e., `filtered_complex.is_minpres`),
|
|
89
|
+
which in that case, doesn't need any computation.
|
|
90
|
+
- If the input is a simplextree, this is done via a the standard Gudhi implementation,
|
|
91
|
+
with parallel (TBB) computations of slices.
|
|
92
|
+
- If the input is a slicer then
|
|
93
|
+
- If the input is vineyard-capable, then slices are computed via vineyards updates.
|
|
94
|
+
It is slower in general, but faster if single threaded.
|
|
95
|
+
In particular, it is usually faster to use this backend if you want to compute the
|
|
96
|
+
signed measure of multiple datasets in a parallel context.
|
|
97
|
+
- Otherwise, slices are computed in parallel.
|
|
98
|
+
It is usually faster to use this backend if not in a parallel context.
|
|
99
|
+
- Rank: Same as Hilbert.
|
|
100
|
+
"""
|
|
101
|
+
if backend is not None:
|
|
102
|
+
raise ValueError(
|
|
103
|
+
"backend is deprecated. reduce the complex before this function."
|
|
104
|
+
)
|
|
105
|
+
if num_collapses > 0:
|
|
106
|
+
raise ValueError(
|
|
107
|
+
"num_collapses is deprecated. reduce the complex before this function."
|
|
108
|
+
)
|
|
109
|
+
## TODO : add timings in verbose
|
|
110
|
+
if len(filtered_complex) == 0:
|
|
111
|
+
return [
|
|
112
|
+
(
|
|
113
|
+
np.empty((0, 2), dtype=filtered_complex.dtype),
|
|
114
|
+
np.empty(shape=(0,), dtype=int),
|
|
115
|
+
)
|
|
116
|
+
]
|
|
117
|
+
if grid_conversion is not None:
|
|
118
|
+
grid = tuple(f for f in grid_conversion)
|
|
119
|
+
raise DeprecationWarning(
|
|
120
|
+
"""
|
|
121
|
+
Parameter `grid_conversion` is deprecated. Use `grid` instead.
|
|
122
|
+
Most of the time there is no conversion anymore.
|
|
123
|
+
"""
|
|
124
|
+
)
|
|
125
|
+
|
|
126
|
+
if degree is not None or len(degrees) == 0:
|
|
127
|
+
degrees = list(degrees) + [degree]
|
|
128
|
+
if None in degrees:
|
|
129
|
+
assert len(degrees) == 1, (
|
|
130
|
+
f"Can only compute one invariant at the time. Got {degrees=}, {invariant=}."
|
|
131
|
+
)
|
|
132
|
+
assert invariant is None or not (
|
|
133
|
+
"hilbert" in invariant or "rank" in invariant
|
|
134
|
+
), (
|
|
135
|
+
f"Hilbert and Rank cannot compute `None` degree. got {degrees=}, {invariant=}."
|
|
136
|
+
)
|
|
137
|
+
invariant = "euler"
|
|
138
|
+
if clean is None:
|
|
139
|
+
clean = True if None in degrees else False
|
|
140
|
+
|
|
141
|
+
assert invariant is None or invariant in [
|
|
142
|
+
"hilbert",
|
|
143
|
+
"rank_invariant",
|
|
144
|
+
"euler",
|
|
145
|
+
"rank",
|
|
146
|
+
"euler_characteristic",
|
|
147
|
+
"hilbert_function",
|
|
148
|
+
"rectangle",
|
|
149
|
+
"hook",
|
|
150
|
+
]
|
|
151
|
+
|
|
152
|
+
assert not plot or filtered_complex.num_parameters == 2, (
|
|
153
|
+
f"Can only plot 2d measures. Got {filtered_complex.num_parameters=}."
|
|
154
|
+
)
|
|
155
|
+
|
|
156
|
+
if grid is None:
|
|
157
|
+
if not filtered_complex.is_squeezed:
|
|
158
|
+
grid = compute_grid(
|
|
159
|
+
filtered_complex, strategy=grid_strategy, **infer_grid_kwargs
|
|
160
|
+
)
|
|
161
|
+
else:
|
|
162
|
+
grid = filtered_complex.filtration_grid
|
|
163
|
+
|
|
164
|
+
if mass_default is None:
|
|
165
|
+
mass_default = mass_default
|
|
166
|
+
elif isinstance(mass_default, str):
|
|
167
|
+
if mass_default == "auto":
|
|
168
|
+
mass_default = np.array([1.1 * np.max(f) - 0.1 * np.min(f) for f in grid])
|
|
169
|
+
elif mass_default == "inf":
|
|
170
|
+
mass_default = np.array([np.inf] * filtered_complex.num_parameters)
|
|
171
|
+
else:
|
|
172
|
+
raise NotImplementedError
|
|
173
|
+
else:
|
|
174
|
+
mass_default = np.asarray(mass_default)
|
|
175
|
+
assert (
|
|
176
|
+
mass_default.ndim == 1
|
|
177
|
+
and mass_default.shape[0] == filtered_complex.num_parameters
|
|
178
|
+
)
|
|
179
|
+
|
|
180
|
+
if not filtered_complex.is_squeezed:
|
|
181
|
+
if verbose:
|
|
182
|
+
print("Coarsening complex...", end="", flush=True)
|
|
183
|
+
t0 = time.time()
|
|
184
|
+
filtered_complex_ = filtered_complex.grid_squeeze(grid)
|
|
185
|
+
|
|
186
|
+
if verbose:
|
|
187
|
+
print(f"Done. ({time.time() - t0:.3f}s)")
|
|
188
|
+
else:
|
|
189
|
+
filtered_complex_ = filtered_complex.copy()
|
|
190
|
+
|
|
191
|
+
# assert filtered_complex_.is_squeezed
|
|
192
|
+
if None not in degrees:
|
|
193
|
+
if is_slicer(filtered_complex_) and filtered_complex_.is_minpres:
|
|
194
|
+
pass
|
|
195
|
+
else:
|
|
196
|
+
max_degree = np.max(degrees) + 1
|
|
197
|
+
if verbose:
|
|
198
|
+
print(f"Pruning simplicies up to {max_degree}...", end="", flush=True)
|
|
199
|
+
t0 = time.time()
|
|
200
|
+
if filtered_complex_.dimension > max_degree:
|
|
201
|
+
filtered_complex_.prune_above_dimension(max_degree)
|
|
202
|
+
if verbose:
|
|
203
|
+
print(f"Done. ({time.time() - t0:.3f}s)")
|
|
204
|
+
|
|
205
|
+
num_parameters = filtered_complex.num_parameters
|
|
206
|
+
assert num_parameters == len(grid), (
|
|
207
|
+
f"Number of parameter do not coincide. Got (grid) {len(grid)} and (filtered complex) {num_parameters}."
|
|
208
|
+
)
|
|
209
|
+
|
|
210
|
+
fix_mass_default = mass_default is not None
|
|
211
|
+
if is_slicer(filtered_complex_):
|
|
212
|
+
if verbose:
|
|
213
|
+
print("Input is a slicer.")
|
|
214
|
+
if backend is not None and not filtered_complex_.is_minpres:
|
|
215
|
+
raise ValueError("giving a backend to this function is deprecated")
|
|
216
|
+
else: # No backend
|
|
217
|
+
if invariant is not None and (
|
|
218
|
+
"rank" in invariant or "hook" in invariant or "rectangle" in invariant
|
|
219
|
+
):
|
|
220
|
+
degrees = np.asarray(degrees, dtype=int)
|
|
221
|
+
if verbose:
|
|
222
|
+
print("Computing rank...", end="", flush=True)
|
|
223
|
+
t0 = time.time()
|
|
224
|
+
sms = _rank_from_slicer(
|
|
225
|
+
filtered_complex_,
|
|
226
|
+
degrees=degrees,
|
|
227
|
+
n_jobs=n_jobs,
|
|
228
|
+
zero_pad=fix_mass_default,
|
|
229
|
+
# grid_shape=tuple(len(g) for g in grid),
|
|
230
|
+
ignore_inf=ignore_infinite_filtration_values,
|
|
231
|
+
verbose=verbose
|
|
232
|
+
)
|
|
233
|
+
fix_mass_default = False
|
|
234
|
+
if verbose:
|
|
235
|
+
print(f"Done. ({time.time() - t0:.3f}s)")
|
|
236
|
+
elif filtered_complex_.is_minpres:
|
|
237
|
+
if verbose:
|
|
238
|
+
print(
|
|
239
|
+
"Reduced slicer. Retrieving measure from it...",
|
|
240
|
+
end="",
|
|
241
|
+
flush=True,
|
|
242
|
+
)
|
|
243
|
+
t0 = time.time()
|
|
244
|
+
sms = [
|
|
245
|
+
_signed_measure_from_slicer(
|
|
246
|
+
filtered_complex_,
|
|
247
|
+
shift=(
|
|
248
|
+
filtered_complex_.minpres_degree & 1 if d is None else d & 1
|
|
249
|
+
),
|
|
250
|
+
)[0]
|
|
251
|
+
for d in degrees
|
|
252
|
+
]
|
|
253
|
+
if verbose:
|
|
254
|
+
print(f"Done. ({time.time() - t0:.3f}s)")
|
|
255
|
+
elif (invariant is None or "euler" in invariant) and (
|
|
256
|
+
len(degrees) == 1 and degrees[0] is None
|
|
257
|
+
):
|
|
258
|
+
if verbose:
|
|
259
|
+
print("Retrieving measure from slicer...", end="", flush=True)
|
|
260
|
+
t0 = time.time()
|
|
261
|
+
sms = _signed_measure_from_slicer(
|
|
262
|
+
filtered_complex_,
|
|
263
|
+
shift=0, # no minpres
|
|
264
|
+
)
|
|
265
|
+
if verbose:
|
|
266
|
+
print(f"Done. ({time.time() - t0:.3f}s)")
|
|
267
|
+
else:
|
|
268
|
+
if verbose:
|
|
269
|
+
print("Computing Hilbert function...", end="", flush=True)
|
|
270
|
+
t0 = time.time()
|
|
271
|
+
sms = _hilbert_signed_measure(
|
|
272
|
+
filtered_complex_,
|
|
273
|
+
degrees=degrees,
|
|
274
|
+
zero_pad=fix_mass_default,
|
|
275
|
+
n_jobs=n_jobs,
|
|
276
|
+
verbose=verbose,
|
|
277
|
+
ignore_inf=ignore_infinite_filtration_values,
|
|
278
|
+
)
|
|
279
|
+
fix_mass_default = False
|
|
280
|
+
if verbose:
|
|
281
|
+
print(f"Done. ({time.time() - t0:.3f}s)")
|
|
282
|
+
|
|
283
|
+
elif is_simplextree_multi(filtered_complex_):
|
|
284
|
+
if verbose:
|
|
285
|
+
print("Input is a simplextree.")
|
|
286
|
+
## we still have a simplextree here
|
|
287
|
+
if invariant in ["rank_invariant", "rank", "hook", "rectangle"]:
|
|
288
|
+
if verbose:
|
|
289
|
+
print("Computing rank invariant...", end="", flush=True)
|
|
290
|
+
t0 = time.time()
|
|
291
|
+
|
|
292
|
+
assert num_parameters == 2, (
|
|
293
|
+
"Rank invariant only implemented for 2-parameter modules."
|
|
294
|
+
)
|
|
295
|
+
assert not coordinate_measure, "Not implemented"
|
|
296
|
+
from multipers.simplex_tree_multi import _rank_signed_measure as smri
|
|
297
|
+
|
|
298
|
+
sms = smri(
|
|
299
|
+
filtered_complex_,
|
|
300
|
+
mass_default=mass_default,
|
|
301
|
+
degrees=degrees,
|
|
302
|
+
expand_collapse=expand_collapse,
|
|
303
|
+
)
|
|
304
|
+
fix_mass_default = False
|
|
305
|
+
if verbose:
|
|
306
|
+
print(f"Done. ({time.time() - t0:.3f}s)")
|
|
307
|
+
elif len(degrees) == 1 and degrees[0] is None:
|
|
308
|
+
if verbose:
|
|
309
|
+
print("Computing Euler Characteristic...", end="", flush=True)
|
|
310
|
+
t0 = time.time()
|
|
311
|
+
assert invariant is None or invariant in [
|
|
312
|
+
"euler",
|
|
313
|
+
"euler_characteristic",
|
|
314
|
+
], "Provide a degree to compute hilbert function."
|
|
315
|
+
# assert not coordinate_measure, "Not implemented"
|
|
316
|
+
from multipers.simplex_tree_multi import _euler_signed_measure
|
|
317
|
+
|
|
318
|
+
sms = [
|
|
319
|
+
_euler_signed_measure(
|
|
320
|
+
filtered_complex_,
|
|
321
|
+
mass_default=mass_default,
|
|
322
|
+
verbose=verbose,
|
|
323
|
+
)
|
|
324
|
+
]
|
|
325
|
+
fix_mass_default = False
|
|
326
|
+
if verbose:
|
|
327
|
+
print(f"Done. ({time.time() - t0:.3f}s)")
|
|
328
|
+
else:
|
|
329
|
+
if verbose:
|
|
330
|
+
print("Computing Hilbert Function...", end="", flush=True)
|
|
331
|
+
t0 = time.time()
|
|
332
|
+
assert invariant is None or invariant in [
|
|
333
|
+
"hilbert",
|
|
334
|
+
"hilbert_function",
|
|
335
|
+
], "Found homological degrees for euler computation."
|
|
336
|
+
from multipers.simplex_tree_multi import (
|
|
337
|
+
_hilbert_signed_measure as hilbert_signed_measure,
|
|
338
|
+
)
|
|
339
|
+
|
|
340
|
+
sms = hilbert_signed_measure(
|
|
341
|
+
filtered_complex_,
|
|
342
|
+
degrees=degrees,
|
|
343
|
+
mass_default=mass_default,
|
|
344
|
+
verbose=verbose,
|
|
345
|
+
n_jobs=n_jobs,
|
|
346
|
+
expand_collapse=expand_collapse,
|
|
347
|
+
)
|
|
348
|
+
fix_mass_default = False
|
|
349
|
+
if verbose:
|
|
350
|
+
print(f"Done. ({time.time() - t0:.3f}s)")
|
|
351
|
+
else:
|
|
352
|
+
raise ValueError("Filtered complex has to be a SimplexTree or a Slicer.")
|
|
353
|
+
|
|
354
|
+
if clean:
|
|
355
|
+
if verbose:
|
|
356
|
+
print("Cleaning measure...", end="", flush=True)
|
|
357
|
+
t0 = time.time()
|
|
358
|
+
sms = clean_sms(sms)
|
|
359
|
+
if verbose:
|
|
360
|
+
print(f"Done. ({time.time() - t0:.3f}s)")
|
|
361
|
+
if grid is not None and not coordinate_measure:
|
|
362
|
+
if verbose:
|
|
363
|
+
print("Pushing back the measure to the grid...", end="", flush=True)
|
|
364
|
+
t0 = time.time()
|
|
365
|
+
sms = sms_in_grid(
|
|
366
|
+
sms,
|
|
367
|
+
grid=grid,
|
|
368
|
+
mass_default=mass_default,
|
|
369
|
+
# num_parameters=num_parameters,
|
|
370
|
+
)
|
|
371
|
+
if verbose:
|
|
372
|
+
print(f"Done. ({time.time() - t0:.3f}s)")
|
|
373
|
+
|
|
374
|
+
if fix_mass_default:
|
|
375
|
+
# TODO : some methods need to use this, this could be optimized
|
|
376
|
+
if verbose:
|
|
377
|
+
print("Seems that fixing mass default is necessary...", end="", flush=True)
|
|
378
|
+
t0 = time.time()
|
|
379
|
+
sms = zero_out_sms(sms, mass_default=mass_default)
|
|
380
|
+
if verbose:
|
|
381
|
+
print(f"Done. ({time.time() - t0:.3f}s)")
|
|
382
|
+
|
|
383
|
+
if invariant == "hook":
|
|
384
|
+
if verbose:
|
|
385
|
+
print(
|
|
386
|
+
"Converting rank decomposition to hook decomposition...",
|
|
387
|
+
end="",
|
|
388
|
+
flush=True,
|
|
389
|
+
)
|
|
390
|
+
t0 = time.time()
|
|
391
|
+
from multipers.point_measure import rectangle_to_hook_minimal_signed_barcode
|
|
392
|
+
|
|
393
|
+
sms = [rectangle_to_hook_minimal_signed_barcode(pts, w) for pts, w in sms]
|
|
394
|
+
if verbose:
|
|
395
|
+
print(f"Done. ({time.time() - t0:.3f}s)")
|
|
396
|
+
if plot:
|
|
397
|
+
plot_signed_measures(sms, alpha=1 if invariant == "hook" else None)
|
|
398
|
+
return sms
|
|
399
|
+
|
|
400
|
+
|
|
401
|
+
def _signed_measure_from_scc(
|
|
402
|
+
minimal_presentation,
|
|
403
|
+
) -> list[tuple[np.ndarray, np.ndarray]]:
|
|
404
|
+
pts = np.concatenate([b[0] for b in minimal_presentation])
|
|
405
|
+
weights = np.concatenate(
|
|
406
|
+
[
|
|
407
|
+
(1 - 2 * (i & 1)) * np.ones(len(b[0]))
|
|
408
|
+
for i, b in enumerate(minimal_presentation)
|
|
409
|
+
]
|
|
410
|
+
)
|
|
411
|
+
sm = [(pts, weights)]
|
|
412
|
+
return sm
|
|
413
|
+
|
|
414
|
+
|
|
415
|
+
def _signed_measure_from_slicer(
|
|
416
|
+
slicer: Slicer_type,
|
|
417
|
+
shift: int = 0,
|
|
418
|
+
) -> list[tuple[np.ndarray, np.ndarray]]:
|
|
419
|
+
assert not slicer.is_kcritical, "Not implemented for k-critical filtrations yet."
|
|
420
|
+
pts = np.array(slicer.get_filtrations())
|
|
421
|
+
dims = slicer.get_dimensions()
|
|
422
|
+
if shift:
|
|
423
|
+
dims += shift
|
|
424
|
+
weights = 1 - 2 * (dims % 2)
|
|
425
|
+
sm = [(pts, weights)]
|
|
426
|
+
return sm
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
from copy import deepcopy
|
|
2
|
+
from typing import Optional
|
|
3
|
+
|
|
4
|
+
import numpy as np
|
|
5
|
+
|
|
6
|
+
import multipers.slicer as mps
|
|
7
|
+
from multipers.simplex_tree_multi import is_simplextree_multi
|
|
8
|
+
from multipers.slicer import (
|
|
9
|
+
_column_type,
|
|
10
|
+
_filtration_container_type,
|
|
11
|
+
_valid_dtype,
|
|
12
|
+
_valid_pers_backend,
|
|
13
|
+
is_slicer,
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
## TODO : maybe optimize this with cython
|
|
18
|
+
def _blocks2boundary_dimension_grades(
|
|
19
|
+
blocks,
|
|
20
|
+
filtration_type=np.float64,
|
|
21
|
+
num_parameters: int = -1,
|
|
22
|
+
inplace: bool = False,
|
|
23
|
+
is_kcritical: bool = False,
|
|
24
|
+
):
|
|
25
|
+
"""
|
|
26
|
+
Turns blocks, aka scc, into the input of non-simplicial slicers.
|
|
27
|
+
"""
|
|
28
|
+
if num_parameters < 0:
|
|
29
|
+
for b in blocks:
|
|
30
|
+
if len(b[0]) > 0:
|
|
31
|
+
if is_kcritical:
|
|
32
|
+
num_parameters = np.asarray(b[0][0]).shape[1]
|
|
33
|
+
else:
|
|
34
|
+
num_parameters = np.asarray(b[0]).shape[1]
|
|
35
|
+
break
|
|
36
|
+
if num_parameters < 0:
|
|
37
|
+
raise ValueError("Empty Filtration")
|
|
38
|
+
rblocks = blocks if inplace else deepcopy(blocks)
|
|
39
|
+
rblocks.reverse()
|
|
40
|
+
block_sizes = [len(b[0]) for b in rblocks]
|
|
41
|
+
S = np.cumsum([0, 0] + block_sizes)
|
|
42
|
+
if is_kcritical:
|
|
43
|
+
multifiltration = tuple(
|
|
44
|
+
stuff
|
|
45
|
+
for b in rblocks
|
|
46
|
+
for stuff in (b[0] if len(b[0]) > 0 else [np.empty((0, num_parameters))])
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
else:
|
|
50
|
+
multifiltration = np.concatenate(
|
|
51
|
+
tuple(
|
|
52
|
+
b[0] if len(b[0]) > 0 else np.empty((0, num_parameters))
|
|
53
|
+
for b in rblocks
|
|
54
|
+
),
|
|
55
|
+
dtype=filtration_type,
|
|
56
|
+
)
|
|
57
|
+
boundary = tuple(x + S[i] for i, b in enumerate(rblocks) for x in b[1])
|
|
58
|
+
dimensions = np.fromiter(
|
|
59
|
+
(i for i, b in enumerate(rblocks) for _ in range(len(b[0]))), dtype=int
|
|
60
|
+
)
|
|
61
|
+
return boundary, dimensions, multifiltration
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def _slicer_from_simplextree(st, backend, vineyard):
|
|
65
|
+
if vineyard:
|
|
66
|
+
if backend == "matrix":
|
|
67
|
+
slicer = mps._SlicerVineSimplicial(st)
|
|
68
|
+
elif backend == "clement":
|
|
69
|
+
raise ValueError("This one takes a minpres")
|
|
70
|
+
elif backend == "graph":
|
|
71
|
+
slicer = mps._SlicerVineGraph(st)
|
|
72
|
+
else:
|
|
73
|
+
raise ValueError(f"Inimplemented backend {backend}.")
|
|
74
|
+
else:
|
|
75
|
+
if backend == "matrix":
|
|
76
|
+
slicer = mps._SlicerNoVineSimplicial(st)
|
|
77
|
+
elif backend == "clement":
|
|
78
|
+
raise ValueError("Clement is Vineyard")
|
|
79
|
+
elif backend == "graph":
|
|
80
|
+
raise ValueError("Graph is Vineyard")
|
|
81
|
+
else:
|
|
82
|
+
raise ValueError(f"Inimplemented backend {backend}.")
|
|
83
|
+
return slicer
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def _slicer_from_blocks(
|
|
87
|
+
blocks,
|
|
88
|
+
pers_backend: _valid_pers_backend,
|
|
89
|
+
vineyard: bool,
|
|
90
|
+
is_kcritical: bool,
|
|
91
|
+
dtype: _valid_dtype,
|
|
92
|
+
col: _column_type,
|
|
93
|
+
filtration_container: _filtration_container_type,
|
|
94
|
+
):
|
|
95
|
+
boundary, dimensions, multifiltrations = _blocks2boundary_dimension_grades(
|
|
96
|
+
blocks,
|
|
97
|
+
inplace=False,
|
|
98
|
+
is_kcritical=is_kcritical,
|
|
99
|
+
)
|
|
100
|
+
slicer = mps.get_matrix_slicer(
|
|
101
|
+
vineyard,
|
|
102
|
+
is_kcritical,
|
|
103
|
+
dtype,
|
|
104
|
+
col,
|
|
105
|
+
pers_backend,
|
|
106
|
+
filtration_container,
|
|
107
|
+
)(boundary, dimensions, multifiltrations)
|
|
108
|
+
return slicer
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def Slicer(
|
|
112
|
+
st=None,
|
|
113
|
+
vineyard: Optional[bool] = None,
|
|
114
|
+
reduce: bool = False,
|
|
115
|
+
reduce_backend: Optional[str] = None,
|
|
116
|
+
dtype: Optional[_valid_dtype] = None,
|
|
117
|
+
kcritical: Optional[bool] = None,
|
|
118
|
+
column_type: Optional[_column_type] = None,
|
|
119
|
+
backend: Optional[_valid_pers_backend] = None,
|
|
120
|
+
filtration_container: Optional[str] = None,
|
|
121
|
+
max_dim: Optional[int] = None,
|
|
122
|
+
return_type_only: bool = False,
|
|
123
|
+
_shift_dimension: int = 0,
|
|
124
|
+
) -> mps.Slicer_type:
|
|
125
|
+
"""
|
|
126
|
+
Given a simplextree or blocks (a.k.a scc for python),
|
|
127
|
+
returns a structure that can compute persistence on line (or more)
|
|
128
|
+
slices, eventually vineyard update, etc.
|
|
129
|
+
|
|
130
|
+
This can be used to compute interval-decomposable module approximations
|
|
131
|
+
or signed measures, using, e.g.
|
|
132
|
+
- `multipers.module_approximation(this, *args)`
|
|
133
|
+
- `multipers.signed_measure(this, *args)`
|
|
134
|
+
|
|
135
|
+
Note : it is recommended and sometime required to apply
|
|
136
|
+
a minimal presentation before computing these functions !
|
|
137
|
+
`mp.slicer.minimal_presentation(slicer, *args, **kwargs)`
|
|
138
|
+
|
|
139
|
+
Input
|
|
140
|
+
-----
|
|
141
|
+
- st : SimplexTreeMulti or scc-like blocks or path to scc file
|
|
142
|
+
- backend: slicer backend, e.g, "matrix", "clement", "graph"
|
|
143
|
+
- vineyard: vineyard capable (may slow down computations if true)
|
|
144
|
+
Output
|
|
145
|
+
------
|
|
146
|
+
The corresponding slicer.
|
|
147
|
+
"""
|
|
148
|
+
if reduce:
|
|
149
|
+
from warnings import warn
|
|
150
|
+
|
|
151
|
+
warn(
|
|
152
|
+
"Deprecated argument `reduce`. just reduce it afterwards.",
|
|
153
|
+
DeprecationWarning,
|
|
154
|
+
)
|
|
155
|
+
if max_dim is not None:
|
|
156
|
+
raise DeprecationWarning("deprecated parameter.")
|
|
157
|
+
if is_slicer(st, allow_minpres=False) or is_simplextree_multi(st):
|
|
158
|
+
dtype = st.dtype if dtype is None else dtype
|
|
159
|
+
is_kcritical = st.is_kcritical if kcritical is None else kcritical
|
|
160
|
+
filtration_container = (
|
|
161
|
+
st.filtration_container
|
|
162
|
+
if filtration_container is None
|
|
163
|
+
else filtration_container
|
|
164
|
+
)
|
|
165
|
+
else:
|
|
166
|
+
dtype = np.float64 if dtype is None else dtype
|
|
167
|
+
is_kcritical = False if kcritical is None else kcritical
|
|
168
|
+
filtration_container = (
|
|
169
|
+
"contiguous" if filtration_container is None else filtration_container
|
|
170
|
+
)
|
|
171
|
+
|
|
172
|
+
if is_slicer(st, allow_minpres=False):
|
|
173
|
+
vineyard = st.is_vine if vineyard is None else vineyard
|
|
174
|
+
column_type = st.col_type if column_type is None else column_type
|
|
175
|
+
backend = st.pers_backend if backend is None else backend
|
|
176
|
+
else:
|
|
177
|
+
vineyard = False if vineyard is None else vineyard
|
|
178
|
+
column_type = "INTRUSIVE_SET" if column_type is None else column_type
|
|
179
|
+
backend = "Matrix" if backend is None else backend
|
|
180
|
+
|
|
181
|
+
_Slicer = mps.get_matrix_slicer(
|
|
182
|
+
is_vineyard=vineyard,
|
|
183
|
+
is_k_critical=is_kcritical,
|
|
184
|
+
dtype=dtype,
|
|
185
|
+
col=column_type,
|
|
186
|
+
pers_backend=backend,
|
|
187
|
+
filtration_container=filtration_container,
|
|
188
|
+
)
|
|
189
|
+
if return_type_only:
|
|
190
|
+
return _Slicer
|
|
191
|
+
|
|
192
|
+
if st is None:
|
|
193
|
+
return _Slicer()
|
|
194
|
+
elif mps.is_slicer(st):
|
|
195
|
+
slicer = _Slicer(st)
|
|
196
|
+
elif is_simplextree_multi(st) and backend == "Graph":
|
|
197
|
+
slicer = _slicer_from_simplextree(st, backend, vineyard)
|
|
198
|
+
if st.is_squeezed:
|
|
199
|
+
slicer.filtration_grid = st.filtration_grid
|
|
200
|
+
|
|
201
|
+
elif isinstance(st, str):
|
|
202
|
+
slicer = _Slicer()._build_from_scc_file(st, shift_dimension=_shift_dimension)
|
|
203
|
+
elif is_simplextree_multi(st):
|
|
204
|
+
slicer = _Slicer().build_from_simplex_tree(st)
|
|
205
|
+
if st.is_squeezed:
|
|
206
|
+
slicer.filtration_grid = st.filtration_grid
|
|
207
|
+
elif backend == "Graph":
|
|
208
|
+
raise ValueError(
|
|
209
|
+
"""
|
|
210
|
+
Graph is simplicial, incompatible with minpres.
|
|
211
|
+
You can try using `multipers.slicer.to_simplextree`."""
|
|
212
|
+
)
|
|
213
|
+
else:
|
|
214
|
+
blocks = st
|
|
215
|
+
slicer = _slicer_from_blocks(
|
|
216
|
+
blocks,
|
|
217
|
+
backend,
|
|
218
|
+
vineyard,
|
|
219
|
+
is_kcritical,
|
|
220
|
+
dtype,
|
|
221
|
+
column_type,
|
|
222
|
+
filtration_container,
|
|
223
|
+
)
|
|
224
|
+
if reduce:
|
|
225
|
+
slicer = mps.minimal_presentation(
|
|
226
|
+
slicer,
|
|
227
|
+
backend=reduce_backend,
|
|
228
|
+
slicer_backend=backend,
|
|
229
|
+
vineyard=vineyard,
|
|
230
|
+
)
|
|
231
|
+
return slicer
|