diff options
Diffstat (limited to 'src/Rips_complex')
-rw-r--r-- | src/Rips_complex/example/example_one_skeleton_rips_from_correlation_matrix.cpp | 22 | ||||
-rw-r--r-- | src/Rips_complex/utilities/rips_correlation_matrix_persistence.cpp | 28 |
2 files changed, 23 insertions, 27 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 index a34ce15c..1343f24d 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 @@ -34,24 +34,22 @@ int main() { double threshold = 0; for (size_t i = 0; i != correlations.size(); ++i) { for (size_t j = 0; j != correlations[i].size(); ++j) { - //Here we check if our data comes from corelation matrix. - 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"; - } - 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]; - } + // Here we check if our data comes from corelation matrix. + 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"; + } + 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]; + } } //----------------------------------------------------------------------------- // Now the correlation matrix is a distance matrix and can be processed further. //----------------------------------------------------------------------------- Distance_matrix distances = correlations; - Rips_complex rips_complex_from_points(distances, threshold); diff --git a/src/Rips_complex/utilities/rips_correlation_matrix_persistence.cpp b/src/Rips_complex/utilities/rips_correlation_matrix_persistence.cpp index 95bce491..c2082fae 100644 --- a/src/Rips_complex/utilities/rips_correlation_matrix_persistence.cpp +++ b/src/Rips_complex/utilities/rips_correlation_matrix_persistence.cpp @@ -63,14 +63,13 @@ int main(int argc, char* argv[]) { 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]; - //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)) - { + // 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]; + if (correlations[i][j] > threshold) threshold = correlations[i][j]; } } @@ -90,16 +89,15 @@ 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. 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. + + // 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<intervals_common> processed_persistence_intervals; processed_persistence_intervals.reserve(pairs.size()); @@ -119,7 +117,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); + write_persistence_intervals_to_stream(processed_persistence_intervals, out); } return 0; } |