| 9 | namespace xgboost::common { |
| 10 | namespace { |
| 11 | void TestBasic(Context const* ctx) { |
| 12 | int n = 128; |
| 13 | ColumnSampler cs; |
| 14 | HostDeviceVector<float> feature_weights; |
| 15 | |
| 16 | // No node sampling |
| 17 | cs.Init(ctx, n, feature_weights, 1.0f, 0.5f, 0.5f); |
| 18 | auto set0 = cs.GetFeatureSet(ctx, 0); |
| 19 | ASSERT_EQ(set0->Size(), 32); |
| 20 | |
| 21 | auto set1 = cs.GetFeatureSet(ctx, 0); |
| 22 | |
| 23 | ASSERT_EQ(set0->HostVector(), set1->HostVector()); |
| 24 | |
| 25 | auto set2 = cs.GetFeatureSet(ctx, 1); |
| 26 | ASSERT_NE(set1->HostVector(), set2->HostVector()); |
| 27 | ASSERT_EQ(set2->Size(), 32); |
| 28 | |
| 29 | // Node sampling |
| 30 | cs.Init(ctx, n, feature_weights, 0.5f, 1.0f, 0.5f); |
| 31 | auto set3 = cs.GetFeatureSet(ctx, 0); |
| 32 | ASSERT_EQ(set3->Size(), 32); |
| 33 | |
| 34 | auto set4 = cs.GetFeatureSet(ctx, 0); |
| 35 | |
| 36 | ASSERT_NE(set3->HostVector(), set4->HostVector()); |
| 37 | ASSERT_EQ(set4->Size(), 32); |
| 38 | |
| 39 | // No level or node sampling, should be the same at different depth |
| 40 | cs.Init(ctx, n, feature_weights, 1.0f, 1.0f, 0.5f); |
| 41 | ASSERT_EQ(cs.GetFeatureSet(ctx, 0)->HostVector(), cs.GetFeatureSet(ctx, 1)->HostVector()); |
| 42 | |
| 43 | cs.Init(ctx, n, feature_weights, 1.0f, 1.0f, 1.0f); |
| 44 | auto set5 = cs.GetFeatureSet(ctx, 0); |
| 45 | ASSERT_EQ(set5->Size(), n); |
| 46 | cs.Init(ctx, n, feature_weights, 1.0f, 1.0f, 1.0f); |
| 47 | auto set6 = cs.GetFeatureSet(ctx, 0); |
| 48 | ASSERT_EQ(set5->HostVector(), set6->HostVector()); |
| 49 | |
| 50 | // Should always be a minimum of one feature |
| 51 | cs.Init(ctx, n, feature_weights, 1e-16f, 1e-16f, 1e-16f); |
| 52 | ASSERT_EQ(cs.GetFeatureSet(ctx, 0)->Size(), 1); |
| 53 | } |
| 54 | } // namespace |
| 55 | |
| 56 | TEST(ColumnSampler, Test) { |
no test coverage detected