multipers 2.3.3b6__cp312-cp312-macosx_11_0_arm64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


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

Files changed (183) hide show
  1. multipers/.dylibs/libc++.1.0.dylib +0 -0
  2. multipers/.dylibs/libtbb.12.16.dylib +0 -0
  3. multipers/__init__.py +33 -0
  4. multipers/_signed_measure_meta.py +453 -0
  5. multipers/_slicer_meta.py +211 -0
  6. multipers/array_api/__init__.py +45 -0
  7. multipers/array_api/numpy.py +41 -0
  8. multipers/array_api/torch.py +58 -0
  9. multipers/data/MOL2.py +458 -0
  10. multipers/data/UCR.py +18 -0
  11. multipers/data/__init__.py +1 -0
  12. multipers/data/graphs.py +466 -0
  13. multipers/data/immuno_regions.py +27 -0
  14. multipers/data/minimal_presentation_to_st_bf.py +0 -0
  15. multipers/data/pytorch2simplextree.py +91 -0
  16. multipers/data/shape3d.py +101 -0
  17. multipers/data/synthetic.py +113 -0
  18. multipers/distances.py +202 -0
  19. multipers/filtration_conversions.pxd +229 -0
  20. multipers/filtration_conversions.pxd.tp +84 -0
  21. multipers/filtrations/__init__.py +18 -0
  22. multipers/filtrations/density.py +574 -0
  23. multipers/filtrations/filtrations.py +361 -0
  24. multipers/filtrations.pxd +224 -0
  25. multipers/function_rips.cpython-312-darwin.so +0 -0
  26. multipers/function_rips.pyx +105 -0
  27. multipers/grids.cpython-312-darwin.so +0 -0
  28. multipers/grids.pyx +433 -0
  29. multipers/gudhi/Persistence_slices_interface.h +132 -0
  30. multipers/gudhi/Simplex_tree_interface.h +239 -0
  31. multipers/gudhi/Simplex_tree_multi_interface.h +551 -0
  32. multipers/gudhi/cubical_to_boundary.h +59 -0
  33. multipers/gudhi/gudhi/Bitmap_cubical_complex.h +450 -0
  34. multipers/gudhi/gudhi/Bitmap_cubical_complex_base.h +1070 -0
  35. multipers/gudhi/gudhi/Bitmap_cubical_complex_periodic_boundary_conditions_base.h +579 -0
  36. multipers/gudhi/gudhi/Debug_utils.h +45 -0
  37. multipers/gudhi/gudhi/Fields/Multi_field.h +484 -0
  38. multipers/gudhi/gudhi/Fields/Multi_field_operators.h +455 -0
  39. multipers/gudhi/gudhi/Fields/Multi_field_shared.h +450 -0
  40. multipers/gudhi/gudhi/Fields/Multi_field_small.h +531 -0
  41. multipers/gudhi/gudhi/Fields/Multi_field_small_operators.h +507 -0
  42. multipers/gudhi/gudhi/Fields/Multi_field_small_shared.h +531 -0
  43. multipers/gudhi/gudhi/Fields/Z2_field.h +355 -0
  44. multipers/gudhi/gudhi/Fields/Z2_field_operators.h +376 -0
  45. multipers/gudhi/gudhi/Fields/Zp_field.h +420 -0
  46. multipers/gudhi/gudhi/Fields/Zp_field_operators.h +400 -0
  47. multipers/gudhi/gudhi/Fields/Zp_field_shared.h +418 -0
  48. multipers/gudhi/gudhi/Flag_complex_edge_collapser.h +337 -0
  49. multipers/gudhi/gudhi/Matrix.h +2107 -0
  50. multipers/gudhi/gudhi/Multi_critical_filtration.h +1038 -0
  51. multipers/gudhi/gudhi/Multi_persistence/Box.h +174 -0
  52. multipers/gudhi/gudhi/Multi_persistence/Line.h +282 -0
  53. multipers/gudhi/gudhi/Off_reader.h +173 -0
  54. multipers/gudhi/gudhi/One_critical_filtration.h +1441 -0
  55. multipers/gudhi/gudhi/Persistence_matrix/Base_matrix.h +769 -0
  56. multipers/gudhi/gudhi/Persistence_matrix/Base_matrix_with_column_compression.h +686 -0
  57. multipers/gudhi/gudhi/Persistence_matrix/Boundary_matrix.h +842 -0
  58. multipers/gudhi/gudhi/Persistence_matrix/Chain_matrix.h +1350 -0
  59. multipers/gudhi/gudhi/Persistence_matrix/Id_to_index_overlay.h +1105 -0
  60. multipers/gudhi/gudhi/Persistence_matrix/Position_to_index_overlay.h +859 -0
  61. multipers/gudhi/gudhi/Persistence_matrix/RU_matrix.h +910 -0
  62. multipers/gudhi/gudhi/Persistence_matrix/allocators/entry_constructors.h +139 -0
  63. multipers/gudhi/gudhi/Persistence_matrix/base_pairing.h +230 -0
  64. multipers/gudhi/gudhi/Persistence_matrix/base_swap.h +211 -0
  65. multipers/gudhi/gudhi/Persistence_matrix/boundary_cell_position_to_id_mapper.h +60 -0
  66. multipers/gudhi/gudhi/Persistence_matrix/boundary_face_position_to_id_mapper.h +60 -0
  67. multipers/gudhi/gudhi/Persistence_matrix/chain_pairing.h +136 -0
  68. multipers/gudhi/gudhi/Persistence_matrix/chain_rep_cycles.h +190 -0
  69. multipers/gudhi/gudhi/Persistence_matrix/chain_vine_swap.h +616 -0
  70. multipers/gudhi/gudhi/Persistence_matrix/columns/chain_column_extra_properties.h +150 -0
  71. multipers/gudhi/gudhi/Persistence_matrix/columns/column_dimension_holder.h +106 -0
  72. multipers/gudhi/gudhi/Persistence_matrix/columns/column_utilities.h +219 -0
  73. multipers/gudhi/gudhi/Persistence_matrix/columns/entry_types.h +327 -0
  74. multipers/gudhi/gudhi/Persistence_matrix/columns/heap_column.h +1140 -0
  75. multipers/gudhi/gudhi/Persistence_matrix/columns/intrusive_list_column.h +934 -0
  76. multipers/gudhi/gudhi/Persistence_matrix/columns/intrusive_set_column.h +934 -0
  77. multipers/gudhi/gudhi/Persistence_matrix/columns/list_column.h +980 -0
  78. multipers/gudhi/gudhi/Persistence_matrix/columns/naive_vector_column.h +1092 -0
  79. multipers/gudhi/gudhi/Persistence_matrix/columns/row_access.h +192 -0
  80. multipers/gudhi/gudhi/Persistence_matrix/columns/set_column.h +921 -0
  81. multipers/gudhi/gudhi/Persistence_matrix/columns/small_vector_column.h +1093 -0
  82. multipers/gudhi/gudhi/Persistence_matrix/columns/unordered_set_column.h +1012 -0
  83. multipers/gudhi/gudhi/Persistence_matrix/columns/vector_column.h +1244 -0
  84. multipers/gudhi/gudhi/Persistence_matrix/matrix_dimension_holders.h +186 -0
  85. multipers/gudhi/gudhi/Persistence_matrix/matrix_row_access.h +164 -0
  86. multipers/gudhi/gudhi/Persistence_matrix/ru_pairing.h +156 -0
  87. multipers/gudhi/gudhi/Persistence_matrix/ru_rep_cycles.h +376 -0
  88. multipers/gudhi/gudhi/Persistence_matrix/ru_vine_swap.h +540 -0
  89. multipers/gudhi/gudhi/Persistent_cohomology/Field_Zp.h +118 -0
  90. multipers/gudhi/gudhi/Persistent_cohomology/Multi_field.h +173 -0
  91. multipers/gudhi/gudhi/Persistent_cohomology/Persistent_cohomology_column.h +128 -0
  92. multipers/gudhi/gudhi/Persistent_cohomology.h +745 -0
  93. multipers/gudhi/gudhi/Points_off_io.h +171 -0
  94. multipers/gudhi/gudhi/Simple_object_pool.h +69 -0
  95. multipers/gudhi/gudhi/Simplex_tree/Simplex_tree_iterators.h +463 -0
  96. multipers/gudhi/gudhi/Simplex_tree/Simplex_tree_node_explicit_storage.h +83 -0
  97. multipers/gudhi/gudhi/Simplex_tree/Simplex_tree_siblings.h +106 -0
  98. multipers/gudhi/gudhi/Simplex_tree/Simplex_tree_star_simplex_iterators.h +277 -0
  99. multipers/gudhi/gudhi/Simplex_tree/hooks_simplex_base.h +62 -0
  100. multipers/gudhi/gudhi/Simplex_tree/indexing_tag.h +27 -0
  101. multipers/gudhi/gudhi/Simplex_tree/serialization_utils.h +62 -0
  102. multipers/gudhi/gudhi/Simplex_tree/simplex_tree_options.h +157 -0
  103. multipers/gudhi/gudhi/Simplex_tree.h +2794 -0
  104. multipers/gudhi/gudhi/Simplex_tree_multi.h +152 -0
  105. multipers/gudhi/gudhi/distance_functions.h +62 -0
  106. multipers/gudhi/gudhi/graph_simplicial_complex.h +104 -0
  107. multipers/gudhi/gudhi/persistence_interval.h +253 -0
  108. multipers/gudhi/gudhi/persistence_matrix_options.h +170 -0
  109. multipers/gudhi/gudhi/reader_utils.h +367 -0
  110. multipers/gudhi/mma_interface_coh.h +256 -0
  111. multipers/gudhi/mma_interface_h0.h +223 -0
  112. multipers/gudhi/mma_interface_matrix.h +293 -0
  113. multipers/gudhi/naive_merge_tree.h +536 -0
  114. multipers/gudhi/scc_io.h +310 -0
  115. multipers/gudhi/truc.h +1403 -0
  116. multipers/io.cpython-312-darwin.so +0 -0
  117. multipers/io.pyx +644 -0
  118. multipers/ml/__init__.py +0 -0
  119. multipers/ml/accuracies.py +90 -0
  120. multipers/ml/invariants_with_persistable.py +79 -0
  121. multipers/ml/kernels.py +176 -0
  122. multipers/ml/mma.py +713 -0
  123. multipers/ml/one.py +472 -0
  124. multipers/ml/point_clouds.py +352 -0
  125. multipers/ml/signed_measures.py +1589 -0
  126. multipers/ml/sliced_wasserstein.py +461 -0
  127. multipers/ml/tools.py +113 -0
  128. multipers/mma_structures.cpython-312-darwin.so +0 -0
  129. multipers/mma_structures.pxd +128 -0
  130. multipers/mma_structures.pyx +2786 -0
  131. multipers/mma_structures.pyx.tp +1094 -0
  132. multipers/multi_parameter_rank_invariant/diff_helpers.h +84 -0
  133. multipers/multi_parameter_rank_invariant/euler_characteristic.h +97 -0
  134. multipers/multi_parameter_rank_invariant/function_rips.h +322 -0
  135. multipers/multi_parameter_rank_invariant/hilbert_function.h +769 -0
  136. multipers/multi_parameter_rank_invariant/persistence_slices.h +148 -0
  137. multipers/multi_parameter_rank_invariant/rank_invariant.h +369 -0
  138. multipers/multiparameter_edge_collapse.py +41 -0
  139. multipers/multiparameter_module_approximation/approximation.h +2330 -0
  140. multipers/multiparameter_module_approximation/combinatory.h +129 -0
  141. multipers/multiparameter_module_approximation/debug.h +107 -0
  142. multipers/multiparameter_module_approximation/euler_curves.h +0 -0
  143. multipers/multiparameter_module_approximation/format_python-cpp.h +286 -0
  144. multipers/multiparameter_module_approximation/heap_column.h +238 -0
  145. multipers/multiparameter_module_approximation/images.h +79 -0
  146. multipers/multiparameter_module_approximation/list_column.h +174 -0
  147. multipers/multiparameter_module_approximation/list_column_2.h +232 -0
  148. multipers/multiparameter_module_approximation/ru_matrix.h +347 -0
  149. multipers/multiparameter_module_approximation/set_column.h +135 -0
  150. multipers/multiparameter_module_approximation/structure_higher_dim_barcode.h +36 -0
  151. multipers/multiparameter_module_approximation/unordered_set_column.h +166 -0
  152. multipers/multiparameter_module_approximation/utilities.h +403 -0
  153. multipers/multiparameter_module_approximation/vector_column.h +223 -0
  154. multipers/multiparameter_module_approximation/vector_matrix.h +331 -0
  155. multipers/multiparameter_module_approximation/vineyards.h +464 -0
  156. multipers/multiparameter_module_approximation/vineyards_trajectories.h +649 -0
  157. multipers/multiparameter_module_approximation.cpython-312-darwin.so +0 -0
  158. multipers/multiparameter_module_approximation.pyx +235 -0
  159. multipers/pickle.py +90 -0
  160. multipers/plots.py +456 -0
  161. multipers/point_measure.cpython-312-darwin.so +0 -0
  162. multipers/point_measure.pyx +395 -0
  163. multipers/simplex_tree_multi.cpython-312-darwin.so +0 -0
  164. multipers/simplex_tree_multi.pxd +134 -0
  165. multipers/simplex_tree_multi.pyx +10840 -0
  166. multipers/simplex_tree_multi.pyx.tp +2009 -0
  167. multipers/slicer.cpython-312-darwin.so +0 -0
  168. multipers/slicer.pxd +3034 -0
  169. multipers/slicer.pxd.tp +234 -0
  170. multipers/slicer.pyx +20481 -0
  171. multipers/slicer.pyx.tp +1088 -0
  172. multipers/tensor/tensor.h +672 -0
  173. multipers/tensor.pxd +13 -0
  174. multipers/test.pyx +44 -0
  175. multipers/tests/__init__.py +62 -0
  176. multipers/torch/__init__.py +1 -0
  177. multipers/torch/diff_grids.py +240 -0
  178. multipers/torch/rips_density.py +310 -0
  179. multipers-2.3.3b6.dist-info/METADATA +128 -0
  180. multipers-2.3.3b6.dist-info/RECORD +183 -0
  181. multipers-2.3.3b6.dist-info/WHEEL +6 -0
  182. multipers-2.3.3b6.dist-info/licenses/LICENSE +21 -0
  183. multipers-2.3.3b6.dist-info/top_level.txt +1 -0
