Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix more edge cases in mape #1977

Merged
merged 1 commit into from
Jan 29, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/objective/regression_objective.hpp
Original file line number Diff line number Diff line change
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