Skip to content

Commit

Permalink
Avoid generating NaNs in UnwoundPathSum.
Browse files Browse the repository at this point in the history
Kudos to Jakub Zakrzewski for tracking down the bug.
  • Loading branch information
Kodiologist authored and hcho3 committed Dec 31, 2018
1 parent f368d0d commit 04038bf
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/tree/tree_model.cc
Original file line number Diff line number Diff line change
Expand Up @@ -293,9 +293,12 @@ bst_float UnwoundPathSum(const PathElement *unique_path, unsigned unique_depth,
total += tmp;
next_one_portion = unique_path[i].pweight - tmp * zero_fraction * ((unique_depth - i)
/ static_cast<bst_float>(unique_depth + 1));
} else {
} else if (zero_fraction != 0) {
total += (unique_path[i].pweight / zero_fraction) / ((unique_depth - i)
/ static_cast<bst_float>(unique_depth + 1));
} else {
CHECK_EQ(unique_path[i].pweight, 0)
<< "Unique path " << i << " must have zero weight";
}
}
return total;
Expand Down

0 comments on commit 04038bf

Please sign in to comment.