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

Function TestAbsoluteError

tests/cpp/objective/test_regression_obj.cc:307–344  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

305}
306
307void TestAbsoluteError(const Context* ctx) {
308 std::unique_ptr<ObjFunction> obj{ObjFunction::Create("reg:absoluteerror", ctx)};
309 obj->Configure({});
310 CheckConfigReload(obj, "reg:absoluteerror");
311
312 MetaInfo info;
313 std::vector<float> labels{0.f, 3.f, 2.f, 5.f, 4.f, 7.f};
314 info.labels.Reshape(6, 1);
315 info.labels.Data()->HostVector() = labels;
316 info.num_row_ = labels.size();
317
318 HostDeviceVector<float> predt{1.f, 2.f, 3.f, 4.f, 5.f, 6.f};
319 info.weights_.HostVector() = {1.f, 1.f, 1.f, 1.f, 1.f, 1.f};
320
321 CheckObjFunction(obj, predt.HostVector(), labels, info.weights_.HostVector(),
322 {1.f, -1.f, 1.f, -1.f, 1.f, -1.f}, info.weights_.HostVector());
323
324 RegTree tree;
325 tree.ExpandNode(0, /*split_index=*/1, 2, true, 0.0f, 2.f, 3.f, 4.f, 2.f, 1.f, 1.f);
326 bst_node_t left_nidx = tree.LeftChild(RegTree::kRoot);
327 bst_node_t right_nidx = tree.RightChild(RegTree::kRoot);
328
329 HostDeviceVector<bst_node_t> position;
330 MakePositionsForTest(info.num_row_, left_nidx, right_nidx, &position);
331
332 auto& h_predt = predt.HostVector();
333 for (size_t i = 0; i < h_predt.size(); ++i) {
334 h_predt[i] = labels[i] + i;
335 }
336
337 tree::TrainParam param;
338 param.Init(Args{});
339 auto lr = param.learning_rate;
340
341 obj->UpdateTreeLeaf(position, info, lr, predt, 0, &tree);
342 ASSERT_EQ(tree[1].LeafValue(), -1.0f * lr);
343 ASSERT_EQ(tree[2].LeafValue(), -4.0f * lr);
344}
345
346void TestAbsoluteErrorLeaf(const Context* ctx) {
347 bst_target_t constexpr kTargets = 3, kRows = 16;

Callers 2

TESTFunction · 0.85
TESTFunction · 0.85

Calls 13

CheckConfigReloadFunction · 0.85
CheckObjFunctionFunction · 0.85
MakePositionsForTestFunction · 0.85
ReshapeMethod · 0.80
ExpandNodeMethod · 0.80
ConfigureMethod · 0.45
DataMethod · 0.45
sizeMethod · 0.45
LeftChildMethod · 0.45
RightChildMethod · 0.45
InitMethod · 0.45
UpdateTreeLeafMethod · 0.45

Tested by

no test coverage detected