diff options
author | vrouvrea <vrouvrea@636b058d-ea47-450e-bf9e-a15bfbe3eedb> | 2018-01-08 12:32:49 +0000 |
---|---|---|
committer | vrouvrea <vrouvrea@636b058d-ea47-450e-bf9e-a15bfbe3eedb> | 2018-01-08 12:32:49 +0000 |
commit | 7cf0599b211bc6cd5e8a64a75550cdf40b3fbb14 (patch) | |
tree | 768f0681a7798d382150643d6a21b893c7199728 | |
parent | d37d7b65e5ecaf3f7ada2874197cae4184594574 (diff) | |
parent | c64433834bdf168975aa7785b03cdcfdd67c6915 (diff) |
Merge of persistence_representations_fix_reading branch + clang format files
git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/trunk@3116 636b058d-ea47-450e-bf9e-a15bfbe3eedb
Former-commit-id: 0bae116ddc294d46e347d61fecc6e76b1e13f053
7 files changed, 127 insertions, 149 deletions
diff --git a/src/Persistence_representations/include/gudhi/PSSK.h b/src/Persistence_representations/include/gudhi/PSSK.h index e2d4225e..630f5623 100644 --- a/src/Persistence_representations/include/gudhi/PSSK.h +++ b/src/Persistence_representations/include/gudhi/PSSK.h @@ -121,10 +121,10 @@ void PSSK::construct(const std::vector<std::pair<double, double> >& intervals_, for (size_t pt_nr = 0; pt_nr != intervals_.size(); ++pt_nr) { // compute the value of intervals_[pt_nr] in the grid: - int x_grid = static_cast<int>((intervals_[pt_nr].first - this->min_) / - (this->max_ - this->min_) * number_of_pixels); - int y_grid = static_cast<int>((intervals_[pt_nr].second - this->min_) / - (this->max_ - this->min_) * number_of_pixels); + int x_grid = + static_cast<int>((intervals_[pt_nr].first - this->min_) / (this->max_ - this->min_) * number_of_pixels); + int y_grid = + static_cast<int>((intervals_[pt_nr].second - this->min_) / (this->max_ - this->min_) * number_of_pixels); if (dbg) { std::cerr << "point : " << intervals_[pt_nr].first << " , " << intervals_[pt_nr].second << std::endl; diff --git a/src/Persistence_representations/include/gudhi/Persistence_heat_maps.h b/src/Persistence_representations/include/gudhi/Persistence_heat_maps.h index 04dd78ad..fb741642 100644 --- a/src/Persistence_representations/include/gudhi/Persistence_heat_maps.h +++ b/src/Persistence_representations/include/gudhi/Persistence_heat_maps.h @@ -582,10 +582,10 @@ void Persistence_heat_maps<Scalling_of_kernels>::construct(const std::vector<std for (size_t pt_nr = 0; pt_nr != intervals_.size(); ++pt_nr) { // compute the value of intervals_[pt_nr] in the grid: - int x_grid = static_cast<int>((intervals_[pt_nr].first - this->min_) / - (this->max_ - this->min_) * number_of_pixels); - int y_grid = static_cast<int>((intervals_[pt_nr].second - this->min_) / - (this->max_ - this->min_) * number_of_pixels); + int x_grid = + static_cast<int>((intervals_[pt_nr].first - this->min_) / (this->max_ - this->min_) * number_of_pixels); + int y_grid = + static_cast<int>((intervals_[pt_nr].second - this->min_) / (this->max_ - this->min_) * number_of_pixels); if (dbg) { std::cerr << "point : " << intervals_[pt_nr].first << " , " << intervals_[pt_nr].second << std::endl; @@ -797,8 +797,7 @@ void Persistence_heat_maps<Scalling_of_kernels>::load_from_file(const char* file std::string temp; std::getline(in, temp); - - while (!in.eof()) { + while (in.good()) { std::getline(in, temp); std::stringstream lineSS; lineSS << temp; diff --git a/src/Persistence_representations/include/gudhi/Persistence_intervals.h b/src/Persistence_representations/include/gudhi/Persistence_intervals.h index 525d58a3..a3f963cf 100644 --- a/src/Persistence_representations/include/gudhi/Persistence_intervals.h +++ b/src/Persistence_representations/include/gudhi/Persistence_intervals.h @@ -402,9 +402,8 @@ std::vector<double> Persistence_intervals::characteristic_function_of_diagram(do } for (size_t pos = beginIt; pos != endIt; ++pos) { - result[pos] += - ((x_max - x_min) / static_cast<double>(number_of_bins)) * - (this->intervals[i].second - this->intervals[i].first); + result[pos] += ((x_max - x_min) / static_cast<double>(number_of_bins)) * + (this->intervals[i].second - this->intervals[i].first); } if (dbg) { std::cerr << "Result at this stage \n"; diff --git a/src/Persistence_representations/include/gudhi/Persistence_intervals_with_distances.h b/src/Persistence_representations/include/gudhi/Persistence_intervals_with_distances.h index d5ab04b4..e476d28a 100644 --- a/src/Persistence_representations/include/gudhi/Persistence_intervals_with_distances.h +++ b/src/Persistence_representations/include/gudhi/Persistence_intervals_with_distances.h @@ -26,7 +26,6 @@ #include <gudhi/Persistence_intervals.h> #include <gudhi/Bottleneck.h> - #include <limits> namespace Gudhi { diff --git a/src/Persistence_representations/include/gudhi/Persistence_landscape.h b/src/Persistence_representations/include/gudhi/Persistence_landscape.h index 5c300112..2d83dcc3 100644 --- a/src/Persistence_representations/include/gudhi/Persistence_landscape.h +++ b/src/Persistence_representations/include/gudhi/Persistence_landscape.h @@ -79,14 +79,16 @@ class Persistence_landscape { /** * Constructor that takes as an input a vector of birth-death pairs. **/ - Persistence_landscape(const std::vector<std::pair<double, double> >& p, size_t number_of_levels = std::numeric_limits<size_t>::max() ); + Persistence_landscape(const std::vector<std::pair<double, double> >& p, + size_t number_of_levels = std::numeric_limits<size_t>::max()); /** * Constructor that reads persistence intervals from file and creates persistence landscape. The format of the *input file is the following: in each line we put birth-death pair. Last line is assumed * to be empty. Even if the points within a line are not ordered, they will be ordered while the input is read. **/ - Persistence_landscape(const char* filename, size_t dimension = std::numeric_limits<unsigned>::max() , size_t number_of_levels = std::numeric_limits<size_t>::max() ); + Persistence_landscape(const char* filename, size_t dimension = std::numeric_limits<unsigned>::max(), + size_t number_of_levels = std::numeric_limits<size_t>::max()); /** * This procedure loads a landscape from file. It erase all the data that was previously stored in this landscape. @@ -285,7 +287,7 @@ class Persistence_landscape { *distance, we need to take its absolute value. This is the purpose of this procedure. **/ Persistence_landscape abs(); - + Persistence_landscape* new_abs(); /** @@ -453,7 +455,8 @@ class Persistence_landscape { size_t number_of_functions_for_vectorization; size_t number_of_functions_for_projections_to_reals; - void construct_persistence_landscape_from_barcode(const std::vector<std::pair<double, double> >& p , size_t number_of_levels = std::numeric_limits<size_t>::max()); + void construct_persistence_landscape_from_barcode(const std::vector<std::pair<double, double> >& p, + size_t number_of_levels = std::numeric_limits<size_t>::max()); Persistence_landscape multiply_lanscape_by_real_number_not_overwrite(double x) const; void multiply_lanscape_by_real_number_overwrite(double x); friend double compute_maximal_distance_non_symmetric(const Persistence_landscape& pl1, @@ -473,7 +476,7 @@ Persistence_landscape::Persistence_landscape(const char* filename, size_t dimens } else { barcode = read_persistence_intervals_in_one_dimension_from_file(filename); } - this->construct_persistence_landscape_from_barcode(barcode,number_of_levels); + this->construct_persistence_landscape_from_barcode(barcode, number_of_levels); this->set_up_numbers_of_functions_for_vectorization_and_projections_to_reals(); } @@ -506,14 +509,14 @@ bool Persistence_landscape::operator==(const Persistence_landscape& rhs) const { return true; } -Persistence_landscape::Persistence_landscape(const std::vector<std::pair<double, double> >& p,size_t number_of_levels) { - this->construct_persistence_landscape_from_barcode(p,number_of_levels); +Persistence_landscape::Persistence_landscape(const std::vector<std::pair<double, double> >& p, + size_t number_of_levels) { + this->construct_persistence_landscape_from_barcode(p, number_of_levels); this->set_up_numbers_of_functions_for_vectorization_and_projections_to_reals(); } void Persistence_landscape::construct_persistence_landscape_from_barcode( - const std::vector<std::pair<double, double> >& p, size_t number_of_levels) - { + const std::vector<std::pair<double, double> >& p, size_t number_of_levels) { bool dbg = false; if (dbg) { std::cerr << "Persistence_landscape::Persistence_landscape( const std::vector< std::pair< double , double > >& p )" @@ -648,12 +651,11 @@ void Persistence_landscape::construct_persistence_landscape_from_barcode( lambda_n.erase(std::unique(lambda_n.begin(), lambda_n.end()), lambda_n.end()); this->land.push_back(lambda_n); - + ++number_of_levels_in_the_landscape; - if ( number_of_levels == number_of_levels_in_the_landscape ) - { - break; - } + if (number_of_levels == number_of_levels_in_the_landscape) { + break; + } } } @@ -857,58 +859,47 @@ Persistence_landscape Persistence_landscape::abs() { return result; } +Persistence_landscape* Persistence_landscape::new_abs() { + Persistence_landscape* result = new Persistence_landscape(*this); + for (size_t level = 0; level != this->land.size(); ++level) { + if (AbsDbg) { + std::cout << "level: " << level << std::endl; + } + std::vector<std::pair<double, double> > lambda_n; + lambda_n.push_back(std::make_pair(-std::numeric_limits<int>::max(), 0)); + for (size_t i = 1; i != this->land[level].size(); ++i) { + if (AbsDbg) { + std::cout << "this->land[" << level << "][" << i << "] : " << this->land[level][i].first << " " + << this->land[level][i].second << std::endl; + } + // if a line segment between this->land[level][i-1] and this->land[level][i] crosses the x-axis, then we have to + // add one landscape point t o result + if ((this->land[level][i - 1].second) * (this->land[level][i].second) < 0) { + double zero = + find_zero_of_a_line_segment_between_those_two_points(this->land[level][i - 1], this->land[level][i]); -Persistence_landscape* Persistence_landscape::new_abs() -{ - Persistence_landscape* result = new Persistence_landscape(*this); - for (size_t level = 0; level != this->land.size(); ++level) - { - if (AbsDbg) - { - std::cout << "level: " << level << std::endl; - } - std::vector<std::pair<double, double> > lambda_n; - lambda_n.push_back(std::make_pair(-std::numeric_limits<int>::max(), 0)); - for (size_t i = 1; i != this->land[level].size(); ++i) - { - if (AbsDbg) - { - std::cout << "this->land[" << level << "][" << i << "] : " << this->land[level][i].first << " " - << this->land[level][i].second << std::endl; - } - // if a line segment between this->land[level][i-1] and this->land[level][i] crosses the x-axis, then we have to - // add one landscape point t o result - if ((this->land[level][i - 1].second) * (this->land[level][i].second) < 0) { - double zero = - find_zero_of_a_line_segment_between_those_two_points(this->land[level][i - 1], this->land[level][i]); - - lambda_n.push_back(std::make_pair(zero, 0)); - lambda_n.push_back(std::make_pair(this->land[level][i].first, fabs(this->land[level][i].second))); - if (AbsDbg) - { - std::cout << "Adding pair : (" << zero << ",0)" << std::endl; - std::cout << "In the same step adding pair : (" << this->land[level][i].first << "," - << fabs(this->land[level][i].second) << ") " << std::endl; - std::cin.ignore(); - } - } - else - { - lambda_n.push_back(std::make_pair(this->land[level][i].first, fabs(this->land[level][i].second))); - if (AbsDbg) - { - std::cout << "Adding pair : (" << this->land[level][i].first << "," << fabs(this->land[level][i].second) - << ") " << std::endl; - std::cin.ignore(); - } - } - } - result->land.push_back(lambda_n); - } - return result; + lambda_n.push_back(std::make_pair(zero, 0)); + lambda_n.push_back(std::make_pair(this->land[level][i].first, fabs(this->land[level][i].second))); + if (AbsDbg) { + std::cout << "Adding pair : (" << zero << ",0)" << std::endl; + std::cout << "In the same step adding pair : (" << this->land[level][i].first << "," + << fabs(this->land[level][i].second) << ") " << std::endl; + std::cin.ignore(); + } + } else { + lambda_n.push_back(std::make_pair(this->land[level][i].first, fabs(this->land[level][i].second))); + if (AbsDbg) { + std::cout << "Adding pair : (" << this->land[level][i].first << "," << fabs(this->land[level][i].second) + << ") " << std::endl; + std::cin.ignore(); + } + } + } + result->land.push_back(lambda_n); + } + return result; } - Persistence_landscape Persistence_landscape::multiply_lanscape_by_real_number_not_overwrite(double x) const { std::vector<std::vector<std::pair<double, double> > > result(this->land.size()); for (size_t dim = 0; dim != this->land.size(); ++dim) { @@ -954,7 +945,7 @@ void Persistence_landscape::load_landscape_from_file(const char* filename) { std::vector<std::pair<double, double> > landscapeAtThisLevel; bool isThisAFirsLine = true; - while (!in.eof()) { + while (in.good()) { getline(in, line); if (!(line.length() == 0 || line[0] == '#')) { std::stringstream lineSS; diff --git a/src/Persistence_representations/include/gudhi/Persistence_vectors.h b/src/Persistence_representations/include/gudhi/Persistence_vectors.h index 0fb49eee..aed48b73 100644 --- a/src/Persistence_representations/include/gudhi/Persistence_vectors.h +++ b/src/Persistence_representations/include/gudhi/Persistence_vectors.h @@ -617,9 +617,7 @@ void Vector_distances_in_diagram<F>::load_from_file(const char* filename) { } double number; - while (true) { - in >> number; - if (in.eof()) break; + while (in >> number) { this->sorted_vector_of_distances.push_back(number); } in.close(); diff --git a/src/Persistence_representations/include/gudhi/read_persistence_from_file.h b/src/Persistence_representations/include/gudhi/read_persistence_from_file.h index 770da15b..450c223c 100644 --- a/src/Persistence_representations/include/gudhi/read_persistence_from_file.h +++ b/src/Persistence_representations/include/gudhi/read_persistence_from_file.h @@ -50,81 +50,73 @@ namespace Persistence_representations { * The procedure returns vector of persistence pairs. **/ std::vector<std::pair<double, double> > read_persistence_intervals_in_one_dimension_from_file( - std::string const& filename, int dimension = -1, double what_to_substitute_for_infinite_bar = -1) { + std::string const& filename, int dimension = -1, double what_to_substitute_for_infinite_bar = -1) { bool dbg = false; std::string line; - std::vector<std::pair<double, double> > barcode_initial = read_persistence_intervals_in_dimension(filename,(int)dimension); + std::vector<std::pair<double, double> > barcode_initial = + read_persistence_intervals_in_dimension(filename, (int)dimension); std::vector<std::pair<double, double> > final_barcode; - final_barcode.reserve( barcode_initial.size() ); - - if ( dbg ) - { - std::cerr << "Here are the intervals that we read from the file : \n"; - for ( size_t i = 0 ; i != barcode_initial.size() ; ++i ) - { - std::cout << barcode_initial[i].first << " " << barcode_initial[i].second << std::endl; - } - getchar(); + final_barcode.reserve(barcode_initial.size()); + + if (dbg) { + std::cerr << "Here are the intervals that we read from the file : \n"; + for (size_t i = 0; i != barcode_initial.size(); ++i) { + std::cout << barcode_initial[i].first << " " << barcode_initial[i].second << std::endl; + } + getchar(); } - - for ( size_t i = 0 ; i != barcode_initial.size() ; ++i ) - { - if ( dbg ) - { - std::cout << "COnsidering interval : " << barcode_initial[i].first << " " << barcode_initial[i].second << std::endl; - } - // if ( barcode_initial[i].first == barcode_initial[i].second ) - //{ - // if ( dbg )std::cout << "It has zero length \n"; - // continue;//zero length intervals are not relevant, so we skip all of them. - //} - - if ( barcode_initial[i].first > barcode_initial[i].second )//note that in this case barcode_initial[i].second != std::numeric_limits<double>::infinity() - { - if ( dbg )std::cout << "Swap and enter \n"; - //swap them to make sure that birth < death - final_barcode.push_back( std::pair<double,double>( barcode_initial[i].second , barcode_initial[i].first ) ); - continue; - } - else - { - if ( barcode_initial[i].second != std::numeric_limits<double>::infinity() ) - { - if ( dbg )std::cout << "Simply enters\n"; - //in this case, due to the previous conditions we know that barcode_initial[i].first < barcode_initial[i].second, so we put them as they are - final_barcode.push_back( std::pair<double,double>( barcode_initial[i].first , barcode_initial[i].second ) ); - } - } - - if ( (barcode_initial[i].second == std::numeric_limits<double>::infinity() ) && ( what_to_substitute_for_infinite_bar != -1 ) ) - { - if ( barcode_initial[i].first < what_to_substitute_for_infinite_bar )//if only birth < death. - { - final_barcode.push_back( std::pair<double,double>( barcode_initial[i].first , what_to_substitute_for_infinite_bar ) ); - } - } - else - { - //if the variable what_to_substitute_for_infinite_bar is not set, then we ignore all the infinite bars. - } + + for (size_t i = 0; i != barcode_initial.size(); ++i) { + if (dbg) { + std::cout << "COnsidering interval : " << barcode_initial[i].first << " " << barcode_initial[i].second + << std::endl; + } + // if ( barcode_initial[i].first == barcode_initial[i].second ) + //{ + // if ( dbg )std::cout << "It has zero length \n"; + // continue;//zero length intervals are not relevant, so we skip all of them. + //} + + if (barcode_initial[i].first > + barcode_initial[i] + .second) // note that in this case barcode_initial[i].second != std::numeric_limits<double>::infinity() + { + if (dbg) std::cout << "Swap and enter \n"; + // swap them to make sure that birth < death + final_barcode.push_back(std::pair<double, double>(barcode_initial[i].second, barcode_initial[i].first)); + continue; + } else { + if (barcode_initial[i].second != std::numeric_limits<double>::infinity()) { + if (dbg) std::cout << "Simply enters\n"; + // in this case, due to the previous conditions we know that barcode_initial[i].first < + // barcode_initial[i].second, so we put them as they are + final_barcode.push_back(std::pair<double, double>(barcode_initial[i].first, barcode_initial[i].second)); + } + } + + if ((barcode_initial[i].second == std::numeric_limits<double>::infinity()) && + (what_to_substitute_for_infinite_bar != -1)) { + if (barcode_initial[i].first < what_to_substitute_for_infinite_bar) // if only birth < death. + { + final_barcode.push_back( + std::pair<double, double>(barcode_initial[i].first, what_to_substitute_for_infinite_bar)); + } + } else { + // if the variable what_to_substitute_for_infinite_bar is not set, then we ignore all the infinite bars. + } } - - - if ( dbg ) - { - std::cerr << "Here are the final bars that we are sending further : \n"; - for ( size_t i = 0 ; i != final_barcode.size() ; ++i ) - { - std::cout << final_barcode[i].first << " " << final_barcode[i].second << std::endl; - } - std::cerr << "final_barcode.size() : " << final_barcode.size() << std::endl; - getchar(); + + if (dbg) { + std::cerr << "Here are the final bars that we are sending further : \n"; + for (size_t i = 0; i != final_barcode.size(); ++i) { + std::cout << final_barcode[i].first << " " << final_barcode[i].second << std::endl; + } + std::cerr << "final_barcode.size() : " << final_barcode.size() << std::endl; + getchar(); } - - - - return final_barcode; + + return final_barcode; } // read_persistence_intervals_in_one_dimension_from_file } // namespace Persistence_representations |