common_persistence_representations.h
1 /* This file is part of the Gudhi Library. The Gudhi library
2  * (Geometric Understanding in Higher Dimensions) is a generic C++
3  * library for computational topology.
4  *
5  * Author(s): Pawel Dlotko
6  *
7  * Copyright (C) 2016 Inria
8  *
9  * This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <http://www.gnu.org/licenses/>.
21  */
22 
23 #ifndef COMMON_PERSISTENCE_REPRESENTATIONS_H_
24 #define COMMON_PERSISTENCE_REPRESENTATIONS_H_
25 
26 #include <utility>
27 #include <string>
28 #include <cmath>
29 
30 namespace Gudhi {
31 namespace Persistence_representations {
32 // this file contain an implementation of some common procedures used in Persistence_representations.
33 
34 // double epsi = std::numeric_limits<double>::epsilon();
35 double epsi = 0.000005;
36 
42 inline bool almost_equal(double a, double b) {
43  if (std::fabs(a - b) < epsi) return true;
44  return false;
45 }
46 
47 // landscapes
51 double minus_length(std::pair<double, double> a) { return a.first - a.second; }
52 double birth_plus_deaths(std::pair<double, double> a) { return a.first + a.second; }
53 
54 // landscapes
59 std::pair<double, double> compute_parameters_of_a_line(std::pair<double, double> p1, std::pair<double, double> p2) {
60  double a = (p2.second - p1.second) / (p2.first - p1.first);
61  double b = p1.second - a * p1.first;
62  return std::make_pair(a, b);
63 }
64 
65 // landscapes
70 double find_zero_of_a_line_segment_between_those_two_points(std::pair<double, double> p1,
71  std::pair<double, double> p2) {
72  if (p1.first == p2.first) return p1.first;
73  if (p1.second * p2.second > 0) {
74  std::ostringstream errMessage;
75  errMessage << "In function find_zero_of_a_line_segment_between_those_two_points the arguments are: (" << p1.first
76  << "," << p1.second << ") and (" << p2.first << "," << p2.second
77  << "). There is no zero in line between those two points. Program terminated.";
78  std::string errMessageStr = errMessage.str();
79  const char* err = errMessageStr.c_str();
80  throw(err);
81  }
82  // we assume here, that x \in [ p1.first, p2.first ] and p1 and p2 are points between which we will put the line
83  // segment
84  double a = (p2.second - p1.second) / (p2.first - p1.first);
85  double b = p1.second - a * p1.first;
86  return -b / a;
87 }
88 
89 // landscapes
95 bool compare_points_sorting(std::pair<double, double> f, std::pair<double, double> s) {
96  if (f.first < s.first) {
97  return true;
98  } else { // f.first >= s.first
99  if (f.first > s.first) {
100  return false;
101  } else { // f.first == s.first
102  if (f.second > s.second) {
103  return true;
104  } else {
105  return false;
106  }
107  }
108  }
109 }
110 
111 // landscapes
116 double function_value(std::pair<double, double> p1, std::pair<double, double> p2, double x) {
117  // we assume here, that x \in [ p1.first, p2.first ] and p1 and p2 are points between which we will put the line
118  // segment
119  double a = (p2.second - p1.second) / (p2.first - p1.first);
120  double b = p1.second - a * p1.first;
121  return (a * x + b);
122 }
123 
124 } // namespace Persistence_representations
125 } // namespace Gudhi
126 
127 #endif // COMMON_PERSISTENCE_REPRESENTATIONS_H_
Definition: SimplicialComplexForAlpha.h:26
GUDHI  Version 2.2.0  - C++ library for Topological Data Analysis (TDA) and Higher Dimensional Geometry Understanding.  - Copyright : GPL v3 Generated on Fri Jun 22 2018 08:12:19 for GUDHI by Doxygen 1.8.13