From 9d1a526de85694b5f075bb88dbd7097a40abf10a Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Tue, 30 May 2017 15:52:00 +0000 Subject: clang format all sources git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/persistence_representation_integration@2477 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 326d664483d6700f82be824f79a0bf5c082b4945 --- .../persistence_landscapes/average_landscapes.cpp | 76 ++++++------ .../compute_distance_of_landscapes.cpp | 128 +++++++++------------ .../compute_scalar_product_of_landscapes.cpp | 102 ++++++++-------- .../persistence_landscapes/create_landscapes.cpp | 56 +++++---- .../persistence_landscapes/plot_landscapes.cpp | 27 ++--- 5 files changed, 172 insertions(+), 217 deletions(-) (limited to 'src/Persistence_representations/utilities/persistence_landscapes') diff --git a/src/Persistence_representations/utilities/persistence_landscapes/average_landscapes.cpp b/src/Persistence_representations/utilities/persistence_landscapes/average_landscapes.cpp index 1e0caa30..9816ff1d 100644 --- a/src/Persistence_representations/utilities/persistence_landscapes/average_landscapes.cpp +++ b/src/Persistence_representations/utilities/persistence_landscapes/average_landscapes.cpp @@ -20,55 +20,47 @@ * along with this program. If not, see . */ - - #include - - using namespace Gudhi; using namespace Gudhi::Persistence_representations; #include +int main(int argc, char** argv) { + std::cout << "This program computes average persistence landscape of persistence landscapes created based on " + "persistence diagrams provided as an input (you must create them first).\n"; + std::cout << "Please call this program with the names of files with persistence landscapes. The program will create " + "a persistence landscape which will be their average \n"; + std::vector filenames; + + if (argc == 1) { + std::cout << "No input files given, the program will now terminate \n"; + return 1; + } + + for (int i = 1; i < argc; ++i) { + filenames.push_back(argv[i]); + } + + std::cout << "Creating persistence landscapes...\n"; + std::vector lands; + for (size_t i = 0; i != filenames.size(); ++i) { + Persistence_landscape* l = new Persistence_landscape; + l->load_landscape_from_file(filenames[i]); + lands.push_back(l); + } + + Persistence_landscape av; + av.compute_average(lands); + + av.print_to_file("average.land"); + + for (size_t i = 0; i != filenames.size(); ++i) { + delete lands[i]; + } -int main( int argc , char** argv ) -{ - std::cout << "This program computes average persistence landscape of persistence landscapes created based on persistence diagrams provided as an input (you must create them first).\n"; - std::cout << "Please call this program with the names of files with persistence landscapes. The program will create a persistence landscape which will be their average \n"; - std::vector< const char* > filenames; - - if ( argc == 1 ) - { - std::cout << "No input files given, the program will now terminate \n"; - return 1; - } - - for ( int i = 1 ; i < argc ; ++i ) - { - filenames.push_back( argv[i] ); - } - - std::cout << "Creating persistence landscapes...\n"; - std::vector< Persistence_landscape* > lands; - for ( size_t i = 0 ; i != filenames.size() ; ++i ) - { - Persistence_landscape* l = new Persistence_landscape; - l->load_landscape_from_file( filenames[i] ); - lands.push_back( l ); - } - - Persistence_landscape av; - av.compute_average( lands ); - - av.print_to_file( "average.land" ); - - for ( size_t i = 0 ; i != filenames.size() ; ++i ) - { - delete lands[i]; - } - - std::cout << "Done \n"; + std::cout << "Done \n"; - return 0; + return 0; } diff --git a/src/Persistence_representations/utilities/persistence_landscapes/compute_distance_of_landscapes.cpp b/src/Persistence_representations/utilities/persistence_landscapes/compute_distance_of_landscapes.cpp index ef969ed0..1c690c53 100644 --- a/src/Persistence_representations/utilities/persistence_landscapes/compute_distance_of_landscapes.cpp +++ b/src/Persistence_representations/utilities/persistence_landscapes/compute_distance_of_landscapes.cpp @@ -22,91 +22,71 @@ #include - - using namespace Gudhi; using namespace Gudhi::Persistence_representations; #include #include +int main(int argc, char** argv) { + std::cout << "This program compute distance of persistence landscapes stored in a file (the file needs to be created " + "beforehand). \n"; + std::cout << "The first parameter of a program is an integer p. The program compute L^p distance of the given " + "landscapes. For L^infty distance choose p = -1. \n"; + std::cout << "The remaining parameters of this programs are names of files with persistence landscapes."; -int main( int argc , char** argv ) -{ - std::cout << "This program compute distance of persistence landscapes stored in a file (the file needs to be created beforehand). \n"; - std::cout << "The first parameter of a program is an integer p. The program compute L^p distance of the given landscapes. For L^infty distance choose p = -1. \n"; - std::cout << "The remaining parameters of this programs are names of files with persistence landscapes."; - - if ( argc < 3 ) - { - std::cout << "Wrong number of parameters, the program will now terminate \n"; - return 1; - } - - int pp = atoi( argv[1] ); - double p = std::numeric_limits::max(); - if ( pp != -1 ) - { - p = pp; - } - + if (argc < 3) { + std::cout << "Wrong number of parameters, the program will now terminate \n"; + return 1; + } - std::vector< const char* > filenames; - for ( int i = 2 ; i < argc ; ++i ) - { - filenames.push_back( argv[i] ); - } - std::vector< Persistence_landscape > landscaspes; - landscaspes.reserve( filenames.size() ); - for ( size_t file_no = 0 ; file_no != filenames.size() ; ++file_no ) - { - std::cout << "Loading persistence landscape from a file : " << filenames[file_no] << std::endl; - Persistence_landscape l; - l.load_landscape_from_file( filenames[file_no] ); - landscaspes.push_back( l ); - } - - //and now we will compute the scalar product of landscapes. - - //first we prepare an array: - std::vector< std::vector< double > > distance( filenames.size() ); - for ( size_t i = 0 ; i != filenames.size() ; ++i ) - { - std::vector< double > v( filenames.size() , 0 ); - distance[i] = v; - } - - //and now we can compute the distances: - for ( size_t i = 0 ; i != landscaspes.size() ; ++i ) - { - for ( size_t j = i ; j != landscaspes.size() ; ++j ) - { - distance[i][j] = distance[j][i] = compute_distance_of_landscapes( landscaspes[i], landscaspes[j] , p ) ; - - } - } - - //and now output the result to the screen and a file: - std::ofstream out; - out.open( "distance" ); - for ( size_t i = 0 ; i != distance.size() ; ++i ) - { - for ( size_t j = 0 ; j != distance.size() ; ++j ) - { - std::cout << distance[i][j] << " "; - out << distance[i][j] << " "; - } - std::cout << std::endl; - out << std::endl; - } - out.close(); - - return 0; -} + int pp = atoi(argv[1]); + double p = std::numeric_limits::max(); + if (pp != -1) { + p = pp; + } + std::vector filenames; + for (int i = 2; i < argc; ++i) { + filenames.push_back(argv[i]); + } + std::vector landscaspes; + landscaspes.reserve(filenames.size()); + for (size_t file_no = 0; file_no != filenames.size(); ++file_no) { + std::cout << "Loading persistence landscape from a file : " << filenames[file_no] << std::endl; + Persistence_landscape l; + l.load_landscape_from_file(filenames[file_no]); + landscaspes.push_back(l); + } + // and now we will compute the scalar product of landscapes. + // first we prepare an array: + std::vector > distance(filenames.size()); + for (size_t i = 0; i != filenames.size(); ++i) { + std::vector v(filenames.size(), 0); + distance[i] = v; + } + // and now we can compute the distances: + for (size_t i = 0; i != landscaspes.size(); ++i) { + for (size_t j = i; j != landscaspes.size(); ++j) { + distance[i][j] = distance[j][i] = compute_distance_of_landscapes(landscaspes[i], landscaspes[j], p); + } + } + // and now output the result to the screen and a file: + std::ofstream out; + out.open("distance"); + for (size_t i = 0; i != distance.size(); ++i) { + for (size_t j = 0; j != distance.size(); ++j) { + std::cout << distance[i][j] << " "; + out << distance[i][j] << " "; + } + std::cout << std::endl; + out << std::endl; + } + out.close(); - + return 0; +} diff --git a/src/Persistence_representations/utilities/persistence_landscapes/compute_scalar_product_of_landscapes.cpp b/src/Persistence_representations/utilities/persistence_landscapes/compute_scalar_product_of_landscapes.cpp index 02b729b2..83121a9c 100644 --- a/src/Persistence_representations/utilities/persistence_landscapes/compute_scalar_product_of_landscapes.cpp +++ b/src/Persistence_representations/utilities/persistence_landscapes/compute_scalar_product_of_landscapes.cpp @@ -22,68 +22,58 @@ #include - - using namespace Gudhi; using namespace Gudhi::Persistence_representations; #include #include +int main(int argc, char** argv) { + std::cout << "This program compute scalar product of persistence landscapes stored in a file (the file needs to be " + "created beforehand). \n"; + std::cout << "The parameters of this programs are names of files with persistence landscapes.\n"; + + std::vector filenames; + for (int i = 1; i < argc; ++i) { + filenames.push_back(argv[i]); + } + std::vector landscaspes; + landscaspes.reserve(filenames.size()); + for (size_t file_no = 0; file_no != filenames.size(); ++file_no) { + std::cout << "Reading persistence landscape from a file : " << filenames[file_no] << std::endl; + Persistence_landscape l; + l.load_landscape_from_file(filenames[file_no]); + landscaspes.push_back(l); + } + + // and now we will compute the scalar product of landscapes. + + // first we prepare an array: + std::vector > scalar_product(filenames.size()); + for (size_t i = 0; i != filenames.size(); ++i) { + std::vector v(filenames.size(), 0); + scalar_product[i] = v; + } + + // and now we can compute the scalar product: + for (size_t i = 0; i != landscaspes.size(); ++i) { + for (size_t j = i; j != landscaspes.size(); ++j) { + scalar_product[i][j] = scalar_product[j][i] = compute_inner_product(landscaspes[i], landscaspes[j]); + } + } -int main( int argc , char** argv ) -{ - std::cout << "This program compute scalar product of persistence landscapes stored in a file (the file needs to be created beforehand). \n"; - std::cout << "The parameters of this programs are names of files with persistence landscapes.\n"; + // and now output the result to the screen and a file: + std::ofstream out; + out.open("scalar_product"); + for (size_t i = 0; i != scalar_product.size(); ++i) { + for (size_t j = 0; j != scalar_product.size(); ++j) { + std::cout << scalar_product[i][j] << " "; + out << scalar_product[i][j] << " "; + } + std::cout << std::endl; + out << std::endl; + } + out.close(); - std::vector< const char* > filenames; - for ( int i = 1 ; i < argc ; ++i ) - { - filenames.push_back( argv[i] ); - } - std::vector< Persistence_landscape > landscaspes; - landscaspes.reserve( filenames.size() ); - for ( size_t file_no = 0 ; file_no != filenames.size() ; ++file_no ) - { - std::cout << "Reading persistence landscape from a file : " << filenames[file_no] << std::endl; - Persistence_landscape l; - l.load_landscape_from_file( filenames[file_no] ); - landscaspes.push_back( l ); - } - - //and now we will compute the scalar product of landscapes. - - //first we prepare an array: - std::vector< std::vector< double > > scalar_product( filenames.size() ); - for ( size_t i = 0 ; i != filenames.size() ; ++i ) - { - std::vector< double > v( filenames.size() , 0 ); - scalar_product[i] = v; - } - - //and now we can compute the scalar product: - for ( size_t i = 0 ; i != landscaspes.size() ; ++i ) - { - for ( size_t j = i ; j != landscaspes.size() ; ++j ) - { - scalar_product[i][j] = scalar_product[j][i] = compute_inner_product( landscaspes[i], landscaspes[j] ) ; - } - } - - //and now output the result to the screen and a file: - std::ofstream out; - out.open( "scalar_product" ); - for ( size_t i = 0 ; i != scalar_product.size() ; ++i ) - { - for ( size_t j = 0 ; j != scalar_product.size() ; ++j ) - { - std::cout << scalar_product[i][j] << " "; - out << scalar_product[i][j] << " "; - } - std::cout << std::endl; - out << std::endl; - } - out.close(); - - return 0; + return 0; } diff --git a/src/Persistence_representations/utilities/persistence_landscapes/create_landscapes.cpp b/src/Persistence_representations/utilities/persistence_landscapes/create_landscapes.cpp index b85c8644..f98fe3ad 100644 --- a/src/Persistence_representations/utilities/persistence_landscapes/create_landscapes.cpp +++ b/src/Persistence_representations/utilities/persistence_landscapes/create_landscapes.cpp @@ -22,41 +22,37 @@ #include - using namespace Gudhi; using namespace Gudhi::Persistence_representations; #include #include +int main(int argc, char** argv) { + std::cout << "This program creates persistence landscapes of diagrams provided as an input. \n"; + std::cout << "The first parameter of the program is the dimension of persistence to be used to construct persistence " + "landscapes. If your file contains "; + std::cout << "the information about dimension of persistence pairs, please provide here the dimension of persistence " + "pairs you want to use. If your input files consist only "; + std::cout << "of birth-death pairs, please set this first parameter to -1 \n"; + std::cout << "The remaining parameters of the program are the names of files with persistence diagrams. \n"; + std::vector filenames; + int dim = atoi(argv[1]); + unsigned dimension = std::numeric_limits::max(); + if (dim >= 0) { + dimension = (unsigned)dim; + } + for (int i = 2; i < argc; ++i) { + filenames.push_back(argv[i]); + } -int main( int argc , char** argv ) -{ - std::cout << "This program creates persistence landscapes of diagrams provided as an input. \n"; - std::cout << "The first parameter of the program is the dimension of persistence to be used to construct persistence landscapes. If your file contains "; - std::cout << "the information about dimension of persistence pairs, please provide here the dimension of persistence pairs you want to use. If your input files consist only "; - std::cout << "of birth-death pairs, please set this first parameter to -1 \n"; - std::cout << "The remaining parameters of the program are the names of files with persistence diagrams. \n"; - std::vector< const char* > filenames; - int dim = atoi(argv[1]); - unsigned dimension = std::numeric_limits::max(); - if ( dim >= 0 ) - { - dimension = (unsigned)dim; - } - for ( int i = 2 ; i < argc ; ++i ) - { - filenames.push_back( argv[i] ); - } - - std::cout << "Creating persistence landscapes...\n"; - for ( size_t i = 0 ; i != filenames.size() ; ++i ) - { - Persistence_landscape l( filenames[i] , dimension ); - std::stringstream ss; - ss << filenames[i] << ".land"; - l.print_to_file( ss.str().c_str() ); - } - std::cout << "Done \n"; - return 0; + std::cout << "Creating persistence landscapes...\n"; + for (size_t i = 0; i != filenames.size(); ++i) { + Persistence_landscape l(filenames[i], dimension); + std::stringstream ss; + ss << filenames[i] << ".land"; + l.print_to_file(ss.str().c_str()); + } + std::cout << "Done \n"; + return 0; } diff --git a/src/Persistence_representations/utilities/persistence_landscapes/plot_landscapes.cpp b/src/Persistence_representations/utilities/persistence_landscapes/plot_landscapes.cpp index 670f0364..4761a095 100644 --- a/src/Persistence_representations/utilities/persistence_landscapes/plot_landscapes.cpp +++ b/src/Persistence_representations/utilities/persistence_landscapes/plot_landscapes.cpp @@ -22,26 +22,23 @@ #include - - using namespace Gudhi; using namespace Gudhi::Persistence_representations; #include #include +int main(int argc, char** argv) { + std::cout << "This program plot persistence landscape stored in a file (the file needs to be created beforehand). " + "Please call the code with the name of a landscape file \n"; + Persistence_landscape l; + l.load_landscape_from_file(argv[1]); + + std::stringstream ss; + ss << argv[1] << "_gnuplot_script"; + l.plot(ss.str().c_str()); + + std::cout << "Done \n"; -int main( int argc , char** argv ) -{ - std::cout << "This program plot persistence landscape stored in a file (the file needs to be created beforehand). Please call the code with the name of a landscape file \n"; - Persistence_landscape l; - l.load_landscape_from_file( argv[1] ); - - std::stringstream ss; - ss << argv[1] << "_gnuplot_script"; - l.plot( ss.str().c_str() ); - - std::cout << "Done \n"; - - return 0; + return 0; } -- cgit v1.2.3