Skip to content

[7.7][ML] Fix handling of numerical precision loss in logistic loss gradient and curvature #1043

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

Merged
merged 1 commit into from
Mar 6, 2020
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
8 changes: 5 additions & 3 deletions lib/maths/CBoostedTreeLoss.cc
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,9 @@ void CBinomialLogistic::gradient(const TMemoryMappedFloatVector& prediction,
double weight) const {
if (prediction(0) > -LOG_EPSILON && actual == 1.0) {
writer(0, -weight * std::exp(-prediction(0)));
} else {
writer(0, weight * (CTools::logisticFunction(prediction(0)) - actual));
}
writer(0, weight * (CTools::logisticFunction(prediction(0)) - actual));
}

void CBinomialLogistic::curvature(const TMemoryMappedFloatVector& prediction,
Expand All @@ -318,9 +319,10 @@ void CBinomialLogistic::curvature(const TMemoryMappedFloatVector& prediction,
double weight) const {
if (prediction(0) > -LOG_EPSILON) {
writer(0, weight * std::exp(-prediction(0)));
} else {
double probability{CTools::logisticFunction(prediction(0))};
writer(0, weight * probability * (1.0 - probability));
}
double probability{CTools::logisticFunction(prediction(0))};
writer(0, weight * probability * (1.0 - probability));
}

bool CBinomialLogistic::isCurvatureConstant() const {
Expand Down