Merge pull request #1153 from khotilov/seed_in_configure

Fixes for repeated Configure calls
This commit is contained in:
Tianqi Chen 2016-04-30 10:43:14 -07:00
commit 2f2ad21de4
2 changed files with 12 additions and 4 deletions

View File

@ -32,7 +32,15 @@ class Booster {
}
inline void SetParam(const std::string& name, const std::string& val) {
cfg_.push_back(std::make_pair(name, val));
auto it = std::find_if(cfg_.begin(), cfg_.end(),
[&name](decltype(*cfg_.begin()) &x) {
return x.first == name;
});
if (it == cfg_.end()) {
cfg_.push_back(std::make_pair(name, val));
} else {
(*it).second = val;
}
if (configured_) {
learner_->Configure(cfg_);
}
@ -277,7 +285,7 @@ int XGDMatrixCreateFromCSC(const bst_ulong* col_ptr,
RowBatch::Entry(static_cast<bst_uint>(i), data[j]),
tid);
}
}
}
mat.info.num_row = mat.row_ptr_.size() - 1;
mat.info.num_col = static_cast<uint64_t>(ncol);
mat.info.num_nonzero = nelem;

View File

@ -189,10 +189,10 @@ class LearnerImpl : public Learner {
mparam.InitAllowUnknown(args);
name_obj_ = cfg_["objective"];
name_gbm_ = cfg_["booster"];
// set seed only before the model is initialized
common::GlobalRandom().seed(tparam.seed);
}
common::GlobalRandom().seed(tparam.seed);
// set number of features correctly.
cfg_["num_feature"] = common::ToString(mparam.num_feature);
cfg_["num_class"] = common::ToString(mparam.num_class);