From a6b1719067462f93a7ee3b7f8f632b85fe27117d Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Tue, 3 Apr 2018 08:40:05 +0000 Subject: Add warnings for rips persistence from correlation matrix (points under the diagonal). Use range instead of vector in write_persistence_intervals_to_stream git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/rips_complex_from_correlation_matrix@3326 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: ea0fdc32c91f1927c5a9f2a3864360895ce8128a --- .../include/gudhi/writing_persistence_to_file.h | 212 ++++++++------------- 1 file changed, 75 insertions(+), 137 deletions(-) (limited to 'src/common/include') diff --git a/src/common/include/gudhi/writing_persistence_to_file.h b/src/common/include/gudhi/writing_persistence_to_file.h index 5457cf48..5020b5fb 100644 --- a/src/common/include/gudhi/writing_persistence_to_file.h +++ b/src/common/include/gudhi/writing_persistence_to_file.h @@ -29,150 +29,88 @@ namespace Gudhi { - /** -* This is a class to store persistence intervals. Its main purpose is to +* This is a class to store persistence intervals. Its main purpose is to * exchange data in between different packages and provide unified way -* of writing a collection of persistence intervals to file. +* of writing a collection of persistence intervals to file. **/ -template -class Persistence_interval_common -{ -public: - /** - * Constructor taking as an input birth and death of the pair. - **/ - Persistence_interval_common( Filtration_type birth , Filtration_type death ): - birth_(birth),death_(death),dimension_(std::numeric_limits::max), - arith_element_(std::numeric_limits::max() ){} - - /** - * Constructor taking as an input birth, death and dimension of the pair. - **/ - Persistence_interval_common( Filtration_type birth , Filtration_type death, - unsigned dim ): - birth_(birth),death_(death),dimension_(dim), - arith_element_(std::numeric_limits::max()){} - - /** - * Constructor taking as an input birth, death, dimension of the pair as well - * as the number p such that this interval is present over Z_p field. - **/ - Persistence_interval_common( Filtration_type birth , Filtration_type death, - unsigned dim , Coefficient_field field ): - birth_(birth),death_(death),dimension_(dim), - arith_element_(field){} - - /** - * Operator to compare two persistence pairs. During the comparision all the - * fields: birth, death, dimensiona and arith_element_ are taken into account - * and they all have to be equal for two pairs to be equal. - **/ - inline bool operator == ( const Persistence_interval_common &i2) - { - return ( - (this->birth_ == i2.birth_) && (this->death_ == i2.death_) && - (this->dimension_ == i2.dimension_) && (this->arith_element_ == i2.arith_element_) - ); - } - - /** - * Check if two persistence paris are not equal. - **/ - inline bool operator != ( const Persistence_interval_common &i2) - { - return (!((*this)==i2)); - } - - - /** - * Operator to compare objects of a type Persistence_interval_common. - * One intervals is smaller than the other if it has lower persistence. - * Note that this operator do not take Arith_element into account when doing comparisions. - **/ - inline bool operator < ( const Persistence_interval_common &i2) - { - return fabs( this->death_-this->birth_ ) < fabs( i2.death_-i2.birth_ ); - //if ( this->birth_ < i2.birth_ ) - //{ - // return true; - //} - //else - //{ - // if ( this->birth_ > i2.birth_ ) - // { - // return false; - // } - // else - // { - // //in this case this->birth_ == i2.birth_ - // if ( this->death_ > i2.death_ ) - // { - // return true; - // } - // else - // { - // if ( this->death_ < i2.death_ ) - // { - // return false; - // } - // else - // { - // //in this case this->death_ == i2.death_ - // if ( this->dimension_ < i2.dimension_ ) - // { - // return true; - // } - // else - // { - // //in this case this->dimension >= i2.dimension - // return false; - // } - // } - // } - // } - //} - } - - friend std::ostream& operator<<(std::ostream& out, const Persistence_interval_common& it) - { - if ( it.arith_element_ != std::numeric_limits::max() ) - { - out << it.arith_element_ << " "; - } - if ( it.dimension_ != std::numeric_limits::max() ) - { - out << it.dimension_ << " "; - } - out << it.birth_ << " " << it.death_ << " "; - return out; - } - -private: - Filtration_type birth_; - Filtration_type death_; - unsigned dimension_; - Coefficient_field arith_element_; -};//Persistence_interval_common +template +class Persistence_interval_common { + public: + /** + * Constructor taking as an input birth and death of the pair. + **/ + Persistence_interval_common(Filtration_type birth, Filtration_type death) + : birth_(birth), + death_(death), + dimension_(std::numeric_limits::max), + arith_element_(std::numeric_limits::max()) {} + /** + * Constructor taking as an input birth, death and dimension of the pair. + **/ + Persistence_interval_common(Filtration_type birth, Filtration_type death, unsigned dim) + : birth_(birth), death_(death), dimension_(dim), arith_element_(std::numeric_limits::max()) {} -/** - * This function write a vector to a stream -**/ -template -void write_persistence_intervals_to_stream( -const std::vector< Persistence_interval_common >& intervals, -//TODO: change to ranges when it is clear how to do that. - std::ostream& out = std::cout ) -{ - for ( auto interval : intervals ) - { - out << interval << "\n"; - } -}//write_persistence_intervals_to_stream + /** +* Constructor taking as an input birth, death, dimension of the pair as well +* as the number p such that this interval is present over Z_p field. +**/ + Persistence_interval_common(Filtration_type birth, Filtration_type death, unsigned dim, Coefficient_field field) + : birth_(birth), death_(death), dimension_(dim), arith_element_(field) {} + + /** + * Operator to compare two persistence pairs. During the comparision all the + * fields: birth, death, dimensiona and arith_element_ are taken into account + * and they all have to be equal for two pairs to be equal. + **/ + inline bool operator==(const Persistence_interval_common& i2) { + return ((this->birth_ == i2.birth_) && (this->death_ == i2.death_) && (this->dimension_ == i2.dimension_) && + (this->arith_element_ == i2.arith_element_)); + } + + /** + * Check if two persistence paris are not equal. + **/ + inline bool operator!=(const Persistence_interval_common& i2) { return (!((*this) == i2)); } + /** + * Operator to compare objects of a type Persistence_interval_common. + * One intervals is smaller than the other if it has lower persistence. + * Note that this operator do not take Arith_element into account when doing comparisions. + **/ + inline bool operator<(const Persistence_interval_common& i2) { + return fabs(this->death_ - this->birth_) < fabs(i2.death_ - i2.birth_); + } + friend std::ostream& operator<<(std::ostream& out, const Persistence_interval_common& it) { + if (it.arith_element_ != std::numeric_limits::max()) { + out << it.arith_element_ << " "; + } + if (it.dimension_ != std::numeric_limits::max()) { + out << it.dimension_ << " "; + } + out << it.birth_ << " " << it.death_ << " "; + return out; + } + private: + Filtration_type birth_; + Filtration_type death_; + unsigned dimension_; + Coefficient_field arith_element_; +}; + +/** + * This function write a vector to a stream +**/ +template +void write_persistence_intervals_to_stream(const Persistence_interval_range& intervals, + std::ostream& out = std::cout) { + for (auto interval : intervals) { + out << interval << "\n"; + } +} } -#endif //WRITING_PERSISTENCE_TO_FILE_H +#endif // WRITING_PERSISTENCE_TO_FILE_H -- cgit v1.2.3