Add Model and Configurable interface. (#4945)

* Apply Configurable to objective functions.
* Apply Model to Learner and Regtree, gbm.
* Add Load/SaveConfig to objs.
* Refactor obj tests to use smart pointer.
* Dummy methods for Save/Load Model.
This commit is contained in:
Jiaming Yuan
2019-10-18 01:56:02 -04:00
committed by GitHub
parent 9fc681001a
commit ae536756ae
31 changed files with 521 additions and 187 deletions

View File

@@ -6,6 +6,8 @@
#include <xgboost/objective.h>
#include <dmlc/registry.h>
#include <sstream>
#include "xgboost/host_device_vector.h"
namespace dmlc {
@@ -17,10 +19,12 @@ namespace xgboost {
ObjFunction* ObjFunction::Create(const std::string& name, GenericParameter const* tparam) {
auto *e = ::dmlc::Registry< ::xgboost::ObjFunctionReg>::Get()->Find(name);
if (e == nullptr) {
std::stringstream ss;
for (const auto& entry : ::dmlc::Registry< ::xgboost::ObjFunctionReg>::List()) {
LOG(INFO) << "Objective candidate: " << entry->name;
ss << "Objective candidate: " << entry->name << "\n";
}
LOG(FATAL) << "Unknown objective function " << name;
LOG(FATAL) << "Unknown objective function: `" << name << "`\n"
<< ss.str();
}
auto pobj = (e->body)();
pobj->tparam_ = tparam;