diff options
author | pdlotko <pdlotko@636b058d-ea47-450e-bf9e-a15bfbe3eedb> | 2016-10-20 09:00:17 +0000 |
---|---|---|
committer | pdlotko <pdlotko@636b058d-ea47-450e-bf9e-a15bfbe3eedb> | 2016-10-20 09:00:17 +0000 |
commit | 60ded8e74aaec4fa519162dd15276c072f2acb2e (patch) | |
tree | f2f805139258ee9e52a8dd6b4964ce2e1c44f61b /src | |
parent | 6775c536373f8288021cb20854cd06d40edf8f82 (diff) |
The last commit before changing inheritance to templates in the library desing.
git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/gudhi_stat@1738 636b058d-ea47-450e-bf9e-a15bfbe3eedb
Former-commit-id: 9432e8ee5d37fda7e1d82fc8e8b0121a41afa5b9
Diffstat (limited to 'src')
9 files changed, 128 insertions, 117 deletions
diff --git a/src/Gudhi_stat/include/gudhi/abstract_classes/Abs_Topological_data_with_averages.h b/src/Gudhi_stat/include/gudhi/abstract_classes/Abs_Topological_data_with_averages.h index 8585a62c..cc2cd00f 100644 --- a/src/Gudhi_stat/include/gudhi/abstract_classes/Abs_Topological_data_with_averages.h +++ b/src/Gudhi_stat/include/gudhi/abstract_classes/Abs_Topological_data_with_averages.h @@ -24,6 +24,7 @@ #ifndef Abs_Topological_data_with_averages_H_ #define Abs_Topological_data_with_averages_H_ #include <gudhi/abstract_classes/Abs_Topological_data.h> +#include <vector> namespace Gudhi diff --git a/src/Gudhi_stat/include/gudhi/abstract_classes/Abs_Topological_data_with_scalar_product.h b/src/Gudhi_stat/include/gudhi/abstract_classes/Abs_Topological_data_with_scalar_product.h index 819b1376..ccda5e63 100644 --- a/src/Gudhi_stat/include/gudhi/abstract_classes/Abs_Topological_data_with_scalar_product.h +++ b/src/Gudhi_stat/include/gudhi/abstract_classes/Abs_Topological_data_with_scalar_product.h @@ -20,11 +20,11 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef Abs_Topological_data_with_scalar_product_H +#ifndef Abs_Topological_data_with_scalar_product_H_ #define Abs_Topological_data_with_scalar_product_H_ #include <gudhi/abstract_classes/Abs_Topological_data.h> - +#include <vector> namespace Gudhi { diff --git a/src/Gudhi_stat/include/gudhi/concretizations/Persistence_heat_maps.h b/src/Gudhi_stat/include/gudhi/concretizations/Persistence_heat_maps.h index 89254f16..e9175af9 100644 --- a/src/Gudhi_stat/include/gudhi/concretizations/Persistence_heat_maps.h +++ b/src/Gudhi_stat/include/gudhi/concretizations/Persistence_heat_maps.h @@ -148,6 +148,17 @@ double arc_tan_of_persistence_of_point( const std::pair< double , double >& poin return atan( point_in_diagram.second - point_in_diagram.first ); } +class weight_by_setting_maximal_interval_to_have_length_one +{ +public: + weight_by_setting_maximal_interval_to_have_length_one( double len ):letngth_of_maximal_interval(len){} + double operator()( const std::pair< double , double >& point_in_diagram ) + { + return (point_in_diagram.second-point_in_diagram.first)/this->letngth_of_maximal_interval; + } +private: + double letngth_of_maximal_interval; +}; diff --git a/src/Gudhi_stat/include/gudhi/concretizations/Persistence_landscape.h b/src/Gudhi_stat/include/gudhi/concretizations/Persistence_landscape.h index f5f96d34..aa74514e 100644 --- a/src/Gudhi_stat/include/gudhi/concretizations/Persistence_landscape.h +++ b/src/Gudhi_stat/include/gudhi/concretizations/Persistence_landscape.h @@ -59,101 +59,6 @@ namespace Gudhi_stat /** - * Extra functions needed in construction of barcodes. -**/ -double minus_length( std::pair<double,double> a ) -{ - return a.first-a.second; -} -double birth_plus_deaths( std::pair<double,double> a ) -{ - return a.first+a.second; -} - - - -/** - * Given two points in R^2, the procedure compute the parameters A and B of the line y = Ax + B that crosses those two points. -**/ -std::pair<double,double> compute_parameters_of_a_line( std::pair<double,double> p1 , std::pair<double,double> p2 ) -{ - double a = (p2.second-p1.second)/( p2.first - p1.first ); - double b = p1.second - a*p1.first; - return std::make_pair(a,b); -} - -/** - * This procedure given two points which lies on the opposide sides of x axis, compute x for which the line connecting those two points crosses x axis. -**/ -double find_zero_of_a_line_segment_between_those_two_points ( std::pair<double,double> p1, std::pair<double,double> p2 ) -{ - if ( p1.first == p2.first )return p1.first; - if ( p1.second*p2.second > 0 ) - { - std::ostringstream errMessage; - errMessage <<"In function find_zero_of_a_line_segment_between_those_two_points the agguments are: (" << p1.first << "," << p1.second << ") and (" << p2.first << "," << p2.second << "). There is no zero in line between those two points. Program terminated."; - std::string errMessageStr = errMessage.str(); - const char* err = errMessageStr.c_str(); - throw(err); - } - //we assume here, that x \in [ p1.first, p2.first ] and p1 and p2 are points between which we will put the line segment - double a = (p2.second - p1.second)/(p2.first - p1.first); - double b = p1.second - a*p1.first; - //cerr << "Line crossing points : (" << p1.first << "," << p1.second << ") oraz (" << p2.first << "," << p2.second << ") : \n"; - //cerr << "a : " << a << " , b : " << b << " , x : " << x << endl; - return -b/a; -} - - - - -/** - * Lexicographical ordering of points . -**/ -bool compare_points_sorting( std::pair<double,double> f, std::pair<double,double> s ) -{ - if ( f.first < s.first ) - { - return true; - } - else - {//f.first >= s.first - if ( f.first > s.first ) - { - return false; - } - else - {//f.first == s.first - if ( f.second > s.second ) - { - return true; - } - else - { - return false; - } - } - } -} - - - -/** - * This procedure takes two points in R^2 and a double value x. It conputes the line pasing through those two points and return the value of that linear function at x. -**/ -double function_value ( std::pair<double,double> p1, std::pair<double,double> p2 , double x ) -{ - //we assume here, that x \in [ p1.first, p2.first ] and p1 and p2 are points between which we will put the line segment - double a = (p2.second - p1.second)/(p2.first - p1.first); - double b = p1.second - a*p1.first; - return (a*x+b); -} - - - - - -/** * A clas implementing persistence landascpes data structures. For theroretical desciritpion, please consult a paper ''Statistical topological data analysis using persistence landscapes'' by Peter Bubenik. * For details of algorithms, please consult ''A persistence landscapes toolbox for topological statistics'' by Peter Bubenik and Pawel Dlotko. * Persistence landscapes allow vertorization, computations of distances, computations of projections to Real, computations of averages and scalar products. Therefore they implement suitable interfaces. diff --git a/src/Gudhi_stat/include/gudhi/concretizations/Persistence_landscape_on_grid.h b/src/Gudhi_stat/include/gudhi/concretizations/Persistence_landscape_on_grid.h index 8afab347..988c9f16 100644 --- a/src/Gudhi_stat/include/gudhi/concretizations/Persistence_landscape_on_grid.h +++ b/src/Gudhi_stat/include/gudhi/concretizations/Persistence_landscape_on_grid.h @@ -42,7 +42,7 @@ #include <gudhi/abstract_classes/Abs_Real_valued_topological_data.h> #include <gudhi/abstract_classes/Abs_Topological_data_with_scalar_product.h> #include <gudhi/concretizations/read_persitence_from_file.h> -#include <gudhi/common_gudhi_stat.h> +#include <gudhi/common_gudhi_stat.h> @@ -54,23 +54,6 @@ namespace Gudhi namespace Gudhi_stat { -/** - * Given two points in R^2, the procedure compute the parameters A and B of the line y = Ax + B that crosses those two points. -**/ -std::pair<double,double> compute_parameters_of_a_line( std::pair<double,double> p1 , std::pair<double,double> p2 ) -{ - double a = (p2.second-p1.second)/( p2.first - p1.first ); - double b = p1.second - a*p1.first; - return std::make_pair(a,b); -} - -struct greater -{ - template<class T> - bool operator()(T const &a, T const &b) const { return a > b; } -}; - - class Persistence_landscape_on_grid : public Abs_Vectorized_topological_data , public Abs_Topological_data_with_distances, @@ -994,7 +977,7 @@ void Persistence_landscape_on_grid::set_up_values_of_landscapes( const std::vect //and now we need to sort the valuesL for ( size_t pt = 0 ; pt != this->values_of_landscapes.size() ; ++pt ) { - std::sort( this->values_of_landscapes[pt].begin() , this->values_of_landscapes[pt].end() , greater() ); + std::sort( this->values_of_landscapes[pt].begin() , this->values_of_landscapes[pt].end() , greater_landscapes_on_grid() ); } }//set_up_values_of_landscapes diff --git a/src/Gudhi_stat/include/gudhi/concretizations/Vector_distances_in_diagram.h b/src/Gudhi_stat/include/gudhi/concretizations/Vector_distances_in_diagram.h index 951d8717..bb350040 100644 --- a/src/Gudhi_stat/include/gudhi/concretizations/Vector_distances_in_diagram.h +++ b/src/Gudhi_stat/include/gudhi/concretizations/Vector_distances_in_diagram.h @@ -31,7 +31,6 @@ #include <limits> - #include <gudhi/abstract_classes/Abs_Vectorized_topological_data.h> #include <gudhi/abstract_classes/Abs_Topological_data_with_averages.h> #include <gudhi/abstract_classes/Abs_Topological_data_with_distances.h> diff --git a/src/Gudhi_stat/include/gudhi/concretizations/read_persitence_from_file.h b/src/Gudhi_stat/include/gudhi/concretizations/read_persitence_from_file.h index 03446289..519c44fa 100644 --- a/src/Gudhi_stat/include/gudhi/concretizations/read_persitence_from_file.h +++ b/src/Gudhi_stat/include/gudhi/concretizations/read_persitence_from_file.h @@ -34,6 +34,114 @@ namespace Gudhi { namespace Gudhi_stat { + + +/** + * This procedure reads birth-death dagta from a file. We assume that in the file, there may be one type of string 'inf' or 'Inf'. If the second parameter of the program is set to -1, + * then those vales are ignored. If the second parameter of this program is set to a positive value, then the infinite intervals will be substituted by that number. +**/ +std::vector< std::pair< double,double > > read_file_names_that_may_contain_inf_string( char* filename , double what_to_substitute_for_infinite_bar = -1 ) +{ + + bool dbg = true; + + if ( !( access( filename, F_OK ) != -1 ) ) + { + cerr << "The file : " << filename << " do not exist. The program will now terminate \n"; + throw "The file from which you are trying to read do not exist. The program will now terminate \n"; + } + + std::string line; + std::vector< std::pair<double,double> > barcode; + + std::ifstream in; + in.open( filename ); + while (!in.eof()) + { + getline(in,line); + if ( !(line.length() == 0 || line[0] == '#') ) + { + std::stringstream lineSS; + lineSS << line; + double beginn, endd; + if ( (line.find("inf") != std::string::npos) || (line.find("Inf") != std::string::npos) ) + { + if ( dbg ) + { + std::cerr << "This line: " << line << " contains infinite interval. We will skip it. \n"; + } + if ( what_to_substitute_for_infinite_bar != -1 ) + { + lineSS >> beginn; + endd = what_to_substitute_for_infinite_bar; + } + else + { + continue; + } + } + else + { + lineSS >> beginn; + lineSS >> endd; + } + if ( beginn > endd ) + { + double b = beginn; + beginn = endd; + endd = b; + } + if ( dbg ) + { + std::cerr << "Getting an interval : " << beginn << "," << endd << std::endl; + } + barcode.push_back( std::make_pair( beginn , endd ) ); + } + } + return barcode; +}//readFileNames + + +/** + * This procedure reads names of files which are stored in a file. +**/ +std::vector< std::string > readFileNames( char* filenameWithFilenames ) +{ + bool dbg = false; + + if ( !( access( filenameWithFilenames, F_OK ) != -1 ) ) + { + cerr << "The file : " << filename << " do not exist. The program will now terminate \n"; + throw "The file from which you are trying to read do not exist. The program will now terminate \n"; + } + + std::vector< std::string > result; + std::ifstream in; + in.open( filenameWithFilenames ); + std::string line; + while (!in.eof()) + { + getline(in,line); + line.erase( std::remove_if( line.begin(), line.end(), ::isspace) , line.end() ); + + if (dbg){std::cerr << "line : " << line << std::endl;} + + if ( (line.length() == 0) || (line[0] == '#') ) + { + //in this case we have a file name. First we should remove all the white spaces. + if ( dbg ){std::cerr << "This is a line with comment, it will be ignored n";} + } + else + { + result.push_back( line.c_str() ); + if (dbg){std::cerr << "Line after removing white spaces : " << line << std::endl;} + } + } + in.close(); + + return result; +}//readFileNames + /** * This method reads persistence from standalone file. The format of the file is as follows: diff --git a/src/Gudhi_stat/utilities/CMakeLists.txt b/src/Gudhi_stat/utilities/CMakeLists.txt index d75acc43..4fc11b57 100644 --- a/src/Gudhi_stat/utilities/CMakeLists.txt +++ b/src/Gudhi_stat/utilities/CMakeLists.txt @@ -100,4 +100,7 @@ add_executable ( persistence_vectors/plot_persistence_vectors persistence_vector target_link_libraries(persistence_vectors/plot_persistence_vectors ${Boost_SYSTEM_LIBRARY}) +#some stat libraries: +#add_executable ( permutation_test permutation_test.cpp ) +#target_link_libraries(permutation_test ${Boost_SYSTEM_LIBRARY}) diff --git a/src/Gudhi_stat/utilities/persistence_vectors/create_persistence_vectors.cpp b/src/Gudhi_stat/utilities/persistence_vectors/create_persistence_vectors.cpp index 8e309b11..657dd2d4 100644 --- a/src/Gudhi_stat/utilities/persistence_vectors/create_persistence_vectors.cpp +++ b/src/Gudhi_stat/utilities/persistence_vectors/create_persistence_vectors.cpp @@ -46,6 +46,7 @@ int main( int argc , char** argv ) for ( size_t i = 0 ; i != filenames.size() ; ++i ) { std::cerr << "Creatign persistence vectors based on a file : " << filenames[i] << std::endl; + //std::vector< std::pair< double , double > > persistence_pairs = read_gudhi_file( filenames[i] , size_t dimension = 0 ) Vector_distances_in_diagram< euclidean_distance<double> > l( filenames[i] , -1 ); std::stringstream ss; ss << filenames[i] << ".vect"; |