multipers 2.2.3__cp310-cp310-win_amd64.whl → 2.3.1__cp310-cp310-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.cp310-win_amd64.pyd +0 -0
  18. multipers/function_rips.pyx +105 -105
  19. multipers/grids.cp310-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.cp310-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.cp310-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.cp310-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.cp310-win_amd64.pyd +0 -0
  152. multipers/point_measure.pyx +322 -320
  153. multipers/simplex_tree_multi.cp310-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.cp310-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
@@ -1,82 +0,0 @@
1
- import numpy as np
2
- import multipers as mp
3
- import gudhi as gd
4
-
5
-
6
- mp.simplex_tree_multi.SAFE_CONVERSION = False
7
-
8
-
9
- def test_random_alpha_safe_conversion():
10
- x = np.random.uniform(size=(200, 2))
11
- num_parameter = 4
12
- st_gudhi = gd.AlphaComplex(points=x).create_simplex_tree()
13
- st_multi = mp.SimplexTreeMulti(
14
- st_gudhi, num_parameters=num_parameter, safe_conversion=True
15
- )
16
- assert (
17
- np.all([s in st_multi for s, f in st_gudhi.get_simplices()])
18
- and st_gudhi.num_simplices() == st_multi.num_simplices
19
- ), "Simplices conversion failed."
20
- assert np.all(
21
- [f.shape[0] == num_parameter for _, f in st_multi.get_simplices()]
22
- ), "Number of parameters is inconcistent"
23
- assert np.all(
24
- [np.isclose(st_multi.filtration(s)[0], f) for s, f in st_gudhi.get_simplices()]
25
- ), "Filtration values conversion failed."
26
-
27
-
28
- def test_random_alpha_unsafe_conversion():
29
- x = np.random.uniform(size=(200, 2))
30
- num_parameter = 4
31
- st_gudhi = gd.AlphaComplex(points=x).create_simplex_tree()
32
- st_multi = mp.SimplexTreeMulti(
33
- st_gudhi, num_parameters=num_parameter, safe_conversion=False
34
- )
35
- assert (
36
- np.all([s in st_multi for s, f in st_gudhi.get_simplices()])
37
- and st_gudhi.num_simplices() == st_multi.num_simplices
38
- ), "Simplices conversion failed."
39
- assert np.all(
40
- [f.shape[0] == num_parameter for _, f in st_multi.get_simplices()]
41
- ), "Number of parameters is inconcistent"
42
- assert np.all(
43
- [np.isclose(st_multi.filtration(s)[0], f) for s, f in st_gudhi.get_simplices()]
44
- ), "Filtration values conversion failed."
45
-
46
-
47
- def test_random_rips_safe_conversion():
48
- x = np.random.uniform(size=(100, 2))
49
- num_parameter = 4
50
- st_gudhi = gd.RipsComplex(points=x).create_simplex_tree()
51
- st_multi = mp.SimplexTreeMulti(
52
- st_gudhi, num_parameters=num_parameter, safe_conversion=True
53
- )
54
- assert (
55
- np.all([s in st_multi for s, f in st_gudhi.get_simplices()])
56
- and st_gudhi.num_simplices() == st_multi.num_simplices
57
- ), "Simplices conversion failed."
58
- assert np.all(
59
- [f.shape[0] == num_parameter for _, f in st_multi.get_simplices()]
60
- ), "Number of parameters is inconcistent"
61
- assert np.all(
62
- [np.isclose(st_multi.filtration(s)[0], f) for s, f in st_gudhi.get_simplices()]
63
- ), "Filtration values conversion failed."
64
-
65
-
66
- def test_random_alpha_unsafe_conversion():
67
- x = np.random.uniform(size=(100, 2))
68
- num_parameter = 4
69
- st_gudhi = gd.RipsComplex(points=x).create_simplex_tree()
70
- st_multi = mp.SimplexTreeMulti(
71
- st_gudhi, num_parameters=num_parameter, safe_conversion=False
72
- )
73
- assert (
74
- np.all([s in st_multi for s, f in st_gudhi.get_simplices()])
75
- and st_gudhi.num_simplices() == st_multi.num_simplices
76
- ), "Simplices conversion failed."
77
- assert np.all(
78
- [f.shape[0] == num_parameter for _, f in st_multi.get_simplices()]
79
- ), "Number of parameters is inconcistent"
80
- assert np.all(
81
- [np.isclose(st_multi.filtration(s)[0], f) for s, f in st_gudhi.get_simplices()]
82
- ), "Filtration values conversion failed."
@@ -1,181 +0,0 @@
1
- import numpy as np
2
- from multipers.point_measure import signed_betti, rank_decomposition_by_rectangles
3
-
4
-
5
- # only tests rank functions with 1 and 2 parameters
6
- def test_rank_decomposition():
7
- # rank of an interval module in 1D on a grid with 2 elements
8
- ri = np.array(
9
- [
10
- [
11
- 1, # 0,0
12
- 1, # 0,1
13
- ],
14
- [0, 1], # 1,0 # 1,1
15
- ]
16
- )
17
- expected_rd = np.array(
18
- [
19
- [
20
- 0, # 0,0
21
- 1, # 0,1
22
- ],
23
- [0, 0], # 1,0 # 1,1
24
- ]
25
- )
26
- rd = rank_decomposition_by_rectangles(ri)
27
- for i in range(2):
28
- for i_ in range(i, 2):
29
- assert rd[i, i_] == expected_rd[i, i_]
30
-
31
- # rank of a sum of two rectangles in 2D on a grid of 2 elements
32
- ri = np.array(
33
- [
34
- [
35
- [
36
- [1, 1], # (0,0), (0,0) # (0,0), (0,1)
37
- [1, 1], # (0,0), (1,0) # (0,0), (1,1)
38
- ],
39
- [
40
- [0, 1], # (0,1), (0,0) # (0,1), (0,1)
41
- [0, 1], # (0,1), (1,0) # (0,1), (1,1)
42
- ],
43
- ],
44
- [
45
- [
46
- [0, 0], # (1,0), (0,0) # (1,0), (0,1)
47
- [2, 2], # (1,0), (1,0) # (1,0), (1,1)
48
- ],
49
- [
50
- [0, 0], # (1,1), (0,0) # (1,1), (0,1)
51
- [0, 2], # (1,1), (1,0) # (1,1), (1,1)
52
- ],
53
- ],
54
- ]
55
- )
56
- expected_rd = np.array(
57
- [
58
- [
59
- [
60
- [0, 0], # (0,0), (0,0) # (0,0), (0,1)
61
- [0, 1], # (0,0), (1,0) # (0,0), (1,1)
62
- ],
63
- [
64
- [0, 0], # (0,1), (0,0) # (0,1), (0,1)
65
- [0, 0], # (0,1), (1,0) # (0,1), (1,1)
66
- ],
67
- ],
68
- [
69
- [
70
- [0, 0], # (1,0), (0,0) # (1,0), (0,1)
71
- [0, 1], # (1,0), (1,0) # (1,0), (1,1)
72
- ],
73
- [
74
- [0, 0], # (1,1), (0,0) # (1,1), (0,1)
75
- [0, 0], # (1,1), (1,0) # (1,1), (1,1)
76
- ],
77
- ],
78
- ]
79
- )
80
-
81
- rd = rank_decomposition_by_rectangles(ri)
82
- for i in range(2):
83
- for i_ in range(i, 2):
84
- for j in range(2):
85
- for j_ in range(j, 2):
86
- assert rd[i, j, i_, j_] == expected_rd[i, j, i_, j_]
87
-
88
-
89
- # only tests Hilbert functions with 1, 2, 3, and 4 parameters
90
- def _test_signed_betti():
91
- np.random.seed(0)
92
- N = 4
93
-
94
- # test 1D
95
- for _ in range(N):
96
- a = np.random.randint(10, 30)
97
-
98
- f = np.random.randint(0, 40, size=(a))
99
- sb = signed_betti(f)
100
-
101
- check = np.zeros(f.shape)
102
- for i in range(f.shape[0]):
103
- for i_ in range(0, i + 1):
104
- check[i] += sb[i_]
105
-
106
- assert np.allclose(check, f)
107
-
108
- # test 2D
109
- for _ in range(N):
110
- a = np.random.randint(10, 30)
111
- b = np.random.randint(10, 30)
112
-
113
- f = np.random.randint(0, 40, size=(a, b))
114
- sb = signed_betti(f)
115
-
116
- check = np.zeros(f.shape)
117
- for i in range(f.shape[0]):
118
- for j in range(f.shape[1]):
119
- for i_ in range(0, i + 1):
120
- for j_ in range(0, j + 1):
121
- check[i, j] += sb[i_, j_]
122
-
123
- assert np.allclose(check, f)
124
-
125
- # test 3D
126
- for _ in range(N):
127
- a = np.random.randint(10, 20)
128
- b = np.random.randint(10, 20)
129
- c = np.random.randint(10, 20)
130
-
131
- f = np.random.randint(0, 40, size=(a, b, c))
132
- sb = signed_betti(f)
133
-
134
- check = np.zeros(f.shape)
135
- for i in range(f.shape[0]):
136
- for j in range(f.shape[1]):
137
- for k in range(f.shape[2]):
138
- for i_ in range(0, i + 1):
139
- for j_ in range(0, j + 1):
140
- for k_ in range(0, k + 1):
141
- check[i, j, k] += sb[i_, j_, k_]
142
-
143
- assert np.allclose(check, f)
144
-
145
- # test 4D
146
- for _ in range(N):
147
- a = np.random.randint(5, 10)
148
- b = np.random.randint(5, 10)
149
- c = np.random.randint(5, 10)
150
- d = np.random.randint(5, 10)
151
-
152
- f = np.random.randint(0, 40, size=(a, b, c, d))
153
- sb = signed_betti(f)
154
-
155
- check = np.zeros(f.shape)
156
- for i in range(f.shape[0]):
157
- for j in range(f.shape[1]):
158
- for k in range(f.shape[2]):
159
- for l in range(f.shape[3]):
160
- for i_ in range(0, i + 1):
161
- for j_ in range(0, j + 1):
162
- for k_ in range(0, k + 1):
163
- for l_ in range(0, l + 1):
164
- check[i, j, k, l] += sb[i_, j_, k_, l_]
165
-
166
- assert np.allclose(check, f)
167
-
168
- for threshold in [True, False]:
169
- for _ in range(N):
170
- a = np.random.randint(5, 10)
171
- b = np.random.randint(5, 10)
172
- c = np.random.randint(5, 10)
173
- d = np.random.randint(5, 10)
174
- e = np.random.randint(5, 10)
175
- f = np.random.randint(5, 10)
176
-
177
- f = np.random.randint(0, 40, size=(a, b, c, d,e,f))
178
- sb = signed_betti(f, threshold=threshold)
179
- sb_ = signed_betti(f, threshold=threshold)
180
-
181
- assert np.allclose(sb, sb_)
@@ -1,89 +0,0 @@
1
- import numpy as np
2
- import pytest
3
-
4
- import multipers as mp
5
- import multipers.io as mio
6
- from multipers.tests import assert_sm, random_st
7
-
8
- np.random.seed(0)
9
-
10
- st = random_st(npts=50).collapse_edges(-2, ignore_warning=True)
11
-
12
- invariants = ["euler", "hilbert", "rank"]
13
- degrees = [0, 1]
14
- mass_defaults = [None, "auto"]
15
- strats = [("regular_closest", 20), ("quantile", 20), ("regular", 17)]
16
-
17
- mio._init_external_softwares()
18
- mpfree_flag = mio._check_available("mpfree")
19
-
20
-
21
- @pytest.mark.parametrize("invariant", invariants)
22
- @pytest.mark.parametrize("degree", degrees)
23
- @pytest.mark.parametrize("mass_default", mass_defaults)
24
- @pytest.mark.parametrize("S", strats)
25
- def test_backends(invariant, degree, mass_default, S):
26
- degree = None if invariant == "euler" else degree
27
- strat, r = S
28
- sms = []
29
- sms.append(
30
- mp.signed_measure(
31
- st,
32
- degree=degree,
33
- grid_strategy=strat,
34
- resolution=r,
35
- mass_default=mass_default,
36
- invariant=invariant,
37
- )[0]
38
- )
39
- sms.append(
40
- mp.signed_measure(
41
- st.grid_squeeze(grid_strategy=strat, resolution=r),
42
- degree=degree,
43
- mass_default=mass_default,
44
- invariant=invariant,
45
- )[0]
46
- )
47
- snv = mp.Slicer(st, vineyard=False)
48
- sv = mp.Slicer(st, vineyard=True)
49
- for s in [sv, snv]:
50
- sms.append(
51
- mp.signed_measure(
52
- s,
53
- degree=1,
54
- grid_strategy=strat,
55
- resolution=r,
56
- mass_default=mass_default,
57
- invariant=invariant,
58
- )[0]
59
- )
60
- if invariant != "euler":
61
- if not mpfree_flag:
62
- pytest.skip(r"Skipping next test, as `mpfree` was not found.")
63
- else:
64
- for s in [sv, snv]:
65
- assert s.minpres(degree=degree).is_minpres, "minpres is not minpres"
66
- sms.append(
67
- mp.signed_measure(
68
- s.minpres(degree=degree),
69
- degree=degree,
70
- grid_strategy=strat,
71
- resolution=r,
72
- mass_default=mass_default,
73
- invariant=invariant,
74
- )[0]
75
- )
76
- sms.append(
77
- mp.signed_measure(
78
- st,
79
- grid_strategy=strat,
80
- degree=degree,
81
- resolution=r,
82
- mass_default=mass_default,
83
- backend="mpfree",
84
- invariant=invariant,
85
- )[0]
86
- )
87
- if mass_default is not None and invariant != "rank":
88
- assert sms[0][1].sum() == 0, "Did not remove all of the mass"
89
- assert_sm(*sms, exact=False, max_error=0.5)
@@ -1,221 +0,0 @@
1
- import pickle as pkl
2
-
3
- import gudhi as gd
4
- import numpy as np
5
- from numpy import array
6
-
7
- import multipers as mp
8
- import pytest
9
- from multipers.tests import assert_st_simplices, random_st
10
-
11
-
12
-
13
- def test_1():
14
- st = mp.SimplexTreeMulti(num_parameters=2)
15
- st.insert([0], [0, 1])
16
- st.insert([1], [1, 0])
17
- st.insert([0, 1], [1, 1])
18
- it = [([0, 1], [1.0, 1.0]), ([0], [0.0, 1.0]), ([1], [1.0, 0.0])]
19
- assert_st_simplices(st, it)
20
-
21
-
22
- def test_2():
23
- from gudhi.rips_complex import RipsComplex
24
-
25
- st2 = RipsComplex(points=[[0, 1], [1, 0], [0, 0]]).create_simplex_tree()
26
- st2 = mp.SimplexTreeMulti(
27
- st2, num_parameters=3, default_values=[1, 2]
28
- ) # the gudhi filtration is placed on axis 0
29
-
30
- it = (
31
- ([0, 1], [np.sqrt(2), 1.0, 2.0]),
32
- ([0, 2], [1.0, 1.0, 2.0]),
33
- ([0], [0.0, 1.0, 2.0]),
34
- ([1, 2], [1.0, 1.0, 2.0]),
35
- ([1], [0.0, 1.0, 2.0]),
36
- ([2], [0.0, 1.0, 2.0]),
37
- )
38
- assert_st_simplices(st2, it)
39
-
40
-
41
- def test_3():
42
- st = gd.SimplexTree() # usual gudhi simplextree
43
- st.insert([0, 1], 1)
44
- st.insert([1], 0)
45
- # converts the simplextree into a multiparameter simplextree
46
- for dtype in [np.int32, np.int64, np.float32, np.float64]:
47
- try:
48
- st_multi = mp.SimplexTreeMulti(st, num_parameters=4, dtype=dtype)
49
- except KeyError:
50
- import sys
51
-
52
- print(f"type {dtype} not compiled, skipping.", file=sys.stderr)
53
- continue ## dtype not compiled
54
- minf = -np.inf if isinstance(dtype(1), np.floating) else np.iinfo(dtype).min
55
- it = [
56
- (array([0, 1]), array([1.0, minf, minf, minf])),
57
- (array([0]), array([1.0, minf, minf, minf])),
58
- (array([1]), array([0.0, minf, minf, minf])),
59
- ]
60
- assert_st_simplices(st_multi, it)
61
-
62
-
63
- has_kcritical = np.any([a().is_kcritical for a in mp.simplex_tree_multi.available_simplextrees])
64
- @pytest.mark.skipif(
65
- not has_kcritical,
66
- reason="kcritical simplextree not compiled, skipping this test",
67
- )
68
- def test_4():
69
- st = mp.SimplexTreeMulti(num_parameters=2, kcritical=True, dtype=np.float64)
70
- st.insert([0, 1, 2], [0, 1])
71
- st.insert([0, 1, 2], [1, 0])
72
- st.remove_maximal_simplex([0, 1, 2])
73
- st.insert([0, 1, 2], [1, 2])
74
- st.insert([0, 1, 2], [2, 1])
75
- st.insert([0, 1, 2], [1.5, 1.5])
76
- st.insert([0, 1, 2], [2.5, 0.5])
77
- st.insert([0, 1, 2], [0.5, 2.5])
78
-
79
- s = mp.Slicer(st, vineyard=True)
80
-
81
- assert np.array_equal(
82
- s.get_filtrations_values(),
83
- array(
84
- [
85
- [0.0, 1.0],
86
- [1.0, 0.0],
87
- [0.0, 1.0],
88
- [1.0, 0.0],
89
- [0.0, 1.0],
90
- [1.0, 0.0],
91
- [0.0, 1.0],
92
- [1.0, 0.0],
93
- [0.0, 1.0],
94
- [1.0, 0.0],
95
- [0.0, 1.0],
96
- [1.0, 0.0],
97
- [0.5, 2.5],
98
- [1.0, 2.0],
99
- [1.5, 1.5],
100
- [2.0, 1.0],
101
- [2.5, 0.5],
102
- ]
103
- ),
104
- ), "Invalid conversion from kcritical st to kcritical slicer."
105
- death_curve = np.asarray(
106
- mp.module_approximation(s, box=[[0, 0], [3, 3]])
107
- .get_module_of_degree(1)[0]
108
- .get_death_list()
109
- )
110
- assert np.array_equal(
111
- death_curve,
112
- array(
113
- [
114
- [0.5, np.inf],
115
- [1.0, 2.5],
116
- [1.5, 2.0],
117
- [2.0, 1.5],
118
- [2.5, 1.0],
119
- [np.inf, 0.5],
120
- ]
121
- ),
122
- )
123
-
124
-
125
- def test_make_filtration_non_decreasing():
126
- st = mp.SimplexTreeMulti(num_parameters=2)
127
- st.insert([0], [1, 2])
128
- st.insert([1], [2, 3])
129
- st.insert([2], [3, 2])
130
-
131
- st.insert([0, 1], [10, 21])
132
- st.insert([2, 0], [11, 20])
133
-
134
- st.insert([0, 1, 2], [-np.inf, -np.inf])
135
- assert (st.filtration([1, 2]) == 3).all()
136
- assert (st.filtration([0, 1, 2]) == [11, 21]).all()
137
- st.make_filtration_non_decreasing()
138
- assert (st.filtration([1, 2]) == 3).all()
139
- assert (st.filtration([0, 1, 2]) == [11, 21]).all()
140
-
141
-
142
- def test_flagify():
143
- st = mp.SimplexTreeMulti(num_parameters=2)
144
-
145
- st.insert([0], [1, 4])
146
- st.insert([1], [2, 3])
147
- st.insert([2], [3, 2])
148
-
149
- st.insert([0, 1], [21, 20])
150
- st.insert([2, 0], [20, 21])
151
- st.insert([1, 2])
152
- st.insert([0, 1, 2], [41, 55])
153
-
154
- st.flagify(2)
155
- assert (st.filtration([0, 1, 2]) == 21).all()
156
- st.flagify(1)
157
- assert (np.array([f for s, f in st]).max(axis=0) == [3, 4]).all()
158
- st.flagify(0)
159
- assert (np.array([f for s, f in st]) == -np.inf).all()
160
-
161
-
162
- def test_distance_matrix_filling():
163
- X = np.random.uniform(size=(200, 2))
164
- D = np.sqrt(((X[None] - X[:, None]) ** 2).sum(axis=-1))
165
- st = gd.RipsComplex(distance_matrix=D).create_simplex_tree()
166
- st = mp.SimplexTreeMulti(st, num_parameters=1)
167
- st2 = mp.SimplexTreeMulti(st)
168
- assert st2.num_parameters == 1
169
- st2.fill_lowerstar(np.zeros(st.num_vertices), 0)
170
- assert st2 != st
171
- st2.fill_distance_matrix(D, 0)
172
- assert st2 == st
173
-
174
-
175
- def test_serialize():
176
- stm = random_st(num_parameters=4)
177
- stm2 = pkl.loads(pkl.dumps(stm))
178
- assert stm == stm2
179
- stm2[[0]][:] = stm2[[0]] + 1
180
- assert not stm == stm2
181
- st1 = stm.project_on_line(parameter=0)
182
- stm = mp.SimplexTreeMulti(st1, num_parameters=3)
183
- assert st1 == stm.project_on_line(
184
- parameter=0
185
- ), "Gudhi<->Multipers conversion failed"
186
-
187
-
188
- @pytest.mark.skipif(
189
- not has_kcritical,
190
- reason="kcritical simplextree not compiled, skipping this test",
191
- )
192
- def test_kcritical_batch_insert():
193
-
194
- st = mp.SimplexTreeMulti(num_parameters=2, kcritical=True, dtype=np.float64)
195
-
196
- vertices = [[0,1]]
197
- vertices_filtrations = np.array([[[-1, -2]],[[-2, -1]]])
198
- st.insert_batch(vertices,vertices_filtrations)
199
-
200
- edges = np.array([[0, 1],[1, 2], [2,0]]).T
201
- edges_filtrations = np.array([
202
- [[1,0],[0,1], [np.inf,np.inf]],
203
- [[1,0],[0,1], [np.inf,np.inf]],
204
- [[1,0],[0,1], [-1,3]],
205
- ])
206
- st.insert_batch(edges, edges_filtrations)
207
-
208
- triangle = np.array([[0,1,2]]).T
209
- triangle_filration = [[[2,2]]]
210
- st.insert_batch(triangle, triangle_filration)
211
-
212
- from numpy import array
213
- goal = [(array([0, 1, 2]), [array([2., 2.])]),
214
- (array([0, 1]), [array([0., 1.]), array([1., 0.])]),
215
- (array([0, 2]), [array([-1., 3.]), array([0., 1.]), array([1., 0.])]),
216
- (array([0]), [array([-1., -2.])]),
217
- (array([1, 2]), [array([0., 1.]), array([1., 0.])]),
218
- (array([1]), [array([-2., -1.])]),
219
- (array([2]), [array([0., 1.]), array([1., 0.])])
220
- ]
221
- assert_st_simplices(st, goal)