From 82c0652b06949b0b002781688565d7ecf30f04fe Mon Sep 17 00:00:00 2001 From: pdlotko Date: Thu, 8 Feb 2018 10:37:21 +0000 Subject: Fixed comments from Marc and Vincent. git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/rips_complex_from_correlation_matrix@3234 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 8b5e08c38cd05512ba8b2824f13a62d35f39bac3 --- ...e_one_skeleton_rips_from_correlation_matrix.cpp | 10 +++--- .../rips_correlation_matrix_persistence.cpp | 40 +++++++++++----------- 2 files changed, 25 insertions(+), 25 deletions(-) (limited to 'src/Rips_complex') 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 index f66c4b04..a34ce15c 100644 --- 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 @@ -40,11 +40,11 @@ int main() { std::cerr << "The input matrix is not a correlation matrix. The program will now terminate.\n"; throw "The input matrix is not a correlation matrix. The program will now terminate.\n"; } - correlations[i][j] = 1 - correlations[i][j]; - } - //Here we make sure that we will get the treshold value equal to maximal - //distance in the matrix. - if ( correlations[i][j] > threshold )threshold = correlations[i][j]; + correlations[i][j] = 1 - correlations[i][j]; + //Here we make sure that we will get the treshold value equal to maximal + //distance in the matrix. + if ( correlations[i][j] > threshold )threshold = correlations[i][j]; + } } //----------------------------------------------------------------------------- diff --git a/src/Rips_complex/utilities/rips_correlation_matrix_persistence.cpp b/src/Rips_complex/utilities/rips_correlation_matrix_persistence.cpp index 3fe0edb0..95bce491 100644 --- a/src/Rips_complex/utilities/rips_correlation_matrix_persistence.cpp +++ b/src/Rips_complex/utilities/rips_correlation_matrix_persistence.cpp @@ -24,7 +24,7 @@ #include #include #include -#include +#include #include @@ -57,28 +57,23 @@ int main(int argc, char* argv[]) { Correlation_matrix correlations = Gudhi::read_lower_triangular_matrix_from_csv_file(csv_matrix_file); + Filtration_value threshold = 0; + // Given a correlation matrix M, we compute component-wise M'[i,j] = 1-M[i,j] to get 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"; + //Here we make sure that the values of corelations lie between -1 and 1. + //If not, we throw an exception. + if ((correlations[i][j] < -1) || (correlations[i][j] > 1)) + { + std::cerr << "The input matrix is not a correlation matrix. The program will now terminate. \n"; + throw "The input matrix is not a correlation matrix. The program will now terminate. \n"; } + if ( correlations[i][j] > threshold ) threshold = correlations[i][j]; } } - Filtration_value threshold; - // If the correlation_min, being minimal corelation is in the range [0,1], - // change it to 1-correlation_min - if ((correlation_min >= 0) && (correlation_min <= 1)) { - threshold = 1 - correlation_min; - } else { - std::cout - << "Wrong value of the treshold corelation (should be between 0 and 1). The program will now terminate.\n"; - return 1; - } - Rips_complex rips_complex_from_file(correlations, threshold); // Construct the Rips complex in a Simplex Tree @@ -95,10 +90,16 @@ int main(int argc, char* argv[]) { Persistent_cohomology pcoh(simplex_tree); // initializes the coefficient field for homology pcoh.init_coefficients(p); - // compute persistence + //compute persistence pcoh.compute_persistent_cohomology(min_persistence); - - // invert the persistence diagram + + + //invert the persistence diagram. The reason for this procedure is the following: + //The input to the program is a corelation matrix M. When processing it, it is + //turned into 1-M and the obtained persistence intervals are in '1-M' units. + //Below we reverse every (birth,death) pair into (1-birth, 1-death) pair + //so that the input and the output to the program is expressed in the same + //units. auto pairs = pcoh.get_persistent_pairs(); std::vector processed_persistence_intervals; processed_persistence_intervals.reserve(pairs.size()); @@ -118,8 +119,7 @@ int main(int argc, char* argv[]) { write_persistence_intervals_to_stream(processed_persistence_intervals); } else { std::ofstream out(filediag); - write_persistence_intervals_to_stream(processed_persistence_intervals, out); - out.close(); + write_persistence_intervals_to_stream(processed_persistence_intervals, out); } return 0; } -- cgit v1.2.3