Unverified Commit 3af7f006 authored by jpkoponen's avatar jpkoponen Committed by GitHub
Browse files

Preventing denormal leaf values. (#2724)

parent 87b6396d
......@@ -89,8 +89,13 @@ class Tree {
/*! \brief Set the output of one leaf */
inline void SetLeafOutput(int leaf, double output) {
// Prevent denormal values because they can cause std::out_of_range exception when converting strings to doubles
if (IsZero(output)) {
leaf_value_[leaf] = 0;
} else {
leaf_value_[leaf] = output;
}
}
/*!
* \brief Adding prediction value of this tree model to scores
......@@ -149,7 +154,13 @@ class Tree {
inline void Shrinkage(double rate) {
#pragma omp parallel for schedule(static, 1024) if (num_leaves_ >= 2048)
for (int i = 0; i < num_leaves_; ++i) {
leaf_value_[i] *= rate;
double new_leaf_value = leaf_value_[i] * rate;
// Prevent denormal values because they can cause std::out_of_range exception when converting strings to doubles
if (IsZero(new_leaf_value)) {
leaf_value_[i] = 0;
} else {
leaf_value_[i] = new_leaf_value;
}
}
shrinkage_ *= rate;
}
......@@ -161,7 +172,13 @@ class Tree {
inline void AddBias(double val) {
#pragma omp parallel for schedule(static, 1024) if (num_leaves_ >= 2048)
for (int i = 0; i < num_leaves_; ++i) {
leaf_value_[i] = val + leaf_value_[i];
double new_leaf_value = val + leaf_value_[i];
// Prevent denormal values because they can cause std::out_of_range exception when converting strings to doubles
if (IsZero(new_leaf_value)) {
leaf_value_[i] = 0;
} else {
leaf_value_[i] = new_leaf_value;
}
}
// force to 1.0
shrinkage_ = 1.0f;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment