| 305 | } |
| 306 | |
| 307 | void 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 | |
| 346 | void TestAbsoluteErrorLeaf(const Context* ctx) { |
| 347 | bst_target_t constexpr kTargets = 3, kRows = 16; |
no test coverage detected