summaryrefslogtreecommitdiff
path: root/src/Persistence_representations/include/gudhi/Persistence_landscape.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/Persistence_representations/include/gudhi/Persistence_landscape.h')
-rw-r--r--src/Persistence_representations/include/gudhi/Persistence_landscape.h130
1 files changed, 60 insertions, 70 deletions
diff --git a/src/Persistence_representations/include/gudhi/Persistence_landscape.h b/src/Persistence_representations/include/gudhi/Persistence_landscape.h
index 5c300112..c5aa7867 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;
@@ -1340,10 +1331,9 @@ void Persistence_landscape::plot(const char* filename, double xRangeBegin, doubl
// this program create a gnuplot script file that allows to plot persistence diagram.
std::ofstream out;
- std::ostringstream nameSS;
- nameSS << filename << "_GnuplotScript";
- std::string nameStr = nameSS.str();
- out.open(nameStr);
+ std::ostringstream gnuplot_script;
+ gnuplot_script << filename << "_GnuplotScript";
+ out.open(gnuplot_script.str().c_str());
if ((xRangeBegin != std::numeric_limits<double>::max()) || (xRangeEnd != std::numeric_limits<double>::max()) ||
(yRangeBegin != std::numeric_limits<double>::max()) || (yRangeEnd != std::numeric_limits<double>::max())) {
@@ -1376,8 +1366,8 @@ void Persistence_landscape::plot(const char* filename, double xRangeBegin, doubl
}
out << "EOF" << std::endl;
}
- std::cout << "Gnuplot script to visualize persistence diagram written to the file: " << nameStr << ". Type load '"
- << nameStr << "' in gnuplot to visualize." << std::endl;
+ std::cout << "To visualize, install gnuplot and type the command: gnuplot -persist -e \"load \'"
+ << gnuplot_script.str().c_str() << "\'\"" << std::endl;
}
} // namespace Persistence_representations