* 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.
81 lines
2.2 KiB
C++
81 lines
2.2 KiB
C++
#include <valarray>
|
|
#include "../../../src/common/random.h"
|
|
#include "../helpers.h"
|
|
#include "gtest/gtest.h"
|
|
|
|
namespace xgboost {
|
|
namespace common {
|
|
TEST(ColumnSampler, Test) {
|
|
int n = 128;
|
|
ColumnSampler cs;
|
|
|
|
// No node sampling
|
|
cs.Init(n, 1.0f, 0.5f, 0.5f);
|
|
auto set0 = *cs.GetFeatureSet(0);
|
|
ASSERT_EQ(set0.Size(), 32);
|
|
|
|
auto set1 = *cs.GetFeatureSet(0);
|
|
|
|
ASSERT_EQ(set0.HostVector(), set1.HostVector());
|
|
|
|
auto set2 = *cs.GetFeatureSet(1);
|
|
ASSERT_NE(set1.HostVector(), set2.HostVector());
|
|
ASSERT_EQ(set2.Size(), 32);
|
|
|
|
// Node sampling
|
|
cs.Init(n, 0.5f, 1.0f, 0.5f);
|
|
auto set3 = *cs.GetFeatureSet(0);
|
|
ASSERT_EQ(set3.Size(), 32);
|
|
|
|
auto set4 = *cs.GetFeatureSet(0);
|
|
|
|
ASSERT_NE(set3.HostVector(), set4.HostVector());
|
|
ASSERT_EQ(set4.Size(), 32);
|
|
|
|
// No level or node sampling, should be the same at different depth
|
|
cs.Init(n, 1.0f, 1.0f, 0.5f);
|
|
ASSERT_EQ(cs.GetFeatureSet(0)->HostVector(),
|
|
cs.GetFeatureSet(1)->HostVector());
|
|
|
|
cs.Init(n, 1.0f, 1.0f, 1.0f);
|
|
auto set5 = *cs.GetFeatureSet(0);
|
|
ASSERT_EQ(set5.Size(), n);
|
|
cs.Init(n, 1.0f, 1.0f, 1.0f);
|
|
auto set6 = *cs.GetFeatureSet(0);
|
|
ASSERT_EQ(set5.HostVector(), set6.HostVector());
|
|
|
|
// Should always be a minimum of one feature
|
|
cs.Init(n, 1e-16f, 1e-16f, 1e-16f);
|
|
ASSERT_EQ(cs.GetFeatureSet(0)->Size(), 1);
|
|
}
|
|
|
|
// Test if different threads using the same seed produce the same result
|
|
TEST(ColumnSampler, ThreadSynchronisation) {
|
|
const int64_t num_threads = 100;
|
|
int n = 128;
|
|
size_t iterations = 10;
|
|
size_t levels = 5;
|
|
std::vector<bst_feature_t> reference_result;
|
|
bool success =
|
|
true; // Cannot use google test asserts in multithreaded region
|
|
#pragma omp parallel num_threads(num_threads)
|
|
{
|
|
for (auto j = 0ull; j < iterations; j++) {
|
|
ColumnSampler cs(j);
|
|
cs.Init(n, 0.5f, 0.5f, 0.5f);
|
|
for (auto level = 0ull; level < levels; level++) {
|
|
auto result = cs.GetFeatureSet(level)->ConstHostVector();
|
|
#pragma omp single
|
|
{ reference_result = result; }
|
|
if (result != reference_result) {
|
|
success = false;
|
|
}
|
|
#pragma omp barrier
|
|
}
|
|
}
|
|
}
|
|
ASSERT_TRUE(success);
|
|
}
|
|
} // namespace common
|
|
} // namespace xgboost
|