summaryrefslogtreecommitdiff
path: root/src/python/include/Persistent_cohomology_interface.h
diff options
context:
space:
mode:
authormathieu <mathieu.carriere3@gmail.com>2020-01-16 15:46:41 -0500
committermathieu <mathieu.carriere3@gmail.com>2020-01-16 15:46:41 -0500
commit436a7fbe36a9de6a969afd5978c3d496773a8690 (patch)
treea753b0c4c0648bac78b8e8b9cf11f1522866bd32 /src/python/include/Persistent_cohomology_interface.h
parentcabc43b34723efa7640313348b844eabe9971e38 (diff)
added wrapper functions
Diffstat (limited to 'src/python/include/Persistent_cohomology_interface.h')
-rw-r--r--src/python/include/Persistent_cohomology_interface.h76
1 files changed, 76 insertions, 0 deletions
diff --git a/src/python/include/Persistent_cohomology_interface.h b/src/python/include/Persistent_cohomology_interface.h
index 8c79e6f3..774eb56a 100644
--- a/src/python/include/Persistent_cohomology_interface.h
+++ b/src/python/include/Persistent_cohomology_interface.h
@@ -73,6 +73,82 @@ persistent_cohomology::Persistent_cohomology<FilteredComplex, persistent_cohomol
return persistence;
}
+ std::vector<std::pair<int, std::pair<std::pair<double, std::vector<int>>, std::pair<double,std::vector<int>>>>> get_persistence_generators(int homology_coeff_field,
+ double min_persistence) {
+ persistent_cohomology::Persistent_cohomology<FilteredComplex,
+ persistent_cohomology::Field_Zp>::init_coefficients(homology_coeff_field);
+ persistent_cohomology::Persistent_cohomology<FilteredComplex,
+ persistent_cohomology::Field_Zp>::compute_persistent_cohomology(min_persistence);
+
+ // Custom sort and output persistence
+ cmp_intervals_by_dim_then_length cmp(stptr_);
+ auto persistent_pairs = persistent_cohomology::Persistent_cohomology<FilteredComplex,
+ persistent_cohomology::Field_Zp>::get_persistent_pairs();
+ std::sort(std::begin(persistent_pairs), std::end(persistent_pairs), cmp);
+
+ std::vector<std::pair<int, std::pair<std::pair<double, std::vector<int>>, std::pair<double,std::vector<int>>>>> persistence;
+ for (auto pair : persistent_pairs) {
+ std::vector<int> splx0, splx1;
+ for (auto vertex : stptr_->simplex_vertex_range(get<0>(pair))){splx0.push_back(vertex);}
+ if (isfinite(stptr_->filtration(get<1>(pair)))){ for (auto vertex : stptr_->simplex_vertex_range(get<1>(pair))){splx1.push_back(vertex);}}
+ persistence.push_back(std::make_pair(stptr_->dimension(get<0>(pair)), std::make_pair(std::make_pair(stptr_->filtration(get<0>(pair)), splx0), std::make_pair(stptr_->filtration(get<1>(pair)), splx1))));
+ }
+ return persistence;
+ }
+
+ void top_dimensional_cofaces(std::vector<int> & cofaces, int splx){
+ if (stptr_->dimension(stptr_->simplex(splx)) == stptr_->dimension()){cofaces.push_back(stptr_->simplex(splx));}
+ else{ for (auto v : stptr_->coboundary_simplex_range(stptr_->simplex(splx))){top_dimensional_cofaces(cofaces, stptr_->key(v));} }
+ }
+
+ std::vector<std::pair<int, std::pair<std::pair<double, int>, std::pair<double, int>>>> get_persistence_cubical_generators(int homology_coeff_field,
+ double min_persistence) {
+
+ // Gather all top-dimensional cells and store their simplex handles
+ std::vector<int> max_splx; for (auto splx : stptr_->filtration_simplex_range()){ if (stptr_->dimension(splx) == stptr_->dimension()) max_splx.push_back(splx); }
+ // Sort these simplex handles and compute the ordering function
+ // This function allows to go directly from the simplex handle to the position of the corresponding top-dimensional cell in the input data
+ std::map<int, int> order; std::sort(max_splx.begin(), max_splx.end()); for (int i = 0; i < max_splx.size(); i++) order.insert(std::make_pair(max_splx[i], i));
+
+ persistent_cohomology::Persistent_cohomology<FilteredComplex,
+ persistent_cohomology::Field_Zp>::init_coefficients(homology_coeff_field);
+ persistent_cohomology::Persistent_cohomology<FilteredComplex,
+ persistent_cohomology::Field_Zp>::compute_persistent_cohomology(min_persistence);
+
+ // Custom sort and output persistence
+ cmp_intervals_by_dim_then_length cmp(stptr_);
+ auto persistent_pairs = persistent_cohomology::Persistent_cohomology<FilteredComplex,
+ persistent_cohomology::Field_Zp>::get_persistent_pairs();
+ std::sort(std::begin(persistent_pairs), std::end(persistent_pairs), cmp);
+
+ std::vector<std::pair<int, std::pair<std::pair<double, int>, std::pair<double, int>>>> persistence;
+ for (auto pair : persistent_pairs) {
+
+ int splx0, splx1;
+
+ double f0 = stptr_->filtration(get<0>(pair));
+ // Recursively get the top-dimensional cells / cofaces associated to the persistence generator
+ std::vector<int> faces0; top_dimensional_cofaces(faces0, stptr_->key(get<0>(pair)));
+ // Find the top-dimensional cell / coface with the same filtration value
+ int cf; for (int i = 0; i < faces0.size(); i++){ if (stptr_->filtration(faces0[i]) == f0){cf = i; break;}}
+ // Retrieve the index of the corresponding top-dimensional cell in the input data
+ splx0 = order[faces0[cf]];
+
+ if (isfinite(stptr_->filtration(get<1>(pair)))){
+ double f1 = stptr_->filtration(get<1>(pair));
+ // Recursively get the top-dimensional cells / cofaces associated to the persistence generator
+ std::vector<int> faces1; top_dimensional_cofaces(faces1, stptr_->key(get<1>(pair)));
+ // Find the top-dimensional cell / coface with the same filtration value
+ int cf; for (int i = 0; i < faces0.size(); i++){ if (stptr_->filtration(faces0[i]) == f0){cf = i; break;}}
+ // Retrieve the index of the corresponding top-dimensional cell in the input data
+ splx1 = order[faces1[cf]];
+ }
+
+ persistence.push_back(std::make_pair(stptr_->dimension(get<0>(pair)), std::make_pair(std::make_pair(stptr_->filtration(get<0>(pair)), splx0), std::make_pair(stptr_->filtration(get<1>(pair)), splx1))));
+ }
+ return persistence;
+ }
+
std::vector<std::pair<std::vector<int>, std::vector<int>>> persistence_pairs() {
auto pairs = persistent_cohomology::Persistent_cohomology<FilteredComplex,
persistent_cohomology::Field_Zp>::get_persistent_pairs();