summaryrefslogtreecommitdiff
path: root/src/Rips_complex/example
diff options
context:
space:
mode:
authorpdlotko <pdlotko@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2017-09-25 20:28:02 +0000
committerpdlotko <pdlotko@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2017-09-25 20:28:02 +0000
commitf48ae2be7dcd552f44723b3a6b02cc9aae361aca (patch)
treecce66d12d54d23e8400908124f9e0064eaeef2f4 /src/Rips_complex/example
parent1d611ca664d78d3b0b53264c52b04a8396383140 (diff)
a missing file...
git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/rips_complex_from_correlation_matrix@2713 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: ecdf0da96de01e37758e157d84aee13c8825dc0e
Diffstat (limited to 'src/Rips_complex/example')
-rw-r--r--src/Rips_complex/example/example_one_skeleton_rips_from_correlation_matrix.cpp77
1 files changed, 77 insertions, 0 deletions
diff --git a/src/Rips_complex/example/example_one_skeleton_rips_from_correlation_matrix.cpp b/src/Rips_complex/example/example_one_skeleton_rips_from_correlation_matrix.cpp
new file mode 100644
index 00000000..0acdfe83
--- /dev/null
+++ b/src/Rips_complex/example/example_one_skeleton_rips_from_correlation_matrix.cpp
@@ -0,0 +1,77 @@
+#include <gudhi/Rips_complex.h>
+#include <gudhi/Simplex_tree.h>
+#include <gudhi/distance_functions.h>
+
+#include <iostream>
+#include <string>
+#include <vector>
+#include <limits> // for std::numeric_limits
+
+int main() {
+ // Type definitions
+ using Simplex_tree = Gudhi::Simplex_tree<>;
+ using Filtration_value = Simplex_tree::Filtration_value;
+ using Rips_complex = Gudhi::rips_complex::Rips_complex<Filtration_value>;
+ using Distance_matrix = std::vector<std::vector<Filtration_value>>;
+
+ // User defined correlation matrix is:
+ // |1 0.06 0.23 0.01 0.89|
+ // |0.06 1 0.74 0.01 0.61|
+ // |0.23 0.74 1 0.72 0.03|
+ // |0.01 0.01 0.72 1 0.7 |
+ // |0.89 0.61 0.03 0.7 1 |
+
+
+ Distance_matrix correlations;
+ correlations.push_back({});
+ correlations.push_back({0.06});
+ correlations.push_back({0.23, 0.74});
+ correlations.push_back({0.01, 0.01, 0.72});
+ correlations.push_back({0.89, 0.61, 0.03, 0.7});
+
+ // ----------------------------------------------------------------------------
+ // Convert correlation matrix to a distance matrix:
+ // ----------------------------------------------------------------------------
+ for ( size_t i = 0 ; i != correlations.size() ; ++i )
+ {
+ for ( size_t j = 0 ; j != correlations[i].size() ; ++j )
+ {
+ correlations[i][j] = 1-correlations[i][j];
+ if ( correlations[i][j] < 0 )
+ {
+ std::cerr << "The input matrix is not a correlation matrix. \n";
+ throw "The input matrix is not a correlation matrix. \n";
+ }
+ }
+ }
+
+ //-----------------------------------------------------------------------------
+ // Now the correlation matrix is really the distance matrix and can be processed further.
+ //-----------------------------------------------------------------------------
+ Distance_matrix distances = correlations;
+
+ double threshold = 1.0;
+ Rips_complex rips_complex_from_points(distances, threshold);
+
+ Simplex_tree stree;
+ rips_complex_from_points.create_complex(stree, 1);
+ // ----------------------------------------------------------------------------
+ // Display information about the one skeleton Rips complex
+ // ----------------------------------------------------------------------------
+ std::cout << "Rips complex is of dimension " << stree.dimension() <<
+ " - " << stree.num_simplices() << " simplices - " <<
+ stree.num_vertices() << " vertices." << std::endl;
+
+ std::cout << "Iterator on Rips complex simplices in the filtration order, with [filtration value]:" <<
+ std::endl;
+ for (auto f_simplex : stree.filtration_simplex_range()) {
+ std::cout << " ( ";
+ for (auto vertex : stree.simplex_vertex_range(f_simplex)) {
+ std::cout << vertex << " ";
+ }
+ std::cout << ") -> " << "[" << stree.filtration(f_simplex) << "] ";
+ std::cout << std::endl;
+ }
+
+ return 0;
+}