MCPcopy Create free account
hub / github.com/catboost/catboost / CalcSampleQuantileLinearSearch

Function CalcSampleQuantileLinearSearch

catboost/libs/helpers/quantile.cpp:79–103  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

77}
78
79static 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
105double CalcSampleQuantile(
106 TConstArrayRef<float> sampleRef,

Callers 1

CalcSampleQuantileFunction · 0.85

Calls 6

xrangeFunction · 0.85
StableSortFunction · 0.85
AccumulateFunction · 0.85
yresizeMethod · 0.80
sizeMethod · 0.45
backMethod · 0.45

Tested by

no test coverage detected