Configuration for init estimation. (#8343)

* Configuration for init estimation.

* Check whether the model needs configuration based on const attribute `ModelFitted`
instead of a mutable state.
* Add parameter `boost_from_average` to tell whether the user has specified base score.
* Add tests.
This commit is contained in:
Jiaming Yuan
2022-10-18 01:52:24 +08:00
committed by GitHub
parent 2176e511fc
commit 031d66ec27
10 changed files with 247 additions and 111 deletions

View File

@@ -723,10 +723,15 @@ class MeanAbsoluteError : public ObjFunction {
out(0) = common::Median(ctx_, info.labels, info.weights_) * w;
}
// Weighted average base score across all workers
collective::Allreduce<collective::Operation::kSum>(out.Values().data(), out.Values().size());
collective::Allreduce<collective::Operation::kSum>(&w, 1);
if (common::CloseTo(w, 0.0)) {
// Mostly for handling empty dataset test.
LOG(WARNING) << "Sum of weights is close to 0.0, skipping base score estimation.";
out(0) = ObjFunction::DefaultBaseScore();
return;
}
std::transform(linalg::cbegin(out), linalg::cend(out), linalg::begin(out),
[w](float v) { return v / w; });
}