multipers 2.3.3b6__cp312-cp312-macosx_10_13_x86_64.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,152 @@
1
+ /* This file is part of the Gudhi Library - https://gudhi.inria.fr/ - which
2
+ * is released under MIT. See file LICENSE or go to
3
+ * https://gudhi.inria.fr/licensing/ for full license details. Author(s): David
4
+ * Loiseaux, Hannah Schreiber
5
+ *
6
+ * Copyright (C) 2023 Inria
7
+ *
8
+ * Modification(s):
9
+ * - YYYY/MM Author: Description of the modification
10
+ */
11
+ #ifndef SIMPLEX_TREE_MULTI_H_
12
+ #define SIMPLEX_TREE_MULTI_H_
13
+
14
+ #include <algorithm>
15
+ #include <cstdint>
16
+ #include <vector>
17
+ #include <gudhi/Simplex_tree.h>
18
+
19
+ namespace Gudhi {
20
+ namespace multi_persistence {
21
+
22
+ /** Model of SimplexTreeOptions, with a multiparameter filtration.
23
+ * \ingroup multi_persistence
24
+ * */
25
+ template <typename Filtration>
26
+ struct Simplex_tree_options_multidimensional_filtration {
27
+ public:
28
+ typedef linear_indexing_tag Indexing_tag;
29
+ typedef int Vertex_handle;
30
+ using Filtration_value = Filtration;
31
+ typedef typename Filtration::value_type value_type;
32
+ typedef std::uint32_t Simplex_key;
33
+ static const bool store_key = true;
34
+ static const bool store_filtration = true;
35
+ static const bool contiguous_vertices = false;
36
+ static const bool link_nodes_by_label = false;
37
+ static const bool stable_simplex_handles = false;
38
+ static const bool is_multi_parameter = true;
39
+ };
40
+
41
+ /**
42
+ * \brief Turns a 1-parameter simplextree into a multiparameter simplextree,
43
+ * and keeps the 1-filtration in the 1st axis.
44
+ * Default values can be specified.
45
+ * \ingroup multi_persistence
46
+ * \tparam simplextree_std A non-multi simplextree
47
+ * \tparam simplextree_multi A multi simplextree
48
+ * \param st Simplextree to copy
49
+ * \param st_multi Multiparameter simplextree container to fill.
50
+ * \param default_values If given, this vector is assume to be of size `num_parameters-1` and contains the default
51
+ * values of axes `1` to `num_parameters`.
52
+ * */
53
+ template <class simplextree_std, class simplextree_multi>
54
+ void multify(simplextree_std &st,
55
+ simplextree_multi &st_multi,
56
+ const int num_parameters,
57
+ const typename simplextree_multi::Options::Filtration_value &default_values = {}) {
58
+ typename simplextree_multi::Options::Filtration_value f(num_parameters);
59
+ static_assert(!simplextree_std::Options::is_multi_parameter && simplextree_multi::Options::is_multi_parameter,
60
+ "Can only convert non-multiparameter to multiparameter simplextree.");
61
+ unsigned int num_default_values = 0;
62
+ if constexpr (simplextree_multi::Options::Filtration_value::is_multi_critical) {
63
+ num_default_values = default_values[0].size();
64
+ } else {
65
+ num_default_values = default_values.size();
66
+ }
67
+ for (auto i = 0u;
68
+ i < std::min(num_default_values, num_parameters < 1 ? 0u : static_cast<unsigned int>(num_parameters - 1));
69
+ i++) {
70
+ if constexpr (simplextree_multi::Options::Filtration_value::is_multi_critical) {
71
+ f[0][i + 1] = default_values[0][i];
72
+ } else {
73
+ f[i + 1] = default_values[i];
74
+ }
75
+ }
76
+
77
+ std::vector<int> simplex;
78
+ simplex.reserve(st.dimension() + 1);
79
+ for (auto &simplex_handle : st.complex_simplex_range()) {
80
+ simplex.clear();
81
+ for (auto vertex : st.simplex_vertex_range(simplex_handle)) simplex.push_back(vertex);
82
+
83
+ if (num_parameters > 0) {
84
+ if constexpr (simplextree_multi::Options::Filtration_value::is_multi_critical) {
85
+ f[0][0] = st.filtration(simplex_handle);
86
+ } else {
87
+ f[0] = st.filtration(simplex_handle);
88
+ }
89
+ }
90
+ st_multi.insert_simplex(simplex, f);
91
+ }
92
+ st_multi.set_number_of_parameters(num_parameters);
93
+ }
94
+
95
+ /**
96
+ * \brief Turns a multiparameter-parameter simplextree into a 1-parameter
97
+ * simplextree.
98
+ * \ingroup multi_persistence
99
+ * \tparam simplextree_std A non-multi simplextree
100
+ * \tparam simplextree_multi A multi simplextree
101
+ * \param st Simplextree to fill.
102
+ * \param st_multi Multiparameter simplextree to convert into a 1 parameter simplex tree.
103
+ * \param dimension The filtration parameter to put into the 1 parameter simplextree.
104
+ * */
105
+ template <class simplextree_std, class simplextree_multi>
106
+ void flatten(simplextree_std &st, simplextree_multi &st_multi, const int dimension = 0) {
107
+ static_assert(!simplextree_std::Options::is_multi_parameter && simplextree_multi::Options::is_multi_parameter,
108
+ "Can only convert multiparameter to non-multiparameter simplextree.");
109
+ for (const auto &simplex_handle : st_multi.complex_simplex_range()) {
110
+ std::vector<int> simplex;
111
+ typename simplextree_multi::Options::value_type f;
112
+ for (auto vertex : st_multi.simplex_vertex_range(simplex_handle)) simplex.push_back(vertex);
113
+ if constexpr (simplextree_multi::Filtration_value::is_multi_critical) {
114
+ f = dimension >= 0 ? st_multi.filtration(simplex_handle)[0][dimension] : 0;
115
+ } else {
116
+ f = dimension >= 0 ? st_multi.filtration(simplex_handle)[dimension] : 0;
117
+ }
118
+ st.insert_simplex(simplex, f);
119
+ }
120
+ }
121
+
122
+ // TODO: following not in the planned version in Gudhi. So either remove from here, or add there.
123
+
124
+ /**
125
+ * \brief Applies a linear form (given by a scalar product, via Riesz
126
+ * representation) to the filtration values of the multiparameter simplextree to
127
+ * get a 1 parameter simplextree. \ingroup multiparameter \tparam
128
+ * simplextree_std A non-multi simplextree \tparam simplextree_multi A multi
129
+ * simplextree \param st Simplextree, with the same simplicial complex as
130
+ * st_multi, whose filtration has to be filled. \param st_multi Multiparameter
131
+ * simplextree to convert into a 1 parameter simplex tree. \param linear_form
132
+ * the linear form to apply.
133
+ * */
134
+ template <class simplextree_std, class simplextree_multi>
135
+ void linear_projection(simplextree_std &st, simplextree_multi &st_multi, const std::vector<double> &linear_form) {
136
+ static_assert(!simplextree_std::Options::is_multi_parameter && simplextree_multi::Options::is_multi_parameter,
137
+ "Can only convert multiparameter to non-multiparameter simplextree.");
138
+ auto sh = st.complex_simplex_range().begin();
139
+ auto sh_multi = st_multi.complex_simplex_range().begin();
140
+ auto end = st.complex_simplex_range().end();
141
+ typename simplextree_multi::Options::Filtration_value multi_filtration;
142
+ for (; sh != end; ++sh, ++sh_multi) {
143
+ multi_filtration = st_multi.filtration(*sh_multi);
144
+ auto projected_filtration = compute_linear_projection(multi_filtration, linear_form);
145
+ st.assign_filtration(*sh, projected_filtration);
146
+ }
147
+ }
148
+
149
+ } // namespace multi_persistence
150
+ } // namespace Gudhi
151
+
152
+ #endif // SIMPLEX_TREE_MULTI_H_
@@ -0,0 +1,62 @@
1
+ /* This file is part of the Gudhi Library - https://gudhi.inria.fr/ - which is released under MIT.
2
+ * See file LICENSE or go to https://gudhi.inria.fr/licensing/ for full license details.
3
+ * Author(s): Clément Maria
4
+ *
5
+ * Copyright (C) 2014 Inria
6
+ *
7
+ * Modification(s):
8
+ * - YYYY/MM Author: Description of the modification
9
+ */
10
+
11
+ #ifndef DISTANCE_FUNCTIONS_H_
12
+ #define DISTANCE_FUNCTIONS_H_
13
+
14
+ #include <gudhi/Debug_utils.h>
15
+
16
+ #include <boost/range/metafunctions.hpp>
17
+ #include <boost/range/size.hpp>
18
+
19
+ #include <cmath> // for std::sqrt
20
+ #include <type_traits> // for std::decay
21
+ #include <iterator> // for std::begin, std::end
22
+ #include <utility>
23
+
24
+ namespace Gudhi {
25
+
26
+ /** @file
27
+ * @brief Global distance functions
28
+ */
29
+
30
+ /** @brief Compute the Euclidean distance between two Points given by a range of coordinates. The points are assumed to
31
+ * have the same dimension. */
32
+ class Euclidean_distance {
33
+ public:
34
+ // boost::range_value is not SFINAE-friendly so we cannot use it in the return type
35
+ template< typename Point >
36
+ typename std::iterator_traits<typename boost::range_iterator<Point>::type>::value_type
37
+ operator()(const Point& p1, const Point& p2) const {
38
+ auto it1 = std::begin(p1);
39
+ auto it2 = std::begin(p2);
40
+ typedef typename boost::range_value<Point>::type NT;
41
+ NT dist = 0;
42
+ for (; it1 != std::end(p1); ++it1, ++it2) {
43
+ GUDHI_CHECK(it2 != std::end(p2), "inconsistent point dimensions");
44
+ NT tmp = *it1 - *it2;
45
+ dist += tmp*tmp;
46
+ }
47
+ GUDHI_CHECK(it2 == std::end(p2), "inconsistent point dimensions");
48
+ using std::sqrt;
49
+ return sqrt(dist);
50
+ }
51
+ template< typename T >
52
+ T operator() (const std::pair< T, T >& f, const std::pair< T, T >& s) const {
53
+ T dx = f.first - s.first;
54
+ T dy = f.second - s.second;
55
+ using std::sqrt;
56
+ return sqrt(dx*dx + dy*dy);
57
+ }
58
+ };
59
+
60
+ } // namespace Gudhi
61
+
62
+ #endif // DISTANCE_FUNCTIONS_H_
@@ -0,0 +1,104 @@
1
+ /* This file is part of the Gudhi Library - https://gudhi.inria.fr/ - which is released under MIT.
2
+ * See file LICENSE or go to https://gudhi.inria.fr/licensing/ for full license details.
3
+ * Author(s): Clément Maria
4
+ *
5
+ * Copyright (C) 2014 Inria
6
+ *
7
+ * Modification(s):
8
+ * - YYYY/MM Author: Description of the modification
9
+ */
10
+
11
+ #ifndef GRAPH_SIMPLICIAL_COMPLEX_H_
12
+ #define GRAPH_SIMPLICIAL_COMPLEX_H_
13
+
14
+ #include <boost/graph/adjacency_list.hpp>
15
+
16
+ #include <utility> // for pair<>
17
+ #include <vector>
18
+ #include <map>
19
+ #include <tuple> // for std::tie
20
+
21
+ namespace Gudhi {
22
+ /** @file
23
+ * @brief Graph simplicial complex methods
24
+ */
25
+
26
+ /* Edge tag for Boost PropertyGraph. */
27
+ struct edge_filtration_t {
28
+ typedef boost::edge_property_tag kind;
29
+ };
30
+
31
+ /* Vertex tag for Boost PropertyGraph. */
32
+ struct vertex_filtration_t {
33
+ typedef boost::vertex_property_tag kind;
34
+ };
35
+
36
+ /** \brief Proximity_graph contains the vertices and edges with their filtration values in order to store the result
37
+ * of `Gudhi::compute_proximity_graph` function.
38
+ *
39
+ * \tparam SimplicialComplexForProximityGraph furnishes `Filtration_value` type definition.
40
+ *
41
+ */
42
+ template <typename SimplicialComplexForProximityGraph>
43
+ using Proximity_graph = typename boost::adjacency_list < boost::vecS, boost::vecS, boost::directedS
44
+ , boost::property < vertex_filtration_t, typename SimplicialComplexForProximityGraph::Filtration_value >
45
+ , boost::property < edge_filtration_t, typename SimplicialComplexForProximityGraph::Filtration_value >>;
46
+
47
+ /** \brief Computes the proximity graph of the points.
48
+ *
49
+ * If points contains n elements, the proximity graph is the graph with n vertices, and an edge [u,v] iff the
50
+ * distance function between points u and v is smaller than threshold.
51
+ *
52
+ * \tparam SimplicialComplexForProximityGraph furnishes `Filtration_value` and `Vertex_handle` type definitions.
53
+ *
54
+ * \tparam ForwardPointRange furnishes `.begin()` and `.end()` methods.
55
+ *
56
+ * \tparam Distance furnishes `operator()(const Point& p1, const Point& p2)`, where
57
+ * `Point` is a point from the `ForwardPointRange`, and that returns a `Filtration_value`.
58
+ */
59
+ template< typename SimplicialComplexForProximityGraph
60
+ , typename ForwardPointRange
61
+ , typename Distance >
62
+ Proximity_graph<SimplicialComplexForProximityGraph> compute_proximity_graph(
63
+ const ForwardPointRange& points,
64
+ typename SimplicialComplexForProximityGraph::Filtration_value threshold,
65
+ Distance distance) {
66
+ using Vertex_handle = typename SimplicialComplexForProximityGraph::Vertex_handle;
67
+ using Filtration_value = typename SimplicialComplexForProximityGraph::Filtration_value;
68
+
69
+ std::vector<std::pair< Vertex_handle, Vertex_handle >> edges;
70
+ std::vector< Filtration_value > edges_fil;
71
+ std::map< Vertex_handle, Filtration_value > vertices;
72
+
73
+ Vertex_handle idx_u, idx_v;
74
+ Filtration_value fil;
75
+ idx_u = 0;
76
+ for (auto it_u = points.begin(); it_u != points.end(); ++it_u) {
77
+ idx_v = idx_u + 1;
78
+ for (auto it_v = it_u + 1; it_v != points.end(); ++it_v, ++idx_v) {
79
+ fil = distance(*it_u, *it_v);
80
+ if (fil <= threshold) {
81
+ edges.emplace_back(idx_u, idx_v);
82
+ edges_fil.push_back(fil);
83
+ }
84
+ }
85
+ ++idx_u;
86
+ }
87
+
88
+ // Points are labeled from 0 to idx_u-1
89
+ Proximity_graph<SimplicialComplexForProximityGraph> skel_graph(edges.begin(), edges.end(), edges_fil.begin(), idx_u);
90
+
91
+ auto vertex_prop = boost::get(vertex_filtration_t(), skel_graph);
92
+
93
+ typename boost::graph_traits<Proximity_graph<SimplicialComplexForProximityGraph>>::vertex_iterator vi, vi_end;
94
+ for (std::tie(vi, vi_end) = boost::vertices(skel_graph);
95
+ vi != vi_end; ++vi) {
96
+ boost::put(vertex_prop, *vi, 0.);
97
+ }
98
+
99
+ return skel_graph;
100
+ }
101
+
102
+ } // namespace Gudhi
103
+
104
+ #endif // GRAPH_SIMPLICIAL_COMPLEX_H_
@@ -0,0 +1,253 @@
1
+ /* This file is part of the Gudhi Library - https://gudhi.inria.fr/ - which is released under MIT.
2
+ * See file LICENSE or go to https://gudhi.inria.fr/licensing/ for full license details.
3
+ * Author(s): Hannah Schreiber
4
+ *
5
+ * Copyright (C) 2024 Inria
6
+ *
7
+ * Modification(s):
8
+ * - YYYY/MM Author: Description of the modification
9
+ */
10
+
11
+ /**
12
+ * @file persistence_interval.h
13
+ * @author Hannah Schreiber
14
+ * @brief Contains @ref Gudhi::persistence_matrix::Persistence_interval class.
15
+ */
16
+
17
+ #ifndef PM_INTERVAL_INCLUDED
18
+ #define PM_INTERVAL_INCLUDED
19
+
20
+ #include <ostream> //std::ostream
21
+ #include <limits> //std::numeric_limits
22
+ #include <tuple>
23
+ #include <utility> //std::move
24
+
25
+ namespace Gudhi {
26
+ namespace persistence_matrix {
27
+
28
+ /**
29
+ * @class Persistence_interval persistence_interval.h gudhi/persistence_interval.h
30
+ * @ingroup persistence_matrix
31
+ *
32
+ * @brief Type for an interval in a persistent diagram or barcode. Stores the birth, death and dimension of the
33
+ * interval. It can be used as a tuple with `get`/`std::get` (birth, death and dimension in this order),
34
+ * `std::tuple_element` and `std::tuple_size`, as well as structured binding.
35
+ *
36
+ * @tparam Dimension Type of the dimension value.
37
+ * @tparam Event_value Type of the birth and death value.
38
+ */
39
+ template <typename Dimension, typename Event_value>
40
+ struct Persistence_interval {
41
+ /**
42
+ * @brief Stores the infinity value for birth and death events. Its value depends on the template parameter
43
+ * `Event_value`:
44
+ * - if `Event_value` has a native infinity value, it takes this value,
45
+ * - otherwise, if `Event_value` is a signed type, it takes value -1,
46
+ * - otherwise, if `Event_value` is a unsigned type, it takes the maximal possible value.
47
+ *
48
+ * Is also used as default value for birth and death attributes when not initialized.
49
+ */
50
+ static constexpr Event_value inf = std::numeric_limits<Event_value>::has_infinity
51
+ ? std::numeric_limits<Event_value>::infinity()
52
+ : static_cast<Event_value>(-1);
53
+
54
+ /**
55
+ * @brief Constructor.
56
+ *
57
+ * @param birth Birth value of the cycle. Default value: @ref inf.
58
+ * @param death Death value of the cycle. Default value: @ref inf.
59
+ * @param dim Dimension of the cycle. Default value: -1.
60
+ */
61
+ Persistence_interval(Event_value birth = inf, Event_value death = inf, Dimension dim = -1)
62
+ : dim(dim), birth(birth), death(death) {}
63
+
64
+ Dimension dim; /**< Dimension of the cycle.*/
65
+ Event_value birth; /**< Birth value of the cycle. */
66
+ Event_value death; /**< Death value of the cycle. */
67
+
68
+ /**
69
+ * @brief operator<<
70
+ *
71
+ * @param stream outstream
72
+ * @param interval interval to stream
73
+ */
74
+ inline friend std::ostream& operator<<(std::ostream& stream, const Persistence_interval& interval) {
75
+ stream << "[" << interval.dim << "] ";
76
+ if constexpr (std::numeric_limits<Event_value>::has_infinity) {
77
+ stream << interval.birth << " - " << interval.death;
78
+ } else {
79
+ if (interval.birth == inf)
80
+ stream << "inf";
81
+ else
82
+ stream << interval.birth;
83
+ stream << " - ";
84
+ if (interval.death == inf)
85
+ stream << "inf";
86
+ else
87
+ stream << interval.death;
88
+ }
89
+ return stream;
90
+ }
91
+
92
+ /**
93
+ * @brief Specialization of `get` for @ref Gudhi::persistence_matrix::Persistence_interval.
94
+ *
95
+ * @tparam I Index of the value to return: 0 for the birth value, 1 for the death value and 2 for the dimension.
96
+ * @return Either the birth value if @p I == 0, the death value if @p I == 1 or the dimension if @p I == 2.
97
+ */
98
+ template <std::size_t I>
99
+ constexpr auto& get() & noexcept {
100
+ static_assert(I < 3, "Value mismatch at argument 1 in template parameter list. Maximal possible value is 2.");
101
+
102
+ if constexpr (I == 0) return birth;
103
+ if constexpr (I == 1) return death;
104
+ if constexpr (I == 2) return dim;
105
+ }
106
+
107
+ /**
108
+ * @brief Specialization of `get` for @ref Gudhi::persistence_matrix::Persistence_interval.
109
+ *
110
+ * @tparam I Index of the value to return: 0 for the birth value, 1 for the death value and 2 for the dimension.
111
+ * @return Either the birth value if @p I == 0, the death value if @p I == 1 or the dimension if @p I == 2.
112
+ */
113
+ template <std::size_t I>
114
+ constexpr const auto& get() const& noexcept {
115
+ static_assert(I < 3, "Value mismatch at argument 1 in template parameter list. Maximal possible value is 2.");
116
+
117
+ if constexpr (I == 0) return birth;
118
+ if constexpr (I == 1) return death;
119
+ if constexpr (I == 2) return dim;
120
+ }
121
+
122
+ /**
123
+ * @brief Specialization of `get` for @ref Gudhi::persistence_matrix::Persistence_interval.
124
+ *
125
+ * @tparam I Index of the value to return: 0 for the birth value, 1 for the death value and 2 for the dimension.
126
+ * @return Either the birth value if @p I == 0, the death value if @p I == 1 or the dimension if @p I == 2.
127
+ */
128
+ template <std::size_t I>
129
+ constexpr auto&& get() && noexcept {
130
+ static_assert(I < 3, "Value mismatch at argument 1 in template parameter list. Maximal possible value is 2.");
131
+
132
+ if constexpr (I == 0) return std::move(birth);
133
+ if constexpr (I == 1) return std::move(death);
134
+ if constexpr (I == 2) return std::move(dim);
135
+ }
136
+
137
+ /**
138
+ * @brief Specialization of `get` for @ref Gudhi::persistence_matrix::Persistence_interval.
139
+ *
140
+ * @tparam I Index of the value to return: 0 for the birth value, 1 for the death value and 2 for the dimension.
141
+ * @return Either the birth value if @p I == 0, the death value if @p I == 1 or the dimension if @p I == 2.
142
+ */
143
+ template <std::size_t I>
144
+ constexpr const auto&& get() const&& noexcept {
145
+ static_assert(I < 3, "Value mismatch at argument 1 in template parameter list. Maximal possible value is 2.");
146
+
147
+ if constexpr (I == 0) return std::move(birth);
148
+ if constexpr (I == 1) return std::move(death);
149
+ if constexpr (I == 2) return std::move(dim);
150
+ }
151
+ };
152
+
153
+ } // namespace persistence_matrix
154
+ } // namespace Gudhi
155
+
156
+ namespace std {
157
+
158
+ /**
159
+ * @ingroup persistence_matrix
160
+ *
161
+ * @brief Partial specialization of `std::tuple_size` for @ref Gudhi::persistence_matrix::Persistence_interval.
162
+ *
163
+ * @tparam Dimension First template parameter of @ref Gudhi::persistence_matrix::Persistence_interval.
164
+ * @tparam Event_value Second template parameter of @ref Gudhi::persistence_matrix::Persistence_interval.
165
+ */
166
+ template <typename Dimension, typename Event_value>
167
+ struct tuple_size<Gudhi::persistence_matrix::Persistence_interval<Dimension, Event_value> >
168
+ : integral_constant<size_t, 3> {};
169
+
170
+ /**
171
+ * @ingroup persistence_matrix
172
+ *
173
+ * @brief Partial specialization of `std::tuple_element` for @ref Gudhi::persistence_matrix::Persistence_interval.
174
+ *
175
+ * @tparam I Index of the type to store: 0 for the birth value type, 1 for the death value type and 2 for the
176
+ * dimension value type.
177
+ * @tparam Dimension First template parameter of @ref Gudhi::persistence_matrix::Persistence_interval.
178
+ * @tparam Event_value Second template parameter of @ref Gudhi::persistence_matrix::Persistence_interval.
179
+ */
180
+ template <size_t I, typename Dimension, typename Event_value>
181
+ struct tuple_element<I, Gudhi::persistence_matrix::Persistence_interval<Dimension, Event_value> > {
182
+ static_assert(I < 3, "Value mismatch at argument 1 in template parameter list. Maximal possible value is 2.");
183
+
184
+ using type = typename conditional <I < 2, Event_value, Dimension>::type;
185
+ };
186
+
187
+ /**
188
+ * @ingroup persistence_matrix
189
+ *
190
+ * @brief Partial specialization of `get` for @ref Gudhi::persistence_matrix::Persistence_interval.
191
+ *
192
+ * @tparam I Index of the value to return: 0 for the birth value, 1 for the death value and 2 for the dimension.
193
+ * @tparam Dimension First template parameter of @ref Gudhi::persistence_matrix::Persistence_interval.
194
+ * @tparam Event_value Second template parameter of @ref Gudhi::persistence_matrix::Persistence_interval.
195
+ * @param i Interval from which the value should be returned.
196
+ * @return Either the birth value if @p I == 0, the death value if @p I == 1 or the dimension if @p I == 2.
197
+ */
198
+ template <size_t I, typename Dimension, typename Event_value>
199
+ constexpr auto& get(Gudhi::persistence_matrix::Persistence_interval<Dimension, Event_value>& i) noexcept {
200
+ return i.template get<I>();
201
+ }
202
+
203
+ /**
204
+ * @ingroup persistence_matrix
205
+ *
206
+ * @brief Partial specialization of `get` for @ref Gudhi::persistence_matrix::Persistence_interval.
207
+ *
208
+ * @tparam I Index of the value to return: 0 for the birth value, 1 for the death value and 2 for the dimension.
209
+ * @tparam Dimension First template parameter of @ref Gudhi::persistence_matrix::Persistence_interval.
210
+ * @tparam Event_value Second template parameter of @ref Gudhi::persistence_matrix::Persistence_interval.
211
+ * @param i Interval from which the value should be returned.
212
+ * @return Either the birth value if @p I == 0, the death value if @p I == 1 or the dimension if @p I == 2.
213
+ */
214
+ template <size_t I, typename Dimension, typename Event_value>
215
+ constexpr const auto& get(const Gudhi::persistence_matrix::Persistence_interval<Dimension, Event_value>& i) noexcept {
216
+ return i.template get<I>();
217
+ }
218
+
219
+ /**
220
+ * @ingroup persistence_matrix
221
+ *
222
+ * @brief Partial specialization of `get` for @ref Gudhi::persistence_matrix::Persistence_interval.
223
+ *
224
+ * @tparam I Index of the value to return: 0 for the birth value, 1 for the death value and 2 for the dimension.
225
+ * @tparam Dimension First template parameter of @ref Gudhi::persistence_matrix::Persistence_interval.
226
+ * @tparam Event_value Second template parameter of @ref Gudhi::persistence_matrix::Persistence_interval.
227
+ * @param i Interval from which the value should be returned.
228
+ * @return Either the birth value if @p I == 0, the death value if @p I == 1 or the dimension if @p I == 2.
229
+ */
230
+ template <size_t I, typename Dimension, typename Event_value>
231
+ constexpr auto&& get(Gudhi::persistence_matrix::Persistence_interval<Dimension, Event_value>&& i) noexcept {
232
+ return std::move(i).template get<I>();
233
+ }
234
+
235
+ /**
236
+ * @ingroup persistence_matrix
237
+ *
238
+ * @brief Partial specialization of `get` for @ref Gudhi::persistence_matrix::Persistence_interval.
239
+ *
240
+ * @tparam I Index of the value to return: 0 for the birth value, 1 for the death value and 2 for the dimension.
241
+ * @tparam Dimension First template parameter of @ref Gudhi::persistence_matrix::Persistence_interval.
242
+ * @tparam Event_value Second template parameter of @ref Gudhi::persistence_matrix::Persistence_interval.
243
+ * @param i Interval from which the value should be returned.
244
+ * @return Either the birth value if @p I == 0, the death value if @p I == 1 or the dimension if @p I == 2.
245
+ */
246
+ template <size_t I, typename Dimension, typename Event_value>
247
+ constexpr const auto&& get(const Gudhi::persistence_matrix::Persistence_interval<Dimension, Event_value>&& i) noexcept {
248
+ return std::move(i).template get<I>();
249
+ }
250
+
251
+ } // namespace std
252
+
253
+ #endif // PM_INTERVAL_INCLUDED