Config for linear updaters. (#5222)

This commit is contained in:
Jiaming Yuan
2020-01-25 11:26:46 +08:00
committed by GitHub
parent 40680368cf
commit 3eb1279bbf
14 changed files with 110 additions and 11 deletions

View File

@@ -112,7 +112,7 @@ TEST(c_api, ConfigIO) {
delete pp_dmat;
}
TEST(c_api, Json_ModelIO) {
TEST(c_api, JsonModelIO) {
size_t constexpr kRows = 10;
dmlc::TemporaryDirectory tempdir;

View File

@@ -16,7 +16,7 @@
namespace xgboost {
namespace gbm {
TEST(GBLinear, Json_IO) {
TEST(GBLinear, JsonIO) {
size_t constexpr kRows = 16, kCols = 16;
LearnerModelParam param;

View File

@@ -103,8 +103,8 @@ TEST(GBTree, ChoosePredictor) {
}
#endif // XGBOOST_USE_CUDA
// Some other parts of test are in `Tree.Json_IO'.
TEST(GBTree, Json_IO) {
// Some other parts of test are in `Tree.JsonIO'.
TEST(GBTree, JsonIO) {
size_t constexpr kRows = 16, kCols = 16;
LearnerModelParam mparam;
@@ -143,7 +143,7 @@ TEST(GBTree, Json_IO) {
ASSERT_EQ(get<String>(j_train_param["num_parallel_tree"]), "1");
}
TEST(Dart, Json_IO) {
TEST(Dart, JsonIO) {
size_t constexpr kRows = 16, kCols = 16;
LearnerModelParam mparam;

View File

@@ -0,0 +1,41 @@
/*!
* Copyright 2020 XGBoost contributors
*/
#ifndef XGBOOST_TEST_JSON_IO_H_
#define XGBOOST_TEST_JSON_IO_H_
#include <xgboost/linear_updater.h>
#include <xgboost/json.h>
#include <string>
#include "../helpers.h"
#include "../../../src/gbm/gblinear_model.h"
namespace xgboost {
inline void TestUpdaterJsonIO(std::string updater_str) {
auto runtime = xgboost::CreateEmptyGenericParam(GPUIDX);
Json config_0 {Object() };
{
auto updater = std::unique_ptr<xgboost::LinearUpdater>(
xgboost::LinearUpdater::Create(updater_str, &runtime));
updater->Configure({{"eta", std::to_string(3.14)}});
updater->SaveConfig(&config_0);
}
{
auto updater = std::unique_ptr<xgboost::LinearUpdater>(
xgboost::LinearUpdater::Create(updater_str, &runtime));
updater->LoadConfig(config_0);
Json config_1 { Object() };
updater->SaveConfig(&config_1);
ASSERT_EQ(config_0, config_1);
auto eta = atof(get<String const>(config_1["linear_train_param"]["eta"]).c_str());
ASSERT_NEAR(eta, 3.14, kRtEps);
}
}
} // namespace xgboost
#endif // XGBOOST_TEST_JSON_IO_H_

View File

@@ -5,12 +5,13 @@
#include <xgboost/gbm.h>
#include "../helpers.h"
#include "test_json_io.h"
#include "../../../src/gbm/gblinear_model.h"
#include "xgboost/base.h"
namespace xgboost {
TEST(Linear, shotgun) {
TEST(Linear, Shotgun) {
size_t constexpr kRows = 10;
size_t constexpr kCols = 10;
@@ -45,6 +46,10 @@ TEST(Linear, shotgun) {
delete pp_dmat;
}
TEST(Shotgun, JsonIO) {
TestUpdaterJsonIO("shotgun");
}
TEST(Linear, coordinate) {
size_t constexpr kRows = 10;
size_t constexpr kCols = 10;
@@ -72,4 +77,8 @@ TEST(Linear, coordinate) {
delete pp_dmat;
}
TEST(Coordinate, JsonIO){
TestUpdaterJsonIO("coord_descent");
}
} // namespace xgboost

View File

@@ -3,6 +3,7 @@
#include <xgboost/gbm.h>
#include "../helpers.h"
#include "test_json_io.h"
#include "../../../src/gbm/gblinear_model.h"
namespace xgboost {
@@ -33,4 +34,8 @@ TEST(Linear, GPUCoordinate) {
delete mat;
}
TEST(GPUCoordinate, JsonIO) {
TestUpdaterJsonIO("gpu_coord_descent");
}
} // namespace xgboost

View File

@@ -36,7 +36,7 @@ TEST(Objective, DeclareUnifiedTest(PairwiseRankingGPair)) {
ASSERT_NO_THROW(obj->DefaultEvalMetric());
}
TEST(Objective, DeclareUnifiedTest(NDCG_Json_IO)) {
TEST(Objective, DeclareUnifiedTest(NDCG_JsonIO)) {
xgboost::GenericParameter tparam;
tparam.UpdateAllowUnknown(Args{});

View File

@@ -134,7 +134,7 @@ TEST(Learner, Configuration) {
}
}
TEST(Learner, Json_ModelIO) {
TEST(Learner, JsonModelIO) {
// Test of comparing JSON object directly.
size_t constexpr kRows = 8;
int32_t constexpr kIters = 4;

View File

@@ -220,7 +220,7 @@ TEST(Tree, DumpDot) {
ASSERT_NE(str.find(R"(graph [ bgcolor="#FFFF00" ])"), std::string::npos);
}
TEST(Tree, Json_IO) {
TEST(Tree, JsonIO) {
RegTree tree;
tree.ExpandNode(0, 0, 0.0f, false, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f);
Json j_tree{Object()};