multipers 2.2.3__cp311-cp311-win_amd64.whl → 2.3.1__cp311-cp311-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.

Potentially problematic release.


This version of multipers might be problematic. Click here for more details.

Files changed (182) hide show
  1. multipers/__init__.py +33 -31
  2. multipers/_signed_measure_meta.py +430 -430
  3. multipers/_slicer_meta.py +211 -212
  4. multipers/data/MOL2.py +458 -458
  5. multipers/data/UCR.py +18 -18
  6. multipers/data/graphs.py +466 -466
  7. multipers/data/immuno_regions.py +27 -27
  8. multipers/data/pytorch2simplextree.py +90 -90
  9. multipers/data/shape3d.py +101 -101
  10. multipers/data/synthetic.py +113 -111
  11. multipers/distances.py +198 -198
  12. multipers/filtration_conversions.pxd.tp +84 -84
  13. multipers/filtrations/__init__.py +18 -0
  14. multipers/{ml/convolutions.py → filtrations/density.py} +563 -520
  15. multipers/filtrations/filtrations.py +289 -0
  16. multipers/filtrations.pxd +224 -224
  17. multipers/function_rips.cp311-win_amd64.pyd +0 -0
  18. multipers/function_rips.pyx +105 -105
  19. multipers/grids.cp311-win_amd64.pyd +0 -0
  20. multipers/grids.pyx +350 -350
  21. multipers/gudhi/Persistence_slices_interface.h +132 -132
  22. multipers/gudhi/Simplex_tree_interface.h +239 -245
  23. multipers/gudhi/Simplex_tree_multi_interface.h +516 -561
  24. multipers/gudhi/cubical_to_boundary.h +59 -59
  25. multipers/gudhi/gudhi/Bitmap_cubical_complex.h +450 -450
  26. multipers/gudhi/gudhi/Bitmap_cubical_complex_base.h +1070 -1070
  27. multipers/gudhi/gudhi/Bitmap_cubical_complex_periodic_boundary_conditions_base.h +579 -579
  28. multipers/gudhi/gudhi/Debug_utils.h +45 -45
  29. multipers/gudhi/gudhi/Fields/Multi_field.h +484 -484
  30. multipers/gudhi/gudhi/Fields/Multi_field_operators.h +455 -455
  31. multipers/gudhi/gudhi/Fields/Multi_field_shared.h +450 -450
  32. multipers/gudhi/gudhi/Fields/Multi_field_small.h +531 -531
  33. multipers/gudhi/gudhi/Fields/Multi_field_small_operators.h +507 -507
  34. multipers/gudhi/gudhi/Fields/Multi_field_small_shared.h +531 -531
  35. multipers/gudhi/gudhi/Fields/Z2_field.h +355 -355
  36. multipers/gudhi/gudhi/Fields/Z2_field_operators.h +376 -376
  37. multipers/gudhi/gudhi/Fields/Zp_field.h +420 -420
  38. multipers/gudhi/gudhi/Fields/Zp_field_operators.h +400 -400
  39. multipers/gudhi/gudhi/Fields/Zp_field_shared.h +418 -418
  40. multipers/gudhi/gudhi/Flag_complex_edge_collapser.h +337 -337
  41. multipers/gudhi/gudhi/Matrix.h +2107 -2107
  42. multipers/gudhi/gudhi/Multi_critical_filtration.h +1038 -1038
  43. multipers/gudhi/gudhi/Multi_persistence/Box.h +171 -171
  44. multipers/gudhi/gudhi/Multi_persistence/Line.h +282 -282
  45. multipers/gudhi/gudhi/Off_reader.h +173 -173
  46. multipers/gudhi/gudhi/One_critical_filtration.h +1433 -1431
  47. multipers/gudhi/gudhi/Persistence_matrix/Base_matrix.h +769 -769
  48. multipers/gudhi/gudhi/Persistence_matrix/Base_matrix_with_column_compression.h +686 -686
  49. multipers/gudhi/gudhi/Persistence_matrix/Boundary_matrix.h +842 -842
  50. multipers/gudhi/gudhi/Persistence_matrix/Chain_matrix.h +1350 -1350
  51. multipers/gudhi/gudhi/Persistence_matrix/Id_to_index_overlay.h +1105 -1105
  52. multipers/gudhi/gudhi/Persistence_matrix/Position_to_index_overlay.h +859 -859
  53. multipers/gudhi/gudhi/Persistence_matrix/RU_matrix.h +910 -910
  54. multipers/gudhi/gudhi/Persistence_matrix/allocators/entry_constructors.h +139 -139
  55. multipers/gudhi/gudhi/Persistence_matrix/base_pairing.h +230 -230
  56. multipers/gudhi/gudhi/Persistence_matrix/base_swap.h +211 -211
  57. multipers/gudhi/gudhi/Persistence_matrix/boundary_cell_position_to_id_mapper.h +60 -60
  58. multipers/gudhi/gudhi/Persistence_matrix/boundary_face_position_to_id_mapper.h +60 -60
  59. multipers/gudhi/gudhi/Persistence_matrix/chain_pairing.h +136 -136
  60. multipers/gudhi/gudhi/Persistence_matrix/chain_rep_cycles.h +190 -190
  61. multipers/gudhi/gudhi/Persistence_matrix/chain_vine_swap.h +616 -616
  62. multipers/gudhi/gudhi/Persistence_matrix/columns/chain_column_extra_properties.h +150 -150
  63. multipers/gudhi/gudhi/Persistence_matrix/columns/column_dimension_holder.h +106 -106
  64. multipers/gudhi/gudhi/Persistence_matrix/columns/column_utilities.h +219 -219
  65. multipers/gudhi/gudhi/Persistence_matrix/columns/entry_types.h +327 -327
  66. multipers/gudhi/gudhi/Persistence_matrix/columns/heap_column.h +1140 -1140
  67. multipers/gudhi/gudhi/Persistence_matrix/columns/intrusive_list_column.h +934 -934
  68. multipers/gudhi/gudhi/Persistence_matrix/columns/intrusive_set_column.h +934 -934
  69. multipers/gudhi/gudhi/Persistence_matrix/columns/list_column.h +980 -980
  70. multipers/gudhi/gudhi/Persistence_matrix/columns/naive_vector_column.h +1092 -1092
  71. multipers/gudhi/gudhi/Persistence_matrix/columns/row_access.h +192 -192
  72. multipers/gudhi/gudhi/Persistence_matrix/columns/set_column.h +921 -921
  73. multipers/gudhi/gudhi/Persistence_matrix/columns/small_vector_column.h +1093 -1093
  74. multipers/gudhi/gudhi/Persistence_matrix/columns/unordered_set_column.h +1012 -1012
  75. multipers/gudhi/gudhi/Persistence_matrix/columns/vector_column.h +1244 -1244
  76. multipers/gudhi/gudhi/Persistence_matrix/matrix_dimension_holders.h +186 -186
  77. multipers/gudhi/gudhi/Persistence_matrix/matrix_row_access.h +164 -164
  78. multipers/gudhi/gudhi/Persistence_matrix/ru_pairing.h +156 -156
  79. multipers/gudhi/gudhi/Persistence_matrix/ru_rep_cycles.h +376 -376
  80. multipers/gudhi/gudhi/Persistence_matrix/ru_vine_swap.h +540 -540
  81. multipers/gudhi/gudhi/Persistent_cohomology/Field_Zp.h +118 -118
  82. multipers/gudhi/gudhi/Persistent_cohomology/Multi_field.h +173 -173
  83. multipers/gudhi/gudhi/Persistent_cohomology/Persistent_cohomology_column.h +128 -128
  84. multipers/gudhi/gudhi/Persistent_cohomology.h +745 -745
  85. multipers/gudhi/gudhi/Points_off_io.h +171 -171
  86. multipers/gudhi/gudhi/Simple_object_pool.h +69 -69
  87. multipers/gudhi/gudhi/Simplex_tree/Simplex_tree_iterators.h +463 -463
  88. multipers/gudhi/gudhi/Simplex_tree/Simplex_tree_node_explicit_storage.h +83 -83
  89. multipers/gudhi/gudhi/Simplex_tree/Simplex_tree_siblings.h +106 -106
  90. multipers/gudhi/gudhi/Simplex_tree/Simplex_tree_star_simplex_iterators.h +277 -277
  91. multipers/gudhi/gudhi/Simplex_tree/hooks_simplex_base.h +62 -62
  92. multipers/gudhi/gudhi/Simplex_tree/indexing_tag.h +27 -27
  93. multipers/gudhi/gudhi/Simplex_tree/serialization_utils.h +62 -62
  94. multipers/gudhi/gudhi/Simplex_tree/simplex_tree_options.h +157 -157
  95. multipers/gudhi/gudhi/Simplex_tree.h +2794 -2794
  96. multipers/gudhi/gudhi/Simplex_tree_multi.h +152 -163
  97. multipers/gudhi/gudhi/distance_functions.h +62 -62
  98. multipers/gudhi/gudhi/graph_simplicial_complex.h +104 -104
  99. multipers/gudhi/gudhi/persistence_interval.h +253 -253
  100. multipers/gudhi/gudhi/persistence_matrix_options.h +170 -170
  101. multipers/gudhi/gudhi/reader_utils.h +367 -367
  102. multipers/gudhi/mma_interface_coh.h +256 -255
  103. multipers/gudhi/mma_interface_h0.h +223 -231
  104. multipers/gudhi/mma_interface_matrix.h +291 -282
  105. multipers/gudhi/naive_merge_tree.h +536 -575
  106. multipers/gudhi/scc_io.h +310 -289
  107. multipers/gudhi/truc.h +957 -888
  108. multipers/io.cp311-win_amd64.pyd +0 -0
  109. multipers/io.pyx +714 -711
  110. multipers/ml/accuracies.py +90 -90
  111. multipers/ml/invariants_with_persistable.py +79 -79
  112. multipers/ml/kernels.py +176 -176
  113. multipers/ml/mma.py +713 -714
  114. multipers/ml/one.py +472 -472
  115. multipers/ml/point_clouds.py +352 -346
  116. multipers/ml/signed_measures.py +1589 -1589
  117. multipers/ml/sliced_wasserstein.py +461 -461
  118. multipers/ml/tools.py +113 -113
  119. multipers/mma_structures.cp311-win_amd64.pyd +0 -0
  120. multipers/mma_structures.pxd +127 -127
  121. multipers/mma_structures.pyx +4 -8
  122. multipers/mma_structures.pyx.tp +1083 -1085
  123. multipers/multi_parameter_rank_invariant/diff_helpers.h +84 -93
  124. multipers/multi_parameter_rank_invariant/euler_characteristic.h +97 -97
  125. multipers/multi_parameter_rank_invariant/function_rips.h +322 -322
  126. multipers/multi_parameter_rank_invariant/hilbert_function.h +769 -769
  127. multipers/multi_parameter_rank_invariant/persistence_slices.h +148 -148
  128. multipers/multi_parameter_rank_invariant/rank_invariant.h +369 -369
  129. multipers/multiparameter_edge_collapse.py +41 -41
  130. multipers/multiparameter_module_approximation/approximation.h +2298 -2295
  131. multipers/multiparameter_module_approximation/combinatory.h +129 -129
  132. multipers/multiparameter_module_approximation/debug.h +107 -107
  133. multipers/multiparameter_module_approximation/format_python-cpp.h +286 -286
  134. multipers/multiparameter_module_approximation/heap_column.h +238 -238
  135. multipers/multiparameter_module_approximation/images.h +79 -79
  136. multipers/multiparameter_module_approximation/list_column.h +174 -174
  137. multipers/multiparameter_module_approximation/list_column_2.h +232 -232
  138. multipers/multiparameter_module_approximation/ru_matrix.h +347 -347
  139. multipers/multiparameter_module_approximation/set_column.h +135 -135
  140. multipers/multiparameter_module_approximation/structure_higher_dim_barcode.h +36 -36
  141. multipers/multiparameter_module_approximation/unordered_set_column.h +166 -166
  142. multipers/multiparameter_module_approximation/utilities.h +403 -419
  143. multipers/multiparameter_module_approximation/vector_column.h +223 -223
  144. multipers/multiparameter_module_approximation/vector_matrix.h +331 -331
  145. multipers/multiparameter_module_approximation/vineyards.h +464 -464
  146. multipers/multiparameter_module_approximation/vineyards_trajectories.h +649 -649
  147. multipers/multiparameter_module_approximation.cp311-win_amd64.pyd +0 -0
  148. multipers/multiparameter_module_approximation.pyx +218 -217
  149. multipers/pickle.py +90 -53
  150. multipers/plots.py +342 -334
  151. multipers/point_measure.cp311-win_amd64.pyd +0 -0
  152. multipers/point_measure.pyx +322 -320
  153. multipers/simplex_tree_multi.cp311-win_amd64.pyd +0 -0
  154. multipers/simplex_tree_multi.pxd +133 -133
  155. multipers/simplex_tree_multi.pyx +115 -48
  156. multipers/simplex_tree_multi.pyx.tp +1947 -1935
  157. multipers/slicer.cp311-win_amd64.pyd +0 -0
  158. multipers/slicer.pxd +301 -120
  159. multipers/slicer.pxd.tp +218 -214
  160. multipers/slicer.pyx +1570 -507
  161. multipers/slicer.pyx.tp +931 -914
  162. multipers/tensor/tensor.h +672 -672
  163. multipers/tensor.pxd +13 -13
  164. multipers/test.pyx +44 -44
  165. multipers/tests/__init__.py +57 -57
  166. multipers/torch/diff_grids.py +217 -217
  167. multipers/torch/rips_density.py +310 -304
  168. {multipers-2.2.3.dist-info → multipers-2.3.1.dist-info}/LICENSE +21 -21
  169. {multipers-2.2.3.dist-info → multipers-2.3.1.dist-info}/METADATA +21 -11
  170. multipers-2.3.1.dist-info/RECORD +182 -0
  171. {multipers-2.2.3.dist-info → multipers-2.3.1.dist-info}/WHEEL +1 -1
  172. multipers/tests/test_diff_helper.py +0 -73
  173. multipers/tests/test_hilbert_function.py +0 -82
  174. multipers/tests/test_mma.py +0 -83
  175. multipers/tests/test_point_clouds.py +0 -49
  176. multipers/tests/test_python-cpp_conversion.py +0 -82
  177. multipers/tests/test_signed_betti.py +0 -181
  178. multipers/tests/test_signed_measure.py +0 -89
  179. multipers/tests/test_simplextreemulti.py +0 -221
  180. multipers/tests/test_slicer.py +0 -221
  181. multipers-2.2.3.dist-info/RECORD +0 -189
  182. {multipers-2.2.3.dist-info → multipers-2.3.1.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,289 @@
1
+ from collections.abc import Sequence
2
+ from typing import Optional
3
+
4
+ import gudhi as gd
5
+ import numpy as np
6
+ from numpy.typing import ArrayLike
7
+ from scipy.spatial import KDTree
8
+ from scipy.spatial.distance import cdist
9
+
10
+ from multipers.filtrations.density import DTM, available_kernels
11
+ from multipers.simplex_tree_multi import SimplexTreeMulti, SimplexTreeMulti_type
12
+
13
+ try:
14
+ import pykeops
15
+
16
+ from multipers.filtrations.density import KDE
17
+ except ImportError:
18
+ from sklearn.neighbors import KernelDensity
19
+ from warnings import warn
20
+ warn("pykeops not found. Falling back to sklearn.")
21
+
22
+ def KDE(bandwidth, kernel, return_log):
23
+ assert return_log, "Sklearn returns log-density."
24
+ return KernelDensity(bandwidth=bandwidth, kernel=kernel)
25
+
26
+
27
+ def RipsLowerstar(
28
+ *,
29
+ points: Optional[ArrayLike] = None,
30
+ distance_matrix: Optional[ArrayLike] = None,
31
+ function=None,
32
+ threshold_radius=None,
33
+ ):
34
+ """
35
+ Computes the Rips complex, with the usual rips filtration as a first parameter,
36
+ and the lower star multi filtration as other parameter.
37
+
38
+ Input:
39
+ - points or distance_matrix: ArrayLike
40
+ - function : ArrayLike of shape (num_data, num_parameters -1)
41
+ - threshold_radius: max edge length of the rips. Defaults at min(max(distance_matrix, axis=1)).
42
+ """
43
+ assert (
44
+ points is not None or distance_matrix is not None
45
+ ), "`points` or `distance_matrix` has to be given."
46
+ if distance_matrix is None:
47
+ distance_matrix = cdist(points, points) # this may be slow...
48
+ if threshold_radius is None:
49
+ threshold_radius = np.min(np.max(distance_matrix, axis=1))
50
+ st = gd.SimplexTree.create_from_array(
51
+ distance_matrix, max_filtration=threshold_radius
52
+ )
53
+ if function is None:
54
+ return SimplexTreeMulti(st, num_parameters=1)
55
+
56
+ function = np.asarray(function)
57
+ if function.ndim == 1:
58
+ function = function[:, None]
59
+ num_parameters = function.shape[1] + 1
60
+ st = SimplexTreeMulti(st, num_parameters=num_parameters)
61
+ for i in range(function.shape[1]):
62
+ st.fill_lowerstar(function[:, i], parameter=1 + i)
63
+ return st
64
+
65
+
66
+ def RipsCodensity(
67
+ points: ArrayLike,
68
+ bandwidth: Optional[float] = None,
69
+ *,
70
+ return_log: bool = True,
71
+ dtm_mass: Optional[float] = None,
72
+ kernel: available_kernels = "gaussian",
73
+ threshold_radius: Optional[float] = None,
74
+ ):
75
+ """
76
+ Computes the Rips density filtration.
77
+ """
78
+ assert (
79
+ bandwidth is None or dtm_mass is None
80
+ ), "Density estimation is either via kernels or dtm."
81
+ if bandwidth is not None:
82
+ kde = KDE(bandwidth=bandwidth, kernel=kernel, return_log=return_log)
83
+ f = -kde.fit(points).score_samples(points)
84
+ elif dtm_mass is not None:
85
+ f = DTM(masses=[dtm_mass]).fit(points).score_samples(points)[0]
86
+ else:
87
+ raise ValueError("Bandwidth or DTM mass has to be given.")
88
+ return RipsLowerstar(points=points, function=f, threshold_radius=threshold_radius)
89
+
90
+
91
+ def DelaunayLowerstar(
92
+ points: ArrayLike,
93
+ function: ArrayLike,
94
+ *,
95
+ distance_matrix: Optional[ArrayLike] = None,
96
+ threshold_radius: Optional[float] = None,
97
+ reduce_degree: int = -1,
98
+ vineyard: Optional[bool] = None,
99
+ dtype=np.float64,
100
+ verbose: bool = False,
101
+ clear: bool = True,
102
+ ):
103
+ """
104
+ Computes the Function Delaunay bifiltration. Similar to RipsLowerstar, but most suited for low-dimensional euclidean data.
105
+ See [Delaunay bifiltrations of functions on point clouds, Alonso et al] https://doi.org/10.1137/1.9781611977912.173
106
+
107
+ Input:
108
+ - points or distance_matrix: ArrayLike
109
+ - function : ArrayLike of shape (num_data, )
110
+ - threshold_radius: max edge length of the rips. Defaults at min(max(distance_matrix, axis=1)).
111
+ """
112
+ from multipers.slicer import from_function_delaunay
113
+ assert distance_matrix is None, "Delaunay cannot be built from distance matrices"
114
+ if threshold_radius is not None:
115
+ raise NotImplementedError("Delaunay with threshold not implemented yet.")
116
+ points = np.asarray(points)
117
+ function = np.asarray(function).squeeze()
118
+ assert (
119
+ function.ndim == 1
120
+ ), "Delaunay Lowerstar is only compatible with 1 additional parameter."
121
+ return from_function_delaunay(
122
+ points,
123
+ function,
124
+ degree=reduce_degree,
125
+ vineyard=vineyard,
126
+ dtype=dtype,
127
+ verbose=verbose,
128
+ clear=clear,
129
+ )
130
+
131
+
132
+ def DelaunayCodensity(
133
+ points: ArrayLike,
134
+ bandwidth: Optional[float] = None,
135
+ *,
136
+ return_log: bool = True,
137
+ dtm_mass: Optional[float] = None,
138
+ kernel: available_kernels = "gaussian",
139
+ threshold_radius: Optional[float] = None,
140
+ reduce_degree: int = -1,
141
+ vineyard: Optional[bool] = None,
142
+ dtype=np.float64,
143
+ verbose: bool = False,
144
+ clear: bool = True,
145
+ ):
146
+ """
147
+ TODO
148
+ """
149
+ assert (
150
+ bandwidth is None or dtm_mass is None
151
+ ), "Density estimation is either via kernels or dtm."
152
+ if bandwidth is not None:
153
+ kde = KDE(bandwidth=bandwidth, kernel=kernel, return_log=return_log)
154
+ f = kde.fit(points).score_samples(points)
155
+ elif dtm_mass is not None:
156
+ f = DTM(masses=[dtm_mass]).fit(points).score_samples(points)[0]
157
+ else:
158
+ raise ValueError("Bandwidth or DTM mass has to be given.")
159
+ return DelaunayLowerstar(
160
+ points=points,
161
+ function=f,
162
+ threshold_radius=threshold_radius,
163
+ reduce_degree=reduce_degree,
164
+ vineyard=vineyard,
165
+ dtype=dtype,
166
+ verbose=verbose,
167
+ clear=clear,
168
+ )
169
+
170
+
171
+ def Cubical(image: ArrayLike, **slicer_kwargs):
172
+ """
173
+ Computes the cubical filtration of an image.
174
+ The last axis dimention is interpreted as the number of parameters.
175
+
176
+ Input:
177
+ - image: ArrayLike of shape (*image_resolution, num_parameters)
178
+ - ** args : specify non-default slicer parameters
179
+ """
180
+ from multipers.slicer import from_bitmap
181
+ return from_bitmap(image, **slicer_kwargs)
182
+
183
+
184
+ def DegreeRips(*, points=None, distance_matrix=None, ks=None, threshold_radius=None):
185
+ """
186
+ The DegreeRips filtration.
187
+ """
188
+
189
+ raise NotImplementedError("Use the default implentation ftm.")
190
+
191
+
192
+ def CoreDelaunay(
193
+ points: ArrayLike,
194
+ *,
195
+ beta: float = 1.0,
196
+ ks: Optional[Sequence[int]] = None,
197
+ precision: str = "safe",
198
+ verbose: bool = False,
199
+ max_alpha_square: float = float("inf"),
200
+ ) -> SimplexTreeMulti_type:
201
+ """
202
+ 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.
203
+
204
+ Input:
205
+ - 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.
206
+ - beta: The beta parameter for the Delaunay Core Bifiltration (default 1.0).
207
+ - 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.
208
+ - precision: The precision of the computation of the AlphaComplex, one of ['safe', 'exact', 'fast'] (default 'safe'). See the GUDHI documentation for more information.
209
+ - verbose: Whether to print progress messages (default False).
210
+ - max_alpha_square: The maximum squared alpha value to consider when createing the alpha complex (default inf). See the GUDHI documentation for more information.
211
+ """
212
+ points = np.asarray(points)
213
+ if ks is None:
214
+ ks = np.arange(1, len(points) + 1)
215
+ else:
216
+ ks = np.asarray(ks, dtype=int)
217
+ ks:np.ndarray
218
+
219
+ assert len(ks) > 0, "The parameter ks must contain at least one value."
220
+ assert np.all(ks > 0), "All values in ks must be positive."
221
+ assert np.all(
222
+ ks <= len(points)
223
+ ), "All values in ks must be less than or equal to the number of points in the point cloud."
224
+ assert len(points) > 0, "The point cloud must contain at least one point."
225
+ assert points.ndim == 2, f"The point cloud must be a 2D array, got {points.ndim}D."
226
+ assert beta >= 0, f"The parameter beta must be positive, got {beta}."
227
+ assert precision in [
228
+ "safe",
229
+ "exact",
230
+ "fast",
231
+ ], f"The parameter precision must be one of ['safe', 'exact', 'fast'], got {precision}."
232
+
233
+ if verbose:
234
+ print(
235
+ f"Computing the Delaunay Core Bifiltration of {len(points)} points in dimension {points.shape[1]} with parameters:"
236
+ )
237
+ print(f"\tbeta = {beta}")
238
+ print(f"\tks = {ks}")
239
+
240
+ if verbose:
241
+ print("Building the alpha complex...")
242
+ alpha_complex = gd.AlphaComplex(
243
+ points=points, precision=precision
244
+ ).create_simplex_tree(max_alpha_square=max_alpha_square)
245
+
246
+ if verbose:
247
+ print("Computing the k-nearest neighbor distances...")
248
+ knn_distances = KDTree(points).query(points, k=ks)[0]
249
+
250
+ max_dim = alpha_complex.dimension()
251
+ vertex_arrays_in_dimension = [[] for _ in range(max_dim + 1)]
252
+ squared_alphas_in_dimension = [[] for _ in range(max_dim + 1)]
253
+ for simplex, alpha_squared in alpha_complex.get_simplices():
254
+ dim = len(simplex) - 1
255
+ squared_alphas_in_dimension[dim].append(alpha_squared)
256
+ vertex_arrays_in_dimension[dim].append(simplex)
257
+
258
+ alphas_in_dimension = [
259
+ np.sqrt(np.array(alpha_squared, dtype=np.float64))
260
+ for alpha_squared in squared_alphas_in_dimension
261
+ ]
262
+ vertex_arrays_in_dimension = [
263
+ np.array(vertex_array, dtype=np.int32)
264
+ for vertex_array in vertex_arrays_in_dimension
265
+ ]
266
+
267
+ simplex_tree_multi = SimplexTreeMulti(
268
+ num_parameters=2, kcritical=True, dtype=np.float64
269
+ )
270
+
271
+ for dim, (vertex_array, alphas) in enumerate(
272
+ zip(vertex_arrays_in_dimension, alphas_in_dimension)
273
+ ):
274
+ num_simplices = len(vertex_array)
275
+ if verbose:
276
+ print(
277
+ f"Inserting {num_simplices} simplices of dimension {dim} ({num_simplices * len(ks)} birth values)..."
278
+ )
279
+ max_knn_distances = np.max(knn_distances[vertex_array], axis=1)
280
+ critical_radii = np.maximum(alphas[:, None], beta * max_knn_distances)
281
+ filtrations = np.stack(
282
+ (critical_radii, -ks * np.ones_like(critical_radii)), axis=-1
283
+ )
284
+ simplex_tree_multi.insert_batch(vertex_array.T, filtrations)
285
+
286
+ if verbose:
287
+ print("Done computing the Delaunay Core Bifiltration.")
288
+
289
+ return simplex_tree_multi