multipers 2.3.3b6__cp311-cp311-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-311-darwin.so +0 -0
- multipers/function_rips.pyx +105 -0
- multipers/grids.cpython-311-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-311-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-311-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-311-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-311-darwin.so +0 -0
- multipers/point_measure.pyx +395 -0
- multipers/simplex_tree_multi.cpython-311-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-311-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,536 @@
|
|
|
1
|
+
#ifndef H0V_MERGE_TREE_H
|
|
2
|
+
#define H0V_MERGE_TREE_H
|
|
3
|
+
|
|
4
|
+
#include <algorithm>
|
|
5
|
+
#include <cassert>
|
|
6
|
+
#include <iostream>
|
|
7
|
+
#include <set>
|
|
8
|
+
#include <unordered_map>
|
|
9
|
+
#include <utility>
|
|
10
|
+
#include <vector>
|
|
11
|
+
|
|
12
|
+
#include <boost/functional/hash.hpp>
|
|
13
|
+
|
|
14
|
+
struct Bar {
|
|
15
|
+
Bar() : dim(-1), birth(-1), death(-1) {}
|
|
16
|
+
|
|
17
|
+
Bar(int dim, int birth, int death) : dim(dim), birth(birth), death(death) {}
|
|
18
|
+
|
|
19
|
+
int dim;
|
|
20
|
+
int birth;
|
|
21
|
+
int death;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
class Naive_bottleneck_forest {
|
|
25
|
+
public:
|
|
26
|
+
using index = int;
|
|
27
|
+
|
|
28
|
+
Naive_bottleneck_forest() {}
|
|
29
|
+
|
|
30
|
+
// assumes that ids of vertices are continuous and start with 0
|
|
31
|
+
Naive_bottleneck_forest(unsigned int numberOfVertices) : forest_(numberOfVertices), weights_() {}
|
|
32
|
+
|
|
33
|
+
friend void swap(Naive_bottleneck_forest &mf1, Naive_bottleneck_forest &mf2) {
|
|
34
|
+
mf1.forest_.swap(mf2.forest_);
|
|
35
|
+
mf1.weights_.swap(mf2.weights_);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
void add_edge(index firstVertexIndex, index secondVertexIndex, index edgeWeight) {
|
|
39
|
+
forest_[firstVertexIndex].children.insert(secondVertexIndex);
|
|
40
|
+
forest_[secondVertexIndex].children.insert(firstVertexIndex);
|
|
41
|
+
weights_.emplace(_get_edge(firstVertexIndex, secondVertexIndex), edgeWeight);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
void swap_out_edges(index inVertex1, index inVertex2, index outVertex1, index outVertex2, index outWeight) {
|
|
45
|
+
if (forest_[inVertex1].parent == inVertex2) {
|
|
46
|
+
forest_[inVertex1].parent = -1;
|
|
47
|
+
forest_[inVertex2].children.erase(inVertex1);
|
|
48
|
+
} else {
|
|
49
|
+
forest_[inVertex2].parent = -1;
|
|
50
|
+
forest_[inVertex1].children.erase(inVertex2);
|
|
51
|
+
}
|
|
52
|
+
weights_.erase(_get_edge(inVertex1, inVertex2));
|
|
53
|
+
|
|
54
|
+
if (forest_[outVertex1].parent == -1) {
|
|
55
|
+
forest_[outVertex1].parent = outVertex2;
|
|
56
|
+
forest_[outVertex2].children.insert(outVertex1);
|
|
57
|
+
} else {
|
|
58
|
+
if (forest_[outVertex2].parent != -1) _reroot(outVertex2);
|
|
59
|
+
forest_[outVertex2].parent = outVertex1;
|
|
60
|
+
forest_[outVertex1].children.insert(outVertex2);
|
|
61
|
+
}
|
|
62
|
+
weights_.emplace(_get_edge(outVertex1, outVertex2), outWeight);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// to call once the tree finished
|
|
66
|
+
void root() {
|
|
67
|
+
for (unsigned int i = 0; i < forest_.size(); ++i) {
|
|
68
|
+
if (forest_[i].parent == -1) {
|
|
69
|
+
_root(i);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// assumes root() was already called and that both vertices are in the same
|
|
75
|
+
// connected component
|
|
76
|
+
index get_bootleneck_weight(index id1, index id2) const {
|
|
77
|
+
auto get_weight = [&](index id) {
|
|
78
|
+
return forest_[id].parent == -1 ? -1 : weights_.at(_get_edge(id, forest_[id].parent));
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
std::unordered_map<index, index> partialBottleneck;
|
|
82
|
+
index r = id1;
|
|
83
|
+
index w = 0;
|
|
84
|
+
partialBottleneck.emplace(r, w);
|
|
85
|
+
while (forest_[r].parent != -1) {
|
|
86
|
+
w = std::max(get_weight(r), w);
|
|
87
|
+
partialBottleneck.emplace(forest_[r].parent, w);
|
|
88
|
+
r = forest_[r].parent;
|
|
89
|
+
}
|
|
90
|
+
r = id2;
|
|
91
|
+
auto bIt = partialBottleneck.find(r);
|
|
92
|
+
w = 0;
|
|
93
|
+
while (forest_[r].parent != -1 && bIt == partialBottleneck.end()) {
|
|
94
|
+
w = std::max(get_weight(r), w);
|
|
95
|
+
r = forest_[r].parent;
|
|
96
|
+
bIt = partialBottleneck.find(r);
|
|
97
|
+
}
|
|
98
|
+
return std::max(w, bIt->second);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
void update_weight(index id1, index id2, index newWeight) { weights_.at(_get_edge(id1, id2)) = newWeight; }
|
|
102
|
+
|
|
103
|
+
void print(std::ostream &stream) const {
|
|
104
|
+
stream << "MSF:\n";
|
|
105
|
+
unsigned int c = 0;
|
|
106
|
+
for (const Node &n : forest_) {
|
|
107
|
+
stream << "[" << c << "] parent: ";
|
|
108
|
+
stream << n.parent << "\n";
|
|
109
|
+
stream << "[" << c << "] children: ";
|
|
110
|
+
for (index id : n.children) stream << id << " ";
|
|
111
|
+
stream << "\n";
|
|
112
|
+
if (n.parent != -1) {
|
|
113
|
+
stream << "[" << c << "] weight of parent edge: ";
|
|
114
|
+
stream << weights_.at(_get_edge(c, n.parent)) << "\n";
|
|
115
|
+
}
|
|
116
|
+
++c;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
private:
|
|
121
|
+
struct Node {
|
|
122
|
+
index parent = -1;
|
|
123
|
+
std::set<index> children = {};
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
std::vector<Node> forest_;
|
|
127
|
+
std::unordered_map<std::pair<index, index>, index, boost::hash<std::pair<index, index>>>
|
|
128
|
+
weights_; // TODO: test other map types and having a pair as key is ugly
|
|
129
|
+
|
|
130
|
+
void _root(index id) {
|
|
131
|
+
const Node &p = forest_[id];
|
|
132
|
+
for (index chID : p.children) {
|
|
133
|
+
Node &ch = forest_[chID];
|
|
134
|
+
ch.children.erase(id);
|
|
135
|
+
ch.parent = id;
|
|
136
|
+
_root(chID);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
void _reroot(index id) {
|
|
141
|
+
index newParent = -1;
|
|
142
|
+
index current = id;
|
|
143
|
+
index oldParent = forest_[id].parent;
|
|
144
|
+
forest_[current].parent = newParent;
|
|
145
|
+
forest_[current].children.insert(oldParent);
|
|
146
|
+
newParent = current;
|
|
147
|
+
current = oldParent;
|
|
148
|
+
oldParent = forest_[current].parent;
|
|
149
|
+
while (oldParent != -1) {
|
|
150
|
+
forest_[current].parent = newParent;
|
|
151
|
+
forest_[current].children.erase(newParent);
|
|
152
|
+
forest_[current].children.insert(oldParent);
|
|
153
|
+
newParent = current;
|
|
154
|
+
current = oldParent;
|
|
155
|
+
oldParent = forest_[current].parent;
|
|
156
|
+
}
|
|
157
|
+
forest_[current].parent = newParent;
|
|
158
|
+
forest_[current].children.erase(newParent);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
std::pair<index, index> _get_edge(index id1, index id2) const {
|
|
162
|
+
return std::make_pair(std::min(id1, id2), std::max(id1, id2));
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
class Naive_merge_forest {
|
|
167
|
+
public:
|
|
168
|
+
using index = int;
|
|
169
|
+
|
|
170
|
+
Naive_merge_forest() {}
|
|
171
|
+
|
|
172
|
+
Naive_merge_forest(unsigned int numberOfSimplices, unsigned int numberOfVertices)
|
|
173
|
+
: forest_(numberOfVertices * 2 - 1),
|
|
174
|
+
barcode_(numberOfSimplices, numberOfVertices),
|
|
175
|
+
positionToID_(numberOfSimplices, -1),
|
|
176
|
+
nextVertexIndex_(0),
|
|
177
|
+
nextEdgeIndex_(numberOfVertices),
|
|
178
|
+
minimumSpanningForest_(numberOfVertices) {}
|
|
179
|
+
|
|
180
|
+
friend void swap(Naive_merge_forest &mf1, Naive_merge_forest &mf2) {
|
|
181
|
+
mf1.forest_.swap(mf2.forest_);
|
|
182
|
+
swap(mf1.barcode_, mf2.barcode_);
|
|
183
|
+
mf1.positionToID_.swap(mf2.positionToID_);
|
|
184
|
+
std::swap(mf1.nextVertexIndex_, mf2.nextVertexIndex_);
|
|
185
|
+
std::swap(mf1.nextEdgeIndex_, mf2.nextEdgeIndex_);
|
|
186
|
+
swap(mf1.minimumSpanningForest_, mf2.minimumSpanningForest_);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// assumes that merge tree is constructed fully with add_edge before any swap
|
|
190
|
+
// is done with vine
|
|
191
|
+
bool add_edge(index edgeIndex, index firstVertexIndex, index secondVertexIndex) {
|
|
192
|
+
index r1 = _get_root(positionToID_[firstVertexIndex]);
|
|
193
|
+
index r2 = _get_root(positionToID_[secondVertexIndex]);
|
|
194
|
+
|
|
195
|
+
if (r1 == r2) {
|
|
196
|
+
barcode_.add_positive_edge(edgeIndex);
|
|
197
|
+
return false; // positive edge
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
assert(positionToID_[edgeIndex] == -1 && "Edge was already added");
|
|
201
|
+
positionToID_[edgeIndex] = nextEdgeIndex_;
|
|
202
|
+
|
|
203
|
+
forest_[r1].parent = nextEdgeIndex_;
|
|
204
|
+
forest_[r2].parent = nextEdgeIndex_;
|
|
205
|
+
forest_[nextEdgeIndex_].leftChild = r1;
|
|
206
|
+
forest_[nextEdgeIndex_].rightChild = r2;
|
|
207
|
+
index rep1 = _is_vertex(r1) ? r1 : forest_[r1].representative;
|
|
208
|
+
index rep2 = _is_vertex(r2) ? r2 : forest_[r2].representative;
|
|
209
|
+
forest_[nextEdgeIndex_].representative = rep1 < rep2 ? rep1 : rep2;
|
|
210
|
+
index pair =
|
|
211
|
+
(forest_[nextEdgeIndex_].representative == rep1) ? forest_[rep2].representative : forest_[rep1].representative;
|
|
212
|
+
barcode_.add_negative_edge(pair, edgeIndex);
|
|
213
|
+
|
|
214
|
+
++nextEdgeIndex_;
|
|
215
|
+
|
|
216
|
+
minimumSpanningForest_.add_edge(positionToID_[firstVertexIndex], positionToID_[secondVertexIndex], edgeIndex);
|
|
217
|
+
|
|
218
|
+
return true; // negative edge
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
void add_vertex(index vertexIndex) {
|
|
222
|
+
positionToID_[vertexIndex] = nextVertexIndex_;
|
|
223
|
+
forest_[nextVertexIndex_++].representative = vertexIndex;
|
|
224
|
+
barcode_.add_vertex(vertexIndex);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
void initialize() {
|
|
228
|
+
barcode_.barcode_.resize(barcode_.nextBarIndex_);
|
|
229
|
+
minimumSpanningForest_.root();
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
void vertex_swap(index position) {
|
|
233
|
+
index nca = _get_nearest_common_ancestor(positionToID_[position], positionToID_[position + 1]);
|
|
234
|
+
|
|
235
|
+
if (nca == -1) { // not in the same connected component
|
|
236
|
+
barcode_.birth_birth_swap(position);
|
|
237
|
+
} else {
|
|
238
|
+
index rightRep = _is_vertex(forest_[nca].rightChild) ? forest_[nca].rightChild
|
|
239
|
+
: forest_[forest_[nca].rightChild].representative;
|
|
240
|
+
index leftRep =
|
|
241
|
+
_is_vertex(forest_[nca].leftChild) ? forest_[nca].leftChild : forest_[forest_[nca].leftChild].representative;
|
|
242
|
+
index ncaPairID = (forest_[nca].representative == rightRep) ? leftRep : rightRep;
|
|
243
|
+
index ncaPos = barcode_.death(forest_[ncaPairID].representative);
|
|
244
|
+
|
|
245
|
+
index e1 = barcode_.death(position);
|
|
246
|
+
index e2 = barcode_.death(position + 1);
|
|
247
|
+
|
|
248
|
+
if ((e1 != -1 && e1 < ncaPos) || (e2 != -1 && e2 < ncaPos)) {
|
|
249
|
+
barcode_.birth_birth_swap(position);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
_update_representative(nca, positionToID_[position], positionToID_[position + 1]);
|
|
254
|
+
std::swap(forest_[positionToID_[position]].representative, forest_[positionToID_[position + 1]].representative);
|
|
255
|
+
std::swap(positionToID_[position], positionToID_[position + 1]);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
void vertex_edge_swap(index position, index eV1Position, index eV2Position) {
|
|
259
|
+
if (_is_positive_edge(position + 1)) {
|
|
260
|
+
barcode_.birth_birth_swap(position);
|
|
261
|
+
} else {
|
|
262
|
+
barcode_.birth_death_swap(position);
|
|
263
|
+
minimumSpanningForest_.update_weight(positionToID_[eV1Position], positionToID_[eV2Position], position);
|
|
264
|
+
}
|
|
265
|
+
forest_[positionToID_[position]].representative = position + 1;
|
|
266
|
+
std::swap(positionToID_[position], positionToID_[position + 1]);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
void edge_vertex_swap(index position, index eV1Position, index eV2Position) {
|
|
270
|
+
if (_is_positive_edge(position)) {
|
|
271
|
+
barcode_.birth_birth_swap(position);
|
|
272
|
+
} else {
|
|
273
|
+
barcode_.death_birth_swap(position);
|
|
274
|
+
minimumSpanningForest_.update_weight(positionToID_[eV1Position], positionToID_[eV2Position], position + 1);
|
|
275
|
+
}
|
|
276
|
+
forest_[positionToID_[position + 1]].representative = position;
|
|
277
|
+
std::swap(positionToID_[position], positionToID_[position + 1]);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
void edge_edge_swap(index position, index e1V1Position, index e1V2Position, index e2V1Position, index e2V2Position) {
|
|
281
|
+
if (_is_positive_edge(position)) {
|
|
282
|
+
_pos_edge_edge_switch(position, e2V1Position, e2V2Position);
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
if (_is_positive_edge(position + 1)) {
|
|
287
|
+
_neg_edge_pos_edge_switch(position, e1V1Position, e1V2Position, e2V1Position, e2V2Position);
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
_neg_edge_neg_edge_switch(position, e1V1Position, e1V2Position, e2V1Position, e2V2Position);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
const std::vector<Bar> &get_barcode() const { return barcode_.barcode_; }
|
|
295
|
+
|
|
296
|
+
int get_dimension(index position) { return !_is_vertex(positionToID_[position]); }
|
|
297
|
+
|
|
298
|
+
inline friend std::ostream &operator<<(std::ostream &stream, Naive_merge_forest &structure) {
|
|
299
|
+
for (unsigned int i = 0; i < structure.forest_.size(); ++i) {
|
|
300
|
+
if (structure.forest_[i].parent == -1) structure._print_subtree(stream, "", i, false);
|
|
301
|
+
}
|
|
302
|
+
structure.minimumSpanningForest_.print(stream);
|
|
303
|
+
return stream;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
private:
|
|
307
|
+
struct Node {
|
|
308
|
+
index parent = -1;
|
|
309
|
+
index leftChild = -1;
|
|
310
|
+
index rightChild = -1;
|
|
311
|
+
index representative = -1; // cc rep for edges, position for vertices
|
|
312
|
+
};
|
|
313
|
+
|
|
314
|
+
struct Barcode {
|
|
315
|
+
Barcode() {}
|
|
316
|
+
|
|
317
|
+
Barcode(int numberOfSimplices, [[maybe_unused]] int numberOfVertices)
|
|
318
|
+
: barcode_(numberOfSimplices), positionToBar_(numberOfSimplices), nextBarIndex_(0) {}
|
|
319
|
+
|
|
320
|
+
friend void swap(Barcode &mf1, Barcode &mf2) {
|
|
321
|
+
mf1.barcode_.swap(mf2.barcode_);
|
|
322
|
+
mf1.positionToBar_.swap(mf2.positionToBar_);
|
|
323
|
+
std::swap(mf1.nextBarIndex_, mf2.nextBarIndex_);
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
void add_birth(index birth) {
|
|
327
|
+
positionToBar_[birth] = nextBarIndex_;
|
|
328
|
+
barcode_[nextBarIndex_].birth = birth;
|
|
329
|
+
++nextBarIndex_;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
void add_vertex(index birth) {
|
|
333
|
+
barcode_[nextBarIndex_].dim = 0;
|
|
334
|
+
add_birth(birth);
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
void add_positive_edge(index birth) {
|
|
338
|
+
barcode_[nextBarIndex_].dim = 1;
|
|
339
|
+
add_birth(birth);
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
void add_negative_edge(index birth, index death) {
|
|
343
|
+
index b = positionToBar_[birth];
|
|
344
|
+
positionToBar_[death] = b;
|
|
345
|
+
barcode_[b].death = death;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
void birth_birth_swap(index position) {
|
|
349
|
+
std::swap(barcode_[positionToBar_[position]].birth, barcode_[positionToBar_[position + 1]].birth);
|
|
350
|
+
std::swap(positionToBar_[position], positionToBar_[position + 1]);
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
void birth_death_swap(index position) {
|
|
354
|
+
std::swap(barcode_[positionToBar_[position]].birth, barcode_[positionToBar_[position + 1]].death);
|
|
355
|
+
std::swap(positionToBar_[position], positionToBar_[position + 1]);
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
void death_death_swap(index position) {
|
|
359
|
+
std::swap(barcode_[positionToBar_[position]].death, barcode_[positionToBar_[position + 1]].death);
|
|
360
|
+
std::swap(positionToBar_[position], positionToBar_[position + 1]);
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
void death_birth_swap(index position) {
|
|
364
|
+
std::swap(barcode_[positionToBar_[position]].death, barcode_[positionToBar_[position + 1]].birth);
|
|
365
|
+
std::swap(positionToBar_[position], positionToBar_[position + 1]);
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
index death(index birth) { return barcode_[positionToBar_[birth]].death; }
|
|
369
|
+
|
|
370
|
+
std::vector<Bar> barcode_;
|
|
371
|
+
std::vector<index> positionToBar_;
|
|
372
|
+
index nextBarIndex_;
|
|
373
|
+
};
|
|
374
|
+
|
|
375
|
+
std::vector<Node> forest_;
|
|
376
|
+
Barcode barcode_;
|
|
377
|
+
std::vector<index> positionToID_;
|
|
378
|
+
index nextVertexIndex_;
|
|
379
|
+
index nextEdgeIndex_;
|
|
380
|
+
Naive_bottleneck_forest minimumSpanningForest_;
|
|
381
|
+
|
|
382
|
+
bool _is_vertex(index nodeIndex) const {
|
|
383
|
+
const Node &n = forest_[nodeIndex];
|
|
384
|
+
return n.leftChild == -1 && n.rightChild == -1;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
bool _is_positive_edge(index position) const { return positionToID_[position] == -1; }
|
|
388
|
+
|
|
389
|
+
index _get_root(index node) const {
|
|
390
|
+
while (forest_[node].parent != -1) {
|
|
391
|
+
node = forest_[node].parent;
|
|
392
|
+
}
|
|
393
|
+
return node;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
index _get_nearest_common_ancestor(index firstIndex, index secondIndex) const {
|
|
397
|
+
std::set<index> path;
|
|
398
|
+
index r = firstIndex;
|
|
399
|
+
path.insert(r);
|
|
400
|
+
while (forest_[r].parent != -1) {
|
|
401
|
+
r = forest_[r].parent;
|
|
402
|
+
path.insert(r);
|
|
403
|
+
}
|
|
404
|
+
r = secondIndex;
|
|
405
|
+
while (r != -1 && path.find(r) == path.end()) {
|
|
406
|
+
r = forest_[r].parent;
|
|
407
|
+
}
|
|
408
|
+
return r;
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
index _is_ancestor_of(index ancID, index descID, index endID = -1) const {
|
|
412
|
+
index r = descID;
|
|
413
|
+
while (r != endID && forest_[r].parent != ancID) {
|
|
414
|
+
r = forest_[r].parent;
|
|
415
|
+
}
|
|
416
|
+
return r; // either returns endID or the child of the ancestor it came
|
|
417
|
+
// through.
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
void _update_representative(index pos, index oldRep, index newRep) {
|
|
421
|
+
index r = pos;
|
|
422
|
+
while (r != -1 && forest_[r].representative == oldRep) {
|
|
423
|
+
forest_[r].representative = newRep;
|
|
424
|
+
r = forest_[r].parent;
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
void _neg_edge_neg_edge_switch(index position,
|
|
429
|
+
index e1V1Position,
|
|
430
|
+
index e1V2Position,
|
|
431
|
+
index e2V1Position,
|
|
432
|
+
index e2V2Position) {
|
|
433
|
+
minimumSpanningForest_.update_weight(positionToID_[e1V1Position], positionToID_[e1V2Position], position + 1);
|
|
434
|
+
minimumSpanningForest_.update_weight(positionToID_[e2V1Position], positionToID_[e2V2Position], position);
|
|
435
|
+
|
|
436
|
+
index e1 = positionToID_[position];
|
|
437
|
+
index e2 = positionToID_[position + 1];
|
|
438
|
+
|
|
439
|
+
if (forest_[e2].leftChild != e1 && forest_[e2].rightChild != e1) {
|
|
440
|
+
barcode_.death_death_swap(position);
|
|
441
|
+
std::swap(positionToID_[position], positionToID_[position + 1]);
|
|
442
|
+
return;
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
index t1 = forest_[e1].leftChild;
|
|
446
|
+
index t2 = forest_[e1].rightChild;
|
|
447
|
+
index t3;
|
|
448
|
+
if (forest_[e2].leftChild == e1)
|
|
449
|
+
t3 = forest_[e2].rightChild;
|
|
450
|
+
else
|
|
451
|
+
t3 = forest_[e2].leftChild;
|
|
452
|
+
|
|
453
|
+
index u = _is_vertex(t1) ? t1 : forest_[t1].representative;
|
|
454
|
+
index v = _is_vertex(t2) ? t2 : forest_[t2].representative;
|
|
455
|
+
index w = _is_vertex(t3) ? t3 : forest_[t3].representative;
|
|
456
|
+
if (forest_[u].representative < forest_[v].representative) {
|
|
457
|
+
std::swap(u, v);
|
|
458
|
+
std::swap(t1, t2);
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
index t = _is_ancestor_of(e1, positionToID_[e2V1Position], e2);
|
|
462
|
+
if (t != t1 && t != t2) t = _is_ancestor_of(e1, positionToID_[e2V2Position], e2);
|
|
463
|
+
|
|
464
|
+
if (t == t1) {
|
|
465
|
+
forest_[e1].leftChild = t1;
|
|
466
|
+
forest_[e2].leftChild = t2;
|
|
467
|
+
forest_[e1].representative = (forest_[u].representative < forest_[w].representative) ? u : w;
|
|
468
|
+
forest_[e2].representative = (forest_[forest_[e1].representative].representative < forest_[v].representative)
|
|
469
|
+
? forest_[e1].representative
|
|
470
|
+
: v;
|
|
471
|
+
forest_[t2].parent = e2;
|
|
472
|
+
} else {
|
|
473
|
+
forest_[e1].leftChild = t2;
|
|
474
|
+
forest_[e2].leftChild = t1;
|
|
475
|
+
forest_[e1].representative = (forest_[v].representative < forest_[w].representative) ? v : w;
|
|
476
|
+
forest_[e2].representative = (forest_[forest_[e1].representative].representative < forest_[u].representative)
|
|
477
|
+
? forest_[e1].representative
|
|
478
|
+
: u;
|
|
479
|
+
forest_[t1].parent = e2;
|
|
480
|
+
}
|
|
481
|
+
forest_[e1].rightChild = t3;
|
|
482
|
+
forest_[e2].rightChild = e1;
|
|
483
|
+
forest_[t3].parent = e1;
|
|
484
|
+
|
|
485
|
+
if (t == t2 || forest_[u].representative < forest_[w].representative) {
|
|
486
|
+
barcode_.death_death_swap(position);
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
void _neg_edge_pos_edge_switch(index position,
|
|
491
|
+
index e1V1Position,
|
|
492
|
+
index e1V2Position,
|
|
493
|
+
index e2V1Position,
|
|
494
|
+
index e2V2Position) {
|
|
495
|
+
index bottleneck =
|
|
496
|
+
minimumSpanningForest_.get_bootleneck_weight(positionToID_[e2V1Position], positionToID_[e2V2Position]);
|
|
497
|
+
|
|
498
|
+
if (bottleneck == position) {
|
|
499
|
+
minimumSpanningForest_.swap_out_edges(positionToID_[e1V1Position],
|
|
500
|
+
positionToID_[e1V2Position],
|
|
501
|
+
positionToID_[e2V1Position],
|
|
502
|
+
positionToID_[e2V2Position],
|
|
503
|
+
position);
|
|
504
|
+
} else {
|
|
505
|
+
minimumSpanningForest_.update_weight(positionToID_[e1V1Position], positionToID_[e1V2Position], position + 1);
|
|
506
|
+
barcode_.death_birth_swap(position);
|
|
507
|
+
std::swap(positionToID_[position], positionToID_[position + 1]);
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
void _pos_edge_edge_switch(index position, index e2V1Position, index e2V2Position) {
|
|
512
|
+
if (_is_positive_edge(position + 1)) {
|
|
513
|
+
barcode_.birth_birth_swap(position);
|
|
514
|
+
} else {
|
|
515
|
+
barcode_.birth_death_swap(position);
|
|
516
|
+
minimumSpanningForest_.update_weight(positionToID_[e2V1Position], positionToID_[e2V2Position], position);
|
|
517
|
+
std::swap(positionToID_[position], positionToID_[position + 1]);
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
void _print_subtree(std::ostream &stream, const std::string &prefix, index id, bool isLeft) {
|
|
522
|
+
if (id != -1) {
|
|
523
|
+
stream << prefix;
|
|
524
|
+
stream << (isLeft ? "├──" : "└──");
|
|
525
|
+
|
|
526
|
+
// print the value of the node
|
|
527
|
+
stream << id << std::endl;
|
|
528
|
+
|
|
529
|
+
// enter the next tree level - left and right branch
|
|
530
|
+
_print_subtree(stream, prefix + (isLeft ? "│ " : " "), forest_[id].leftChild, true);
|
|
531
|
+
_print_subtree(stream, prefix + (isLeft ? "│ " : " "), forest_[id].rightChild, false);
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
};
|
|
535
|
+
|
|
536
|
+
#endif // H0V_MERGE_TREE_H
|