Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix goss with constant hessian #3077

Merged
merged 1 commit into from
May 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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