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:
@@ -1,5 +1,5 @@
|
||||
/*!
|
||||
* Copyright 2015 by Contributors
|
||||
* Copyright 2015-2019 by Contributors
|
||||
* \file custom_metric.cc
|
||||
* \brief This is an example to define plugin of xgboost.
|
||||
* This plugin defines the additional metric function.
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <xgboost/base.h>
|
||||
#include <dmlc/parameter.h>
|
||||
#include <xgboost/objective.h>
|
||||
#include <xgboost/json.h>
|
||||
|
||||
namespace xgboost {
|
||||
namespace obj {
|
||||
@@ -69,6 +70,16 @@ class MyLogistic : public ObjFunction {
|
||||
return -std::log(1.0f / base_score - 1.0f);
|
||||
}
|
||||
|
||||
void SaveConfig(Json* p_out) const override {
|
||||
auto& out = *p_out;
|
||||
out["name"] = String("my_logistic");
|
||||
out["my_logistic_param"] = toJson(param_);
|
||||
}
|
||||
|
||||
void LoadConfig(Json const& in) override {
|
||||
fromJson(in["my_logistic_param"], ¶m_);
|
||||
}
|
||||
|
||||
private:
|
||||
MyLogisticParam param_;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user