| 77 | } |
| 78 | |
| 79 | static double CalcSampleQuantileLinearSearch( |
| 80 | TConstArrayRef<float> sampleRef, |
| 81 | TConstArrayRef<float> weightsRef, |
| 82 | const double alpha |
| 83 | ) { |
| 84 | const int sampleSize = sampleRef.size(); |
| 85 | TVector<TValueWithWeight> elements; |
| 86 | elements.yresize(sampleSize); |
| 87 | for (auto i : xrange(sampleSize)) { |
| 88 | elements[i] = {sampleRef[i], weightsRef[i]}; |
| 89 | } |
| 90 | StableSort(elements, [](const TValueWithWeight& elem1, const TValueWithWeight& elem2) { |
| 91 | return elem1.Value < elem2.Value; |
| 92 | }); |
| 93 | const double totalWeight = Accumulate(weightsRef, 0.0); |
| 94 | const double needWeight = totalWeight * alpha; |
| 95 | double sumWeight = 0; |
| 96 | for (const auto& element : elements) { |
| 97 | sumWeight += element.Weight; |
| 98 | if (sumWeight >= needWeight - DBL_EPSILON) { |
| 99 | return element.Value; |
| 100 | } |
| 101 | } |
| 102 | return elements.back().Value; |
| 103 | } |
| 104 | |
| 105 | double CalcSampleQuantile( |
| 106 | TConstArrayRef<float> sampleRef, |
no test coverage detected