Loading...
Searching...
No Matches
common_persistence_representations.h
/* This file is part of the Gudhi Library - https://gudhi.inria.fr/ - which is released under MIT.
* See file LICENSE or go to https://gudhi.inria.fr/licensing/ for full license details.
* Author(s): Pawel Dlotko
*
* Copyright (C) 2016 Inria
*
* Modification(s):
* - YYYY/MM Author: Description of the modification
*/
#ifndef COMMON_PERSISTENCE_REPRESENTATIONS_H_
#define COMMON_PERSISTENCE_REPRESENTATIONS_H_
#include <utility>
#include <string>
#include <cmath>
#include <boost/math/constants/constants.hpp>
namespace Gudhi {
namespace Persistence_representations {
// this file contain an implementation of some common procedures used in Persistence_representations.
static constexpr double pi = boost::math::constants::pi<double>();
using Persistence_diagram = std::vector<std::pair<double, double> >;
// double epsi = std::numeric_limits<double>::epsilon();
double epsi = 0.000005;
inline bool almost_equal(double a, double b) {
if (std::fabs(a - b) < epsi) return true;
return false;
}
// landscapes
double minus_length(std::pair<double, double> a) { return a.first - a.second; }
double birth_plus_deaths(std::pair<double, double> a) { return a.first + a.second; }
// landscapes
std::pair<double, double> compute_parameters_of_a_line(std::pair<double, double> p1, std::pair<double, double> p2) {
double a = (p2.second - p1.second) / (p2.first - p1.first);
double b = p1.second - a * p1.first;
return std::make_pair(a, b);
}
// landscapes
double find_zero_of_a_line_segment_between_those_two_points(std::pair<double, double> p1,
std::pair<double, double> p2) {
if (p1.first == p2.first) return p1.first;
if (p1.second * p2.second > 0) {
std::ostringstream errMessage;
errMessage << "In function find_zero_of_a_line_segment_between_those_two_points the arguments are: (" << p1.first
<< "," << p1.second << ") and (" << p2.first << "," << p2.second
<< "). There is no zero in line between those two points. Program terminated.";
std::string errMessageStr = errMessage.str();
const char* err = errMessageStr.c_str();
throw(err);
}
// we assume here, that x \in [ p1.first, p2.first ] and p1 and p2 are points between which we will put the line
// segment
double a = (p2.second - p1.second) / (p2.first - p1.first);
double b = p1.second - a * p1.first;
return -b / a;
}
// landscapes
bool compare_points_sorting(std::pair<double, double> f, std::pair<double, double> s) {
if (f.first < s.first) {
return true;
} else { // f.first >= s.first
if (f.first > s.first) {
return false;
} else { // f.first == s.first
if (f.second > s.second) {
return true;
} else {
return false;
}
}
}
}
// landscapes
double function_value(std::pair<double, double> p1, std::pair<double, double> p2, double x) {
// we assume here, that x \in [ p1.first, p2.first ] and p1 and p2 are points between which we will put the line
// segment
double a = (p2.second - p1.second) / (p2.first - p1.first);
double b = p1.second - a * p1.first;
return (a * x + b);
}
} // namespace Persistence_representations
} // namespace Gudhi
#endif // COMMON_PERSISTENCE_REPRESENTATIONS_H_
Gudhi
Gudhi namespace.
Definition SimplicialComplexForAlpha.h:14