multipers 2.3.3b6__cp313-cp313-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.
Potentially problematic release.
This version of multipers might be problematic. Click here for more details.
- multipers/.dylibs/libc++.1.0.dylib +0 -0
- multipers/.dylibs/libtbb.12.16.dylib +0 -0
- multipers/__init__.py +33 -0
- multipers/_signed_measure_meta.py +453 -0
- multipers/_slicer_meta.py +211 -0
- multipers/array_api/__init__.py +45 -0
- multipers/array_api/numpy.py +41 -0
- multipers/array_api/torch.py +58 -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 +229 -0
- multipers/filtration_conversions.pxd.tp +84 -0
- multipers/filtrations/__init__.py +18 -0
- multipers/filtrations/density.py +574 -0
- multipers/filtrations/filtrations.py +361 -0
- multipers/filtrations.pxd +224 -0
- multipers/function_rips.cpython-313-darwin.so +0 -0
- multipers/function_rips.pyx +105 -0
- multipers/grids.cpython-313-darwin.so +0 -0
- multipers/grids.pyx +433 -0
- multipers/gudhi/Persistence_slices_interface.h +132 -0
- multipers/gudhi/Simplex_tree_interface.h +239 -0
- multipers/gudhi/Simplex_tree_multi_interface.h +551 -0
- multipers/gudhi/cubical_to_boundary.h +59 -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 +45 -0
- multipers/gudhi/gudhi/Fields/Multi_field.h +484 -0
- multipers/gudhi/gudhi/Fields/Multi_field_operators.h +455 -0
- multipers/gudhi/gudhi/Fields/Multi_field_shared.h +450 -0
- multipers/gudhi/gudhi/Fields/Multi_field_small.h +531 -0
- multipers/gudhi/gudhi/Fields/Multi_field_small_operators.h +507 -0
- multipers/gudhi/gudhi/Fields/Multi_field_small_shared.h +531 -0
- multipers/gudhi/gudhi/Fields/Z2_field.h +355 -0
- multipers/gudhi/gudhi/Fields/Z2_field_operators.h +376 -0
- multipers/gudhi/gudhi/Fields/Zp_field.h +420 -0
- multipers/gudhi/gudhi/Fields/Zp_field_operators.h +400 -0
- multipers/gudhi/gudhi/Fields/Zp_field_shared.h +418 -0
- multipers/gudhi/gudhi/Flag_complex_edge_collapser.h +337 -0
- multipers/gudhi/gudhi/Matrix.h +2107 -0
- multipers/gudhi/gudhi/Multi_critical_filtration.h +1038 -0
- multipers/gudhi/gudhi/Multi_persistence/Box.h +174 -0
- multipers/gudhi/gudhi/Multi_persistence/Line.h +282 -0
- multipers/gudhi/gudhi/Off_reader.h +173 -0
- multipers/gudhi/gudhi/One_critical_filtration.h +1441 -0
- multipers/gudhi/gudhi/Persistence_matrix/Base_matrix.h +769 -0
- multipers/gudhi/gudhi/Persistence_matrix/Base_matrix_with_column_compression.h +686 -0
- multipers/gudhi/gudhi/Persistence_matrix/Boundary_matrix.h +842 -0
- multipers/gudhi/gudhi/Persistence_matrix/Chain_matrix.h +1350 -0
- multipers/gudhi/gudhi/Persistence_matrix/Id_to_index_overlay.h +1105 -0
- multipers/gudhi/gudhi/Persistence_matrix/Position_to_index_overlay.h +859 -0
- multipers/gudhi/gudhi/Persistence_matrix/RU_matrix.h +910 -0
- multipers/gudhi/gudhi/Persistence_matrix/allocators/entry_constructors.h +139 -0
- multipers/gudhi/gudhi/Persistence_matrix/base_pairing.h +230 -0
- multipers/gudhi/gudhi/Persistence_matrix/base_swap.h +211 -0
- multipers/gudhi/gudhi/Persistence_matrix/boundary_cell_position_to_id_mapper.h +60 -0
- multipers/gudhi/gudhi/Persistence_matrix/boundary_face_position_to_id_mapper.h +60 -0
- multipers/gudhi/gudhi/Persistence_matrix/chain_pairing.h +136 -0
- multipers/gudhi/gudhi/Persistence_matrix/chain_rep_cycles.h +190 -0
- multipers/gudhi/gudhi/Persistence_matrix/chain_vine_swap.h +616 -0
- multipers/gudhi/gudhi/Persistence_matrix/columns/chain_column_extra_properties.h +150 -0
- multipers/gudhi/gudhi/Persistence_matrix/columns/column_dimension_holder.h +106 -0
- multipers/gudhi/gudhi/Persistence_matrix/columns/column_utilities.h +219 -0
- multipers/gudhi/gudhi/Persistence_matrix/columns/entry_types.h +327 -0
- multipers/gudhi/gudhi/Persistence_matrix/columns/heap_column.h +1140 -0
- multipers/gudhi/gudhi/Persistence_matrix/columns/intrusive_list_column.h +934 -0
- multipers/gudhi/gudhi/Persistence_matrix/columns/intrusive_set_column.h +934 -0
- multipers/gudhi/gudhi/Persistence_matrix/columns/list_column.h +980 -0
- multipers/gudhi/gudhi/Persistence_matrix/columns/naive_vector_column.h +1092 -0
- multipers/gudhi/gudhi/Persistence_matrix/columns/row_access.h +192 -0
- multipers/gudhi/gudhi/Persistence_matrix/columns/set_column.h +921 -0
- multipers/gudhi/gudhi/Persistence_matrix/columns/small_vector_column.h +1093 -0
- multipers/gudhi/gudhi/Persistence_matrix/columns/unordered_set_column.h +1012 -0
- multipers/gudhi/gudhi/Persistence_matrix/columns/vector_column.h +1244 -0
- multipers/gudhi/gudhi/Persistence_matrix/matrix_dimension_holders.h +186 -0
- multipers/gudhi/gudhi/Persistence_matrix/matrix_row_access.h +164 -0
- multipers/gudhi/gudhi/Persistence_matrix/ru_pairing.h +156 -0
- multipers/gudhi/gudhi/Persistence_matrix/ru_rep_cycles.h +376 -0
- multipers/gudhi/gudhi/Persistence_matrix/ru_vine_swap.h +540 -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 +745 -0
- multipers/gudhi/gudhi/Points_off_io.h +171 -0
- multipers/gudhi/gudhi/Simple_object_pool.h +69 -0
- multipers/gudhi/gudhi/Simplex_tree/Simplex_tree_iterators.h +463 -0
- multipers/gudhi/gudhi/Simplex_tree/Simplex_tree_node_explicit_storage.h +83 -0
- multipers/gudhi/gudhi/Simplex_tree/Simplex_tree_siblings.h +106 -0
- multipers/gudhi/gudhi/Simplex_tree/Simplex_tree_star_simplex_iterators.h +277 -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 +62 -0
- multipers/gudhi/gudhi/Simplex_tree/simplex_tree_options.h +157 -0
- multipers/gudhi/gudhi/Simplex_tree.h +2794 -0
- multipers/gudhi/gudhi/Simplex_tree_multi.h +152 -0
- multipers/gudhi/gudhi/distance_functions.h +62 -0
- multipers/gudhi/gudhi/graph_simplicial_complex.h +104 -0
- multipers/gudhi/gudhi/persistence_interval.h +253 -0
- multipers/gudhi/gudhi/persistence_matrix_options.h +170 -0
- multipers/gudhi/gudhi/reader_utils.h +367 -0
- multipers/gudhi/mma_interface_coh.h +256 -0
- multipers/gudhi/mma_interface_h0.h +223 -0
- multipers/gudhi/mma_interface_matrix.h +293 -0
- multipers/gudhi/naive_merge_tree.h +536 -0
- multipers/gudhi/scc_io.h +310 -0
- multipers/gudhi/truc.h +1403 -0
- multipers/io.cpython-313-darwin.so +0 -0
- multipers/io.pyx +644 -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 +1589 -0
- multipers/ml/sliced_wasserstein.py +461 -0
- multipers/ml/tools.py +113 -0
- multipers/mma_structures.cpython-313-darwin.so +0 -0
- multipers/mma_structures.pxd +128 -0
- multipers/mma_structures.pyx +2786 -0
- multipers/mma_structures.pyx.tp +1094 -0
- multipers/multi_parameter_rank_invariant/diff_helpers.h +84 -0
- multipers/multi_parameter_rank_invariant/euler_characteristic.h +97 -0
- multipers/multi_parameter_rank_invariant/function_rips.h +322 -0
- multipers/multi_parameter_rank_invariant/hilbert_function.h +769 -0
- multipers/multi_parameter_rank_invariant/persistence_slices.h +148 -0
- multipers/multi_parameter_rank_invariant/rank_invariant.h +369 -0
- multipers/multiparameter_edge_collapse.py +41 -0
- multipers/multiparameter_module_approximation/approximation.h +2330 -0
- multipers/multiparameter_module_approximation/combinatory.h +129 -0
- multipers/multiparameter_module_approximation/debug.h +107 -0
- multipers/multiparameter_module_approximation/euler_curves.h +0 -0
- multipers/multiparameter_module_approximation/format_python-cpp.h +286 -0
- multipers/multiparameter_module_approximation/heap_column.h +238 -0
- multipers/multiparameter_module_approximation/images.h +79 -0
- multipers/multiparameter_module_approximation/list_column.h +174 -0
- multipers/multiparameter_module_approximation/list_column_2.h +232 -0
- multipers/multiparameter_module_approximation/ru_matrix.h +347 -0
- multipers/multiparameter_module_approximation/set_column.h +135 -0
- multipers/multiparameter_module_approximation/structure_higher_dim_barcode.h +36 -0
- multipers/multiparameter_module_approximation/unordered_set_column.h +166 -0
- multipers/multiparameter_module_approximation/utilities.h +403 -0
- multipers/multiparameter_module_approximation/vector_column.h +223 -0
- multipers/multiparameter_module_approximation/vector_matrix.h +331 -0
- multipers/multiparameter_module_approximation/vineyards.h +464 -0
- multipers/multiparameter_module_approximation/vineyards_trajectories.h +649 -0
- multipers/multiparameter_module_approximation.cpython-313-darwin.so +0 -0
- multipers/multiparameter_module_approximation.pyx +235 -0
- multipers/pickle.py +90 -0
- multipers/plots.py +456 -0
- multipers/point_measure.cpython-313-darwin.so +0 -0
- multipers/point_measure.pyx +395 -0
- multipers/simplex_tree_multi.cpython-313-darwin.so +0 -0
- multipers/simplex_tree_multi.pxd +134 -0
- multipers/simplex_tree_multi.pyx +10840 -0
- multipers/simplex_tree_multi.pyx.tp +2009 -0
- multipers/slicer.cpython-313-darwin.so +0 -0
- multipers/slicer.pxd +3034 -0
- multipers/slicer.pxd.tp +234 -0
- multipers/slicer.pyx +20481 -0
- multipers/slicer.pyx.tp +1088 -0
- multipers/tensor/tensor.h +672 -0
- multipers/tensor.pxd +13 -0
- multipers/test.pyx +44 -0
- multipers/tests/__init__.py +62 -0
- multipers/torch/__init__.py +1 -0
- multipers/torch/diff_grids.py +240 -0
- multipers/torch/rips_density.py +310 -0
- multipers-2.3.3b6.dist-info/METADATA +128 -0
- multipers-2.3.3b6.dist-info/RECORD +183 -0
- multipers-2.3.3b6.dist-info/WHEEL +6 -0
- multipers-2.3.3b6.dist-info/licenses/LICENSE +21 -0
- multipers-2.3.3b6.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,361 @@
|
|
|
1
|
+
from collections.abc import Sequence
|
|
2
|
+
from typing import Optional
|
|
3
|
+
from warnings import warn
|
|
4
|
+
|
|
5
|
+
import gudhi as gd
|
|
6
|
+
import numpy as np
|
|
7
|
+
from numpy.typing import ArrayLike
|
|
8
|
+
from scipy.spatial import KDTree
|
|
9
|
+
|
|
10
|
+
from multipers.array_api import api_from_tensor, api_from_tensors
|
|
11
|
+
from multipers.filtrations.density import DTM, available_kernels
|
|
12
|
+
from multipers.grids import compute_grid
|
|
13
|
+
from multipers.simplex_tree_multi import SimplexTreeMulti, SimplexTreeMulti_type
|
|
14
|
+
|
|
15
|
+
try:
|
|
16
|
+
import pykeops
|
|
17
|
+
|
|
18
|
+
from multipers.filtrations.density import KDE
|
|
19
|
+
except ImportError:
|
|
20
|
+
from sklearn.neighbors import KernelDensity
|
|
21
|
+
|
|
22
|
+
warn("pykeops not found. Falling back to sklearn.")
|
|
23
|
+
|
|
24
|
+
def KDE(bandwidth, kernel, return_log):
|
|
25
|
+
assert return_log, "Sklearn returns log-density."
|
|
26
|
+
return KernelDensity(bandwidth=bandwidth, kernel=kernel)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def RipsLowerstar(
|
|
30
|
+
*,
|
|
31
|
+
points: Optional[ArrayLike] = None,
|
|
32
|
+
distance_matrix: Optional[ArrayLike] = None,
|
|
33
|
+
function: Optional[ArrayLike] = None,
|
|
34
|
+
threshold_radius: Optional[float] = None,
|
|
35
|
+
):
|
|
36
|
+
"""
|
|
37
|
+
Computes the Rips complex, with the usual rips filtration as a first parameter,
|
|
38
|
+
and the lower star multi filtration as other parameter.
|
|
39
|
+
|
|
40
|
+
Input:
|
|
41
|
+
- points or distance_matrix: ArrayLike
|
|
42
|
+
- function : ArrayLike of shape (num_data, num_parameters -1)
|
|
43
|
+
- threshold_radius: max edge length of the rips. Defaults at min(max(distance_matrix, axis=1)).
|
|
44
|
+
"""
|
|
45
|
+
assert (
|
|
46
|
+
points is not None or distance_matrix is not None
|
|
47
|
+
), "`points` or `distance_matrix` has to be given."
|
|
48
|
+
if distance_matrix is None:
|
|
49
|
+
api = api_from_tensor(points)
|
|
50
|
+
points = api.astensor(points)
|
|
51
|
+
D = api.cdist(points, points) # this may be slow...
|
|
52
|
+
else:
|
|
53
|
+
api = api_from_tensor(distance_matrix)
|
|
54
|
+
D = api.astensor(distance_matrix)
|
|
55
|
+
|
|
56
|
+
if threshold_radius is None:
|
|
57
|
+
threshold_radius = api.min(api.maxvalues(D, axis=1))
|
|
58
|
+
st = gd.SimplexTree.create_from_array(
|
|
59
|
+
api.asnumpy(D), max_filtration=threshold_radius
|
|
60
|
+
)
|
|
61
|
+
if function is None:
|
|
62
|
+
return SimplexTreeMulti(st, num_parameters=1)
|
|
63
|
+
|
|
64
|
+
function = api.astensor(function)
|
|
65
|
+
if function.ndim == 1:
|
|
66
|
+
function = function[:, None]
|
|
67
|
+
if function.ndim != 2:
|
|
68
|
+
raise ValueError(
|
|
69
|
+
f"""
|
|
70
|
+
`function.ndim` should be 0 or 1 . Got {function.ndim=}.{function=}
|
|
71
|
+
"""
|
|
72
|
+
)
|
|
73
|
+
num_parameters = function.shape[1] + 1
|
|
74
|
+
st = SimplexTreeMulti(st, num_parameters=num_parameters)
|
|
75
|
+
for i in range(function.shape[1]):
|
|
76
|
+
st.fill_lowerstar(api.asnumpy(function[:, i]), parameter=1 + i)
|
|
77
|
+
if api.has_grad(D) or api.has_grad(function):
|
|
78
|
+
from multipers.grids import compute_grid
|
|
79
|
+
|
|
80
|
+
grid = compute_grid([D.ravel(), *[f for f in function.T]])
|
|
81
|
+
st = st.grid_squeeze(grid)
|
|
82
|
+
return st
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def RipsCodensity(
|
|
86
|
+
points: ArrayLike,
|
|
87
|
+
bandwidth: Optional[float] = None,
|
|
88
|
+
*,
|
|
89
|
+
return_log: bool = True,
|
|
90
|
+
dtm_mass: Optional[float] = None,
|
|
91
|
+
kernel: available_kernels = "gaussian",
|
|
92
|
+
threshold_radius: Optional[float] = None,
|
|
93
|
+
):
|
|
94
|
+
"""
|
|
95
|
+
Computes the Rips density filtration.
|
|
96
|
+
"""
|
|
97
|
+
assert (
|
|
98
|
+
bandwidth is None or dtm_mass is None
|
|
99
|
+
), "Density estimation is either via kernels or dtm."
|
|
100
|
+
if bandwidth is not None:
|
|
101
|
+
kde = KDE(bandwidth=bandwidth, kernel=kernel, return_log=return_log)
|
|
102
|
+
f = -kde.fit(points).score_samples(points)
|
|
103
|
+
elif dtm_mass is not None:
|
|
104
|
+
f = DTM(masses=[dtm_mass]).fit(points).score_samples(points)[0]
|
|
105
|
+
else:
|
|
106
|
+
raise ValueError("Bandwidth or DTM mass has to be given.")
|
|
107
|
+
return RipsLowerstar(points=points, function=f, threshold_radius=threshold_radius)
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def DelaunayLowerstar(
|
|
111
|
+
points: ArrayLike,
|
|
112
|
+
function: ArrayLike,
|
|
113
|
+
*,
|
|
114
|
+
distance_matrix: Optional[ArrayLike] = None,
|
|
115
|
+
threshold_radius: Optional[float] = None,
|
|
116
|
+
reduce_degree: int = -1,
|
|
117
|
+
vineyard: Optional[bool] = None,
|
|
118
|
+
dtype=np.float64,
|
|
119
|
+
verbose: bool = False,
|
|
120
|
+
clear: bool = True,
|
|
121
|
+
flagify: bool = False,
|
|
122
|
+
):
|
|
123
|
+
"""
|
|
124
|
+
Computes the Function Delaunay bifiltration. Similar to RipsLowerstar, but most suited for low-dimensional euclidean data.
|
|
125
|
+
See [Delaunay bifiltrations of functions on point clouds, Alonso et al] https://doi.org/10.1137/1.9781611977912.173
|
|
126
|
+
|
|
127
|
+
Input:
|
|
128
|
+
- points or distance_matrix: ArrayLike
|
|
129
|
+
- function : ArrayLike of shape (num_data, )
|
|
130
|
+
- threshold_radius: max edge length of the rips. Defaults at min(max(distance_matrix, axis=1)).
|
|
131
|
+
"""
|
|
132
|
+
from multipers.slicer import from_function_delaunay
|
|
133
|
+
|
|
134
|
+
if flagify and reduce_degree >= 0:
|
|
135
|
+
raise ValueError(
|
|
136
|
+
"Got {reduce_degree=} and {flagify=}. Cannot flagify with reduce degree."
|
|
137
|
+
)
|
|
138
|
+
assert distance_matrix is None, "Delaunay cannot be built from distance matrices"
|
|
139
|
+
if threshold_radius is not None:
|
|
140
|
+
raise NotImplementedError("Delaunay with threshold not implemented yet.")
|
|
141
|
+
api = api_from_tensors(points, function)
|
|
142
|
+
if not flagify and (api.has_grad(points) or api.has_grad(function)):
|
|
143
|
+
warn("Cannot keep points gradient unless using `flagify=True`.")
|
|
144
|
+
points = api.astensor(points)
|
|
145
|
+
function = api.astensor(function).squeeze()
|
|
146
|
+
assert (
|
|
147
|
+
function.ndim == 1
|
|
148
|
+
), "Delaunay Lowerstar is only compatible with 1 additional parameter."
|
|
149
|
+
slicer = from_function_delaunay(
|
|
150
|
+
api.asnumpy(points),
|
|
151
|
+
api.asnumpy(function),
|
|
152
|
+
degree=reduce_degree,
|
|
153
|
+
vineyard=vineyard,
|
|
154
|
+
dtype=dtype,
|
|
155
|
+
verbose=verbose,
|
|
156
|
+
clear=clear,
|
|
157
|
+
)
|
|
158
|
+
if reduce_degree >= 0:
|
|
159
|
+
# Force resolution to avoid confusion with hilbert.
|
|
160
|
+
slicer = slicer.minpres(degree=reduce_degree, force=True)
|
|
161
|
+
if flagify:
|
|
162
|
+
from multipers.slicer import to_simplextree
|
|
163
|
+
|
|
164
|
+
slicer = to_simplextree(slicer)
|
|
165
|
+
slicer.flagify(2)
|
|
166
|
+
|
|
167
|
+
if api.has_grad(points) or api.has_grad(function):
|
|
168
|
+
distances = api.cdist(points, points) / 2
|
|
169
|
+
grid = compute_grid([distances.ravel(), function])
|
|
170
|
+
slicer = slicer.grid_squeeze(grid)
|
|
171
|
+
slicer = slicer._clean_filtration_grid()
|
|
172
|
+
|
|
173
|
+
return slicer
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
def DelaunayCodensity(
|
|
177
|
+
points: ArrayLike,
|
|
178
|
+
bandwidth: Optional[float] = None,
|
|
179
|
+
*,
|
|
180
|
+
return_log: bool = True,
|
|
181
|
+
dtm_mass: Optional[float] = None,
|
|
182
|
+
kernel: available_kernels = "gaussian",
|
|
183
|
+
threshold_radius: Optional[float] = None,
|
|
184
|
+
reduce_degree: int = -1,
|
|
185
|
+
vineyard: Optional[bool] = None,
|
|
186
|
+
dtype=np.float64,
|
|
187
|
+
verbose: bool = False,
|
|
188
|
+
clear: bool = True,
|
|
189
|
+
flagify: bool = False,
|
|
190
|
+
):
|
|
191
|
+
"""
|
|
192
|
+
TODO
|
|
193
|
+
"""
|
|
194
|
+
assert (
|
|
195
|
+
bandwidth is None or dtm_mass is None
|
|
196
|
+
), "Density estimation is either via kernels or dtm."
|
|
197
|
+
if bandwidth is not None:
|
|
198
|
+
kde = KDE(bandwidth=bandwidth, kernel=kernel, return_log=return_log)
|
|
199
|
+
f = -kde.fit(points).score_samples(points)
|
|
200
|
+
elif dtm_mass is not None:
|
|
201
|
+
f = DTM(masses=[dtm_mass]).fit(points).score_samples(points)[0]
|
|
202
|
+
else:
|
|
203
|
+
raise ValueError("Bandwidth or DTM mass has to be given.")
|
|
204
|
+
return DelaunayLowerstar(
|
|
205
|
+
points=points,
|
|
206
|
+
function=f,
|
|
207
|
+
threshold_radius=threshold_radius,
|
|
208
|
+
reduce_degree=reduce_degree,
|
|
209
|
+
vineyard=vineyard,
|
|
210
|
+
dtype=dtype,
|
|
211
|
+
verbose=verbose,
|
|
212
|
+
clear=clear,
|
|
213
|
+
flagify=flagify,
|
|
214
|
+
)
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
def Cubical(image: ArrayLike, **slicer_kwargs):
|
|
218
|
+
"""
|
|
219
|
+
Computes the cubical filtration of an image.
|
|
220
|
+
The last axis dimention is interpreted as the number of parameters.
|
|
221
|
+
|
|
222
|
+
Input:
|
|
223
|
+
- image: ArrayLike of shape (*image_resolution, num_parameters)
|
|
224
|
+
- ** args : specify non-default slicer parameters
|
|
225
|
+
"""
|
|
226
|
+
from multipers.slicer import from_bitmap
|
|
227
|
+
|
|
228
|
+
api = api_from_tensor(image)
|
|
229
|
+
image = api.astensor(image)
|
|
230
|
+
if api.has_grad(image):
|
|
231
|
+
img2 = image.reshape(-1, image.shape[-1]).T
|
|
232
|
+
grid = compute_grid(img2)
|
|
233
|
+
coord_img = np.empty(image.shape, dtype=np.int32)
|
|
234
|
+
slice_shape = image.shape[:-1]
|
|
235
|
+
for i in range(image.shape[-1]):
|
|
236
|
+
coord_img[..., i] = np.searchsorted(
|
|
237
|
+
api.asnumpy(grid[i]),
|
|
238
|
+
api.asnumpy(image[..., i]).reshape(-1),
|
|
239
|
+
).reshape(slice_shape)
|
|
240
|
+
slicer = from_bitmap(coord_img, **slicer_kwargs)
|
|
241
|
+
slicer.filtration_grid = grid
|
|
242
|
+
return slicer
|
|
243
|
+
|
|
244
|
+
return from_bitmap(image, **slicer_kwargs)
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
def DegreeRips(*, points=None, distance_matrix=None, ks=None, threshold_radius=None):
|
|
248
|
+
"""
|
|
249
|
+
The DegreeRips filtration.
|
|
250
|
+
"""
|
|
251
|
+
|
|
252
|
+
raise NotImplementedError("Use the default implentation ftm.")
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
def CoreDelaunay(
|
|
256
|
+
points: ArrayLike,
|
|
257
|
+
*,
|
|
258
|
+
beta: float = 1.0,
|
|
259
|
+
ks: Optional[Sequence[int]] = None,
|
|
260
|
+
precision: str = "safe",
|
|
261
|
+
verbose: bool = False,
|
|
262
|
+
max_alpha_square: float = float("inf"),
|
|
263
|
+
) -> SimplexTreeMulti_type:
|
|
264
|
+
"""
|
|
265
|
+
Computes the Delaunay core bifiltration of a point cloud presented in the paper "Core Bifiltration" https://arxiv.org/abs/2405.01214, and returns the (multi-critical) bifiltration as a SimplexTreeMulti. The Delaunay core bifiltration is an alpha complex version of the core bifiltration which is smaller in size. Moreover, along the horizontal line k=1, the Delaunay core bifiltration is identical to the alpha complex.
|
|
266
|
+
|
|
267
|
+
Input:
|
|
268
|
+
- points: The point cloud as an ArrayLike of shape (n, d) where n is the number of points and d is the dimension of the points.
|
|
269
|
+
- beta: The beta parameter for the Delaunay Core Bifiltration (default 1.0).
|
|
270
|
+
- ks: The list of k-values to include in the bifiltration (default None). If None, the k-values are set to [1, 2, ..., n] where n is the number of points in the point cloud. For large point clouds, it is recommended to set ks to a smaller list of k-values to reduce computation time. The values in ks must all be integers, positive, and less than or equal to the number of points in the point cloud.
|
|
271
|
+
- precision: The precision of the computation of the AlphaComplex, one of ['safe', 'exact', 'fast'] (default 'safe'). See the GUDHI documentation for more information.
|
|
272
|
+
- verbose: Whether to print progress messages (default False).
|
|
273
|
+
- max_alpha_square: The maximum squared alpha value to consider when createing the alpha complex (default inf). See the GUDHI documentation for more information.
|
|
274
|
+
"""
|
|
275
|
+
points = np.asarray(points)
|
|
276
|
+
if ks is None:
|
|
277
|
+
ks = np.arange(1, len(points) + 1)
|
|
278
|
+
else:
|
|
279
|
+
ks = np.asarray(ks, dtype=int)
|
|
280
|
+
ks: np.ndarray
|
|
281
|
+
|
|
282
|
+
assert len(ks) > 0, "The parameter ks must contain at least one value."
|
|
283
|
+
assert np.all(ks > 0), "All values in ks must be positive."
|
|
284
|
+
assert np.all(
|
|
285
|
+
ks <= len(points)
|
|
286
|
+
), "All values in ks must be less than or equal to the number of points in the point cloud."
|
|
287
|
+
assert len(points) > 0, "The point cloud must contain at least one point."
|
|
288
|
+
assert points.ndim == 2, f"The point cloud must be a 2D array, got {points.ndim}D."
|
|
289
|
+
assert beta >= 0, f"The parameter beta must be positive, got {beta}."
|
|
290
|
+
assert precision in [
|
|
291
|
+
"safe",
|
|
292
|
+
"exact",
|
|
293
|
+
"fast",
|
|
294
|
+
], f"""
|
|
295
|
+
The parameter precision must be one of ['safe', 'exact', 'fast'],
|
|
296
|
+
got {precision}.
|
|
297
|
+
"""
|
|
298
|
+
|
|
299
|
+
if verbose:
|
|
300
|
+
print(
|
|
301
|
+
f"""Computing the Delaunay Core Bifiltration
|
|
302
|
+
of {len(points)} points in dimension {points.shape[1]}
|
|
303
|
+
with parameters:
|
|
304
|
+
"""
|
|
305
|
+
)
|
|
306
|
+
print(f"\tbeta = {beta}")
|
|
307
|
+
print(f"\tks = {ks}")
|
|
308
|
+
|
|
309
|
+
if verbose:
|
|
310
|
+
print("Building the alpha complex...")
|
|
311
|
+
alpha_complex = gd.AlphaComplex(
|
|
312
|
+
points=points, precision=precision
|
|
313
|
+
).create_simplex_tree(max_alpha_square=max_alpha_square)
|
|
314
|
+
|
|
315
|
+
if verbose:
|
|
316
|
+
print("Computing the k-nearest neighbor distances...")
|
|
317
|
+
knn_distances = KDTree(points).query(points, k=ks)[0]
|
|
318
|
+
|
|
319
|
+
max_dim = alpha_complex.dimension()
|
|
320
|
+
vertex_arrays_in_dimension = [[] for _ in range(max_dim + 1)]
|
|
321
|
+
squared_alphas_in_dimension = [[] for _ in range(max_dim + 1)]
|
|
322
|
+
for simplex, alpha_squared in alpha_complex.get_simplices():
|
|
323
|
+
dim = len(simplex) - 1
|
|
324
|
+
squared_alphas_in_dimension[dim].append(alpha_squared)
|
|
325
|
+
vertex_arrays_in_dimension[dim].append(simplex)
|
|
326
|
+
|
|
327
|
+
alphas_in_dimension = [
|
|
328
|
+
np.sqrt(np.array(alpha_squared, dtype=np.float64))
|
|
329
|
+
for alpha_squared in squared_alphas_in_dimension
|
|
330
|
+
]
|
|
331
|
+
vertex_arrays_in_dimension = [
|
|
332
|
+
np.array(vertex_array, dtype=np.int32)
|
|
333
|
+
for vertex_array in vertex_arrays_in_dimension
|
|
334
|
+
]
|
|
335
|
+
|
|
336
|
+
simplex_tree_multi = SimplexTreeMulti(
|
|
337
|
+
num_parameters=2, kcritical=True, dtype=np.float64
|
|
338
|
+
)
|
|
339
|
+
|
|
340
|
+
for dim, (vertex_array, alphas) in enumerate(
|
|
341
|
+
zip(vertex_arrays_in_dimension, alphas_in_dimension)
|
|
342
|
+
):
|
|
343
|
+
num_simplices = len(vertex_array)
|
|
344
|
+
if verbose:
|
|
345
|
+
print(
|
|
346
|
+
f"""
|
|
347
|
+
Inserting {num_simplices} simplices of dimension {dim}
|
|
348
|
+
({num_simplices * len(ks)} birth values)...
|
|
349
|
+
"""
|
|
350
|
+
)
|
|
351
|
+
max_knn_distances = np.max(knn_distances[vertex_array], axis=1)
|
|
352
|
+
critical_radii = np.maximum(alphas[:, None], beta * max_knn_distances)
|
|
353
|
+
filtrations = np.stack(
|
|
354
|
+
(critical_radii, -ks * np.ones_like(critical_radii)), axis=-1
|
|
355
|
+
)
|
|
356
|
+
simplex_tree_multi.insert_batch(vertex_array.T, filtrations)
|
|
357
|
+
|
|
358
|
+
if verbose:
|
|
359
|
+
print("Done computing the Delaunay Core Bifiltration.")
|
|
360
|
+
|
|
361
|
+
return simplex_tree_multi
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
from libcpp.utility cimport pair
|
|
2
|
+
from libcpp cimport bool
|
|
3
|
+
from libcpp.vector cimport vector
|
|
4
|
+
from libcpp cimport tuple
|
|
5
|
+
from libc.stdint cimport uintptr_t,intptr_t
|
|
6
|
+
from cpython cimport Py_buffer
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
cdef extern from "gudhi/One_critical_filtration.h" namespace "Gudhi::multi_filtration":
|
|
10
|
+
cdef cppclass One_critical_filtration[T=*]:
|
|
11
|
+
## Copied from cython vector
|
|
12
|
+
ctypedef size_t size_type
|
|
13
|
+
ctypedef ptrdiff_t difference_type
|
|
14
|
+
ctypedef T value_type
|
|
15
|
+
|
|
16
|
+
cppclass const_iterator
|
|
17
|
+
cppclass iterator:
|
|
18
|
+
iterator() except +
|
|
19
|
+
iterator(iterator&) except +
|
|
20
|
+
value_type& operator*()
|
|
21
|
+
iterator operator++()
|
|
22
|
+
iterator operator--()
|
|
23
|
+
iterator operator++(int)
|
|
24
|
+
iterator operator--(int)
|
|
25
|
+
iterator operator+(size_type)
|
|
26
|
+
iterator operator-(size_type)
|
|
27
|
+
difference_type operator-(iterator)
|
|
28
|
+
difference_type operator-(const_iterator)
|
|
29
|
+
bint operator==(iterator)
|
|
30
|
+
bint operator==(const_iterator)
|
|
31
|
+
bint operator!=(iterator)
|
|
32
|
+
bint operator!=(const_iterator)
|
|
33
|
+
bint operator<(iterator)
|
|
34
|
+
bint operator<(const_iterator)
|
|
35
|
+
bint operator>(iterator)
|
|
36
|
+
bint operator>(const_iterator)
|
|
37
|
+
bint operator<=(iterator)
|
|
38
|
+
bint operator<=(const_iterator)
|
|
39
|
+
bint operator>=(iterator)
|
|
40
|
+
bint operator>=(const_iterator)
|
|
41
|
+
cppclass const_iterator:
|
|
42
|
+
const_iterator() except +
|
|
43
|
+
const_iterator(iterator&) except +
|
|
44
|
+
const_iterator(const_iterator&) except +
|
|
45
|
+
operator=(iterator&) except +
|
|
46
|
+
const value_type& operator*()
|
|
47
|
+
const_iterator operator++()
|
|
48
|
+
const_iterator operator--()
|
|
49
|
+
const_iterator operator++(int)
|
|
50
|
+
const_iterator operator--(int)
|
|
51
|
+
const_iterator operator+(size_type)
|
|
52
|
+
const_iterator operator-(size_type)
|
|
53
|
+
difference_type operator-(iterator)
|
|
54
|
+
difference_type operator-(const_iterator)
|
|
55
|
+
bint operator==(iterator)
|
|
56
|
+
bint operator==(const_iterator)
|
|
57
|
+
bint operator!=(iterator)
|
|
58
|
+
bint operator!=(const_iterator)
|
|
59
|
+
bint operator<(iterator)
|
|
60
|
+
bint operator<(const_iterator)
|
|
61
|
+
bint operator>(iterator)
|
|
62
|
+
bint operator>(const_iterator)
|
|
63
|
+
bint operator<=(iterator)
|
|
64
|
+
bint operator<=(const_iterator)
|
|
65
|
+
bint operator>=(iterator)
|
|
66
|
+
bint operator>=(const_iterator)
|
|
67
|
+
|
|
68
|
+
cppclass const_reverse_iterator
|
|
69
|
+
cppclass reverse_iterator:
|
|
70
|
+
reverse_iterator() except +
|
|
71
|
+
reverse_iterator(reverse_iterator&) except +
|
|
72
|
+
value_type& operator*()
|
|
73
|
+
reverse_iterator operator++()
|
|
74
|
+
reverse_iterator operator--()
|
|
75
|
+
reverse_iterator operator++(int)
|
|
76
|
+
reverse_iterator operator--(int)
|
|
77
|
+
reverse_iterator operator+(size_type)
|
|
78
|
+
reverse_iterator operator-(size_type)
|
|
79
|
+
difference_type operator-(iterator)
|
|
80
|
+
difference_type operator-(const_iterator)
|
|
81
|
+
bint operator==(reverse_iterator)
|
|
82
|
+
bint operator==(const_reverse_iterator)
|
|
83
|
+
bint operator!=(reverse_iterator)
|
|
84
|
+
bint operator!=(const_reverse_iterator)
|
|
85
|
+
bint operator<(reverse_iterator)
|
|
86
|
+
bint operator<(const_reverse_iterator)
|
|
87
|
+
bint operator>(reverse_iterator)
|
|
88
|
+
bint operator>(const_reverse_iterator)
|
|
89
|
+
bint operator<=(reverse_iterator)
|
|
90
|
+
bint operator<=(const_reverse_iterator)
|
|
91
|
+
bint operator>=(reverse_iterator)
|
|
92
|
+
bint operator>=(const_reverse_iterator)
|
|
93
|
+
cppclass const_reverse_iterator:
|
|
94
|
+
const_reverse_iterator() except +
|
|
95
|
+
const_reverse_iterator(reverse_iterator&) except +
|
|
96
|
+
operator=(reverse_iterator&) except +
|
|
97
|
+
const value_type& operator*()
|
|
98
|
+
const_reverse_iterator operator++()
|
|
99
|
+
const_reverse_iterator operator--()
|
|
100
|
+
const_reverse_iterator operator++(int)
|
|
101
|
+
const_reverse_iterator operator--(int)
|
|
102
|
+
const_reverse_iterator operator+(size_type)
|
|
103
|
+
const_reverse_iterator operator-(size_type)
|
|
104
|
+
difference_type operator-(iterator)
|
|
105
|
+
difference_type operator-(const_iterator)
|
|
106
|
+
bint operator==(reverse_iterator)
|
|
107
|
+
bint operator==(const_reverse_iterator)
|
|
108
|
+
bint operator!=(reverse_iterator)
|
|
109
|
+
bint operator!=(const_reverse_iterator)
|
|
110
|
+
bint operator<(reverse_iterator)
|
|
111
|
+
bint operator<(const_reverse_iterator)
|
|
112
|
+
bint operator>(reverse_iterator)
|
|
113
|
+
bint operator>(const_reverse_iterator)
|
|
114
|
+
bint operator<=(reverse_iterator)
|
|
115
|
+
bint operator<=(const_reverse_iterator)
|
|
116
|
+
bint operator>=(reverse_iterator)
|
|
117
|
+
bint operator>=(const_reverse_iterator)
|
|
118
|
+
value_type& operator[](size_type)
|
|
119
|
+
#vector& operator=(vector&)
|
|
120
|
+
void assign(size_type, const value_type&)
|
|
121
|
+
void assign[InputIt](InputIt, InputIt) except +
|
|
122
|
+
value_type& at(size_type) except +
|
|
123
|
+
value_type& back()
|
|
124
|
+
iterator begin()
|
|
125
|
+
const_iterator const_begin "begin"()
|
|
126
|
+
const_iterator cbegin()
|
|
127
|
+
size_type capacity()
|
|
128
|
+
void clear() nogil
|
|
129
|
+
bint empty() nogil
|
|
130
|
+
iterator end()
|
|
131
|
+
const_iterator const_end "end"()
|
|
132
|
+
const_iterator cend()
|
|
133
|
+
iterator erase(iterator)
|
|
134
|
+
iterator erase(iterator, iterator)
|
|
135
|
+
value_type& front()
|
|
136
|
+
iterator insert(iterator, const value_type&) except +
|
|
137
|
+
iterator insert(iterator, size_type, const value_type&) except +
|
|
138
|
+
iterator insert[InputIt](iterator, InputIt, InputIt) except +
|
|
139
|
+
size_type max_size()
|
|
140
|
+
void pop_back()
|
|
141
|
+
void push_back(value_type&) except + nogil
|
|
142
|
+
reverse_iterator rbegin()
|
|
143
|
+
const_reverse_iterator const_rbegin "rbegin"()
|
|
144
|
+
const_reverse_iterator crbegin()
|
|
145
|
+
reverse_iterator rend()
|
|
146
|
+
const_reverse_iterator const_rend "rend"()
|
|
147
|
+
const_reverse_iterator crend()
|
|
148
|
+
void reserve(size_type) except + nogil
|
|
149
|
+
void resize(size_type) except + nogil
|
|
150
|
+
void resize(size_type, value_type&) except +
|
|
151
|
+
# size_type size()
|
|
152
|
+
size_type num_parameters() nogil
|
|
153
|
+
size_type num_generators() nogil
|
|
154
|
+
void swap(vector&)
|
|
155
|
+
|
|
156
|
+
# C++11 methods
|
|
157
|
+
value_type* data()
|
|
158
|
+
const value_type* const_data "data"()
|
|
159
|
+
void shrink_to_fit() except +
|
|
160
|
+
iterator emplace(const_iterator, ...) except +
|
|
161
|
+
value_type& emplace_back(...) except +
|
|
162
|
+
|
|
163
|
+
## end of copied from cython vector
|
|
164
|
+
|
|
165
|
+
One_critical_filtration() except + nogil
|
|
166
|
+
One_critical_filtration(vector[value_type]&) except + nogil
|
|
167
|
+
One_critical_filtration(One_critical_filtration&) except + nogil
|
|
168
|
+
|
|
169
|
+
One_critical_filtration(int) nogil
|
|
170
|
+
One_critical_filtration& operator=(const One_critical_filtration&) except +
|
|
171
|
+
@staticmethod
|
|
172
|
+
vector[value_type]& vector[value_type]() nogil
|
|
173
|
+
|
|
174
|
+
void push_to_least_common_upper_bound(One_critical_filtration[T]&) nogil
|
|
175
|
+
void pull_to_greatest_common_lower_bound(One_critical_filtration[T]&) nogil
|
|
176
|
+
|
|
177
|
+
bool is_finite() nogil
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
cdef extern from "gudhi/Multi_critical_filtration.h" namespace "Gudhi::multi_filtration":
|
|
181
|
+
cdef cppclass Multi_critical_filtration[T=*]:
|
|
182
|
+
ctypedef size_t size_type
|
|
183
|
+
ctypedef One_critical_filtration[T] filtration_type
|
|
184
|
+
Multi_critical_filtration() except + nogil
|
|
185
|
+
Multi_critical_filtration(One_critical_filtration[T]) except +
|
|
186
|
+
Multi_critical_filtration[T]& operator=(const Multi_critical_filtration[T]&) except +
|
|
187
|
+
size_t num_parameters() noexcept nogil
|
|
188
|
+
size_t num_generators() noexcept nogil
|
|
189
|
+
void add_guaranteed_generator(One_critical_filtration[T]) nogil
|
|
190
|
+
void add_generator(One_critical_filtration[T]) nogil
|
|
191
|
+
void reserve(size_t) noexcept nogil
|
|
192
|
+
void simplify() nogil
|
|
193
|
+
void set_num_generators(size_t) nogil
|
|
194
|
+
One_critical_filtration[T]& operator[](int) nogil
|
|
195
|
+
|
|
196
|
+
void push_to_least_common_upper_bound(One_critical_filtration[T]&) except + nogil
|
|
197
|
+
void pull_to_greatest_common_lower_bound(One_critical_filtration[T]&) except + nogil
|
|
198
|
+
|
|
199
|
+
cdef extern from "gudhi/Multi_persistence/Box.h" namespace "Gudhi::multi_persistence":
|
|
200
|
+
cdef cppclass Box[T=*]:
|
|
201
|
+
ctypedef vector[T] corner_type
|
|
202
|
+
Box() except +
|
|
203
|
+
Box( vector[T]&, vector[T]&) nogil
|
|
204
|
+
Box( pair[vector[T], vector[T]]&) nogil
|
|
205
|
+
void inflate(T) nogil
|
|
206
|
+
const One_critical_filtration[T]& get_lower_corner() nogil
|
|
207
|
+
const One_critical_filtration[T]& get_upper_corner() nogil
|
|
208
|
+
bool contains(vector[T]&) nogil
|
|
209
|
+
pair[One_critical_filtration[T], One_critical_filtration[T]] get_bounding_corners() nogil
|
|
210
|
+
|
|
211
|
+
cdef extern from "gudhi/Multi_persistence/Line.h" namespace "Gudhi::multi_persistence":
|
|
212
|
+
cdef cppclass Line[T=*]:
|
|
213
|
+
ctypedef One_critical_filtration[T] point_type
|
|
214
|
+
Line() except + nogil
|
|
215
|
+
Line(One_critical_filtration[T]&) except + nogil
|
|
216
|
+
Line(One_critical_filtration[T]&, One_critical_filtration[T]&) except + nogil
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
# ------ useful types:
|
|
223
|
+
# ctypedef One_critical_filtration[float] Generator
|
|
224
|
+
# ctypedef Multi_critical_filtration[float] kcritical
|
|
Binary file
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# cimport multipers.tensor as mt
|
|
2
|
+
from libc.stdint cimport intptr_t, uint16_t, uint32_t, int32_t
|
|
3
|
+
from libcpp.vector cimport vector
|
|
4
|
+
from libcpp cimport bool, int, float
|
|
5
|
+
from libcpp.utility cimport pair, tuple
|
|
6
|
+
from typing import Optional,Iterable,Callable
|
|
7
|
+
|
|
8
|
+
import numpy as np
|
|
9
|
+
cimport numpy as cnp
|
|
10
|
+
cnp.import_array()
|
|
11
|
+
|
|
12
|
+
ctypedef double value_type
|
|
13
|
+
python_value_type=np.float64
|
|
14
|
+
|
|
15
|
+
ctypedef int32_t indices_type # uint fails for some reason
|
|
16
|
+
python_indices_type=np.int32
|
|
17
|
+
|
|
18
|
+
ctypedef int32_t tensor_dtype
|
|
19
|
+
python_tensor_dtype = np.int32
|
|
20
|
+
|
|
21
|
+
ctypedef pair[vector[vector[indices_type]], vector[tensor_dtype]] signed_measure_type
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
from multipers.simplex_tree_multi import SimplexTreeMulti_Ff64
|
|
25
|
+
from gudhi.simplex_tree import SimplexTree
|
|
26
|
+
|
|
27
|
+
cdef extern from "multi_parameter_rank_invariant/function_rips.h" namespace "Gudhi::multiparameter::function_rips":
|
|
28
|
+
void compute_function_rips_surface_python(const intptr_t, tensor_dtype* , const vector[indices_type], indices_type,indices_type, bool, bool, indices_type) except + nogil
|
|
29
|
+
signed_measure_type compute_function_rips_signed_measure_python(const intptr_t, tensor_dtype* , const vector[indices_type], indices_type,indices_type, bool, bool, indices_type) except + nogil
|
|
30
|
+
pair[vector[value_type],int] get_degree_rips_st_python(const intptr_t,const intptr_t, const vector[int]) except + nogil
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
import multipers.grids as mpg
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def get_degree_rips(st, vector[int] degrees, grid_strategy="exact", resolution=0):
|
|
38
|
+
assert isinstance(st,SimplexTree), "Input has to be a Gudhi simplextree for now."
|
|
39
|
+
assert st.dimension() == 1, "Simplextree has to be of dimension 1. You can use the `prune_above_dimension` method."
|
|
40
|
+
degree_rips_st = SimplexTreeMulti_Ff64(num_parameters=degrees.size())
|
|
41
|
+
cdef intptr_t simplextree_ptr = st.thisptr
|
|
42
|
+
cdef intptr_t st_multi_ptr = degree_rips_st.thisptr
|
|
43
|
+
cdef pair[vector[value_type],int] out
|
|
44
|
+
with nogil:
|
|
45
|
+
out = get_degree_rips_st_python(simplextree_ptr, st_multi_ptr, degrees)
|
|
46
|
+
filtrations = np.asarray(out.first)
|
|
47
|
+
cdef int max_degree = out.second
|
|
48
|
+
cdef bool inf_flag = filtrations[-1] == np.inf
|
|
49
|
+
if inf_flag:
|
|
50
|
+
filtrations = filtrations[:-1]
|
|
51
|
+
filtrations, = mpg.compute_grid([filtrations],strategy=grid_strategy,resolution=resolution)
|
|
52
|
+
if inf_flag:
|
|
53
|
+
filtrations = np.concatenate([filtrations, [np.inf]])
|
|
54
|
+
degree_rips_st.grid_squeeze([filtrations]*degree_rips_st.num_parameters, inplace=True, coordinate_values=True)
|
|
55
|
+
degree_rips_st.filtration_grid = [filtrations, np.asarray(degrees)[::-1]]
|
|
56
|
+
degree_rips_st._is_function_simplextree=True
|
|
57
|
+
return degree_rips_st,max_degree
|
|
58
|
+
|
|
59
|
+
def function_rips_surface(st_multi, vector[indices_type] homological_degrees, bool mobius_inversion=True, bool zero_pad=False, indices_type n_jobs=0):
|
|
60
|
+
assert st_multi.is_squeezed, "Squeeze first !"
|
|
61
|
+
cdef intptr_t st_multi_ptr = st_multi.thisptr
|
|
62
|
+
cdef indices_type I = len(st_multi.filtration_grid[0])
|
|
63
|
+
cdef indices_type J = st_multi.num_parameters
|
|
64
|
+
container_shape = (homological_degrees.size(),I,J)
|
|
65
|
+
container_array = np.ascontiguousarray(np.zeros(container_shape, dtype=python_tensor_dtype).flatten())
|
|
66
|
+
assert len(container_array) < np.iinfo(np.uint32).max, "Too large container. Raise an issue on github if you encounter this issue. (Due to tensor's operator[])"
|
|
67
|
+
cdef tensor_dtype[::1] container = container_array
|
|
68
|
+
cdef tensor_dtype* container_ptr = &container[0]
|
|
69
|
+
with nogil:
|
|
70
|
+
compute_function_rips_surface_python(st_multi_ptr,container_ptr, homological_degrees, I,J, mobius_inversion, zero_pad, n_jobs)
|
|
71
|
+
filtration_grid = st_multi.filtration_grid
|
|
72
|
+
if filtration_grid[0][-1] == np.inf:
|
|
73
|
+
filtration_grid[0][-1] = filtration_grid[0][-2]
|
|
74
|
+
return filtration_grid, container_array.reshape(container_shape)
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def function_rips_signed_measure(st_multi, vector[indices_type] homological_degrees, bool mobius_inversion=True, bool zero_pad=False, indices_type n_jobs=0, bool reconvert = True):
|
|
79
|
+
assert st_multi.is_squeezed
|
|
80
|
+
cdef intptr_t st_multi_ptr = st_multi.thisptr
|
|
81
|
+
cdef indices_type I = len(st_multi.filtration_grid[0])
|
|
82
|
+
cdef indices_type J = st_multi.num_parameters
|
|
83
|
+
container_shape = (homological_degrees.size(),I,J)
|
|
84
|
+
container_array = np.ascontiguousarray(np.zeros(container_shape, dtype=python_tensor_dtype).flatten())
|
|
85
|
+
assert len(container_array) < np.iinfo(np.uint32).max, "Too large container. Raise an issue on github if you encounter this issue. (Due to tensor's operator[])"
|
|
86
|
+
cdef tensor_dtype[::1] container = container_array
|
|
87
|
+
cdef tensor_dtype* container_ptr = &container[0]
|
|
88
|
+
cdef signed_measure_type out
|
|
89
|
+
# TODO nogil
|
|
90
|
+
with nogil:
|
|
91
|
+
out = compute_function_rips_signed_measure_python(st_multi_ptr,container_ptr, homological_degrees, I,J, mobius_inversion, zero_pad, n_jobs)
|
|
92
|
+
pts, weights = np.asarray(out.first, dtype=int).reshape(-1, 3), np.asarray(out.second, dtype=int)
|
|
93
|
+
|
|
94
|
+
degree_indices = [np.argwhere(pts[:,0] == degree_index).flatten() for degree_index, degree in enumerate(homological_degrees)] ## TODO : maybe optimize
|
|
95
|
+
sms = [(pts[id,1:],weights[id]) for id in degree_indices]
|
|
96
|
+
if not reconvert: return sms
|
|
97
|
+
|
|
98
|
+
grid_conversion = st_multi.filtration_grid
|
|
99
|
+
for degree_index,(pts,weights) in enumerate(sms):
|
|
100
|
+
coords = np.empty(shape=pts.shape, dtype=float)
|
|
101
|
+
for i in range(coords.shape[1]):
|
|
102
|
+
coords[:,i] = np.asarray(grid_conversion[i])[pts[:,i]]
|
|
103
|
+
sms[degree_index]=(coords, weights)
|
|
104
|
+
|
|
105
|
+
return sms
|
|
Binary file
|