Config for linear updaters. (#5222)
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
namespace xgboost {
|
||||
namespace gbm {
|
||||
|
||||
TEST(GBLinear, Json_IO) {
|
||||
TEST(GBLinear, JsonIO) {
|
||||
size_t constexpr kRows = 16, kCols = 16;
|
||||
|
||||
LearnerModelParam param;
|
||||
|
||||
@@ -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;
|
||||
|
||||
41
tests/cpp/linear/test_json_io.h
Normal file
41
tests/cpp/linear/test_json_io.h
Normal 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_
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
@@ -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{});
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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()};
|
||||
|
||||
Reference in New Issue
Block a user