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

Function CheckObjFunctionImpl

tests/cpp/helpers.cc:101–121  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

99}
100
101void CheckObjFunctionImpl(std::unique_ptr<xgboost::ObjFunction> const& obj,
102 std::vector<xgboost::bst_float> preds,
103 std::vector<xgboost::bst_float> labels,
104 std::vector<xgboost::bst_float> weights, xgboost::MetaInfo const& info,
105 std::vector<xgboost::bst_float> out_grad,
106 std::vector<xgboost::bst_float> out_hess) {
107 xgboost::HostDeviceVector<xgboost::bst_float> in_preds(preds);
108 xgboost::linalg::Matrix<xgboost::GradientPair> out_gpair;
109 obj->GetGradient(in_preds, info, 0, &out_gpair);
110 std::vector<xgboost::GradientPair>& gpair = out_gpair.Data()->HostVector();
111
112 ASSERT_EQ(gpair.size(), in_preds.Size());
113 for (int i = 0; i < static_cast<int>(gpair.size()); ++i) {
114 EXPECT_NEAR(gpair[i].GetGrad(), out_grad[i], 0.01)
115 << "Unexpected grad for pred=" << preds[i] << " label=" << labels[i]
116 << " weight=" << (weights.empty() ? 1.0 : weights[i]);
117 EXPECT_NEAR(gpair[i].GetHess(), out_hess[i], 0.01)
118 << "Unexpected hess for pred=" << preds[i] << " label=" << labels[i]
119 << " weight=" << (weights.empty() ? 1.0 : weights[i]);
120 }
121}
122
123void CheckObjFunction(std::unique_ptr<xgboost::ObjFunction> const& obj,
124 std::vector<xgboost::bst_float> preds, std::vector<xgboost::bst_float> labels,

Callers 2

CheckObjFunctionFunction · 0.85
CheckRankingObjFunctionFunction · 0.85

Calls 7

GetGradMethod · 0.80
GetHessMethod · 0.80
GetGradientMethod · 0.45
DataMethod · 0.45
sizeMethod · 0.45
SizeMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected