Loading...
Searching...
No Matches
PSSK.h
1/* This file is part of the Gudhi Library - https://gudhi.inria.fr/ - which is released under MIT.
2 * See file LICENSE or go to https://gudhi.inria.fr/licensing/ for full license details.
3 * Author(s): Pawel Dlotko
4 *
5 * Copyright (C) 2016 Inria
6 *
7 * Modification(s):
8 * - YYYY/MM Author: Description of the modification
9 */
10
11#ifndef PSSK_H_
12#define PSSK_H_
13
14// gudhi include
15#include <gudhi/Persistence_heat_maps.h>
16
17#include <limits>
18#include <utility>
19#include <vector>
20
21namespace Gudhi {
22namespace Persistence_representations {
23
34class PSSK : public Persistence_heat_maps<constant_scaling_function> {
35 public:
37
38 PSSK(const std::vector<std::pair<double, double> >& interval,
39 std::vector<std::vector<double> > filter = create_Gaussian_filter(5, 1), size_t number_of_pixels = 1000,
40 double min_ = -1, double max_ = -1)
42 this->construct(interval, filter, number_of_pixels, min_, max_);
43 }
44
45 PSSK(const char* filename, std::vector<std::vector<double> > filter = create_Gaussian_filter(5, 1),
46 size_t number_of_pixels = 1000, double min_ = -1, double max_ = -1,
47 unsigned dimension = std::numeric_limits<unsigned>::max())
49 std::vector<std::pair<double, double> > intervals_;
50 if (dimension == std::numeric_limits<unsigned>::max()) {
51 intervals_ = read_persistence_intervals_in_one_dimension_from_file(filename);
52 } else {
53 intervals_ = read_persistence_intervals_in_one_dimension_from_file(filename, dimension);
54 }
55 this->construct(intervals_, filter, number_of_pixels, min_, max_);
56 }
57
58 protected:
59 void construct(const std::vector<std::pair<double, double> >& intervals_,
60 std::vector<std::vector<double> > filter = create_Gaussian_filter(5, 1),
61 size_t number_of_pixels = 1000, double min_ = -1, double max_ = -1);
62};
63
64// if min_ == max_, then the program is requested to set up the values itself based on persistence intervals
65void PSSK::construct(const std::vector<std::pair<double, double> >& intervals_,
66 std::vector<std::vector<double> > filter, size_t number_of_pixels, double min_, double max_) {
67 bool dbg = false;
68 if (dbg) {
69 std::cerr << "Entering construct procedure \n";
70 getchar();
71 }
72
73 if (min_ == max_) {
74 // in this case, we want the program to set up the min_ and max_ values by itself.
75 min_ = std::numeric_limits<int>::max();
76 max_ = -std::numeric_limits<int>::max();
77
78 for (size_t i = 0; i != intervals_.size(); ++i) {
79 if (intervals_[i].first < min_) min_ = intervals_[i].first;
80 if (intervals_[i].second > max_) max_ = intervals_[i].second;
81 }
82 // now we have the structure filled in, and moreover we know min_ and max_ values of the interval, so we know the
83 // range.
84
85 // add some more space:
86 min_ -= fabs(max_ - min_) / 100;
87 max_ += fabs(max_ - min_) / 100;
88 }
89
90 if (dbg) {
91 std::cerr << "min_ : " << min_ << std::endl;
92 std::cerr << "max_ : " << max_ << std::endl;
93 std::cerr << "number_of_pixels : " << number_of_pixels << std::endl;
94 getchar();
95 }
96
97 this->min_ = min_;
98 this->max_ = max_;
99
100 // initialization of the structure heat_map
101 std::vector<std::vector<double> > heat_map_;
102 for (size_t i = 0; i != number_of_pixels; ++i) {
103 std::vector<double> v(number_of_pixels, 0);
104 heat_map_.push_back(v);
105 }
106 this->heat_map = heat_map_;
107
108 if (dbg) std::cerr << "Done creating of the heat map, now we will fill in the structure \n";
109
110 for (size_t pt_nr = 0; pt_nr != intervals_.size(); ++pt_nr) {
111 // compute the value of intervals_[pt_nr] in the grid:
112 int x_grid =
113 static_cast<int>((intervals_[pt_nr].first - this->min_) / (this->max_ - this->min_) * number_of_pixels);
114 int y_grid =
115 static_cast<int>((intervals_[pt_nr].second - this->min_) / (this->max_ - this->min_) * number_of_pixels);
116
117 if (dbg) {
118 std::cerr << "point : " << intervals_[pt_nr].first << " , " << intervals_[pt_nr].second << std::endl;
119 std::cerr << "x_grid : " << x_grid << std::endl;
120 std::cerr << "y_grid : " << y_grid << std::endl;
121 }
122
123 // x_grid and y_grid gives a center of the kernel. We want to have its lower left corner. To get this, we need to
124 // shift x_grid and y_grid by a grid diameter.
125 x_grid -= filter.size() / 2;
126 y_grid -= filter.size() / 2;
127 // note that the numbers x_grid and y_grid may be negative.
128
129 if (dbg) {
130 std::cerr << "After shift : \n";
131 std::cerr << "x_grid : " << x_grid << std::endl;
132 std::cerr << "y_grid : " << y_grid << std::endl;
133 std::cerr << "filter.size() : " << filter.size() << std::endl;
134 getchar();
135 }
136
137 for (size_t i = 0; i != filter.size(); ++i) {
138 for (size_t j = 0; j != filter.size(); ++j) {
139 // if the point (x_grid+i,y_grid+j) is the correct point in the grid.
140 if (((x_grid + i) >= 0) && (x_grid + i < this->heat_map.size()) && ((y_grid + j) >= 0) &&
141 (y_grid + j < this->heat_map.size())) {
142 if (dbg) {
143 std::cerr << y_grid + j << " " << x_grid + i << std::endl;
144 }
145 this->heat_map[y_grid + j][x_grid + i] += filter[i][j];
146 this->heat_map[x_grid + i][y_grid + j] += -filter[i][j];
147 }
148 }
149 }
150 }
151} // construct
152
153} // namespace Persistence_representations
154} // namespace Gudhi
155
156#endif // PSSK_H_
A class implementing persistence heat maps.
Definition: Persistence_heat_maps.h:178