summaryrefslogtreecommitdiff
path: root/src/Persistence_representations/include/gudhi/Persistence_intervals.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/Persistence_representations/include/gudhi/Persistence_intervals.h')
-rw-r--r--src/Persistence_representations/include/gudhi/Persistence_intervals.h65
1 files changed, 35 insertions, 30 deletions
diff --git a/src/Persistence_representations/include/gudhi/Persistence_intervals.h b/src/Persistence_representations/include/gudhi/Persistence_intervals.h
index e2db4572..f4324cb2 100644
--- a/src/Persistence_representations/include/gudhi/Persistence_intervals.h
+++ b/src/Persistence_representations/include/gudhi/Persistence_intervals.h
@@ -6,6 +6,8 @@
*
* Modification(s):
* - YYYY/MM Author: Description of the modification
+ * - 2019/12 Vincent Rouvreau: Fix #118 - Make histogram_of_lengths and cumulative_histogram_of_lengths
+ * return the exact number_of_bins (was failing on x86)
*/
#ifndef PERSISTENCE_INTERVALS_H_
@@ -107,7 +109,7 @@ class Persistence_intervals {
std::vector<size_t> cumulative_histogram_of_lengths(size_t number_of_bins = 10) const;
/**
- * In this procedure we assume that each barcode is a characteristic function of a hight equal to its length. The
+ * In this procedure we assume that each barcode is a characteristic function of a height equal to its length. The
*persistence diagram is a sum of such a functions. The procedure below construct a function being a
* sum of the characteristic functions of persistence intervals. The first two parameters are the range in which the
*function is to be computed and the last parameter is the number of bins in
@@ -183,7 +185,7 @@ class Persistence_intervals {
out.close();
- std::cout << "To visualize, install gnuplot and type the command: gnuplot -persist -e \"load \'"
+ std::clog << "To visualize, install gnuplot and type the command: gnuplot -persist -e \"load \'"
<< gnuplot_script.str().c_str() << "\'\"" << std::endl;
}
@@ -205,7 +207,7 @@ class Persistence_intervals {
/**
* This is a simple function projecting the persistence intervals to a real number. The function we use here is a sum
*of squared lengths of intervals. It can be naturally interpreted as
- * sum of step function, where the step hight it equal to the length of the interval.
+ * sum of step function, where the step height it equal to the length of the interval.
* At the moment this function is not tested, since it is quite likely to be changed in the future. Given this, when
*using it, keep in mind that it
* will be most likely changed in the next versions.
@@ -291,7 +293,7 @@ std::vector<std::pair<double, double> > Persistence_intervals::dominant_interval
for (size_t i = 0; i != std::min(where_to_cut, position_length_vector.size()); ++i) {
result.push_back(this->intervals[position_length_vector[i].first]);
if (dbg)
- std::cerr << "Position : " << position_length_vector[i].first << " length : " << position_length_vector[i].second
+ std::clog << "Position : " << position_length_vector[i].first << " length : " << position_length_vector[i].second
<< std::endl;
}
@@ -301,7 +303,7 @@ std::vector<std::pair<double, double> > Persistence_intervals::dominant_interval
std::vector<size_t> Persistence_intervals::histogram_of_lengths(size_t number_of_bins) const {
bool dbg = false;
- if (dbg) std::cerr << "this->intervals.size() : " << this->intervals.size() << std::endl;
+ if (dbg) std::clog << "this->intervals.size() : " << this->intervals.size() << std::endl;
// first find the length of the longest interval:
double lengthOfLongest = 0;
for (size_t i = 0; i != this->intervals.size(); ++i) {
@@ -311,7 +313,7 @@ std::vector<size_t> Persistence_intervals::histogram_of_lengths(size_t number_of
}
if (dbg) {
- std::cerr << "lengthOfLongest : " << lengthOfLongest << std::endl;
+ std::clog << "lengthOfLongest : " << lengthOfLongest << std::endl;
}
// this is a container we will use to store the resulting histogram
@@ -328,16 +330,19 @@ std::vector<size_t> Persistence_intervals::histogram_of_lengths(size_t number_of
++result[position];
if (dbg) {
- std::cerr << "i : " << i << std::endl;
- std::cerr << "Interval : [" << this->intervals[i].first << " , " << this->intervals[i].second << " ] \n";
- std::cerr << "relative_length_of_this_interval : " << relative_length_of_this_interval << std::endl;
- std::cerr << "position : " << position << std::endl;
+ std::clog << "i : " << i << std::endl;
+ std::clog << "Interval : [" << this->intervals[i].first << " , " << this->intervals[i].second << " ] \n";
+ std::clog << "relative_length_of_this_interval : " << relative_length_of_this_interval << std::endl;
+ std::clog << "position : " << position << std::endl;
getchar();
}
}
+ // we want number of bins equals to number_of_bins (some unexpected results on x86)
+ result[number_of_bins-1]+=result[number_of_bins];
+ result.resize(number_of_bins);
if (dbg) {
- for (size_t i = 0; i != result.size(); ++i) std::cerr << result[i] << std::endl;
+ for (size_t i = 0; i != result.size(); ++i) std::clog << result[i] << std::endl;
}
return result;
}
@@ -363,7 +368,7 @@ std::vector<double> Persistence_intervals::characteristic_function_of_diagram(do
for (size_t i = 0; i != this->intervals.size(); ++i) {
if (dbg) {
- std::cerr << "Interval : " << this->intervals[i].first << " , " << this->intervals[i].second << std::endl;
+ std::clog << "Interval : " << this->intervals[i].first << " , " << this->intervals[i].second << std::endl;
}
size_t beginIt = 0;
@@ -385,8 +390,8 @@ std::vector<double> Persistence_intervals::characteristic_function_of_diagram(do
}
if (dbg) {
- std::cerr << "beginIt : " << beginIt << std::endl;
- std::cerr << "endIt : " << endIt << std::endl;
+ std::clog << "beginIt : " << beginIt << std::endl;
+ std::clog << "endIt : " << endIt << std::endl;
}
for (size_t pos = beginIt; pos != endIt; ++pos) {
@@ -394,11 +399,11 @@ std::vector<double> Persistence_intervals::characteristic_function_of_diagram(do
(this->intervals[i].second - this->intervals[i].first);
}
if (dbg) {
- std::cerr << "Result at this stage \n";
+ std::clog << "Result at this stage \n";
for (size_t aa = 0; aa != result.size(); ++aa) {
- std::cerr << result[aa] << " ";
+ std::clog << result[aa] << " ";
}
- std::cerr << std::endl;
+ std::clog << std::endl;
}
}
return result;
@@ -450,9 +455,9 @@ inline double compute_euclidean_distance(const std::pair<double, double>& f, con
std::vector<double> Persistence_intervals::k_n_n(size_t k, size_t where_to_cut) const {
bool dbg = false;
if (dbg) {
- std::cerr << "Here are the intervals : \n";
+ std::clog << "Here are the intervals : \n";
for (size_t i = 0; i != this->intervals.size(); ++i) {
- std::cerr << "[ " << this->intervals[i].first << " , " << this->intervals[i].second << "] \n";
+ std::clog << "[ " << this->intervals[i].first << " , " << this->intervals[i].second << "] \n";
}
getchar();
}
@@ -481,12 +486,12 @@ std::vector<double> Persistence_intervals::k_n_n(size_t k, size_t where_to_cut)
distances_from_diagonal[i] = distanceToDiagonal;
if (dbg) {
- std::cerr << "Here are the distances form the point : [" << this->intervals[i].first << " , "
+ std::clog << "Here are the distances form the point : [" << this->intervals[i].first << " , "
<< this->intervals[i].second << "] in the diagram \n";
for (size_t aa = 0; aa != distancesFromI.size(); ++aa) {
- std::cerr << "To : " << i + aa << " : " << distancesFromI[aa] << " ";
+ std::clog << "To : " << i + aa << " : " << distancesFromI[aa] << " ";
}
- std::cerr << std::endl;
+ std::clog << std::endl;
getchar();
}
@@ -497,18 +502,18 @@ std::vector<double> Persistence_intervals::k_n_n(size_t k, size_t where_to_cut)
}
}
if (dbg) {
- std::cerr << "Here is the distance matrix : \n";
+ std::clog << "Here is the distance matrix : \n";
for (size_t i = 0; i != distances.size(); ++i) {
for (size_t j = 0; j != distances.size(); ++j) {
- std::cerr << distances[i][j] << " ";
+ std::clog << distances[i][j] << " ";
}
- std::cerr << std::endl;
+ std::clog << std::endl;
}
- std::cerr << std::endl << std::endl << "And here are the distances to the diagonal : " << std::endl;
+ std::clog << std::endl << std::endl << "And here are the distances to the diagonal : " << std::endl;
for (size_t i = 0; i != distances_from_diagonal.size(); ++i) {
- std::cerr << distances_from_diagonal[i] << " ";
+ std::clog << distances_from_diagonal[i] << " ";
}
- std::cerr << std::endl << std::endl;
+ std::clog << std::endl << std::endl;
getchar();
}
@@ -521,13 +526,13 @@ std::vector<double> Persistence_intervals::k_n_n(size_t k, size_t where_to_cut)
if (k > distancesFromI.size()) {
if (dbg) {
- std::cerr << "There are not enough neighbors in your set. We set the result to plus infty \n";
+ std::clog << "There are not enough neighbors in your set. We set the result to plus infty \n";
}
result.push_back(std::numeric_limits<double>::max());
} else {
if (distances_from_diagonal[i] > distancesFromI[k]) {
if (dbg) {
- std::cerr << "The k-th n.n. is on a diagonal. Therefore we set up a distance to diagonal \n";
+ std::clog << "The k-th n.n. is on a diagonal. Therefore we set up a distance to diagonal \n";
}
result.push_back(distances_from_diagonal[i]);
} else {