diff options
author | pdlotko <pdlotko@636b058d-ea47-450e-bf9e-a15bfbe3eedb> | 2016-06-30 19:59:01 +0000 |
---|---|---|
committer | pdlotko <pdlotko@636b058d-ea47-450e-bf9e-a15bfbe3eedb> | 2016-06-30 19:59:01 +0000 |
commit | c5bc4b47a409d98bd517156dc8d25f318d944c2c (patch) | |
tree | 16ed177121837e4c8de4e3aa2b52dfcf469c23db /src/Gudhi_stat | |
parent | 1271cb057566ac6177db77b2d7eeb3eb62be902f (diff) |
Adding Marc's comments.
git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/gudhi_stat@1372 636b058d-ea47-450e-bf9e-a15bfbe3eedb
Former-commit-id: 69203954cddee77e64669e381f349bdc28163e20
Diffstat (limited to 'src/Gudhi_stat')
3 files changed, 32 insertions, 38 deletions
diff --git a/src/Gudhi_stat/example/persistence_landscape.cpp b/src/Gudhi_stat/example/persistence_landscape.cpp index d080cd09..7bd04b4d 100644 --- a/src/Gudhi_stat/example/persistence_landscape.cpp +++ b/src/Gudhi_stat/example/persistence_landscape.cpp @@ -40,10 +40,8 @@ int main( int argc , char** argv ) { std::cerr << "To run this program, please provide a name of a file with persistence landscape \n"; //return 1; - } - //char* filename = argv[1]; - char* filename = (char*)"../test/data/file_with_diagram"; - Persistence_landscape p(filename); + } + Persistence_landscape p("../test/data/file_with_diagram"); Persistence_landscape q; q.load_landscape_from_file( "file_with_landscape_from_file_with_diagram" ); diff --git a/src/Gudhi_stat/include/gudhi/concretizations/Persistence_landscapes.h b/src/Gudhi_stat/include/gudhi/concretizations/Persistence_landscapes.h index cd399a41..f728bfbe 100644 --- a/src/Gudhi_stat/include/gudhi/concretizations/Persistence_landscapes.h +++ b/src/Gudhi_stat/include/gudhi/concretizations/Persistence_landscapes.h @@ -120,7 +120,7 @@ double find_zero_of_a_line_segment_between_those_two_points ( std::pair<double,d /** - * This function compare pairs of doubles for sorting purposes. + * Lexicographical ordering of points . **/ bool compare_points_sorting( std::pair<double,double> f, std::pair<double,double> s ) { @@ -162,11 +162,7 @@ double function_value ( std::pair<double,double> p1, std::pair<double,double> p2 } -/** - *Function internally used for operations on persistence landascapes. -**/ -inline double add(double x, double y){return x+y;} -inline double sub(double x, double y){return x-y;} + /** @@ -198,7 +194,7 @@ public: /** * Assignement operator. **/ - Persistence_landscape operator=( const Persistence_landscape& org ); + Persistence_landscape& operator=( const Persistence_landscape& org ); /** * Copy constructor. @@ -265,7 +261,7 @@ public: **/ friend Persistence_landscape add_two_landscapes ( const Persistence_landscape& land1 , const Persistence_landscape& land2 ) { - return operation_on_pair_of_landscapes(land1,land2,add); + return operation_on_pair_of_landscapes< std::plus<double> >(land1,land2); } /** @@ -273,7 +269,7 @@ public: **/ friend Persistence_landscape subtract_two_landscapes ( const Persistence_landscape& land1 , const Persistence_landscape& land2 ) { - return operation_on_pair_of_landscapes(land1,land2,sub); + return operation_on_pair_of_landscapes< std::minus<double> >(land1,land2); } /** @@ -328,7 +324,7 @@ public: /** - * Operator *=. The second parameter is a real number. + * Operator *=. The second parameter is a real number by which the y values of all landscape functions are multiplied. The x-values remain unchanged. **/ Persistence_landscape operator *= ( double x ) { @@ -381,7 +377,7 @@ public: /** * Computations of a L^i norm of landscape, where i is the input parameter. **/ - double compute_norm_of_landscape( int i ) + double compute_norm_of_landscape( double i ) { Persistence_landscape l; if ( i != -1 ) @@ -542,7 +538,7 @@ private: void construct_persistence_landscape_from_barcode( const std::vector< std::pair< double , double > > & p ); Persistence_landscape multiply_lanscape_by_real_number_not_overwrite( double x )const; void multiply_lanscape_by_real_number_overwrite( double x ); - friend Persistence_landscape operation_on_pair_of_landscapes ( const Persistence_landscape& land1 , const Persistence_landscape& land2 , double (*oper)(double,double) ); + template < typename oper > friend Persistence_landscape operation_on_pair_of_landscapes ( const Persistence_landscape& land1 , const Persistence_landscape& land2 ); friend double compute_maximal_distance_non_symmetric( const Persistence_landscape& pl1, const Persistence_landscape& pl2 ); void set_up_numbers_of_functions_for_vectorization_and_projections_to_reals() @@ -649,7 +645,7 @@ bool Persistence_landscape::operator == ( const Persistence_landscape& rhs )con } -Persistence_landscape Persistence_landscape::operator=( const Persistence_landscape& oryginal ) +Persistence_landscape& Persistence_landscape::operator=( const Persistence_landscape& oryginal ) { std::vector< std::vector< std::pair<double,double> > > land( oryginal.land.size() ); for ( size_t i = 0 ; i != oryginal.land.size() ; ++i ) @@ -1146,13 +1142,15 @@ void Persistence_landscape::load_landscape_from_file( const char* filename ) } -bool operation_on_pair_of_landscapesDBG = false; -Persistence_landscape operation_on_pair_of_landscapes ( const Persistence_landscape& land1 , const Persistence_landscape& land2 , double (*oper)(double,double) ) +template < typename T > +Persistence_landscape operation_on_pair_of_landscapes ( const Persistence_landscape& land1 , const Persistence_landscape& land2 ) { + bool operation_on_pair_of_landscapesDBG = false; if ( operation_on_pair_of_landscapesDBG ){std::cout << "operation_on_pair_of_landscapes\n";std::cin.ignore();} Persistence_landscape result; std::vector< std::vector< std::pair<double,double> > > land( std::max( land1.land.size() , land2.land.size() ) ); result.land = land; + T oper; for ( size_t i = 0 ; i != std::min( land1.land.size() , land2.land.size() ) ; ++i ) { @@ -1175,9 +1173,14 @@ Persistence_landscape operation_on_pair_of_landscapes ( const Persistence_landsc { std::cout << "first \n"; std::cout << " function_value(land2.land[i][q-1],land2.land[i][q],land1.land[i][p].first) : "<< function_value(land2.land[i][q-1],land2.land[i][q],land1.land[i][p].first) << "\n"; - std::cout << "oper( " << land1.land[i][p].second <<"," << function_value(land2.land[i][q-1],land2.land[i][q],land1.land[i][p].first) << " : " << oper( land1.land[i][p].second , function_value(land2.land[i][q-1],land2.land[i][q],land1.land[i][p].first) ) << "\n"; + //std::cout << "oper( " << land1.land[i][p].second <<"," << function_value(land2.land[i][q-1],land2.land[i][q],land1.land[i][p].first) << " : " << oper( land1.land[i][p].second , function_value(land2.land[i][q-1],land2.land[i][q],land1.land[i][p].first) ) << "\n"; } - lambda_n.push_back( std::make_pair( land1.land[i][p].first , oper( land1.land[i][p].second , function_value(land2.land[i][q-1],land2.land[i][q],land1.land[i][p].first) ) ) ); + lambda_n.push_back( + std::make_pair( + land1.land[i][p].first , + oper( (double)land1.land[i][p].second , function_value(land2.land[i][q-1],land2.land[i][q],land1.land[i][p].first) ) + ) + ); ++p; continue; } diff --git a/src/Gudhi_stat/test/persistence_lanscapes_test.cpp b/src/Gudhi_stat/test/persistence_lanscapes_test.cpp index 71363832..2e4369ab 100644 --- a/src/Gudhi_stat/test/persistence_lanscapes_test.cpp +++ b/src/Gudhi_stat/test/persistence_lanscapes_test.cpp @@ -44,9 +44,8 @@ using namespace std; BOOST_AUTO_TEST_CASE(check_construction_of_landscape) -{ - char* filename = (char*)"data/file_with_diagram"; - Persistence_landscape p(filename); +{ + Persistence_landscape p( "data/file_with_diagram" ); Persistence_landscape q; q.load_landscape_from_file( "data/file_with_landscape_from_file_with_diagram" ); @@ -57,8 +56,7 @@ BOOST_AUTO_TEST_CASE(check_construction_of_landscape) BOOST_AUTO_TEST_CASE(check_computations_of_integrals) { - char* filename = (char*)"data/file_with_diagram"; - Persistence_landscape p(filename); + Persistence_landscape p( "data/file_with_diagram" ); double integral = p.compute_integral_of_landscape(); //cerr << integral << " " << 2.34992 << endl; BOOST_CHECK( fabs( integral - 2.34992 ) <= 0.00001 ); @@ -67,8 +65,7 @@ BOOST_AUTO_TEST_CASE(check_computations_of_integrals) BOOST_AUTO_TEST_CASE(check_computations_of_integrals_for_each_level_separatelly) { - char* filename = (char*)"data/file_with_diagram"; - Persistence_landscape p(filename); + Persistence_landscape p( "data/file_with_diagram" ); std::vector< double > integrals_fir_different_levels; integrals_fir_different_levels.push_back( 0.216432 ); @@ -111,8 +108,7 @@ BOOST_AUTO_TEST_CASE(check_computations_of_integrals_for_each_level_separatelly) BOOST_AUTO_TEST_CASE(check_computations_of_integrals_of_powers_of_landscape) { - char* filename = (char*)"data/file_with_diagram"; - Persistence_landscape p(filename); + Persistence_landscape p( "data/file_with_diagram" ); std::vector<double> integrals_fir_different_powers; integrals_fir_different_powers.push_back( 0.216432 ); @@ -130,8 +126,7 @@ BOOST_AUTO_TEST_CASE(check_computations_of_integrals_of_powers_of_landscape) BOOST_AUTO_TEST_CASE(check_computations_of_values_on_different_points) { - char* filename = (char*)"data/file_with_diagram"; - Persistence_landscape p(filename); + Persistence_landscape p( "data/file_with_diagram" ); BOOST_CHECK( fabs( p.compute_value_at_a_given_point(1,0.0) ) <= 0.00001 ); @@ -150,9 +145,8 @@ BOOST_AUTO_TEST_CASE(check_computations_of_values_on_different_points) BOOST_AUTO_TEST_CASE(check_computations_sum_differences_and_multiplications) -{ - char* filename = (char*)"data/file_with_diagram"; - Persistence_landscape p(filename); +{ + Persistence_landscape p( "data/file_with_diagram" ); Persistence_landscape second; second.load_landscape_from_file("data/file_with_landscape_from_file_with_diagram_1" ); @@ -178,9 +172,8 @@ BOOST_AUTO_TEST_CASE(check_computations_sum_differences_and_multiplications) BOOST_AUTO_TEST_CASE(check_computations_of_maxima_and_norms) -{ - char* filename = (char*)"data/file_with_diagram"; - Persistence_landscape p(filename); +{ + Persistence_landscape p( "data/file_with_diagram" ); Persistence_landscape second; second.load_landscape_from_file("data/file_with_landscape_from_file_with_diagram_1" ); Persistence_landscape sum = p + second; |