diff options
Diffstat (limited to 'src/Gudhi_stat/utilities/persistence_intervals')
6 files changed, 359 insertions, 0 deletions
diff --git a/src/Gudhi_stat/utilities/persistence_intervals/CMakeLists.txt b/src/Gudhi_stat/utilities/persistence_intervals/CMakeLists.txt new file mode 100644 index 00000000..96cb1a5e --- /dev/null +++ b/src/Gudhi_stat/utilities/persistence_intervals/CMakeLists.txt @@ -0,0 +1,22 @@ +cmake_minimum_required(VERSION 2.6) +project(GUDHI_STAT) + + + +#persitence diagrams +add_executable ( plot_persistence_intervals plot_persistence_intervals.cpp ) +target_link_libraries( plot_persistence_intervals ${Boost_SYSTEM_LIBRARY}) + +add_executable ( compute_birth_death_range_in_persistence_diagram compute_birth_death_range_in_persistence_diagram.cpp ) +target_link_libraries( compute_birth_death_range_in_persistence_diagram ${Boost_SYSTEM_LIBRARY}) + +add_executable ( compute_number_of_dominant_intervals compute_number_of_dominant_intervals.cpp ) +target_link_libraries( compute_number_of_dominant_intervals ${Boost_SYSTEM_LIBRARY}) + +add_executable ( plot_histogram_of_intervals_lengths plot_histogram_of_intervals_lengths.cpp ) +target_link_libraries( plot_histogram_of_intervals_lengths ${Boost_SYSTEM_LIBRARY}) + +add_executable ( plot_persistence_Betti_numebrs plot_persistence_Betti_numebrs.cpp ) +target_link_libraries( plot_persistence_Betti_numebrs ${Boost_SYSTEM_LIBRARY}) + +#when we have bottleneck and wasserstein distance computations, add suitable programs here. diff --git a/src/Gudhi_stat/utilities/persistence_intervals/compute_birth_death_range_in_persistence_diagram.cpp b/src/Gudhi_stat/utilities/persistence_intervals/compute_birth_death_range_in_persistence_diagram.cpp new file mode 100644 index 00000000..145040fe --- /dev/null +++ b/src/Gudhi_stat/utilities/persistence_intervals/compute_birth_death_range_in_persistence_diagram.cpp @@ -0,0 +1,69 @@ +/* This file is part of the Gudhi Library. The Gudhi library + * (Geometric Understanding in Higher Dimensions) is a generic C++ + * library for computational topology. + * + * Author(s): Pawel Dlotko + * + * Copyright (C) 2015 INRIA (France) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + + + +#include <gudhi/reader_utils.h> +#include <gudhi/persistence_representations/Persistence_intervals.h> + +#include <iostream> +#include <vector> +#include <limits> + + + +using namespace Gudhi; +using namespace Gudhi::Gudhi_stat; + + +int main( int argc , char** argv ) +{ + //std::cout << "This program compute minimum birth and the maximum death time for a collection of persistence intervals \n"; + //if ( argc != 2 ) + //{ + // std::cout << "To run this program, please provide the name of a file with persistence diagram \n"; + // return 1; + //} + //Persistence_intervals p( argv[1] ); + //std::pair<double,double> min_max_ = p.min_max(); + //std::cout << "Birth-death range : min: " << min_max_.first << ", max: " << min_max_.second << endl; + + std::vector< const char* > filenames; + for ( int i = 1 ; i < argc ; ++i ) + { + filenames.push_back( argv[i] ); + } + + double min_ = std::numeric_limits<double>::max(); + double max_ = -std::numeric_limits<double>::max(); + + for ( size_t file_no = 0 ; file_no != filenames.size() ; ++file_no ) + { + std::cout << "Creating diagram based on a file : " << filenames[file_no] << std::endl; + Persistence_intervals p( filenames[file_no] ); + std::pair<double,double> min_max_ = p.min_max(); + if ( min_max_.first < min_ )min_ = min_max_.first; + if ( min_max_.second > max_ )max_ = min_max_.second; + } + std::cout << "Birth-death range : min: " << min_ << ", max: " << max_ << std::endl; + return 0; +} diff --git a/src/Gudhi_stat/utilities/persistence_intervals/compute_number_of_dominant_intervals.cpp b/src/Gudhi_stat/utilities/persistence_intervals/compute_number_of_dominant_intervals.cpp new file mode 100644 index 00000000..eeda703a --- /dev/null +++ b/src/Gudhi_stat/utilities/persistence_intervals/compute_number_of_dominant_intervals.cpp @@ -0,0 +1,54 @@ +/* This file is part of the Gudhi Library. The Gudhi library + * (Geometric Understanding in Higher Dimensions) is a generic C++ + * library for computational topology. + * + * Author(s): Pawel Dlotko + * + * Copyright (C) 2015 INRIA (France) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + + + +#include <gudhi/reader_utils.h> +#include <gudhi/persistence_representations/Persistence_intervals.h> + +#include <iostream> + + + +using namespace Gudhi; +using namespace Gudhi::Gudhi_stat; + + +int main( int argc , char** argv ) +{ + std::cout << "This program compute the dominant intervals. A number of intervals to be displayed is a parameter of this program. \n"; + if ( argc != 3 ) + { + std::cout << "To run this program, please provide the name of a file with persistence diagram and number of dominant intervals you would like to get \n"; + return 1; + } + + Persistence_intervals p( argv[1] ); + std::vector< std::pair<double,double> > dominant_intervals = p.dominant_intervals( atoi( argv[2] ) ); + std::cout << "Here are the dominant intervals : " << std::endl; + for ( size_t i = 0 ; i != dominant_intervals.size() ; ++i ) + { + std::cout << " " << dominant_intervals[i].first<< "," << dominant_intervals[i].second << " "<< std::endl; + } + + return 0; +} diff --git a/src/Gudhi_stat/utilities/persistence_intervals/plot_histogram_of_intervals_lengths.cpp b/src/Gudhi_stat/utilities/persistence_intervals/plot_histogram_of_intervals_lengths.cpp new file mode 100644 index 00000000..db9c3f98 --- /dev/null +++ b/src/Gudhi_stat/utilities/persistence_intervals/plot_histogram_of_intervals_lengths.cpp @@ -0,0 +1,66 @@ +/* This file is part of the Gudhi Library. The Gudhi library + * (Geometric Understanding in Higher Dimensions) is a generic C++ + * library for computational topology. + * + * Author(s): Pawel Dlotko + * + * Copyright (C) 2015 INRIA (France) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + + + +#include <gudhi/reader_utils.h> +#include <gudhi/persistence_representations/Persistence_intervals.h> + +#include <iostream> + + + +using namespace Gudhi; +using namespace Gudhi::Gudhi_stat; + + +int main( int argc , char** argv ) +{ + std::cout << "This program compute a histogram of barcode's length. A number of bins in the histogram is a parameter of this program. \n"; + if ( argc != 3 ) + { + std::cout << "To run this program, please provide the name of a file with persistence diagram and number of dominant intervals you would like to get \n"; + return 1; + } + + Persistence_intervals p( argv[1] ); + std::vector< std::pair<double,double> > dominant_intervals = p.dominant_intervals( atoi( argv[2] ) ); + std::vector< size_t > histogram = p.histogram_of_lengths( 10 ); + + std::stringstream gnuplot_script; + gnuplot_script << argv[1] << "_Gnuplot_script"; + std::ofstream out; + out.open( gnuplot_script.str().c_str() ); + + out << "set style data histogram" << std::endl; + out << "set style histogram cluster gap 1" << std::endl; + out << "set style fill solid border -1" << std::endl; + out << "plot '-' notitle" << std::endl; + for ( size_t i = 0 ; i != histogram.size() ; ++i ) + { + out << histogram[i] << std::endl; + } + out << std::endl; + std::cout << "To vizualize, open gnuplot and type: load \'" << gnuplot_script.str().c_str() << "\'" << std::endl; + out.close(); + return 0; +} diff --git a/src/Gudhi_stat/utilities/persistence_intervals/plot_persistence_Betti_numebrs.cpp b/src/Gudhi_stat/utilities/persistence_intervals/plot_persistence_Betti_numebrs.cpp new file mode 100644 index 00000000..cb89f6b9 --- /dev/null +++ b/src/Gudhi_stat/utilities/persistence_intervals/plot_persistence_Betti_numebrs.cpp @@ -0,0 +1,90 @@ +/* This file is part of the Gudhi Library. The Gudhi library + * (Geometric Understanding in Higher Dimensions) is a generic C++ + * library for computational topology. + * + * Author(s): Pawel Dlotko + * + * Copyright (C) 2015 INRIA (France) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + + + +#include <gudhi/reader_utils.h> +#include <gudhi/persistence_representations/Persistence_intervals.h> + +#include <iostream> + + + +using namespace Gudhi; +using namespace Gudhi::Gudhi_stat; + + +int main( int argc , char** argv ) +{ + std::cout << "This program compute a plot of persistence Betti numbers. The input parameter is a file with persistence intervals. \n"; + if ( argc != 2 ) + { + std::cout << "To run this program, please provide the name of a file with persistence diagram and number of dominant intervals you would like to get \n"; + return 1; + } + + + + std::stringstream gnuplot_script; + gnuplot_script << argv[1] << "_Gnuplot_script"; + std::ofstream out; + out.open( gnuplot_script.str().c_str() ); + + Persistence_intervals p( argv[1] ); + std::vector< std::pair< double , size_t > > pbns = p.compute_persistent_betti_numbers(); + + //set up the ranges so that we see the image well. + double xRangeBegin = pbns[0].first; + double xRangeEnd = pbns[ pbns.size()-1 ].first; + double yRangeBegin = 0; + double yRangeEnd = 0; + for ( size_t i = 0 ; i != pbns.size() ; ++i ) + { + if ( pbns[i].second > yRangeEnd )yRangeEnd = pbns[i].second; + } + xRangeBegin -= (xRangeEnd -xRangeBegin)/100.0; + xRangeEnd += (xRangeEnd -xRangeBegin)/100.0; + yRangeEnd += yRangeEnd/100; + + + out << "set xrange [" << xRangeBegin << " : " << xRangeEnd << "]" << std::endl; + out << "set yrange [" << yRangeBegin << " : " << yRangeEnd << "]" << std::endl; + out << "plot '-' using 1:2 notitle with lp " << std::endl; + double previous_y = 0; + for ( size_t i = 0 ; i != pbns.size() ; ++i ) + { + out << pbns[i].first << " " << previous_y << std::endl; + out << pbns[i].first << " " << pbns[i].second << std::endl; + previous_y = pbns[i].second; + } + out << std::endl; + out.close(); + + //for ( size_t i = 0 ; i != pbns.size() ; ++i ) + //{ + // std::cout << pbns[i].first << " " << pbns[i].second << std::endl; + //} + + std::cout << "To vizualize, open gnuplot and type: load \'" << gnuplot_script.str().c_str() << "\'" << std::endl; + + return 0; +} diff --git a/src/Gudhi_stat/utilities/persistence_intervals/plot_persistence_intervals.cpp b/src/Gudhi_stat/utilities/persistence_intervals/plot_persistence_intervals.cpp new file mode 100644 index 00000000..04a05caa --- /dev/null +++ b/src/Gudhi_stat/utilities/persistence_intervals/plot_persistence_intervals.cpp @@ -0,0 +1,58 @@ +/* This file is part of the Gudhi Library. The Gudhi library + * (Geometric Understanding in Higher Dimensions) is a generic C++ + * library for computational topology. + * + * Author(s): Pawel Dlotko + * + * Copyright (C) 2015 INRIA (France) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + + + +#include <gudhi/reader_utils.h> +#include <gudhi/persistence_representations/Persistence_intervals.h> +#include <gudhi/read_persitence_from_file.h> + +#include <iostream> + + + +using namespace Gudhi; +using namespace Gudhi::Gudhi_stat; + + +double epsilon = 0.0000005; + + +int main( int argc , char** argv ) +{ + if ( argc != 2 ) + { + std::cout << "To run this program, please provide the name of a file with persistence diagram \n"; + return 1; + } + std::vector< std::pair< double , double > > intervals = read_gudhi_file( argv[1] , 2 ); + Persistence_intervals b( intervals ); + b.plot( argv[1] ); + return 0; +} + + + + + + + |