Use `UpdateAllowUnknown' for non-model related parameter. (#4961)

* Use `UpdateAllowUnknown' for non-model related parameter.

Model parameter can not pack an additional boolean value due to binary IO
format.  This commit deals only with non-model related parameter configuration.

* Add tidy command line arg for use-dmlc-gtest.
This commit is contained in:
Jiaming Yuan
2019-10-23 05:50:12 -04:00
committed by GitHub
parent f24be2efb4
commit ac457c56a2
44 changed files with 189 additions and 112 deletions

View File

@@ -225,7 +225,7 @@ using GradientPairInteger = detail::GradientPairInternal<int64_t>;
using Args = std::vector<std::pair<std::string, std::string> >;
/*! \brief small eps gap for minimum split decision. */
const bst_float kRtEps = 1e-6f;
constexpr bst_float kRtEps = 1e-6f;
/*! \brief define unsigned long for openmp loop */
using omp_ulong = dmlc::omp_ulong; // NOLINT

View File

@@ -5,14 +5,13 @@
#ifndef XGBOOST_GENERIC_PARAMETERS_H_
#define XGBOOST_GENERIC_PARAMETERS_H_
#include <dmlc/parameter.h>
#include <xgboost/logging.h>
#include <xgboost/parameter.h>
#include <string>
namespace xgboost {
struct GenericParameter : public dmlc::Parameter<GenericParameter> {
struct GenericParameter : public XGBoostParameter<GenericParameter> {
// stored random seed
int seed;
// whether seed the PRNG each iteration

View File

@@ -5,6 +5,7 @@
#define XGBOOST_JSON_H_
#include <xgboost/logging.h>
#include <xgboost/parameter.h>
#include <string>
#include <map>
@@ -533,7 +534,7 @@ using Null = JsonNull;
// Utils tailored for XGBoost.
template <typename Type>
Object toJson(dmlc::Parameter<Type> const& param) {
Object toJson(XGBoostParameter<Type> const& param) {
Object obj;
for (auto const& kv : param.__DICT__()) {
obj[kv.first] = kv.second;
@@ -542,13 +543,13 @@ Object toJson(dmlc::Parameter<Type> const& param) {
}
template <typename Type>
void fromJson(Json const& obj, dmlc::Parameter<Type>* param) {
void fromJson(Json const& obj, XGBoostParameter<Type>* param) {
auto const& j_param = get<Object const>(obj);
std::map<std::string, std::string> m;
for (auto const& kv : j_param) {
m[kv.first] = get<String const>(kv.second);
}
param->InitAllowUnknown(m);
param->UpdateAllowUnknown(m);
}
} // namespace xgboost
#endif // XGBOOST_JSON_H_

View File

@@ -9,9 +9,10 @@
#define XGBOOST_LOGGING_H_
#include <dmlc/logging.h>
#include <dmlc/parameter.h>
#include <dmlc/thread_local.h>
#include <xgboost/base.h>
#include <xgboost/parameter.h>
#include <sstream>
#include <map>
@@ -35,7 +36,7 @@ class BaseLogger {
};
// Parsing both silent and debug_verbose is to provide backward compatibility.
struct ConsoleLoggerParam : public dmlc::Parameter<ConsoleLoggerParam> {
struct ConsoleLoggerParam : public XGBoostParameter<ConsoleLoggerParam> {
bool silent; // deprecated.
int verbosity;

View File

@@ -60,6 +60,7 @@ struct TreeParam : public dmlc::Parameter<TreeParam> {
// other arguments are set by the algorithm.
DMLC_DECLARE_FIELD(num_roots).set_lower_bound(1).set_default(1)
.describe("Number of start root of trees.");
DMLC_DECLARE_FIELD(num_nodes).set_lower_bound(1).set_default(1);
DMLC_DECLARE_FIELD(num_feature)
.describe("Number of features used in tree construction.");
DMLC_DECLARE_FIELD(size_leaf_vector).set_lower_bound(0).set_default(0)
@@ -83,7 +84,7 @@ struct RTreeNodeStat {
/*! \brief weight of current node */
bst_float base_weight;
/*! \brief number of child that is leaf node known up to now */
int leaf_child_cnt;
int leaf_child_cnt {0};
bool operator==(const RTreeNodeStat& b) const {
return loss_chg == b.loss_chg && sum_hess == b.sum_hess &&
base_weight == b.base_weight && leaf_child_cnt == b.leaf_child_cnt;
@@ -98,6 +99,7 @@ class RegTree : public Model {
public:
/*! \brief auxiliary statistics of node to help tree building */
using SplitCondT = bst_float;
static constexpr int32_t kInvalidNodeId {-1};
/*! \brief tree node */
class Node {
public:
@@ -106,6 +108,12 @@ class RegTree : public Model {
static_assert(sizeof(Node) == 4 * sizeof(int) + sizeof(Info),
"Node: 64 bit align");
}
Node(int32_t cleft, int32_t cright, int32_t parent,
uint32_t split_ind, float split_cond, bool default_left) :
parent_{parent}, cleft_{cleft}, cright_{cright} {
this->SetSplit(split_ind, split_cond, default_left);
}
/*! \brief index of left child */
XGBOOST_DEVICE int LeftChild() const {
return this->cleft_;
@@ -219,11 +227,11 @@ class RegTree : public Model {
};
// pointer to parent, highest bit is used to
// indicate whether it's a left child or not
int parent_;
int32_t parent_{kInvalidNodeId};
// pointer to left, right
int cleft_, cright_;
int32_t cleft_{kInvalidNodeId}, cright_{kInvalidNodeId};
// split feature index, left split or right split depends on the highest bit
unsigned sindex_{0};
uint32_t sindex_{0};
// extra info
Info info_;
};