Unverified Commit 7f91dc66 authored by mjmckp's avatar mjmckp Committed by GitHub
Browse files

Use high precision conversion from double to string in Tree::ToString() for...


Use high precision conversion from double to string in Tree::ToString() for new linear tree members (#3938)

* Fix index out-of-range exception generated by BaggingHelper on small datasets.

Prior to this change, the line "score_t threshold = tmp_gradients[top_k - 1];" would generate an exception, since tmp_gradients would be empty when the cnt input value to the function is zero.

* Update goss.hpp

* Update goss.hpp

* Add API method LGBM_BoosterPredictForMats which runs prediction on a data set given as of array of pointers to rows (as opposed to existing method LGBM_BoosterPredictForMat which requires data given as contiguous array)

* Fix incorrect upstream merge

* Add link to LightGBM.NET

* Fix indenting to 2 spaces

* Dummy edit to trigger CI

* Dummy edit to trigger CI

* remove duplicate functions from merge

* In Tree::ToString() method, print double values for linear tree models with high precision, so that the tree may be accurately reproduced elsewhere (LightGBM.Net in particular)

* Need to use more precise StringToArray instead of StringToArrayFast when parsing double valued arrays for linear trees, to ensure models round-trip via string or file correctly.
Co-authored-by: default avatarmatthew-peacock <matthew.peacock@whiteoakam.com>
Co-authored-by: default avatarGuolin Ke <guolin.ke@outlook.com>
parent 7880b79f
......@@ -376,7 +376,7 @@ std::string Tree::ToString() const {
if (is_linear_) {
str_buf << "leaf_const="
<< ArrayToString(leaf_const_, num_leaves_) << '\n';
<< ArrayToString<true>(leaf_const_, num_leaves_) << '\n';
std::vector<int> num_feat(num_leaves_);
for (int i = 0; i < num_leaves_; ++i) {
num_feat[i] = static_cast<int>(leaf_coeff_[i].size());
......@@ -394,7 +394,7 @@ std::string Tree::ToString() const {
str_buf << "leaf_coeff=";
for (int i = 0; i < num_leaves_; ++i) {
if (num_feat[i] > 0) {
str_buf << ArrayToString(leaf_coeff_[i], leaf_coeff_[i].size()) << ' ';
str_buf << ArrayToString<true>(leaf_coeff_[i], leaf_coeff_[i].size()) << ' ';
}
str_buf << ' ';
}
......@@ -769,7 +769,7 @@ Tree::Tree(const char* str, size_t* used_len) {
if (is_linear_) {
if (key_vals.count("leaf_const")) {
leaf_const_ = Common::StringToArrayFast<double>(key_vals["leaf_const"], num_leaves_);
leaf_const_ = Common::StringToArray<double>(key_vals["leaf_const"], num_leaves_);
} else {
leaf_const_.resize(num_leaves_);
}
......@@ -791,7 +791,7 @@ Tree::Tree(const char* str, size_t* used_len) {
}
std::vector<double> all_leaf_coeff;
if (key_vals.count("leaf_coeff")) {
all_leaf_coeff = Common::StringToArrayFast<double>(key_vals["leaf_coeff"], total_num_feat);
all_leaf_coeff = Common::StringToArray<double>(key_vals["leaf_coeff"], total_num_feat);
}
int sum_num_feat = 0;
for (int i = 0; i < num_leaves_; ++i) {
......
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