Skip to content

Commit

Permalink
fix more edge cases in mape (#1977)
Browse files Browse the repository at this point in the history
  • Loading branch information
guolinke committed Jan 29, 2019
1 parent b7e772b commit a2f5c50
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/objective/regression_objective.hpp
Expand Up @@ -9,6 +9,7 @@
namespace LightGBM {

#define PercentileFun(T, data_reader, cnt_data, alpha) {\
if (cnt_data <= 1) { return data_reader(0); }\
std::vector<T> ref_data(cnt_data);\
for (data_size_t i = 0; i < cnt_data; ++i) {\
ref_data[i] = data_reader(i);\
Expand Down Expand Up @@ -36,6 +37,7 @@ namespace LightGBM {
}\

#define WeightedPercentileFun(T, data_reader, weight_reader, cnt_data, alpha) {\
if (cnt_data <= 1) { return data_reader(0); }\
std::vector<data_size_t> sorted_idx(cnt_data);\
for (data_size_t i = 0; i < cnt_data; ++i) {\
sorted_idx[i] = i;\
Expand All @@ -48,6 +50,7 @@ namespace LightGBM {
}\
double threshold = weighted_cdf[cnt_data - 1] * alpha;\
size_t pos = std::upper_bound(weighted_cdf.begin(), weighted_cdf.end(), threshold) - weighted_cdf.begin();\
pos = std::min(pos, static_cast<size_t>(cnt_data -1));\
if (pos == 0 || pos == static_cast<size_t>(cnt_data - 1)) {\
return data_reader(sorted_idx[pos]);\
}\
Expand Down

0 comments on commit a2f5c50

Please sign in to comment.