Normalize the number of points in a bin
| 61 | |
| 62 | /// Normalize the number of points in a bin |
| 63 | std::vector<std::vector<double>> |
| 64 | histnormalize2(const std::vector<std::vector<size_t>> &bin_count, |
| 65 | const std::vector<double> &xbin_edges, |
| 66 | const std::vector<double> &ybin_edges, size_t data_size, |
| 67 | enum histogram::normalization normalization_algorithm) { |
| 68 | std::vector<std::vector<double>> values( |
| 69 | bin_count.size(), std::vector<double>(bin_count[0].size(), 0)); |
| 70 | switch (normalization_algorithm) { |
| 71 | case histogram::normalization::count: |
| 72 | for (size_t i = 0; i < bin_count.size(); ++i) { |
| 73 | for (size_t j = 0; j < bin_count[0].size(); ++j) { |
| 74 | values[i][j] = static_cast<double>(bin_count[i][j]); |
| 75 | } |
| 76 | } |
| 77 | break; |
| 78 | case histogram::normalization::count_density: |
| 79 | for (size_t i = 0; i < bin_count.size(); ++i) { |
| 80 | for (size_t j = 0; j < bin_count[0].size(); ++j) { |
| 81 | const double x_bin_width_i = |
| 82 | xbin_edges[i + 1] - xbin_edges[i]; |
| 83 | const double y_bin_width_i = |
| 84 | ybin_edges[j + 1] - ybin_edges[j]; |
| 85 | const double bin_area_i = x_bin_width_i * y_bin_width_i; |
| 86 | values[i][j] = |
| 87 | static_cast<double>(bin_count[i][j]) / bin_area_i; |
| 88 | } |
| 89 | } |
| 90 | break; |
| 91 | case histogram::normalization::cummulative_count: |
| 92 | for (size_t i = 0; i < bin_count.size(); ++i) { |
| 93 | if (i == 0) { |
| 94 | values[0][0] = static_cast<double>(bin_count[0][0]); |
| 95 | } else { |
| 96 | values[i][0] = |
| 97 | static_cast<double>(bin_count[i][0]) + values[i - 1][0]; |
| 98 | } |
| 99 | double line_sum = values[i][0]; |
| 100 | for (size_t j = 1; j < bin_count[0].size(); ++j) { |
| 101 | if (i == 0) { |
| 102 | values[i][j] = bin_count[i][j] + line_sum; |
| 103 | } else { |
| 104 | values[i][j] = |
| 105 | bin_count[i][j] + line_sum + values[i - 1][j]; |
| 106 | } |
| 107 | line_sum += bin_count[i][j]; |
| 108 | } |
| 109 | } |
| 110 | break; |
| 111 | case histogram::normalization::probability: |
| 112 | for (size_t i = 0; i < bin_count.size(); ++i) { |
| 113 | for (size_t j = 0; j < bin_count[0].size(); ++j) { |
| 114 | // const double x_bin_width_i = xbin_edges[i + 1] - |
| 115 | // xbin_edges[i]; const double y_bin_width_i = ybin_edges[j |
| 116 | // + 1] - ybin_edges[j]; const double bin_area_i = |
| 117 | // x_bin_width_i*y_bin_width_i; |
| 118 | values[i][j] = |
| 119 | static_cast<double>(bin_count[i][j]) / data_size; |
| 120 | } |