26 #include <gudhi/Graph_matching.h> 37 namespace persistence_diagram {
39 inline double bottleneck_distance_approx(Persistence_graph& g,
double e) {
40 double b_lower_bound = 0.;
41 double b_upper_bound = g.diameter_bound();
42 const double alpha = std::pow(g.size(), 1. / 5.);
44 Graph_matching biggest_unperfect(g);
45 while (b_upper_bound - b_lower_bound > 2 * e) {
46 double step = b_lower_bound + (b_upper_bound - b_lower_bound) / alpha;
47 #if !defined FLT_EVAL_METHOD || FLT_EVAL_METHOD < 0 || FLT_EVAL_METHOD > 1 50 volatile double drop_excess_precision = step;
51 step = drop_excess_precision;
54 if (step <= b_lower_bound || step >= b_upper_bound)
57 while (m.multi_augment()) {}
59 m = biggest_unperfect;
62 biggest_unperfect = m;
66 return (b_lower_bound + b_upper_bound) / 2.;
69 inline double bottleneck_distance_exact(Persistence_graph& g) {
70 std::vector<double> sd = g.sorted_distances();
71 long lower_bound_i = 0;
72 long upper_bound_i = sd.size() - 1;
73 const double alpha = std::pow(g.size(), 1. / 5.);
75 Graph_matching biggest_unperfect(g);
76 while (lower_bound_i != upper_bound_i) {
77 long step = lower_bound_i +
static_cast<long> ((upper_bound_i - lower_bound_i - 1) / alpha);
79 while (m.multi_augment()) {}
81 m = biggest_unperfect;
84 biggest_unperfect = m;
85 lower_bound_i = step + 1;
88 return sd.at(lower_bound_i);
110 template<
typename Persistence_diagram1,
typename Persistence_diagram2>
112 double e = (std::numeric_limits<double>::min)()) {
113 Persistence_graph g(diag1, diag2, e);
114 if (g.bottleneck_alive() == std::numeric_limits<double>::infinity())
115 return std::numeric_limits<double>::infinity();
116 return (std::max)(g.bottleneck_alive(), e == 0. ? bottleneck_distance_exact(g) : bottleneck_distance_approx(g, e));
123 #endif // BOTTLENECK_H_ Definition: SimplicialComplexForAlpha.h:26
double bottleneck_distance(const Persistence_diagram1 &diag1, const Persistence_diagram2 &diag2, double e=(std::numeric_limits< double >::min)())
Function to compute the Bottleneck distance between two persistence diagrams.
Definition: Bottleneck.h:111