summaryrefslogtreecommitdiff
path: root/src/Persistent_cohomology/example/plain_homology.cpp
diff options
context:
space:
mode:
authorvrouvrea <vrouvrea@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2016-05-24 15:17:14 +0000
committervrouvrea <vrouvrea@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2016-05-24 15:17:14 +0000
commit6dae848dd4672fae2c9a6b5ae9059b44855e26a3 (patch)
tree3d5783eb979ef75703005c44de24e78dacbb09f9 /src/Persistent_cohomology/example/plain_homology.cpp
parentb16152118574b9f2127df3b7f4495f75f3b079c1 (diff)
get_persistence and Betti numbers
git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/get_persistence@1190 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 6da18e680111a9a1ad7753779a94a1e8ce49702c
Diffstat (limited to 'src/Persistent_cohomology/example/plain_homology.cpp')
-rw-r--r--src/Persistent_cohomology/example/plain_homology.cpp51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/Persistent_cohomology/example/plain_homology.cpp b/src/Persistent_cohomology/example/plain_homology.cpp
index 0a692717..9e5adb5d 100644
--- a/src/Persistent_cohomology/example/plain_homology.cpp
+++ b/src/Persistent_cohomology/example/plain_homology.cpp
@@ -24,6 +24,7 @@
#include <gudhi/Persistent_cohomology.h>
#include <iostream>
+#include <vector>
using namespace Gudhi;
@@ -41,6 +42,24 @@ struct MyOptions : Simplex_tree_options_full_featured {
};
typedef Simplex_tree<MyOptions> ST;
+ /*
+ * Compare two intervals by dimension, then by length.
+ */
+ struct cmp_intervals_by_dim_then_length {
+ explicit cmp_intervals_by_dim_then_length(ST * sc)
+ : sc_(sc) {
+ }
+ template<typename Persistent_interval>
+ bool operator()(const Persistent_interval & p1, const Persistent_interval & p2) {
+ if (sc_->dimension(get < 0 > (p1)) == sc_->dimension(get < 0 > (p2)))
+ return (sc_->filtration(get < 1 > (p1)) - sc_->filtration(get < 0 > (p1))
+ > sc_->filtration(get < 1 > (p2)) - sc_->filtration(get < 0 > (p2)));
+ else
+ return (sc_->dimension(get < 0 > (p1)) > sc_->dimension(get < 0 > (p2)));
+ }
+ ST* sc_;
+ };
+
int main() {
ST st;
@@ -81,4 +100,36 @@ int main() {
// 2 1 0 inf
// means that in Z/2Z-homology, the Betti numbers are b0=2 and b1=1.
pcoh.output_diagram();
+
+
+ // ********************************************************
+ // get_persistence
+ // ********************************************************
+ std::cout << std::endl;
+ std::cout << std::endl;
+
+ // First version
+ std::vector<int> betti_numbers = pcoh.betti_numbers();
+ std::cout << "The Betti numbers are : ";
+ for (std::size_t i = 0; i < betti_numbers.size(); i++)
+ std::cout << "b" << i << " = " << betti_numbers[i] << " ; ";
+ std::cout << std::endl;
+
+ // Second version
+ std::cout << "The Betti numbers are : ";
+ for (int i = 0; i < st.dimension(); i++)
+ std::cout << "b" << i << " = " << pcoh.betti_number(i) << " ; ";
+ std::cout << std::endl;
+
+ // Get persistence
+ cmp_intervals_by_dim_then_length cmp(&st);
+ auto persistent_pairs = pcoh.get_persistent_pairs();
+ std::sort(std::begin(persistent_pairs), std::end(persistent_pairs), cmp);
+ for (auto pair : persistent_pairs) {
+ std::cout << st.dimension(get<0>(pair)) << " "
+ << st.filtration(get<0>(pair)) << " "
+ << st.filtration(get<1>(pair)) << std::endl;
+ }
+
+
}