Pseudo-huber loss metric added (#5647)

- Add pseudo huber loss objective.
- Add pseudo huber loss metric.

Co-authored-by: Reetz <s02reetz@iavgroup.local>
This commit is contained in:
LionOrCatThatIsTheQuestion
2020-05-18 15:08:07 +02:00
committed by GitHub
parent 535479e69f
commit 83981a9ce3
6 changed files with 89 additions and 0 deletions

View File

@@ -44,6 +44,18 @@ TEST(Metric, DeclareUnifiedTest(MAE)) {
delete metric;
}
TEST(Metric, DeclareUnifiedTest(MPHE)) {
auto lparam = xgboost::CreateEmptyGenericParam(GPUIDX);
xgboost::Metric * metric = xgboost::Metric::Create("mphe", &lparam);
metric->Configure({});
ASSERT_STREQ(metric->Name(), "mphe");
EXPECT_NEAR(GetMetricEval(metric, {0, 1}, {0, 1}), 0, 1e-10);
EXPECT_NEAR(GetMetricEval(metric,
{0.1f, 0.9f, 0.1f, 0.9f},
{ 0, 0, 1, 1}), 0.17517f, 1e-4);
delete metric;
}
TEST(Metric, DeclareUnifiedTest(LogLoss)) {
auto lparam = xgboost::CreateEmptyGenericParam(GPUIDX);
xgboost::Metric * metric = xgboost::Metric::Create("logloss", &lparam);

View File

@@ -55,6 +55,29 @@ TEST(Objective, DeclareUnifiedTest(SquaredLog)) {
ASSERT_EQ(obj->DefaultEvalMetric(), std::string{"rmsle"});
}
TEST(Objective, DeclareUnifiedTest(PseudoHuber)) {
GenericParameter tparam = CreateEmptyGenericParam(GPUIDX);
std::vector<std::pair<std::string, std::string>> args;
std::unique_ptr<ObjFunction> obj { ObjFunction::Create("reg:pseudohubererror", &tparam) };
obj->Configure(args);
CheckConfigReload(obj, "reg:pseudohubererror");
CheckObjFunction(obj,
{0.1f, 0.2f, 0.4f, 0.8f, 1.6f}, // pred
{1.0f, 1.0f, 1.0f, 1.0f, 1.0f}, // labels
{1.0f, 1.0f, 1.0f, 1.0f, 1.0f}, // weights
{-0.668965f, -0.624695f, -0.514496f, -0.196116f, 0.514496f}, // out_grad
{ 0.410660f, 0.476140f, 0.630510f, 0.9428660f, 0.630510f}); // out_hess
CheckObjFunction(obj,
{0.1f, 0.2f, 0.4f, 0.8f, 1.6f}, // pred
{1.0f, 1.0f, 1.0f, 1.0f, 1.0f}, // labels
{}, // empty weights
{-0.668965f, -0.624695f, -0.514496f, -0.196116f, 0.514496f}, // out_grad
{ 0.410660f, 0.476140f, 0.630510f, 0.9428660f, 0.630510f}); // out_hess
ASSERT_EQ(obj->DefaultEvalMetric(), std::string{"mphe"});
}
TEST(Objective, DeclareUnifiedTest(LogisticRegressionGPair)) {
GenericParameter tparam = CreateEmptyGenericParam(GPUIDX);
std::vector<std::pair<std::string, std::string>> args;