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

Method HistogramPercentile

library/cpp/expression/expression_variable.cpp:114–137  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

112 return G(secondOperand) ? ToDouble() : secondOperand.ToDouble();
113}
114double TExpressionVariable::HistogramPercentile(const TExpressionVariable& percentile) const {
115 if (!ToHistogramPointsAndBins().IsValidData(percentile.ToDouble())) {
116 return 0;
117 }
118
119 const auto& result = ToHistogramPointsAndBins().FindBinAndPartion(percentile.ToDouble());
120 const auto& binIndex = result.first;
121 const auto& partion = result.second;
122
123 // if percentile in [last point; +inf) return last point * 1.1
124 if (static_cast<size_t>(binIndex) == ToHistogramPointsAndBins().GetBins().size() - 1) {
125 return ToHistogramPointsAndBins().GetPoints().back() * 1.1;
126 }
127
128 auto leftBorderPoint = binIndex != 0 ? ToHistogramPointsAndBins().GetPoints()[binIndex - 1] : 0;
129 auto rightBorderPoint = ToHistogramPointsAndBins().GetPoints()[binIndex];
130
131 // if right border is max_int return left border * 1.1
132 if (rightBorderPoint == std::numeric_limits<int>::max()) {
133 return ToHistogramPointsAndBins().GetPoints()[ToHistogramPointsAndBins().GetPoints().size() - 2] * 1.1;
134 }
135
136 return leftBorderPoint + (rightBorderPoint - leftBorderPoint) * partion;
137}
138double TExpressionVariable::Or(const TExpressionVariable& secondOperand) const {
139 return !(IsZeroDoubleValue() && secondOperand.IsZeroDoubleValue());
140}

Callers 2

CalcVariantExpressionMethod · 0.80
Y_UNIT_TESTFunction · 0.80

Calls 7

IsValidDataMethod · 0.80
FindBinAndPartionMethod · 0.80
GetBinsMethod · 0.80
maxFunction · 0.50
ToDoubleMethod · 0.45
sizeMethod · 0.45
backMethod · 0.45

Tested by

no test coverage detected