Calculate exact quantile as truth
| 75 | |
| 76 | // Calculate exact quantile as truth |
| 77 | std::vector<double> ExactQuantile(std::vector<double> values, |
| 78 | const std::vector<double>& quantiles) { |
| 79 | std::sort(values.begin(), values.end()); |
| 80 | |
| 81 | std::vector<double> output; |
| 82 | for (double q : quantiles) { |
| 83 | const double index = (values.size() - 1) * q; |
| 84 | const int64_t lower_index = static_cast<int64_t>(index); |
| 85 | const double fraction = index - lower_index; |
| 86 | if (fraction == 0) { |
| 87 | output.push_back(values[lower_index]); |
| 88 | } else { |
| 89 | const double lerp = |
| 90 | fraction * values[lower_index + 1] + (1 - fraction) * values[lower_index]; |
| 91 | output.push_back(lerp); |
| 92 | } |
| 93 | } |
| 94 | return output; |
| 95 | } |
| 96 | |
| 97 | void TestRandom(size_t size) { |
| 98 | const std::vector<double> fixed_quantiles = {0, 0.01, 0.1, 0.2, 0.5, 0.8, 0.9, 0.99, 1}; |