diff options
Diffstat (limited to 'src/Persistence_representations/include/gudhi/Persistence_landscape_on_grid_exact.h')
-rw-r--r-- | src/Persistence_representations/include/gudhi/Persistence_landscape_on_grid_exact.h | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/src/Persistence_representations/include/gudhi/Persistence_landscape_on_grid_exact.h b/src/Persistence_representations/include/gudhi/Persistence_landscape_on_grid_exact.h index 25f71e27..52f24195 100644 --- a/src/Persistence_representations/include/gudhi/Persistence_landscape_on_grid_exact.h +++ b/src/Persistence_representations/include/gudhi/Persistence_landscape_on_grid_exact.h @@ -82,24 +82,25 @@ class Persistence_landscape_on_grid_exact { */ std::vector<std::vector<double> > vectorize() const { std::vector<std::vector<double> > ls; for(int i = 0; i < nb_ls; i++) ls.emplace_back(); - int num_pts = diagram.size(); double step = (max_x - min_x)/res_x; + int num_pts = diagram.size(); double step = (max_x - min_x)/(res_x - 1); + + std::vector<std::vector<double> > ls_t; for(int i = 0; i < res_x; i++) ls_t.emplace_back(); + for(int j = 0; j < num_pts; j++){ + double px = diagram[j].first; double py = diagram[j].second; double mid = (px+py)/2; + int first = std::ceil((px-min_x)/step); int middle = std::ceil((mid-min_x)/step); int last = std::ceil((py-min_x)/step); double x = min_x + first*step; + for(int i = first; i < middle; i++){ double value = std::sqrt(2)*(x-px); ls_t[i].push_back(value); x += step; } + for(int i = middle; i < last; i++){ double value = std::sqrt(2)*(py-x); ls_t[i].push_back(value); x += step; } + } for(int i = 0; i < res_x; i++){ - double x = min_x + i*step; double t = x / std::sqrt(2); std::vector<double> events; - for(int j = 0; j < num_pts; j++){ - double px = diagram[j].first; double py = diagram[j].second; - if(t >= px && t <= py){ if(t >= (px+py)/2) events.push_back(std::sqrt(2)*(py-t)); else events.push_back(std::sqrt(2)*(t-px)); } - } - - std::sort(events.begin(), events.end(), [](const double & a, const double & b){return a > b;}); int nb_events = events.size(); - for (int j = 0; j < nb_ls; j++){ if(j < nb_events) ls[j].push_back(events[j]); else ls[j].push_back(0); } + std::sort(ls_t[i].begin(), ls_t[i].end(), [](const double & a, const double & b){return a > b;}); + int nb_events_i = ls_t[i].size(); + for (int j = 0; j < nb_ls; j++){ if(j < nb_events_i) ls[j].push_back(ls_t[i][j]); else ls[j].push_back(0); } } + return ls; } - - - }; // class Persistence_landscape_on_grid_exact } // namespace Persistence_representations } // namespace Gudhi |