added code for instance based weighing for rank objectives (#3379)

* added code for instance based weighing for rank objectives

* Fix lint
This commit is contained in:
ngoyal2707
2018-06-22 15:10:59 -07:00
committed by Philip Hyunsu Cho
parent d062c6f61b
commit 5cd851ccef
5 changed files with 85 additions and 10 deletions

View File

@@ -1,28 +0,0 @@
// Copyright by Contributors
#include <xgboost/metric.h>
#include "../helpers.h"
TEST(Metric, MultiClassError) {
xgboost::Metric * metric = xgboost::Metric::Create("merror");
ASSERT_STREQ(metric->Name(), "merror");
EXPECT_ANY_THROW(GetMetricEval(metric, {0}, {0, 0}));
EXPECT_NEAR(GetMetricEval(
metric, {1, 0, 0, 0, 1, 0, 0, 0, 1}, {0, 1, 2}), 0, 1e-10);
EXPECT_NEAR(GetMetricEval(metric,
{0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f},
{0, 1, 2}),
0.666f, 0.001f);
}
TEST(Metric, MultiClassLogLoss) {
xgboost::Metric * metric = xgboost::Metric::Create("mlogloss");
ASSERT_STREQ(metric->Name(), "mlogloss");
EXPECT_ANY_THROW(GetMetricEval(metric, {0}, {0, 0}));
EXPECT_NEAR(GetMetricEval(
metric, {1, 0, 0, 0, 1, 0, 0, 0, 1}, {0, 1, 2}), 0, 1e-10);
EXPECT_NEAR(GetMetricEval(metric,
{0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f},
{0, 1, 2}),
2.302f, 0.001f);
}

View File

@@ -0,0 +1,28 @@
// Copyright by Contributors
#include <xgboost/objective.h>
#include "../helpers.h"
TEST(Objective, PairwiseRankingGPair) {
xgboost::ObjFunction * obj = xgboost::ObjFunction::Create("rank:pairwise");
std::vector<std::pair<std::string, std::string> > args;
obj->Configure(args);
// Test with setting sample weight to second query group
CheckRankingObjFunction(obj,
{0, 0.1f, 0, 0.1f},
{0, 1, 0, 1},
{2.0f, 0.0f},
{0, 2, 4},
{1.9f, -1.9f, 0.0f, 0.0f},
{1.995f, 1.995f, 0.0f, 0.0f});
CheckRankingObjFunction(obj,
{0, 0.1f, 0, 0.1f},
{0, 1, 0, 1},
{1.0f, 1.0f},
{0, 2, 4},
{0.95f, -0.95f, 0.95f, -0.95f},
{0.9975f, 0.9975f, 0.9975f, 0.9975f});
ASSERT_NO_THROW(obj->DefaultEvalMetric());
}