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

@@ -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