MCPcopy Create free account
hub / github.com/dmlc/xgboost / CheckSampledRows

Function CheckSampledRows

tests/cpp/tree/test_sampler.h:17–35  ·  view source on GitHub ↗

Check that multi-target rows are consistently sampled and return count.

Source from the content-addressed store, hash-verified

15namespace xgboost::tree {
16// Check that multi-target rows are consistently sampled and return count.
17inline bst_idx_t CheckSampledRows(linalg::MatrixView<GradientPair const> gpair_0,
18 linalg::MatrixView<GradientPair const> gpair_1) {
19 CHECK_EQ(gpair_0.Shape(0), gpair_1.Shape(0));
20 CHECK_GE(gpair_1.Shape(1), gpair_1.Shape(1));
21 auto n_samples = gpair_0.Shape(0);
22 auto n_targets = gpair_1.Shape(1);
23 bst_idx_t sampled_count = 0;
24 for (std::size_t i = 0; i < n_samples; ++i) {
25 bool first_is_zero = gpair_0(i, 0).GetHess() == 0.0f;
26 for (bst_target_t t = 0; t < n_targets; ++t) {
27 bool is_zero = (gpair_1(i, t).GetGrad() == 0.0f && gpair_1(i, t).GetHess() == 0.0f);
28 EXPECT_EQ(first_is_zero, is_zero);
29 }
30 if (!first_is_zero) {
31 ++sampled_count;
32 }
33 }
34 return sampled_count;
35}
36
37// Check that sampling mask was correctly applied from split gradient to value gradient.
38inline void CheckSamplingMask(linalg::MatrixView<GradientPair> h_split,

Callers 2

CheckSamplingMaskFunction · 0.85
CheckSamplingFunction · 0.85

Calls 3

ShapeMethod · 0.80
GetHessMethod · 0.80
GetGradMethod · 0.80

Tested by

no test coverage detected