* Extract interaction constraints from split evaluator. The reason for doing so is mostly for model IO, where num_feature and interaction_constraints are copied in split evaluator. Also interaction constraint by itself is a feature selector, acting like column sampler and it's inefficient to bury it deep in the evaluator chain. Lastly removing one another copied parameter is a win. * Enable inc for approx tree method. As now the implementation is spited up from evaluator class, it's also enabled for approx method. * Removing obsoleted code in colmaker. They are never documented nor actually used in real world. Also there isn't a single test for those code blocks. * Unifying the types used for row and column. As the size of input dataset is marching to billion, incorrect use of int is subject to overflow, also singed integer overflow is undefined behaviour. This PR starts the procedure for unifying used index type to unsigned integers. There's optimization that can utilize this undefined behaviour, but after some testings I don't see the optimization is beneficial to XGBoost.
70 lines
1.9 KiB
C++
70 lines
1.9 KiB
C++
#include <gtest/gtest.h>
|
|
|
|
#include <xgboost/tree_model.h>
|
|
#include <xgboost/tree_updater.h>
|
|
|
|
#include "../helpers.h"
|
|
|
|
namespace xgboost {
|
|
namespace tree {
|
|
|
|
TEST(GrowHistMaker, InteractionConstraint) {
|
|
size_t constexpr kRows = 32;
|
|
size_t constexpr kCols = 16;
|
|
|
|
GenericParameter param;
|
|
param.UpdateAllowUnknown(Args{{"gpu_id", "0"}});
|
|
|
|
auto pp_dmat = CreateDMatrix(kRows, kCols, 0.6, 3);
|
|
auto p_dmat = *pp_dmat;
|
|
|
|
HostDeviceVector<GradientPair> gradients (kRows);
|
|
std::vector<GradientPair>& h_gradients = gradients.HostVector();
|
|
|
|
xgboost::SimpleLCG gen;
|
|
xgboost::SimpleRealUniformDistribution<bst_float> dist(0.0f, 1.0f);
|
|
|
|
for (size_t i = 0; i < kRows; ++i) {
|
|
bst_float grad = dist(&gen);
|
|
bst_float hess = dist(&gen);
|
|
h_gradients[i] = GradientPair(grad, hess);
|
|
}
|
|
|
|
{
|
|
// With constraints
|
|
RegTree tree;
|
|
tree.param.num_feature = kCols;
|
|
|
|
std::unique_ptr<TreeUpdater> updater { TreeUpdater::Create("grow_histmaker", ¶m) };
|
|
updater->Configure(Args{
|
|
{"interaction_constraints", "[[0, 1]]"},
|
|
{"num_feature", std::to_string(kCols)}});
|
|
updater->Update(&gradients, p_dmat.get(), {&tree});
|
|
|
|
ASSERT_EQ(tree.NumExtraNodes(), 4);
|
|
ASSERT_EQ(tree[0].SplitIndex(), 1);
|
|
|
|
ASSERT_EQ(tree[tree[0].LeftChild()].SplitIndex(), 0);
|
|
ASSERT_EQ(tree[tree[0].RightChild()].SplitIndex(), 0);
|
|
}
|
|
{
|
|
// Without constraints
|
|
RegTree tree;
|
|
tree.param.num_feature = kCols;
|
|
|
|
std::unique_ptr<TreeUpdater> updater { TreeUpdater::Create("grow_histmaker", ¶m) };
|
|
updater->Configure(Args{{"num_feature", std::to_string(kCols)}});
|
|
updater->Update(&gradients, p_dmat.get(), {&tree});
|
|
|
|
ASSERT_EQ(tree.NumExtraNodes(), 10);
|
|
ASSERT_EQ(tree[0].SplitIndex(), 1);
|
|
|
|
ASSERT_NE(tree[tree[0].LeftChild()].SplitIndex(), 0);
|
|
ASSERT_NE(tree[tree[0].RightChild()].SplitIndex(), 0);
|
|
}
|
|
delete pp_dmat;
|
|
}
|
|
|
|
} // namespace tree
|
|
} // namespace xgboost
|