@@ -0,0 +1,649 @@
1
+ /* This file is part of the MMA Library -
2
+ * https://gitlab.inria.fr/dloiseau/multipers - which is released under MIT. See
3
+ * file LICENSE for full license details. Author(s): David Loiseaux
4
+ *
5
+ * Copyright (C) 2021 Inria
6
+ *
7
+ * Modification(s):
8
+ * - 2022/03 Hannah Schreiber: Integration of the new Vineyard_persistence
9
+ * class, renaming and cleanup.
10
+ * - 2022/05 Hannah Schreiber: Addition of Box class.
11
+ */
12
+ /**
13
+ * @file vineyards_trajectories.h
14
+ * @author David Loiseaux, Hannah Schreiber
15
+ * @brief This file contains the functions related to trajectories of barcodes
16
+ * via vineyards.
17
+ */
18
+
19
+ #ifndef VINEYARDS_TRAJECTORIES_H_INCLUDED
20
+ #define VINEYARDS_TRAJECTORIES_H_INCLUDED
21
+
22
+ #include <iostream>
23
+ #include <vector>
24
+ // #include <iomanip>
25
+ #include <cassert>
26
+ #include <cmath>
27
+ #include <limits>
28
+ // #include "gudhi/Simplex_tree.h"
29
+
30
+ #include "format_python-cpp.h"
31
+ #include "structure_higher_dim_barcode.h"
32
+ #include "vineyards.h"
33
+ // #include "combinatory.h"
34
+ #include "debug.h"
35
+
36
+ #include "ru_matrix.h"
37
+ #include "utilities.h"
38
+ /*#include "heap_column.h"*/
39
+ /*#include "list_column.h"*/
40
+ // #include "list_column_2.h"
41
+ /*#include "vector_column.h"*/
42
+ /*#include "set_column.h"*/
43
+ /*#include "unordered_set_column.h"*/
44
+ #include <gudhi/Multi_persistence/Box.h>
45
+
46
+ namespace Gudhi::multiparameter::mma {
47
+
48
+ using Gudhi::multi_persistence::Box;
49
+ std::vector<std::vector<std::vector<interval_type>>>
50
+ compute_vineyard_barcode(boundary_matrix &boundaryMatrix,
51
+ const std::vector<filtration_type> &filtersList,
52
+ value_type precision, Box<value_type> &box,
53
+ bool threshold = false, bool multithread = false,
54
+ const bool verbose = false);
55
+
56
+ std::vector<std::vector<interval_type>> compute_vineyard_barcode_in_dimension(
57
+ boundary_matrix &boundaryMatrix,
58
+ const std::vector<filtration_type> &filtersList, value_type precision,
59
+ Box<value_type> &box, dimension_type dimension, bool threshold = false,
60
+ const bool verbose = false);
61
+
62
+ void compute_vineyard_barcode_recursively(
63
+ std::vector<std::vector<std::vector<interval_type>>> &output,
64
+ Vineyard_persistence<Vineyard_matrix_type> &persistence,
65
+ const boundary_matrix &boundaryMatrix, point_type &basepoint,
66
+ std::vector<unsigned int> &position, unsigned int last,
67
+ filtration_type &filter, const std::vector<filtration_type> &filtersList,
68
+ const value_type precision, const Box<value_type> &box,
69
+ const std::vector<unsigned int> &size, bool first = false,
70
+ bool threshold = false, bool multithread = false);
71
+
72
+ void compute_vineyard_barcode_recursively_in_higher_dimension(
73
+ std::vector<std::vector<std::vector<interval_type>>> &output,
74
+ Vineyard_persistence<Vineyard_matrix_type> &persistence,
75
+ const boundary_matrix &boundaryMatrix, const point_type &basepoint,
76
+ const std::vector<unsigned int> &position, unsigned int last,
77
+ filtration_type &filter, const std::vector<filtration_type> &filtersList,
78
+ const value_type precision, const Box<value_type> &box,
79
+ const std::vector<unsigned int> &size, bool threshold = false,
80
+ bool multithread = false);
81
+
82
+ void get_filter_from_line(const point_type &lineBasepoint,
83
+ const std::vector<filtration_type> &filterList,
84
+ filtration_type &newFilter,
85
+ const Box<value_type> &box, bool ignoreLast = false);
86
+
87
+ void threshold_up(point_type &point, const Box<value_type> &box,
88
+ const point_type &basepoint = point_type(1, negInf));
89
+
90
+ void threshold_down(point_type &point, const Box<value_type> &box,
91
+ const point_type &basepoint = point_type(1, negInf));
92
+ // template<typename T>
93
+ // bool is_smaller(const std::vector<T>& x, const std::vector<T>& y);
94
+ // template<typename T>
95
+ // bool is_greater(const std::vector<T>& x, const std::vector<T>& y);
96
+ // boundary_matrix simplex_tree_to_boundary_matrix(Gudhi::Simplex_tree<>
97
+ // &simplexfiltration_value_typeree);
98
+
99
+ // filtration_value_typeODO improve multithread
100
+ // Main function of vineyard computation. It computes the fibered barcodes of
101
+ // any multipersistence module, with exact matching.
102
+ // Input :
103
+ // B : sparse boundary matrix which is the converted
104
+ //simplextree by
105
+ // functions of format_python_cpp
106
+ // filters_list : [[filtration of dimension i for simplex s
107
+ // for s] for i]
108
+ // is the list of filters of each simplex of each filtration
109
+ // dimension
110
+ // precision : size of the line grid (ie. distance between
111
+ // 2 lines) box : [min, max] where min and max are points of R^n, and n is the
112
+ // dimension of the filter list.
113
+ // All of the bars along a line crossing this box
114
+ // will be computed threshold : If set to true, will intersect the bars with the
115
+ // box.
116
+ // Useful for plots / images
117
+ // multithread : if set to true, will compute the
118
+ // trajectories in parallel. filtration_value_typehis is a WIP; as this imply
119
+ // more memory operations, this is
120
+ // rarely significantly faster than the other implementation.
121
+ // OUTPUT :
122
+ // [[[(birth,death) for line] for summand] for dimension]
123
+ /**
124
+ * @brief Main function of vineyard computation. It computes the fibered
125
+ * barcodes of any multipersistence module, with exact matching.
126
+ *
127
+ * @param B Sparse boundary matrix of a chain complex
128
+ * @param filters_list associated filtration of @p B Format :
129
+ * [[filtration of dimension i for simplex s for s] for i]
130
+ * @param precision precision of the line grid ie. distance between two lines
131
+ * @param box [min, max] where min and max are points of \f$ \mathbb R^n \f$,
132
+ * and n is the dimension of the filter list.
133
+ * All of the bars along a line crossing this box will be computed
134
+ * @param threshold if set to true, will threshold the barcodes with the box
135
+ * @param multithread if set to true, will turn on the multithread flags of the
136
+ * code (WIP)
137
+ * @return vector<vector<vector<interval>>> List of barcodes along the lines
138
+ * intersecting the box. Format : [[[(birth,death) for line] for summand] for
139
+ * dimension]
140
+ */
141
+ // Assumes matrix ordered by dimensions
142
+
143
+ std::vector<std::vector<std::vector<interval_type>>>
144
+ compute_vineyard_barcode(boundary_matrix &boundaryMatrix,
145
+ const std::vector<filtration_type> &filtersList,
146
+ value_type precision, Box<value_type> &box,
147
+ bool threshold, bool multithread, bool verbose) {
148
+ Gudhi::multiparameter::mma::verbose = verbose;
149
+ // Checks if dimensions are compatibles
150
+ assert(!filtersList.empty() && "A non trivial filters list is needed !");
151
+ assert(filtersList.size() == box.get_lower_corner().size() &&
152
+ filtersList.size() == box.get_upper_corner().size() &&
153
+ "Filtration and box must be of the same dimension");
154
+ if constexpr (Debug::debug) {
155
+ for (unsigned int i = 1; i < boundaryMatrix.size(); i++)
156
+ assert(boundaryMatrix.at(i - 1).size() <= boundaryMatrix.at(i).size() &&
157
+ "Boundary matrix has to be sorted by dimension!");
158
+ }
159
+
160
+ const unsigned int filtrationDimension = filtersList.size();
161
+ if (verbose)
162
+ std::cout << "Filtration dimension : " << filtrationDimension << std::flush
163
+ << std::endl;
164
+
165
+ unsigned int numberSimplices = boundaryMatrix.size();
166
+ if (verbose)
167
+ std::cout << "Number of simplices : " << numberSimplices << std::endl;
168
+
169
+ filtration_type filter(numberSimplices); // container of filters
170
+
171
+ std::vector<unsigned int> sizeLine(filtrationDimension - 1);
172
+ for (unsigned int i = 0; i < filtrationDimension - 1; i++)
173
+ sizeLine[i] = static_cast<unsigned int>(std::ceil(
174
+ std::abs(box.get_upper_corner()[i] - box.get_lower_corner().back() -
175
+ box.get_lower_corner()[i] + box.get_upper_corner().back()) /
176
+ precision));
177
+
178
+ unsigned int numberOfLines = Combinatorics::prod(sizeLine);
179
+ if (verbose)
180
+ std::cout << "Precision : " << precision << std::endl;
181
+ if (verbose)
182
+ std::cout << "Number of lines : " << numberOfLines << std::endl;
183
+
184
+ auto basePoint = box.get_lower_corner();
185
+ for (unsigned int i = 0; i < basePoint.size() - 1; i++)
186
+ basePoint[i] -= box.get_upper_corner().back();
187
+ basePoint.back() = 0;
188
+
189
+ get_filter_from_line(basePoint, filtersList, filter, box, true);
190
+ // where is the cursor in the output matrix
191
+ std::vector<unsigned int> position(filtrationDimension - 1, 0);
192
+
193
+ if (filtersList[0].size() < numberSimplices) {
194
+ filtration_type tmp = filter;
195
+ Filtration_creator::get_lower_star_filtration(boundaryMatrix, tmp, filter);
196
+ }
197
+
198
+ Vineyard_persistence<Vineyard_matrix_type> persistence(boundaryMatrix, filter,
199
+ verbose);
200
+ persistence.initialize_barcode();
201
+ auto &firstBarcode = persistence.get_diagram();
202
+
203
+ // filtered by dimension so last one is of maximal dimension
204
+ unsigned int maxDimension = firstBarcode.back().dim;
205
+ std::vector<std::vector<std::vector<interval_type>>> output(maxDimension + 1);
206
+
207
+ std::vector<unsigned int> numberOfFeaturesByDimension(maxDimension + 1);
208
+ for (unsigned int i = 0; i < firstBarcode.size(); i++) {
209
+ numberOfFeaturesByDimension[firstBarcode[i].dim]++;
210
+ }
211
+
212
+ for (unsigned int i = 0; i < maxDimension + 1; i++) {
213
+ output[i] = std::vector<std::vector<interval_type>>(
214
+ numberOfFeaturesByDimension[i],
215
+ std::vector<interval_type>(numberOfLines));
216
+ }
217
+
218
+ auto elapsed = clock();
219
+ if (verbose)
220
+ std::cout << "Multithreading status : " << multithread << std::endl;
221
+ if (verbose)
222
+ std::cout << "Starting recursive vineyard loop..." << std::flush;
223
+
224
+ compute_vineyard_barcode_recursively(
225
+ output, persistence, boundaryMatrix, basePoint, position, 0, filter,
226
+ filtersList, precision, box, sizeLine, true, threshold, multithread);
227
+
228
+ elapsed = clock() - elapsed;
229
+ if (verbose)
230
+ std::cout << " Done ! It took "
231
+ << (static_cast<float>(elapsed) / CLOCKS_PER_SEC) << " seconds."
232
+ << std::endl;
233
+ return output;
234
+ }
235
+
236
+ // Same as vineyard_alt but only returns one dimension
237
+ // TODO : reduce computation by only computing this dimension instead of all of
238
+ // them
239
+ /**
240
+ * @brief Returns only one dimension of the \ref vineyard_alt code.
241
+ *
242
+ * @param B
243
+ * @param filters_list
244
+ * @param precision
245
+ * @param box
246
+ * @param dimension
247
+ * @param threshold
248
+ * @param verbose
249
+ * @param debug
250
+ * @return vector<vector<interval>>
251
+ */
252
+
253
+ std::vector<std::vector<interval_type>> compute_vineyard_barcode_in_dimension(
254
+ boundary_matrix &boundaryMatrix,
255
+ const std::vector<filtration_type> &filtersList, value_type precision,
256
+ Box<value_type> &box, dimension_type dimension, bool threshold,
257
+ const bool verbose) {
258
+ return compute_vineyard_barcode(boundaryMatrix, filtersList, precision, box,
259
+ threshold, false, verbose)[dimension];
260
+ }
261
+
262
+ // This is the core compute function of vineyard_alt.
263
+ // It updates and store in `output` the barcodes of a line, and calls itself
264
+ // on the next line until reaching the borders of the box
265
+ // INPUT :
266
+ // output : Where to store the barcodes.
267
+ // persistence : holding previous barcode information.
268
+ // basepoint : basepoint of the current line on the
269
+ // hyperplane {x_n=0}. position : index pointer of where to fill the output.
270
+ // last : which dimensions needs to be increased on this
271
+ // trajectory
272
+ // (for recursive trajectories).
273
+ // filter : container for filer of simplices.
274
+ // filters_list : holding the filtration value of each
275
+ // simplices.
276
+ // Format : [[filtration of simplex s in the kth filtration for s]
277
+ // for k].
278
+ // precision : line grid scale (ie. distance between two
279
+ // consecutive lines). box : [min, max] where min and max are points of R^n, and
280
+ // n is the
281
+ // dimension of the filter list.
282
+ // All of the bars along a line crossing this box
283
+ // will be computed. size : size of the output matrix. first : true if it is the
284
+ // first barcode. In that case we don't need
285
+ // to call a vineyard update.
286
+ // threshold : if true, intersects bars with the box.
287
+ // multithread : if set to true, will compute the
288
+ // trajectories in parallel. This is a WIP; as this imply more memory
289
+ // operations, this is
290
+ // rarely significantly faster than the other implementation.
291
+ /**
292
+ * @brief Recursive version of \ref vineyard_alt.
293
+ *
294
+ * @param output
295
+ * @param persistence
296
+ * @param basepoint
297
+ * @param position
298
+ * @param last
299
+ * @param filter
300
+ * @param filters_list
301
+ * @param precision
302
+ * @param box
303
+ * @param size
304
+ * @param first
305
+ * @param threshold
306
+ * @param multithread
307
+ */
308
+
309
+ void compute_vineyard_barcode_recursively(
310
+ std::vector<std::vector<std::vector<interval_type>>> &output,
311
+ Vineyard_persistence<Vineyard_matrix_type> &persistence,
312
+ const boundary_matrix &boundaryMatrix, point_type &basepoint,
313
+ std::vector<unsigned int> &position, unsigned int last,
314
+ filtration_type &filter, const std::vector<filtration_type> &filtersList,
315
+ const value_type precision, const Box<value_type> &box,
316
+ const std::vector<unsigned int> &size, bool first, bool threshold,
317
+ bool multithread) {
318
+ if (!first) {
319
+ get_filter_from_line(basepoint, filtersList, filter, box, true);
320
+ if (filtersList[0].size() < boundaryMatrix.size()) {
321
+ filtration_type tmp = filter;
322
+ Filtration_creator::get_lower_star_filtration(boundaryMatrix, tmp,
323
+ filter);
324
+ }
325
+ }
326
+
327
+ // if (verbose && Debug::debug) Debug::disp_vect(basepoint);
328
+
329
+ persistence.update(filter); // Updates the RU decomposition of persistence.
330
+ // Computes the diagram from the RU decomposition
331
+ const diagram_type &dgm = persistence.get_diagram();
332
+
333
+ // Fills the barcode of the line having the basepoint basepoint
334
+ unsigned int feature = 0;
335
+ int oldDim = 0;
336
+
337
+ // %TODO parallelize this loop, last part is not compatible yet
338
+ for (unsigned int i = 0; i < dgm.size(); i++) {
339
+ dimension_type dim = dgm[i].dim;
340
+ value_type baseBirth = dgm[i].birth;
341
+ value_type baseDeath = dgm[i].death;
342
+
343
+ unsigned int index = get_index_from_position_and_size(position, size);
344
+ point_type &birth = output[dim][feature][index].first;
345
+ point_type &death = output[dim][feature][index].second;
346
+
347
+ // If the bar is trivial, we skip it
348
+ if (baseBirth != inf && baseBirth != baseDeath) {
349
+ birth.resize(filtersList.size());
350
+ death.resize(filtersList.size());
351
+
352
+ // computes birth and death point from the bar and the basepoint of the
353
+ // line
354
+ for (unsigned int j = 0; j < filtersList.size() - 1; j++) {
355
+ birth[j] = basepoint[j] + baseBirth;
356
+ death[j] = basepoint[j] + baseDeath;
357
+ }
358
+ birth.back() = baseBirth;
359
+ death.back() = baseDeath;
360
+
361
+ // Threshold birth and death if threshold is set to true
362
+ if (threshold && birth.back() != inf) {
363
+ threshold_down(birth, box, basepoint);
364
+ threshold_up(death, box, basepoint);
365
+ }
366
+
367
+ // if (verbose) {
368
+ // std::cout << birth.back() << " " << death.back();
369
+ // if (threshold) std::cout << ", threshold" << std::endl;
370
+ // else std::cout << ", no threshold" << std::endl;
371
+ // }
372
+
373
+ // If this threshold has turned this bar to a trivial bar, we skip it
374
+ if (birth.back() >= death.back()) {
375
+ birth.clear();
376
+ death.clear();
377
+ }
378
+ }
379
+
380
+ // If next bar is of upper dimension, or we reached the end, then we
381
+ // update the pointer index of where to fill the next bar in output.
382
+ if (i + 1 < dgm.size() && oldDim < dgm[i + 1].dim) {
383
+ oldDim = dgm[i + 1].dim;
384
+ feature = 0;
385
+ } else
386
+ feature++;
387
+
388
+ // if (verbose)
389
+ // std::cout <<"Feature : " << feature << " dim : " << oldDim <<
390
+ // std::endl;
391
+ }
392
+
393
+ // recursive calls of bigger dims, minus current dim (to make less copies)
394
+ compute_vineyard_barcode_recursively_in_higher_dimension(
395
+ output, persistence, boundaryMatrix, basepoint, position, last, filter,
396
+ filtersList, precision, box, size, threshold, multithread);
397
+
398
+ // We keep -last- on the same thread / memory as the previous call
399
+ // we reached a border and finished this path
400
+ if (size[last] - 1 == position[last])
401
+ return;
402
+
403
+ // If we didn't reached the end, go to the next line
404
+ basepoint[last] += precision;
405
+ position[last]++;
406
+ compute_vineyard_barcode_recursively(
407
+ output, persistence, boundaryMatrix, basepoint, position, last, filter,
408
+ filtersList, precision, box, size, false, threshold, multithread);
409
+ }
410
+
411
+ // For persistence dimension higher than 3, this function will be called for
412
+ // Tree-like recursion of vineyard_alt.
413
+ /**
414
+ * @brief Subfonction of \ref vinyard_alt_recursive to handle dimensions
415
+ * greater than 3.
416
+ *
417
+ * @param output
418
+ * @param persistence
419
+ * @param basepoint
420
+ * @param position
421
+ * @param last
422
+ * @param filter
423
+ * @param filters_list
424
+ * @param precision
425
+ * @param box
426
+ * @param size
427
+ * @param threshold
428
+ * @param multithread
429
+ */
430
+
431
+ void compute_vineyard_barcode_recursively_in_higher_dimension(
432
+ std::vector<std::vector<std::vector<interval_type>>> &output,
433
+ Vineyard_persistence<Vineyard_matrix_type> &persistence,
434
+ const boundary_matrix &boundaryMatrix, const point_type &basepoint,
435
+ const std::vector<unsigned int> &position, unsigned int last,
436
+ filtration_type &filter, const std::vector<filtration_type> &filtersList,
437
+ const value_type precision, const Box<value_type> &box,
438
+ const std::vector<unsigned int> &size, bool threshold, bool multithread) {
439
+ if (filtersList.size() > 1 && last + 2 < filtersList.size()) {
440
+ // if (verbose && Debug::debug) Debug::disp_vect(basepoint);
441
+ // if (verbose) std::cout << multithread << std::endl;
442
+
443
+ if (multithread) {
444
+ /* #pragma omp parallel for */
445
+ for (unsigned int i = last + 1; i < filtersList.size() - 1; i++) {
446
+ if (size[i] - 1 == position[i])
447
+ continue;
448
+ // TODO check if it get deleted at each loop !! WARNING
449
+ auto copyPersistence = persistence;
450
+ auto copyBasepoint = basepoint;
451
+ auto copyPosition = position;
452
+ copyBasepoint[i] += precision;
453
+ copyPosition[i]++;
454
+ compute_vineyard_barcode_recursively(
455
+ output, copyPersistence, boundaryMatrix, copyBasepoint,
456
+ copyPosition, i, filter, filtersList, precision, box, size, false,
457
+ threshold, multithread);
458
+ }
459
+ } else {
460
+ // No need to copy when not multithreaded.
461
+ // Memory operations are slower than vineyard.
462
+ // %TODO improve trajectory of vineyard
463
+ auto copyPersistence = persistence;
464
+ auto copyBasepoint = basepoint;
465
+ auto copyPosition = position;
466
+ for (unsigned int i = last + 1; i < filtersList.size() - 1; i++) {
467
+ if (size[i] - 1 == position[i])
468
+ continue;
469
+ copyPersistence = persistence;
470
+ copyBasepoint = basepoint;
471
+ copyPosition = position;
472
+ copyBasepoint[i] += precision;
473
+ copyPosition[i]++;
474
+ compute_vineyard_barcode_recursively(
475
+ output, copyPersistence, boundaryMatrix, copyBasepoint,
476
+ copyPosition, i, filter, filtersList, precision, box, size, false,
477
+ threshold, multithread);
478
+ }
479
+ }
480
+ }
481
+ }
482
+
483
+ // INPUT :
484
+ // a slope 1 line is characterized by its intersection with {x_n=0} named
485
+ // line_basepoint.
486
+ // filter_list is : for each coordinate i, and simplex j filter_list[i,j]
487
+ //is
488
+ // the filtration value of simplex j on line induced by [0,e_i]
489
+ // OUTPUT:
490
+ // filtration value of simplex j on the line.
491
+ /**
492
+ * @brief Writes the filters of each simplex on new_filter along the a slope 1
493
+ * line.
494
+ *
495
+ * @param line_basepoint Basepoint of a slope 1 line in \f$\mathbb R^n\f$
496
+ * @param filter_list Multi-filtration of simplices. Format :
497
+ * [[filtration_value for simplex] for dimension]
498
+ * @param new_filter Container of the output.
499
+ * @param ignore_last Ignore this parameter. It is meant for compatibility
500
+ * with old functions.
501
+ */
502
+
503
+ void get_filter_from_line(const point_type &lineBasepoint,
504
+ const std::vector<filtration_type> &filterList,
505
+ filtration_type &newFilter,
506
+ const Box<value_type> &box, bool ignoreLast) {
507
+ // if (verbose && Debug::debug) {
508
+ // Debug::disp_vect(lineBasepoint);
509
+ // }
510
+
511
+ unsigned int dimension = lineBasepoint.size() + 1 - ignoreLast;
512
+
513
+ // value_type minLength = box.get_lower_corner().back();
514
+ // value_type maxLength = box.get_upper_corner().back();
515
+ // // #pragma omp parallel for reduction(max : minLength)
516
+ // for (unsigned int i = 0; i<dimension-1; i++){
517
+ // minLength = std::max(minLength, box.get_lower_corner()[i] -
518
+ // lineBasepoint[i]);
519
+ // }
520
+ // // #pragma omp parallel for reduction(min : maxLength)
521
+ // for (unsigned int i = 0; i<dimension-1; i++){
522
+ // maxLength = std::min(maxLength, box.get_upper_corner()[i] -
523
+ // lineBasepoint[i]);
524
+ // }
525
+
526
+ filtration_type relativeFiltrationValues(dimension);
527
+ for (unsigned int i = 0; i < filterList[0].size(); i++) {
528
+ for (unsigned int j = 0; j < dimension - 1; j++) {
529
+ relativeFiltrationValues[j] = filterList[j][i] - lineBasepoint[j];
530
+ }
531
+ relativeFiltrationValues[dimension - 1] = filterList[dimension - 1][i];
532
+ value_type length = *max_element(relativeFiltrationValues.begin(),
533
+ relativeFiltrationValues.end());
534
+
535
+ // newFilter[i] = std::min(std::max(length,minLength), maxLength);
536
+ newFilter[i] = length;
537
+ }
538
+
539
+ // if (verbose && Debug::debug) {
540
+ // Debug::disp_vect(newFilter);
541
+ // }
542
+ }
543
+
544
+ /**
545
+ * @brief Threshold a point to the negative cone of d=box.second
546
+ * (ie. the set \f$\{x \in \mathbb R^n \mid x \le d\} \f$)
547
+ * along the slope 1 line crossing this point.
548
+ *
549
+ * @param point The point to threshold.
550
+ * @param box box.second is the point defining where to threshold.
551
+ * @param basepoint Basepoint of the slope 1 line crossing the point.
552
+ * Meant to handle infinite cases (when the point have infinite coordinates,
553
+ * we cannot infer the line).
554
+ */
555
+
556
+ void threshold_up(point_type &point, const Box<value_type> &box,
557
+ const point_type &basepoint) {
558
+ Gudhi::multi_filtration::One_critical_filtration
559
+ point_(point);
560
+ // if (is_smaller(point, box.get_upper_corner())) return;
561
+ if (point_ <= box.get_upper_corner())
562
+ return;
563
+
564
+ // if (verbose && Debug::debug) Debug::disp_vect(point);
565
+
566
+ if (basepoint[0] == negInf)
567
+ return;
568
+
569
+ // ie. point at infinity, assumes [basepoint,0] is smaller than box.second
570
+ if (point.back() == inf) {
571
+ // if (verbose) std::cout << " Infinite point" << std::endl;
572
+
573
+ value_type threshold = box.get_upper_corner().back();
574
+ for (unsigned int i = 0; i < point.size(); i++) {
575
+ threshold = std::min(threshold, box.get_upper_corner()[i] - basepoint[i]);
576
+ }
577
+ for (unsigned int i = 0; i < point.size() - 1; i++)
578
+ point[i] = basepoint[i] + threshold;
579
+ point.back() = threshold;
580
+
581
+ return;
582
+ }
583
+
584
+ // if (!is_greater(point, box.get_lower_corner())) {
585
+ if (box.get_lower_corner() <= point_) {
586
+ point[0] = inf; // puts point to infinity
587
+ // if (verbose) std::cout << "buggy point" << std::endl;
588
+ return;
589
+ }
590
+ // in this last case, at least 1 coord of point is is_greater than a coord of
591
+ // box.second
592
+
593
+ value_type threshold = point[0] - box.get_upper_corner()[0];
594
+ for (std::size_t i = 1; i < point.size(); i++) {
595
+ threshold = std::max(threshold, point[i] - box.get_upper_corner()[i]);
596
+ }
597
+
598
+ // if (verbose)
599
+ // std::cout << "Thresholding the point with "<< threshold << " at
600
+ // ";
601
+
602
+ for (std::size_t i = 0; i < point.size(); i++)
603
+ point[i] -= threshold;
604
+
605
+ // if (verbose && Debug::debug) Debug::disp_vect(point);
606
+ }
607
+
608
+ /**
609
+ * @brief Threshold a point to the positive cone of b=box.first
610
+ * (ie. the set \f$\{x \in \mathbb R^n \mid x \ge b\})
611
+ * along the slope 1 line crossing this point.
612
+ *
613
+ * @param point The point to threshold.
614
+ * @param box box.fist is the point defining where to threshold.
615
+ * @param basepoint Basepoint of the slope 1 line crossing the point.
616
+ * Meant to handle infinite cases (when the point have infinite coordinates,
617
+ * we cannot infer the line).
618
+ */
619
+
620
+ void threshold_down(point_type &point, const Box<value_type> &box,
621
+ const point_type &basepoint) {
622
+ if (basepoint[0] == negInf)
623
+ return;
624
+
625
+ if (point.back() == inf) { // ie. point at infinity -> feature never appearing
626
+ return;
627
+ }
628
+
629
+ // if (is_greater(point, box.get_lower_corner())) return;
630
+ if (point >= box.get_lower_corner())
631
+ return;
632
+
633
+ // if (!is_smaller(point, box.get_upper_corner())) {
634
+ if (!(point <= box.get_upper_corner())) {
635
+ point[0] = inf; // puts point to infinity
636
+ return;
637
+ }
638
+
639
+ value_type threshold = box.get_lower_corner()[0] - point[0];
640
+ for (unsigned int i = 1; i < point.size(); i++) {
641
+ threshold = std::max(threshold, box.get_lower_corner()[i] - point[i]);
642
+ }
643
+ for (unsigned int i = 0; i < point.size(); i++)
644
+ point[i] += threshold;
645
+ }
646
+
647
+ } // namespace Gudhi::multiparameter::mma
648
+
649
+ #endif // VINEYARDS_TRAJECTORIES_H_INCLUDED