summaryrefslogtreecommitdiff
path: root/src/Simplex_tree/include/gudhi/Simplex_tree.h
diff options
context:
space:
mode:
authormathieu <mathieu.carriere3@gmail.com>2020-02-04 19:44:52 -0500
committermathieu <mathieu.carriere3@gmail.com>2020-02-04 19:44:52 -0500
commit360cc2cc31e9e81b99f5c21aa2b4e79b066baabf (patch)
tree7632ef2dc88fef03116e326a497e61f4e811299a /src/Simplex_tree/include/gudhi/Simplex_tree.h
parentf2020f6bb3a4d2bbd774aa630151ef1db53ac4f8 (diff)
fixed Vincent's comments
Diffstat (limited to 'src/Simplex_tree/include/gudhi/Simplex_tree.h')
-rw-r--r--src/Simplex_tree/include/gudhi/Simplex_tree.h74
1 files changed, 58 insertions, 16 deletions
diff --git a/src/Simplex_tree/include/gudhi/Simplex_tree.h b/src/Simplex_tree/include/gudhi/Simplex_tree.h
index 301f7aae..42cf4246 100644
--- a/src/Simplex_tree/include/gudhi/Simplex_tree.h
+++ b/src/Simplex_tree/include/gudhi/Simplex_tree.h
@@ -1467,34 +1467,68 @@ class Simplex_tree {
}
}
- /** \brief Retrieve good values for extended persistence, and separate the diagrams into the ordinary, relative, extended+ and extended- subdiagrams. Need extend_filtration to be called first!
- * @param[in] dgm Persistence diagram obtained after calling this->extend_filtration and this->get_persistence.
- * @return A vector of four persistence diagrams. The first one is Ordinary, the second one is Relative, the third one is Extended+ and the fourth one is Extended-.
+ /** \brief Retrieve good values for extended persistence, and separate the
+ * diagrams into the ordinary, relative, extended+ and extended- subdiagrams.
+ * Need extend_filtration to be called first!
+ * @param[in] dgm Persistence diagram obtained after calling this->extend_filtration
+ * and this->get_persistence.
+ * @return A vector of four persistence diagrams. The first one is Ordinary, the
+ * second one is Relative, the third one is Extended+ and the fourth one is Extended-.
*/
std::vector<std::vector<std::pair<int, std::pair<double, double>>>> compute_extended_persistence_subdiagrams(const std::vector<std::pair<int, std::pair<double, double>>>& dgm){
- std::vector<std::vector<std::pair<int, std::pair<double, double>>>> new_dgm(4); double x, y;
- for(unsigned int i = 0; i < dgm.size(); i++){ int h = dgm[i].first; double px = dgm[i].second.first; double py = dgm[i].second.second;
+ std::vector<std::vector<std::pair<int, std::pair<double, double>>>> new_dgm(4);
+ double x, y;
+ for(unsigned int i = 0; i < dgm.size(); i++){
+ int h = dgm[i].first;
+ double px = dgm[i].second.first;
+ double py = dgm[i].second.second;
if(std::isinf(py)) continue;
else{
- if ((px <= -1) & (py <= -1)){x = minval_ + (maxval_-minval_)*(px + 2); y = minval_ + (maxval_-minval_)*(py + 2); new_dgm[0].push_back(std::make_pair(h, std::make_pair(x,y))); }
- if ((px >= 1) & (py >= 1)){x = minval_ - (maxval_-minval_)*(px - 2); y = minval_ - (maxval_-minval_)*(py - 2); new_dgm[1].push_back(std::make_pair(h, std::make_pair(x,y))); }
- if ((px <= -1) & (py >= 1)){x = minval_ + (maxval_-minval_)*(px + 2); y = minval_ - (maxval_-minval_)*(py - 2);
- if (x <= y) new_dgm[2].push_back(std::make_pair(h, std::make_pair(x,y)));
- else new_dgm[3].push_back(std::make_pair(h, std::make_pair(x,y)));
+ if ((px <= -1) & (py <= -1)){
+ x = minval_ + (maxval_-minval_)*(px + 2);
+ y = minval_ + (maxval_-minval_)*(py + 2);
+ new_dgm[0].push_back(std::make_pair(h, std::make_pair(x,y)));
+ }
+ if ((px >= 1) & (py >= 1)){
+ x = minval_ - (maxval_-minval_)*(px - 2);
+ y = minval_ - (maxval_-minval_)*(py - 2);
+ new_dgm[1].push_back(std::make_pair(h, std::make_pair(x,y)));
+ }
+ if ((px <= -1) & (py >= 1)){
+ x = minval_ + (maxval_-minval_)*(px + 2);
+ y = minval_ - (maxval_-minval_)*(py - 2);
+ if (x <= y){
+ new_dgm[2].push_back(std::make_pair(h, std::make_pair(x,y)));
+ }
+ else{
+ new_dgm[3].push_back(std::make_pair(h, std::make_pair(x,y)));
+ }
}
}
}
return new_dgm;
}
- /** \brief Extend filtration for computing extended persistence. This function only uses the filtration values at the 0-dimensional simplices, and computes the extended persistence diagram induced by the lower-star filtration computed with these values. Note that after calling this function, the filtration values are actually modified. The function compute_extended_persistence_subdiagrams retrieves the original values and separates the extended persistence diagram points w.r.t. their types (Ord, Rel, Ext+, Ext-) and should always be called after computing the persistent homology of the extended simplicial complex.
+ /** \brief Extend filtration for computing extended persistence.
+ * This function only uses the filtration values at the 0-dimensional simplices,
+ * and computes the extended persistence diagram induced by the lower-star filtration
+ * computed with these values. Note that after calling this function, the filtration
+ * values are actually modified. The function compute_extended_persistence_subdiagrams
+ * retrieves the original values and separates the extended persistence diagram points
+ * w.r.t. their types (Ord, Rel, Ext+, Ext-) and should always be called after
+ * computing the persistent homology of the extended simplicial complex.
*/
void extend_filtration() {
// Compute maximum and minimum of filtration values
- int maxvert = -std::numeric_limits<double>::infinity();
+ int maxvert = -std::numeric_limits<int>::infinity();
std::vector<double> filt;
- for (auto sh : this->complex_simplex_range()) {if (this->dimension(sh) == 0){filt.push_back(this->filtration(sh)); maxvert = std::max(*this->simplex_vertex_range(sh).begin(), maxvert);}}
+ for (auto sh : this->complex_simplex_range()) {
+ if (this->dimension(sh) == 0){
+ filt.push_back(this->filtration(sh));
+ maxvert = std::max(*this->simplex_vertex_range(sh).begin(), maxvert);
+ }
+ }
minval_ = *std::min_element(filt.begin(), filt.end());
maxval_ = *std::max_element(filt.begin(), filt.end());
maxvert += 1;
@@ -1502,13 +1536,20 @@ class Simplex_tree {
// Compute vectors of integers corresponding to the Simplex handles
std::vector<std::vector<int> > splxs;
for (auto sh : this->complex_simplex_range()) {
- std::vector<int> vr; for (auto vh : this->simplex_vertex_range(sh)){vr.push_back(vh);}
+ std::vector<int> vr;
+ for (auto vh : this->simplex_vertex_range(sh)){
+ vr.push_back(vh);
+ }
splxs.push_back(vr);
}
// Add point for coning the simplicial complex
int count = this->num_simplices();
- std::vector<int> cone; cone.push_back(maxvert); auto ins = this->insert_simplex(cone, -3); this->assign_key(ins.first, count); count++;
+ std::vector<int> cone;
+ cone.push_back(maxvert);
+ auto ins = this->insert_simplex(cone, -3);
+ this->assign_key(ins.first, count);
+ count++;
// For each simplex
for (auto vr : splxs){
@@ -1531,7 +1572,8 @@ class Simplex_tree {
count++;
}
- this->make_filtration_non_decreasing(); this->initialize_filtration();
+ this->make_filtration_non_decreasing();
+ this->initialize_filtration();
}