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

@@ -41,17 +41,13 @@ std::string CreateBigTestData(size_t n_entries) {
return tmp_file;
}
void CheckObjFunction(xgboost::ObjFunction * obj,
void _CheckObjFunction(xgboost::ObjFunction * obj,
std::vector<xgboost::bst_float> preds,
std::vector<xgboost::bst_float> labels,
std::vector<xgboost::bst_float> weights,
xgboost::MetaInfo info,
std::vector<xgboost::bst_float> out_grad,
std::vector<xgboost::bst_float> out_hess) {
xgboost::MetaInfo info;
info.num_row_ = labels.size();
info.labels_ = labels;
info.weights_ = weights;
xgboost::HostDeviceVector<xgboost::bst_float> in_preds(preds);
xgboost::HostDeviceVector<xgboost::GradientPair> out_gpair;
@@ -69,6 +65,37 @@ void CheckObjFunction(xgboost::ObjFunction * obj,
}
}
void CheckObjFunction(xgboost::ObjFunction * obj,
std::vector<xgboost::bst_float> preds,
std::vector<xgboost::bst_float> labels,
std::vector<xgboost::bst_float> weights,
std::vector<xgboost::bst_float> out_grad,
std::vector<xgboost::bst_float> out_hess) {
xgboost::MetaInfo info;
info.num_row_ = labels.size();
info.labels_ = labels;
info.weights_ = weights;
_CheckObjFunction(obj, preds, labels, weights, info, out_grad, out_hess);
}
void CheckRankingObjFunction(xgboost::ObjFunction * obj,
std::vector<xgboost::bst_float> preds,
std::vector<xgboost::bst_float> labels,
std::vector<xgboost::bst_float> weights,
std::vector<xgboost::bst_uint> groups,
std::vector<xgboost::bst_float> out_grad,
std::vector<xgboost::bst_float> out_hess) {
xgboost::MetaInfo info;
info.num_row_ = labels.size();
info.labels_ = labels;
info.weights_ = weights;
info.group_ptr_ = groups;
_CheckObjFunction(obj, preds, labels, weights, info, out_grad, out_hess);
}
xgboost::bst_float GetMetricEval(xgboost::Metric * metric,
std::vector<xgboost::bst_float> preds,
std::vector<xgboost::bst_float> labels,

View File

@@ -32,6 +32,14 @@ void CheckObjFunction(xgboost::ObjFunction * obj,
std::vector<xgboost::bst_float> out_grad,
std::vector<xgboost::bst_float> out_hess);
void CheckRankingObjFunction(xgboost::ObjFunction * obj,
std::vector<xgboost::bst_float> preds,
std::vector<xgboost::bst_float> labels,
std::vector<xgboost::bst_float> weights,
std::vector<xgboost::bst_uint> groups,
std::vector<xgboost::bst_float> out_grad,
std::vector<xgboost::bst_float> out_hess);
xgboost::bst_float GetMetricEval(
xgboost::Metric * metric,
std::vector<xgboost::bst_float> preds,

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());
}