16#include <gudhi/Graph_matching.h>
18#include <CGAL/version.h>
28#if CGAL_VERSION_NR < 1041101000
29# error bottleneck_distance is only available for CGAL >= 4.11
34namespace persistence_diagram {
36inline double bottleneck_distance_approx(Persistence_graph& g,
double e) {
37 double b_lower_bound = 0.;
38 double b_upper_bound = g.max_dist_to_diagonal();
39 int graph_size = g.size();
43 const double alpha = std::pow(graph_size, 1. / 5.);
45 Graph_matching biggest_unperfect(g);
46 while (b_upper_bound - b_lower_bound > 2 * e) {
47 double step = b_lower_bound + (b_upper_bound - b_lower_bound) / alpha;
48#if !defined FLT_EVAL_METHOD || FLT_EVAL_METHOD < 0 || FLT_EVAL_METHOD > 1
51 volatile double drop_excess_precision = step;
52 step = drop_excess_precision;
55 if (step <= b_lower_bound || step >= b_upper_bound)
58 while (m.multi_augment()) {}
60 m = biggest_unperfect;
63 biggest_unperfect = m;
67 return (b_lower_bound + b_upper_bound) / 2.;
70inline double bottleneck_distance_exact(Persistence_graph& g) {
71 std::vector<double> sd = g.sorted_distances();
72 long lower_bound_i = 0;
73 long upper_bound_i = sd.size() - 1;
74 const double alpha = std::pow(g.size(), 1. / 5.);
76 Graph_matching biggest_unperfect(g);
77 while (lower_bound_i != upper_bound_i) {
78 long step = lower_bound_i +
static_cast<long> ((upper_bound_i - lower_bound_i - 1) / alpha);
80 while (m.multi_augment()) {}
82 m = biggest_unperfect;
85 biggest_unperfect = m;
86 lower_bound_i = step + 1;
89 return sd.at(lower_bound_i);
115template<
typename Persistence_diagram1,
typename Persistence_diagram2>
117 double e = (std::numeric_limits<double>::min)()) {
118 Persistence_graph g(diag1, diag2, e);
119 if (g.bottleneck_alive() == std::numeric_limits<double>::infinity())
120 return std::numeric_limits<double>::infinity();
121 return (std::max)(g.bottleneck_alive(), e == 0. ? bottleneck_distance_exact(g) : bottleneck_distance_approx(g, e));
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:116
Gudhi namespace.
Definition: SimplicialComplexForAlpha.h:14