Skip to content

Commit

Permalink
fix goss with constant hessian (#3077)
Browse files Browse the repository at this point in the history
  • Loading branch information
guolinke authored May 15, 2020
1 parent 9085f4e commit 5cc38e6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
9 changes: 3 additions & 6 deletions src/boosting/gbdt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,11 @@ void GBDT::Init(const Config* config, const Dataset* train_data, const Objective
objective_function_ = objective_function;
num_tree_per_iteration_ = num_class_;
if (objective_function_ != nullptr) {
is_constant_hessian_ = objective_function_->IsConstantHessian();
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()));

// init tree learner
Expand Down Expand Up @@ -653,11 +652,9 @@ void GBDT::ResetTrainingData(const Dataset* train_data, const ObjectiveFunction*

objective_function_ = objective_function;
if (objective_function_ != nullptr) {
is_constant_hessian_ = objective_function_->IsConstantHessian();
CHECK_EQ(num_tree_per_iteration_, objective_function_->NumModelPerIteration());
} else {
is_constant_hessian_ = false;
}
is_constant_hessian_ = GetIsConstHessian(objective_function);

// push training metrics
training_metrics_.clear();
Expand Down
7 changes: 7 additions & 0 deletions src/boosting/gbdt.h
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,13 @@ class GBDT : public GBDTBase {
const char* SubModelName() const override { return "tree"; }

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
*/
Expand Down
5 changes: 5 additions & 0 deletions src/boosting/goss.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@ class GOSS: public GBDT {
bag_data_cnt_);
}
}

protected:
bool GetIsConstHessian(const ObjectiveFunction*) override {
return false;
}
};

} // namespace LightGBM
Expand Down

0 comments on commit 5cc38e6

Please sign in to comment.