| 525 | } |
| 526 | |
| 527 | std::vector<size_t> |
| 528 | histogram::histogram_count(const std::vector<double> &data, |
| 529 | const std::vector<double> &edges) { |
| 530 | std::vector<size_t> bin_counts(edges.size() - 1, 0); |
| 531 | for (const double &v : data) { |
| 532 | // find first edge that does not compare less than v |
| 533 | auto it = std::lower_bound(edges.begin(), edges.end(), v); |
| 534 | bool out_of_range = it == edges.begin() || it == edges.end(); |
| 535 | if (!out_of_range) { |
| 536 | ++bin_counts[it - edges.begin() - 1]; |
| 537 | } else if (it == edges.begin()) { |
| 538 | if (v == *it) { |
| 539 | ++bin_counts[0]; |
| 540 | } |
| 541 | } |
| 542 | } |
| 543 | return bin_counts; |
| 544 | } |
| 545 | |
| 546 | std::vector<double> |
| 547 | histogram::histogram_normalize(const std::vector<size_t> &bin_count, |