Unverified Commit 5cc38e6a authored by Guolin Ke's avatar Guolin Ke Committed by GitHub
Browse files

fix goss with constant hessian (#3077)

parent 9085f4e2
...@@ -70,12 +70,11 @@ void GBDT::Init(const Config* config, const Dataset* train_data, const Objective ...@@ -70,12 +70,11 @@ void GBDT::Init(const Config* config, const Dataset* train_data, const Objective
objective_function_ = objective_function; objective_function_ = objective_function;
num_tree_per_iteration_ = num_class_; num_tree_per_iteration_ = num_class_;
if (objective_function_ != nullptr) { if (objective_function_ != nullptr) {
is_constant_hessian_ = objective_function_->IsConstantHessian();
num_tree_per_iteration_ = objective_function_->NumModelPerIteration(); num_tree_per_iteration_ = objective_function_->NumModelPerIteration();
} else {
is_constant_hessian_ = false;
} }
is_constant_hessian_ = GetIsConstHessian(objective_function);
tree_learner_ = std::unique_ptr<TreeLearner>(TreeLearner::CreateTreeLearner(config_->tree_learner, config_->device_type, config_.get())); tree_learner_ = std::unique_ptr<TreeLearner>(TreeLearner::CreateTreeLearner(config_->tree_learner, config_->device_type, config_.get()));
// init tree learner // init tree learner
...@@ -653,11 +652,9 @@ void GBDT::ResetTrainingData(const Dataset* train_data, const ObjectiveFunction* ...@@ -653,11 +652,9 @@ void GBDT::ResetTrainingData(const Dataset* train_data, const ObjectiveFunction*
objective_function_ = objective_function; objective_function_ = objective_function;
if (objective_function_ != nullptr) { if (objective_function_ != nullptr) {
is_constant_hessian_ = objective_function_->IsConstantHessian();
CHECK_EQ(num_tree_per_iteration_, objective_function_->NumModelPerIteration()); CHECK_EQ(num_tree_per_iteration_, objective_function_->NumModelPerIteration());
} else {
is_constant_hessian_ = false;
} }
is_constant_hessian_ = GetIsConstHessian(objective_function);
// push training metrics // push training metrics
training_metrics_.clear(); training_metrics_.clear();
......
...@@ -375,6 +375,13 @@ class GBDT : public GBDTBase { ...@@ -375,6 +375,13 @@ class GBDT : public GBDTBase {
const char* SubModelName() const override { return "tree"; } const char* SubModelName() const override { return "tree"; }
protected: protected:
virtual bool GetIsConstHessian(const ObjectiveFunction* objective_function) {
if (objective_function != nullptr) {
return objective_function->IsConstantHessian();
} else {
return false;
}
}
/*! /*!
* \brief Print eval result and check early stopping * \brief Print eval result and check early stopping
*/ */
......
...@@ -153,6 +153,11 @@ class GOSS: public GBDT { ...@@ -153,6 +153,11 @@ class GOSS: public GBDT {
bag_data_cnt_); bag_data_cnt_);
} }
} }
protected:
bool GetIsConstHessian(const ObjectiveFunction*) override {
return false;
}
}; };
} // namespace LightGBM } // namespace LightGBM
......
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