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.
- multipers/.dylibs/libc++.1.0.dylib +0 -0
- multipers/.dylibs/libtbb.12.16.dylib +0 -0
- multipers/__init__.py +33 -0
- multipers/_signed_measure_meta.py +453 -0
- multipers/_slicer_meta.py +211 -0
- multipers/array_api/__init__.py +45 -0
- multipers/array_api/numpy.py +41 -0
- multipers/array_api/torch.py +58 -0
- multipers/data/MOL2.py +458 -0
- multipers/data/UCR.py +18 -0
- multipers/data/__init__.py +1 -0
- multipers/data/graphs.py +466 -0
- multipers/data/immuno_regions.py +27 -0
- multipers/data/minimal_presentation_to_st_bf.py +0 -0
- multipers/data/pytorch2simplextree.py +91 -0
- multipers/data/shape3d.py +101 -0
- multipers/data/synthetic.py +113 -0
- multipers/distances.py +202 -0
- multipers/filtration_conversions.pxd +229 -0
- multipers/filtration_conversions.pxd.tp +84 -0
- multipers/filtrations/__init__.py +18 -0
- multipers/filtrations/density.py +574 -0
- multipers/filtrations/filtrations.py +361 -0
- multipers/filtrations.pxd +224 -0
- multipers/function_rips.cpython-312-darwin.so +0 -0
- multipers/function_rips.pyx +105 -0
- multipers/grids.cpython-312-darwin.so +0 -0
- multipers/grids.pyx +433 -0
- multipers/gudhi/Persistence_slices_interface.h +132 -0
- multipers/gudhi/Simplex_tree_interface.h +239 -0
- multipers/gudhi/Simplex_tree_multi_interface.h +551 -0
- multipers/gudhi/cubical_to_boundary.h +59 -0
- multipers/gudhi/gudhi/Bitmap_cubical_complex.h +450 -0
- multipers/gudhi/gudhi/Bitmap_cubical_complex_base.h +1070 -0
- multipers/gudhi/gudhi/Bitmap_cubical_complex_periodic_boundary_conditions_base.h +579 -0
- multipers/gudhi/gudhi/Debug_utils.h +45 -0
- multipers/gudhi/gudhi/Fields/Multi_field.h +484 -0
- multipers/gudhi/gudhi/Fields/Multi_field_operators.h +455 -0
- multipers/gudhi/gudhi/Fields/Multi_field_shared.h +450 -0
- multipers/gudhi/gudhi/Fields/Multi_field_small.h +531 -0
- multipers/gudhi/gudhi/Fields/Multi_field_small_operators.h +507 -0
- multipers/gudhi/gudhi/Fields/Multi_field_small_shared.h +531 -0
- multipers/gudhi/gudhi/Fields/Z2_field.h +355 -0
- multipers/gudhi/gudhi/Fields/Z2_field_operators.h +376 -0
- multipers/gudhi/gudhi/Fields/Zp_field.h +420 -0
- multipers/gudhi/gudhi/Fields/Zp_field_operators.h +400 -0
- multipers/gudhi/gudhi/Fields/Zp_field_shared.h +418 -0
- multipers/gudhi/gudhi/Flag_complex_edge_collapser.h +337 -0
- multipers/gudhi/gudhi/Matrix.h +2107 -0
- multipers/gudhi/gudhi/Multi_critical_filtration.h +1038 -0
- multipers/gudhi/gudhi/Multi_persistence/Box.h +174 -0
- multipers/gudhi/gudhi/Multi_persistence/Line.h +282 -0
- multipers/gudhi/gudhi/Off_reader.h +173 -0
- multipers/gudhi/gudhi/One_critical_filtration.h +1441 -0
- multipers/gudhi/gudhi/Persistence_matrix/Base_matrix.h +769 -0
- multipers/gudhi/gudhi/Persistence_matrix/Base_matrix_with_column_compression.h +686 -0
- multipers/gudhi/gudhi/Persistence_matrix/Boundary_matrix.h +842 -0
- multipers/gudhi/gudhi/Persistence_matrix/Chain_matrix.h +1350 -0
- multipers/gudhi/gudhi/Persistence_matrix/Id_to_index_overlay.h +1105 -0
- multipers/gudhi/gudhi/Persistence_matrix/Position_to_index_overlay.h +859 -0
- multipers/gudhi/gudhi/Persistence_matrix/RU_matrix.h +910 -0
- multipers/gudhi/gudhi/Persistence_matrix/allocators/entry_constructors.h +139 -0
- multipers/gudhi/gudhi/Persistence_matrix/base_pairing.h +230 -0
- multipers/gudhi/gudhi/Persistence_matrix/base_swap.h +211 -0
- multipers/gudhi/gudhi/Persistence_matrix/boundary_cell_position_to_id_mapper.h +60 -0
- multipers/gudhi/gudhi/Persistence_matrix/boundary_face_position_to_id_mapper.h +60 -0
- multipers/gudhi/gudhi/Persistence_matrix/chain_pairing.h +136 -0
- multipers/gudhi/gudhi/Persistence_matrix/chain_rep_cycles.h +190 -0
- multipers/gudhi/gudhi/Persistence_matrix/chain_vine_swap.h +616 -0
- multipers/gudhi/gudhi/Persistence_matrix/columns/chain_column_extra_properties.h +150 -0
- multipers/gudhi/gudhi/Persistence_matrix/columns/column_dimension_holder.h +106 -0
- multipers/gudhi/gudhi/Persistence_matrix/columns/column_utilities.h +219 -0
- multipers/gudhi/gudhi/Persistence_matrix/columns/entry_types.h +327 -0
- multipers/gudhi/gudhi/Persistence_matrix/columns/heap_column.h +1140 -0
- multipers/gudhi/gudhi/Persistence_matrix/columns/intrusive_list_column.h +934 -0
- multipers/gudhi/gudhi/Persistence_matrix/columns/intrusive_set_column.h +934 -0
- multipers/gudhi/gudhi/Persistence_matrix/columns/list_column.h +980 -0
- multipers/gudhi/gudhi/Persistence_matrix/columns/naive_vector_column.h +1092 -0
- multipers/gudhi/gudhi/Persistence_matrix/columns/row_access.h +192 -0
- multipers/gudhi/gudhi/Persistence_matrix/columns/set_column.h +921 -0
- multipers/gudhi/gudhi/Persistence_matrix/columns/small_vector_column.h +1093 -0
- multipers/gudhi/gudhi/Persistence_matrix/columns/unordered_set_column.h +1012 -0
- multipers/gudhi/gudhi/Persistence_matrix/columns/vector_column.h +1244 -0
- multipers/gudhi/gudhi/Persistence_matrix/matrix_dimension_holders.h +186 -0
- multipers/gudhi/gudhi/Persistence_matrix/matrix_row_access.h +164 -0
- multipers/gudhi/gudhi/Persistence_matrix/ru_pairing.h +156 -0
- multipers/gudhi/gudhi/Persistence_matrix/ru_rep_cycles.h +376 -0
- multipers/gudhi/gudhi/Persistence_matrix/ru_vine_swap.h +540 -0
- multipers/gudhi/gudhi/Persistent_cohomology/Field_Zp.h +118 -0
- multipers/gudhi/gudhi/Persistent_cohomology/Multi_field.h +173 -0
- multipers/gudhi/gudhi/Persistent_cohomology/Persistent_cohomology_column.h +128 -0
- multipers/gudhi/gudhi/Persistent_cohomology.h +745 -0
- multipers/gudhi/gudhi/Points_off_io.h +171 -0
- multipers/gudhi/gudhi/Simple_object_pool.h +69 -0
- multipers/gudhi/gudhi/Simplex_tree/Simplex_tree_iterators.h +463 -0
- multipers/gudhi/gudhi/Simplex_tree/Simplex_tree_node_explicit_storage.h +83 -0
- multipers/gudhi/gudhi/Simplex_tree/Simplex_tree_siblings.h +106 -0
- multipers/gudhi/gudhi/Simplex_tree/Simplex_tree_star_simplex_iterators.h +277 -0
- multipers/gudhi/gudhi/Simplex_tree/hooks_simplex_base.h +62 -0
- multipers/gudhi/gudhi/Simplex_tree/indexing_tag.h +27 -0
- multipers/gudhi/gudhi/Simplex_tree/serialization_utils.h +62 -0
- multipers/gudhi/gudhi/Simplex_tree/simplex_tree_options.h +157 -0
- multipers/gudhi/gudhi/Simplex_tree.h +2794 -0
- multipers/gudhi/gudhi/Simplex_tree_multi.h +152 -0
- multipers/gudhi/gudhi/distance_functions.h +62 -0
- multipers/gudhi/gudhi/graph_simplicial_complex.h +104 -0
- multipers/gudhi/gudhi/persistence_interval.h +253 -0
- multipers/gudhi/gudhi/persistence_matrix_options.h +170 -0
- multipers/gudhi/gudhi/reader_utils.h +367 -0
- multipers/gudhi/mma_interface_coh.h +256 -0
- multipers/gudhi/mma_interface_h0.h +223 -0
- multipers/gudhi/mma_interface_matrix.h +293 -0
- multipers/gudhi/naive_merge_tree.h +536 -0
- multipers/gudhi/scc_io.h +310 -0
- multipers/gudhi/truc.h +1403 -0
- multipers/io.cpython-312-darwin.so +0 -0
- multipers/io.pyx +644 -0
- multipers/ml/__init__.py +0 -0
- multipers/ml/accuracies.py +90 -0
- multipers/ml/invariants_with_persistable.py +79 -0
- multipers/ml/kernels.py +176 -0
- multipers/ml/mma.py +713 -0
- multipers/ml/one.py +472 -0
- multipers/ml/point_clouds.py +352 -0
- multipers/ml/signed_measures.py +1589 -0
- multipers/ml/sliced_wasserstein.py +461 -0
- multipers/ml/tools.py +113 -0
- multipers/mma_structures.cpython-312-darwin.so +0 -0
- multipers/mma_structures.pxd +128 -0
- multipers/mma_structures.pyx +2786 -0
- multipers/mma_structures.pyx.tp +1094 -0
- multipers/multi_parameter_rank_invariant/diff_helpers.h +84 -0
- multipers/multi_parameter_rank_invariant/euler_characteristic.h +97 -0
- multipers/multi_parameter_rank_invariant/function_rips.h +322 -0
- multipers/multi_parameter_rank_invariant/hilbert_function.h +769 -0
- multipers/multi_parameter_rank_invariant/persistence_slices.h +148 -0
- multipers/multi_parameter_rank_invariant/rank_invariant.h +369 -0
- multipers/multiparameter_edge_collapse.py +41 -0
- multipers/multiparameter_module_approximation/approximation.h +2330 -0
- multipers/multiparameter_module_approximation/combinatory.h +129 -0
- multipers/multiparameter_module_approximation/debug.h +107 -0
- multipers/multiparameter_module_approximation/euler_curves.h +0 -0
- multipers/multiparameter_module_approximation/format_python-cpp.h +286 -0
- multipers/multiparameter_module_approximation/heap_column.h +238 -0
- multipers/multiparameter_module_approximation/images.h +79 -0
- multipers/multiparameter_module_approximation/list_column.h +174 -0
- multipers/multiparameter_module_approximation/list_column_2.h +232 -0
- multipers/multiparameter_module_approximation/ru_matrix.h +347 -0
- multipers/multiparameter_module_approximation/set_column.h +135 -0
- multipers/multiparameter_module_approximation/structure_higher_dim_barcode.h +36 -0
- multipers/multiparameter_module_approximation/unordered_set_column.h +166 -0
- multipers/multiparameter_module_approximation/utilities.h +403 -0
- multipers/multiparameter_module_approximation/vector_column.h +223 -0
- multipers/multiparameter_module_approximation/vector_matrix.h +331 -0
- multipers/multiparameter_module_approximation/vineyards.h +464 -0
- multipers/multiparameter_module_approximation/vineyards_trajectories.h +649 -0
- multipers/multiparameter_module_approximation.cpython-312-darwin.so +0 -0
- multipers/multiparameter_module_approximation.pyx +235 -0
- multipers/pickle.py +90 -0
- multipers/plots.py +456 -0
- multipers/point_measure.cpython-312-darwin.so +0 -0
- multipers/point_measure.pyx +395 -0
- multipers/simplex_tree_multi.cpython-312-darwin.so +0 -0
- multipers/simplex_tree_multi.pxd +134 -0
- multipers/simplex_tree_multi.pyx +10840 -0
- multipers/simplex_tree_multi.pyx.tp +2009 -0
- multipers/slicer.cpython-312-darwin.so +0 -0
- multipers/slicer.pxd +3034 -0
- multipers/slicer.pxd.tp +234 -0
- multipers/slicer.pyx +20481 -0
- multipers/slicer.pyx.tp +1088 -0
- multipers/tensor/tensor.h +672 -0
- multipers/tensor.pxd +13 -0
- multipers/test.pyx +44 -0
- multipers/tests/__init__.py +62 -0
- multipers/torch/__init__.py +1 -0
- multipers/torch/diff_grids.py +240 -0
- multipers/torch/rips_density.py +310 -0
- multipers-2.3.3b6.dist-info/METADATA +128 -0
- multipers-2.3.3b6.dist-info/RECORD +183 -0
- multipers-2.3.3b6.dist-info/WHEEL +6 -0
- multipers-2.3.3b6.dist-info/licenses/LICENSE +21 -0
- multipers-2.3.3b6.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,403 @@
|
|
|
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): Hannah Schreiber
|
|
4
|
+
*
|
|
5
|
+
* Copyright (C) 2022 Inria
|
|
6
|
+
*
|
|
7
|
+
* Modification(s):
|
|
8
|
+
* - YYYY/MM Author: Description of the modification
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
#ifndef UTILITIES_H
|
|
12
|
+
#define UTILITIES_H
|
|
13
|
+
|
|
14
|
+
#include <cassert>
|
|
15
|
+
#include <gudhi/Simplex_tree_multi.h>
|
|
16
|
+
#include <gudhi/One_critical_filtration.h>
|
|
17
|
+
#include <gudhi/Multi_persistence/Box.h>
|
|
18
|
+
#include <limits>
|
|
19
|
+
#include <vector>
|
|
20
|
+
|
|
21
|
+
namespace Gudhi::multiparameter::mma {
|
|
22
|
+
|
|
23
|
+
constexpr const bool verbose = false;
|
|
24
|
+
|
|
25
|
+
using index = unsigned int;
|
|
26
|
+
using value_type = double;
|
|
27
|
+
using filtration_type = Gudhi::multi_filtration::One_critical_filtration<value_type>;
|
|
28
|
+
using multifiltration_type = std::vector<filtration_type>;
|
|
29
|
+
using python_filtration_type = std::vector<value_type>;
|
|
30
|
+
using python_multifiltration_type = std::vector<python_filtration_type>;
|
|
31
|
+
|
|
32
|
+
using dimension_type = int;
|
|
33
|
+
using persistence_pair = std::pair<value_type, value_type>;
|
|
34
|
+
using boundary_type = std::vector<index>;
|
|
35
|
+
using boundary_matrix = std::vector<boundary_type>;
|
|
36
|
+
using permutation_type = std::vector<std::size_t>;
|
|
37
|
+
using point_type = Gudhi::multi_filtration::One_critical_filtration<value_type>;
|
|
38
|
+
using corner_type = Gudhi::multi_filtration::One_critical_filtration<value_type>;
|
|
39
|
+
using corners_type = std::pair<std::vector<corner_type>, std::vector<corner_type>>;
|
|
40
|
+
// using python_bar =
|
|
41
|
+
// std::pair<std::vector<value_type>,
|
|
42
|
+
// std::vector<value_type>>; // This type is for python
|
|
43
|
+
using multipers_barcode = std::vector<std::vector<value_type>>;
|
|
44
|
+
const value_type inf = std::numeric_limits<value_type>::infinity();
|
|
45
|
+
const value_type negInf = -1 * inf;
|
|
46
|
+
using interval_type = std::pair<point_type, point_type>;
|
|
47
|
+
|
|
48
|
+
// template<typename T>
|
|
49
|
+
// bool is_smaller(const std::vector<T>& x, const std::vector<T>& y)
|
|
50
|
+
// {
|
|
51
|
+
// for (unsigned int i = 0; i < std::min(x.size(), y.size()); i++)
|
|
52
|
+
// if (x[i] > y[i]) return false;
|
|
53
|
+
// return true;
|
|
54
|
+
// }
|
|
55
|
+
// template<typename T>
|
|
56
|
+
// bool is_greater(const std::vector<T>& x, const std::vector<T>& y)
|
|
57
|
+
// {
|
|
58
|
+
// for (unsigned int i = 0; i < std::min(x.size(), y.size()); i++)
|
|
59
|
+
// if (x[i] < y[i]) return false;
|
|
60
|
+
// return true;
|
|
61
|
+
// }
|
|
62
|
+
|
|
63
|
+
struct Bar {
|
|
64
|
+
Bar() : dim(-1), birth(-1), death(-1) {}
|
|
65
|
+
|
|
66
|
+
Bar(dimension_type dim, int birth, int death) : dim(dim), birth(birth), death(death) {}
|
|
67
|
+
|
|
68
|
+
dimension_type dim;
|
|
69
|
+
int birth;
|
|
70
|
+
int death;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
using barcode_type = std::vector<Bar>;
|
|
74
|
+
|
|
75
|
+
struct Diagram_point {
|
|
76
|
+
Diagram_point() : dim(-1), birth(-1), death(-1) {}
|
|
77
|
+
|
|
78
|
+
Diagram_point(dimension_type dim, value_type birth, value_type death) : dim(dim), birth(birth), death(death) {}
|
|
79
|
+
|
|
80
|
+
dimension_type dim;
|
|
81
|
+
value_type birth;
|
|
82
|
+
value_type death;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
using diagram_type = std::vector<Diagram_point>;
|
|
86
|
+
|
|
87
|
+
template <typename filtration_type = filtration_type>
|
|
88
|
+
struct MultiDiagram_point {
|
|
89
|
+
public:
|
|
90
|
+
MultiDiagram_point() : dim(-1), birth({}), death({}) {}
|
|
91
|
+
|
|
92
|
+
MultiDiagram_point(dimension_type dim, filtration_type birth, filtration_type death)
|
|
93
|
+
: dim(dim), birth(birth), death(death) {}
|
|
94
|
+
|
|
95
|
+
dimension_type get_dimension() const { return dim; }
|
|
96
|
+
|
|
97
|
+
const filtration_type &get_birth() const { return birth; }
|
|
98
|
+
|
|
99
|
+
const filtration_type &get_death() const { return death; }
|
|
100
|
+
|
|
101
|
+
private:
|
|
102
|
+
dimension_type dim;
|
|
103
|
+
filtration_type birth;
|
|
104
|
+
filtration_type death;
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
template <typename filtration_type, typename value_type>
|
|
108
|
+
struct MultiDiagram { // for python interface
|
|
109
|
+
static_assert(std::is_same_v<typename filtration_type::value_type, value_type>,
|
|
110
|
+
"filtration_type and value_type must be the same");
|
|
111
|
+
|
|
112
|
+
public:
|
|
113
|
+
using iterator = typename std::vector<MultiDiagram_point<filtration_type>>::const_iterator;
|
|
114
|
+
|
|
115
|
+
MultiDiagram() {}
|
|
116
|
+
|
|
117
|
+
MultiDiagram(std::vector<MultiDiagram_point<filtration_type>> &m) : multiDiagram(m) {}
|
|
118
|
+
|
|
119
|
+
using python_bar = std::pair<std::vector<typename filtration_type::value_type>,
|
|
120
|
+
std::vector<typename filtration_type::value_type>>; // This type is for python
|
|
121
|
+
|
|
122
|
+
std::vector<python_bar> get_points(const dimension_type dimension = -1) const { // dump for python interface
|
|
123
|
+
std::vector<python_bar> out;
|
|
124
|
+
out.reserve(multiDiagram.size());
|
|
125
|
+
for (const MultiDiagram_point<filtration_type> &pt : multiDiagram) {
|
|
126
|
+
if (dimension == -1 || pt.get_dimension() == dimension) {
|
|
127
|
+
if (pt.get_birth().size() > 0 && pt.get_death().size() > 0 && !pt.get_birth().is_plus_inf() &&
|
|
128
|
+
!pt.get_death().is_minus_inf())
|
|
129
|
+
out.push_back({pt.get_birth(), pt.get_death()});
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
/* out.shrink_to_fit(); */
|
|
133
|
+
return out;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
std::vector<std::vector<double>> to_multipers(
|
|
137
|
+
const dimension_type dimension = -1) const { // dump for python interface
|
|
138
|
+
std::vector<std::vector<double>> out;
|
|
139
|
+
out.reserve(multiDiagram.size());
|
|
140
|
+
for (const MultiDiagram_point<filtration_type> &pt : multiDiagram) {
|
|
141
|
+
if (dimension == -1 || pt.get_dimension() == dimension) {
|
|
142
|
+
const auto &b = pt.get_birth().template as_type<double>();
|
|
143
|
+
const auto &d = pt.get_death().template as_type<double>();
|
|
144
|
+
assert(!(b.is_plus_inf() || b.is_minus_inf() || d.is_plus_inf() || d.is_minus_inf()));
|
|
145
|
+
out.push_back({b[0], d[0], b[1], d[1]});
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
out.shrink_to_fit();
|
|
149
|
+
return out;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
iterator begin() const { return this->multiDiagram.begin(); }
|
|
153
|
+
|
|
154
|
+
iterator end() const { return this->multiDiagram.end(); }
|
|
155
|
+
|
|
156
|
+
unsigned int size() { return this->multiDiagram.size(); }
|
|
157
|
+
|
|
158
|
+
void set(std::vector<MultiDiagram_point<filtration_type>> &m) { this->multiDiagram.swap(m); }
|
|
159
|
+
|
|
160
|
+
std::vector<MultiDiagram_point<filtration_type>> &getref() { return this->multiDiagram; }
|
|
161
|
+
|
|
162
|
+
MultiDiagram_point<filtration_type> &operator[](unsigned int i) { return this->multiDiagram[i]; }
|
|
163
|
+
|
|
164
|
+
MultiDiagram_point<filtration_type> &at(const unsigned int i) { return multiDiagram[i]; }
|
|
165
|
+
|
|
166
|
+
private:
|
|
167
|
+
std::vector<MultiDiagram_point<filtration_type>> multiDiagram;
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
template <typename filtration_type, typename value_type>
|
|
171
|
+
struct MultiDiagrams {
|
|
172
|
+
static_assert(std::is_same_v<typename filtration_type::value_type, value_type>,
|
|
173
|
+
"filtration_type and value_type must be the same");
|
|
174
|
+
|
|
175
|
+
public:
|
|
176
|
+
using iterator = typename std::vector<MultiDiagram<filtration_type, value_type>>::const_iterator;
|
|
177
|
+
using nciterator = typename std::vector<MultiDiagram<filtration_type, value_type>>::iterator;
|
|
178
|
+
|
|
179
|
+
MultiDiagrams() {}
|
|
180
|
+
|
|
181
|
+
MultiDiagrams(unsigned int size) : multiDiagrams(size) {}
|
|
182
|
+
|
|
183
|
+
std::vector<std::vector<std::vector<double>>> to_multipers() {
|
|
184
|
+
unsigned int nsummands = this->multiDiagrams.front().size();
|
|
185
|
+
unsigned int nlines = this->multiDiagrams.size();
|
|
186
|
+
// std::vector<std::vector<std::vector<double>>> out(nsummands,
|
|
187
|
+
// std::vector<std::vector<double>>(nlines, std::vector<double>(5)));
|
|
188
|
+
std::vector<std::vector<std::vector<double>>> out(nsummands);
|
|
189
|
+
for (unsigned int i = 0; i < nsummands; i++) {
|
|
190
|
+
out[i].reserve(nlines);
|
|
191
|
+
for (unsigned int j = 0; j < nlines; j++) {
|
|
192
|
+
const MultiDiagram_point<filtration_type> &pt = this->multiDiagrams[j][i];
|
|
193
|
+
/* if(pt.get_birth().is_plus_inf() || pt.get_death().is_minus_inf()) */
|
|
194
|
+
/* out[i].push_back({0, 0, 0, 0,static_cast<value_type>(j)}); */
|
|
195
|
+
/* else */
|
|
196
|
+
double a, b, c, d;
|
|
197
|
+
double inf = std::numeric_limits<double>::infinity();
|
|
198
|
+
if (pt.get_birth().is_plus_inf()) {
|
|
199
|
+
a = 0;
|
|
200
|
+
b = 0;
|
|
201
|
+
} else if (pt.get_birth().is_minus_inf()) {
|
|
202
|
+
a = -inf;
|
|
203
|
+
b = -inf;
|
|
204
|
+
} else {
|
|
205
|
+
a = pt.get_birth()[0];
|
|
206
|
+
b = pt.get_birth()[1];
|
|
207
|
+
}
|
|
208
|
+
if (pt.get_death().is_plus_inf()) {
|
|
209
|
+
c = inf;
|
|
210
|
+
d = inf;
|
|
211
|
+
}
|
|
212
|
+
if (pt.get_death().is_minus_inf()) {
|
|
213
|
+
c = 0;
|
|
214
|
+
d = 0;
|
|
215
|
+
} else {
|
|
216
|
+
c = pt.get_death()[0];
|
|
217
|
+
d = pt.get_death()[1];
|
|
218
|
+
}
|
|
219
|
+
/* out[i].push_back({pt.get_birth()[0], pt.get_death()[0],
|
|
220
|
+
* pt.get_birth()[1], pt.get_death()[1],static_cast<value_type>(j)}); */
|
|
221
|
+
out[i].push_back({a, c, b, d, static_cast<double>(j)});
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
return out;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
using __for_python_plot_type = std::pair<std::vector<std::pair<double, double>>, std::vector<unsigned int>>;
|
|
228
|
+
|
|
229
|
+
__for_python_plot_type _for_python_plot(dimension_type dimension = -1, value_type min_persistence = 0) {
|
|
230
|
+
__for_python_plot_type out;
|
|
231
|
+
auto &bars = out.first;
|
|
232
|
+
auto &summand_idx = out.second;
|
|
233
|
+
bars.reserve(this->multiDiagrams.size() * this->multiDiagrams[0].size() * 2);
|
|
234
|
+
summand_idx.reserve(this->multiDiagrams.size() * this->multiDiagrams[0].size());
|
|
235
|
+
for (const MultiDiagram<filtration_type, value_type> &multiDiagram : this->multiDiagrams) {
|
|
236
|
+
unsigned int count = 0;
|
|
237
|
+
for (const MultiDiagram_point<filtration_type> &bar : multiDiagram) {
|
|
238
|
+
const auto &birth = bar.get_birth().template as_type<double>();
|
|
239
|
+
const auto &death = bar.get_death().template as_type<double>();
|
|
240
|
+
if ((dimension == -1 || bar.get_dimension() == dimension) && birth.size() > 1 && death.size() > 1 &&
|
|
241
|
+
(death[0] > birth[0] + min_persistence)) {
|
|
242
|
+
// Checking >1 ensure that filtration is not inf or -inf or nan.
|
|
243
|
+
bars.push_back({birth[0], death[0]});
|
|
244
|
+
bars.push_back({birth[1], death[1]});
|
|
245
|
+
summand_idx.push_back(count);
|
|
246
|
+
}
|
|
247
|
+
count++;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
return out;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
MultiDiagram<filtration_type, value_type> &operator[](const unsigned int i) { return multiDiagrams[i]; }
|
|
254
|
+
|
|
255
|
+
MultiDiagram<filtration_type, value_type> &at(const unsigned int i) { return multiDiagrams[i]; }
|
|
256
|
+
|
|
257
|
+
iterator begin() const { return this->multiDiagrams.begin(); } // cython bug : iterators like bc in bcs crash)
|
|
258
|
+
|
|
259
|
+
iterator end() const { return this->multiDiagrams.end(); }
|
|
260
|
+
|
|
261
|
+
using python_bar = std::pair<std::vector<value_type>,
|
|
262
|
+
std::vector<value_type>>; // This type is for python
|
|
263
|
+
using barcodes = std::vector<std::vector<python_bar>>;
|
|
264
|
+
|
|
265
|
+
barcodes get_points() {
|
|
266
|
+
unsigned int nsummands = this->multiDiagrams.front().size();
|
|
267
|
+
unsigned int nlines = this->multiDiagrams.size();
|
|
268
|
+
// std::vector<std::vector<std::vector<double>>> out(nsummands,
|
|
269
|
+
// std::vector<std::vector<double>>(nlines, std::vector<double>(5)));
|
|
270
|
+
barcodes out(nlines, std::vector<python_bar>(nsummands));
|
|
271
|
+
for (unsigned int i = 0; i < nlines; i++) {
|
|
272
|
+
for (unsigned int j = 0; j < nsummands; j++) {
|
|
273
|
+
const MultiDiagram_point<filtration_type> &pt = this->multiDiagrams[i][j];
|
|
274
|
+
out[i][j] = {pt.get_birth(), pt.get_death()};
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
return out;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
unsigned int size() const { return this->multiDiagrams.size(); }
|
|
281
|
+
|
|
282
|
+
private:
|
|
283
|
+
std::vector<MultiDiagram<filtration_type, value_type>> multiDiagrams;
|
|
284
|
+
/* inline bool _is_inf(const std::vector<value_type> &truc) const{ */
|
|
285
|
+
/* for (const auto coord : truc) */
|
|
286
|
+
/* if (coord != inf) return false; */
|
|
287
|
+
/* return true; */
|
|
288
|
+
/* } */
|
|
289
|
+
/* inline bool _is_negInf(const std::vector<value_type> &truc) const{ */
|
|
290
|
+
/* for (const auto coord : truc) */
|
|
291
|
+
/* if (coord != negInf) return false; */
|
|
292
|
+
/* return true; */
|
|
293
|
+
/* } */
|
|
294
|
+
};
|
|
295
|
+
|
|
296
|
+
void inline threshold_up(point_type &point,
|
|
297
|
+
const Gudhi::multi_persistence::Box<value_type> &box,
|
|
298
|
+
const point_type &basepoint) {
|
|
299
|
+
Gudhi::multi_filtration::One_critical_filtration point_(point);
|
|
300
|
+
// if (is_smaller(point, box.get_upper_corner())) return;
|
|
301
|
+
if (point_ <= box.get_upper_corner()) return;
|
|
302
|
+
|
|
303
|
+
// if (verbose && Debug::debug) Debug::disp_vect(point);
|
|
304
|
+
|
|
305
|
+
if (basepoint[0] == negInf) [[unlikely]]
|
|
306
|
+
return;
|
|
307
|
+
|
|
308
|
+
// ie. point at infinity, assumes [basepoint,0] is smaller than box.second
|
|
309
|
+
if (point.back() == inf) [[unlikely]] {
|
|
310
|
+
// if (verbose) std::cout << " Infinite point" << std::endl;
|
|
311
|
+
|
|
312
|
+
value_type threshold = box.get_upper_corner().back();
|
|
313
|
+
for (unsigned int i = 0; i < point.size(); i++) {
|
|
314
|
+
threshold = std::min(threshold, box.get_upper_corner()[i] - basepoint[i]);
|
|
315
|
+
}
|
|
316
|
+
for (unsigned int i = 0; i < point.size() - 1; i++) point[i] = basepoint[i] + threshold;
|
|
317
|
+
point.back() = threshold;
|
|
318
|
+
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
// if (!is_greater(point, box.get_lower_corner())) {
|
|
323
|
+
if (box.get_lower_corner() <= point_) {
|
|
324
|
+
point[0] = inf; // puts point to infinity
|
|
325
|
+
// if (verbose) std::cout << "buggy point" << std::endl;
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
// in this last case, at least 1 coord of point is is_greater than a coord of
|
|
329
|
+
// box.second
|
|
330
|
+
|
|
331
|
+
value_type threshold = point[0] - box.get_upper_corner()[0];
|
|
332
|
+
for (std::size_t i = 1; i < point.size(); i++) {
|
|
333
|
+
threshold = std::max(threshold, point[i] - box.get_upper_corner()[i]);
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
// if (verbose)
|
|
337
|
+
// std::cout << "Thresholding the point with "<< threshold << " at
|
|
338
|
+
// ";
|
|
339
|
+
|
|
340
|
+
for (std::size_t i = 0; i < point.size(); i++) point[i] -= threshold;
|
|
341
|
+
|
|
342
|
+
// if (verbose && Debug::debug) Debug::disp_vect(point);
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* @brief Threshold a point to the positive cone of b=box.first
|
|
347
|
+
* (ie. the set \f$\{x \in \mathbb R^n \mid x \ge b\})
|
|
348
|
+
* along the slope 1 line crossing this point.
|
|
349
|
+
*
|
|
350
|
+
* @param point The point to threshold.
|
|
351
|
+
* @param box box.fist is the point defining where to threshold.
|
|
352
|
+
* @param basepoint Basepoint of the slope 1 line crossing the point.
|
|
353
|
+
* Meant to handle infinite cases (when the point have infinite coordinates,
|
|
354
|
+
* we cannot infer the line).
|
|
355
|
+
*/
|
|
356
|
+
|
|
357
|
+
void inline threshold_down(point_type &point,
|
|
358
|
+
const Gudhi::multi_persistence::Box<value_type> &box,
|
|
359
|
+
const point_type &basepoint) {
|
|
360
|
+
if (basepoint[0] == negInf) [[unlikely]]
|
|
361
|
+
return;
|
|
362
|
+
|
|
363
|
+
if (point.back() == inf) [[unlikely]] { // ie. point at infinity -> feature never appearing
|
|
364
|
+
return;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
// if (is_greater(point, box.get_lower_corner())) return;
|
|
368
|
+
if (point >= box.get_lower_corner()) return;
|
|
369
|
+
|
|
370
|
+
// if (!is_smaller(point, box.get_upper_corner())) {
|
|
371
|
+
if (!(point <= box.get_upper_corner())) {
|
|
372
|
+
point[0] = inf; // puts point to infinity
|
|
373
|
+
return;
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
value_type threshold = box.get_lower_corner()[0] - point[0];
|
|
377
|
+
for (unsigned int i = 1; i < point.size(); i++) {
|
|
378
|
+
threshold = std::max(threshold, box.get_lower_corner()[i] - point[i]);
|
|
379
|
+
}
|
|
380
|
+
for (unsigned int i = 0; i < point.size(); i++) point[i] += threshold;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
} // namespace Gudhi::multiparameter::mma
|
|
384
|
+
|
|
385
|
+
//// Different implementations of the matrix columns. Set seems to be the
|
|
386
|
+
/// fastest / in our tests. / using Vineyard_matrix_type =
|
|
387
|
+
/// RU_matrix<Heap_column>; / using Vineyard_matrix_type =
|
|
388
|
+
/// RU_matrix<List_column>; / using Vineyard_matrix_type =
|
|
389
|
+
/// RU_matrix<Vector_column>; / using Vineyard_matrix_type =
|
|
390
|
+
/// RU_matrix<Unordered_set_column>;
|
|
391
|
+
// #include "ru_matrix.h"
|
|
392
|
+
///*#include "heap_column.h"*/
|
|
393
|
+
///*#include "list_column.h"*/
|
|
394
|
+
//// #include "list_column_2.h"
|
|
395
|
+
///*#include "vector_column.h"*/
|
|
396
|
+
// #include "set_column.h"
|
|
397
|
+
///*#include "unordered_set_column.h"*/
|
|
398
|
+
//
|
|
399
|
+
// namespace Gudhi::multiparameter::mma {
|
|
400
|
+
// using Vineyard_matrix_type = RU_matrix<Set_column>;
|
|
401
|
+
//}
|
|
402
|
+
|
|
403
|
+
#endif // UTILITIES_H
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
/* This file is part of the MMA Library - https://gitlab.inria.fr/dloiseau/multipers - which is released under MIT.
|
|
2
|
+
* See file LICENSE for full license details.
|
|
3
|
+
* Author(s): Hannah Schreiber
|
|
4
|
+
*
|
|
5
|
+
* Copyright (C) 2022 Inria
|
|
6
|
+
*
|
|
7
|
+
* Modification(s):
|
|
8
|
+
* - YYYY/MM Author: Description of the modification
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
#ifndef VECTORCOLUMN_H
|
|
12
|
+
#define VECTORCOLUMN_H
|
|
13
|
+
|
|
14
|
+
#include <iostream>
|
|
15
|
+
#include <list>
|
|
16
|
+
#include <unordered_set>
|
|
17
|
+
|
|
18
|
+
#include "utilities.h"
|
|
19
|
+
|
|
20
|
+
namespace Vineyard {
|
|
21
|
+
|
|
22
|
+
class Vector_column
|
|
23
|
+
{
|
|
24
|
+
public:
|
|
25
|
+
Vector_column();
|
|
26
|
+
Vector_column(boundary_type& boundary);
|
|
27
|
+
Vector_column(Vector_column& column);
|
|
28
|
+
Vector_column(Vector_column&& column) noexcept;
|
|
29
|
+
|
|
30
|
+
void get_content(boundary_type& container);
|
|
31
|
+
bool contains(unsigned int value) const;
|
|
32
|
+
bool is_empty();
|
|
33
|
+
dimension_type get_dimension() const;
|
|
34
|
+
int get_pivot();
|
|
35
|
+
void clear();
|
|
36
|
+
void clear(unsigned int value);
|
|
37
|
+
void reorder(std::vector<index>& valueMap);
|
|
38
|
+
void add(Vector_column& column);
|
|
39
|
+
|
|
40
|
+
Vector_column& operator=(Vector_column other);
|
|
41
|
+
|
|
42
|
+
friend void swap(Vector_column& col1, Vector_column& col2);
|
|
43
|
+
|
|
44
|
+
private:
|
|
45
|
+
int dim_;
|
|
46
|
+
std::vector<unsigned int> column_;
|
|
47
|
+
std::unordered_set<unsigned int> erasedValues_;
|
|
48
|
+
|
|
49
|
+
void _cleanValues();
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
inline Vector_column::Vector_column() : dim_(0)
|
|
53
|
+
{}
|
|
54
|
+
|
|
55
|
+
inline Vector_column::Vector_column(boundary_type &boundary)
|
|
56
|
+
: dim_(boundary.size() == 0 ? 0 : boundary.size() - 1),
|
|
57
|
+
column_(boundary)
|
|
58
|
+
{}
|
|
59
|
+
|
|
60
|
+
inline Vector_column::Vector_column(Vector_column &column)
|
|
61
|
+
: dim_(column.dim_),
|
|
62
|
+
column_(column.column_),
|
|
63
|
+
erasedValues_(column.erasedValues_)
|
|
64
|
+
{}
|
|
65
|
+
|
|
66
|
+
inline Vector_column::Vector_column(Vector_column &&column) noexcept
|
|
67
|
+
: dim_(std::exchange(column.dim_, 0)),
|
|
68
|
+
column_(std::move(column.column_)),
|
|
69
|
+
erasedValues_(std::move(column.erasedValues_))
|
|
70
|
+
{}
|
|
71
|
+
|
|
72
|
+
inline void Vector_column::get_content(boundary_type &container)
|
|
73
|
+
{
|
|
74
|
+
_cleanValues();
|
|
75
|
+
std::copy(column_.begin(), column_.end(), std::back_inserter(container));
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
inline bool Vector_column::contains(unsigned int value) const
|
|
79
|
+
{
|
|
80
|
+
if (erasedValues_.find(value) != erasedValues_.end()) return false;
|
|
81
|
+
|
|
82
|
+
for (unsigned int v : column_){
|
|
83
|
+
if (v == value) return true;
|
|
84
|
+
}
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
inline bool Vector_column::is_empty()
|
|
89
|
+
{
|
|
90
|
+
_cleanValues();
|
|
91
|
+
return column_.empty();
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
inline dimension_type Vector_column::get_dimension() const
|
|
95
|
+
{
|
|
96
|
+
return dim_;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
inline int Vector_column::get_pivot()
|
|
100
|
+
{
|
|
101
|
+
while (!column_.empty() &&
|
|
102
|
+
erasedValues_.find(column_.back()) != erasedValues_.end()) {
|
|
103
|
+
erasedValues_.erase(column_.back());
|
|
104
|
+
column_.pop_back();
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (column_.empty()) return -1;
|
|
108
|
+
|
|
109
|
+
return column_.back();
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
inline void Vector_column::clear()
|
|
113
|
+
{
|
|
114
|
+
column_.clear();
|
|
115
|
+
erasedValues_.clear();
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
inline void Vector_column::clear(unsigned int value)
|
|
119
|
+
{
|
|
120
|
+
erasedValues_.insert(value);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
inline void Vector_column::reorder(std::vector<index> &valueMap)
|
|
124
|
+
{
|
|
125
|
+
std::vector<unsigned int> newColumn;
|
|
126
|
+
for (unsigned int& v : column_) {
|
|
127
|
+
if (erasedValues_.find(v) == erasedValues_.end())
|
|
128
|
+
newColumn.push_back(valueMap.at(v));
|
|
129
|
+
}
|
|
130
|
+
std::sort(newColumn.begin(), newColumn.end());
|
|
131
|
+
erasedValues_.clear();
|
|
132
|
+
column_.swap(newColumn);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
inline void Vector_column::add(Vector_column &column)
|
|
136
|
+
{
|
|
137
|
+
if (column.is_empty()) return;
|
|
138
|
+
if (column_.empty()){
|
|
139
|
+
std::copy(column.column_.begin(), column.column_.end(), std::back_inserter(column_));
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
std::vector<unsigned int> newColumn;
|
|
144
|
+
|
|
145
|
+
std::vector<unsigned int>::iterator itToAdd = column.column_.begin();
|
|
146
|
+
std::vector<unsigned int>::iterator itTarget = column_.begin();
|
|
147
|
+
unsigned int valToAdd = *itToAdd;
|
|
148
|
+
unsigned int valTarget = *itTarget;
|
|
149
|
+
|
|
150
|
+
while (itToAdd != column.column_.end() && itTarget != column_.end())
|
|
151
|
+
{
|
|
152
|
+
while (itToAdd != column.column_.end() &&
|
|
153
|
+
column.erasedValues_.find(valToAdd) != column.erasedValues_.end()) {
|
|
154
|
+
itToAdd++;
|
|
155
|
+
valToAdd = *itToAdd;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
while (itTarget != column_.end() &&
|
|
159
|
+
erasedValues_.find(valTarget) != erasedValues_.end()) {
|
|
160
|
+
itTarget++;
|
|
161
|
+
valTarget = *itTarget;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
if (itToAdd != column.column_.end() && itTarget != column_.end()){
|
|
165
|
+
if (valToAdd == valTarget){
|
|
166
|
+
itTarget++;
|
|
167
|
+
itToAdd++;
|
|
168
|
+
} else if (valToAdd < valTarget){
|
|
169
|
+
newColumn.push_back(valToAdd);
|
|
170
|
+
itToAdd++;
|
|
171
|
+
} else {
|
|
172
|
+
newColumn.push_back(valTarget);
|
|
173
|
+
itTarget++;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
valToAdd = *itToAdd;
|
|
178
|
+
valTarget = *itTarget;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
while (itToAdd != column.column_.end()){
|
|
182
|
+
newColumn.push_back(*itToAdd);
|
|
183
|
+
itToAdd++;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
while (itTarget != column_.end()){
|
|
187
|
+
newColumn.push_back(*itTarget);
|
|
188
|
+
itTarget++;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
column_.swap(newColumn);
|
|
192
|
+
erasedValues_.clear();
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
inline Vector_column &Vector_column::operator=(Vector_column other)
|
|
196
|
+
{
|
|
197
|
+
std::swap(dim_, other.dim_);
|
|
198
|
+
std::swap(column_, other.column_);
|
|
199
|
+
std::swap(erasedValues_, other.erasedValues_);
|
|
200
|
+
return *this;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
inline void Vector_column::_cleanValues()
|
|
204
|
+
{
|
|
205
|
+
std::vector<unsigned int> newColumn;
|
|
206
|
+
for (unsigned int v : column_){
|
|
207
|
+
if (erasedValues_.find(v) == erasedValues_.end())
|
|
208
|
+
newColumn.push_back(v);
|
|
209
|
+
}
|
|
210
|
+
erasedValues_.clear();
|
|
211
|
+
column_.swap(newColumn);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
inline void swap(Vector_column& col1, Vector_column& col2)
|
|
215
|
+
{
|
|
216
|
+
std::swap(col1.dim_, col2.dim_);
|
|
217
|
+
col1.column_.swap(col2.column_);
|
|
218
|
+
std::swap(col1.erasedValues_, col2.erasedValues_);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
} //namespace Vineyard
|
|
222
|
+
|
|
223
|
+
#endif // VECTORCOLUMN_H
|