Skip to content

Commit

Permalink
added code for instance based weighing for rank objectives
Browse files Browse the repository at this point in the history
  • Loading branch information
Naman Goyal committed Jun 11, 2018
1 parent a960391 commit e00ddec
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/objective/rank_obj.cc
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ class LambdaRankObj : public ObjFunction {
for (unsigned pid = i; pid < j; ++pid) {
unsigned ridx = std::uniform_int_distribution<unsigned>(0, nleft + nright - 1)(rnd);
if (ridx < nleft) {
pairs.emplace_back(rec[ridx].second, rec[pid].second);
pairs.emplace_back(rec[ridx].second, rec[pid].second, info.GetWeight(k));
} else {
pairs.emplace_back(rec[pid].second, rec[ridx+j-i].second);
pairs.emplace_back(rec[pid].second, rec[ridx+j-i].second, info.GetWeight(k));
}
}
}
Expand Down Expand Up @@ -152,6 +152,9 @@ class LambdaRankObj : public ObjFunction {
// constructor
LambdaPair(unsigned pos_index, unsigned neg_index)
: pos_index(pos_index), neg_index(neg_index), weight(1.0f) {}
// constructor
LambdaPair(unsigned pos_index, unsigned neg_index, bst_float weight)
: pos_index(pos_index), neg_index(neg_index), weight(weight) {}
};
/*!
* \brief get lambda weight for existing pairs
Expand Down Expand Up @@ -205,7 +208,7 @@ class LambdaRankObjNDCG : public LambdaRankObj {
((1 << neg_label) - 1) * pos_loginv + ((1 << pos_label) - 1) * neg_loginv;
bst_float delta = (original - changed) * IDCG;
if (delta < 0.0f) delta = - delta;
pair.weight = delta;
pair.weight *= delta;
}
}
}
Expand Down Expand Up @@ -301,7 +304,7 @@ class LambdaRankObjMAP : public LambdaRankObj {
std::vector<MAPStats> map_stats;
GetMAPStats(sorted_list, &map_stats);
for (auto & pair : pairs) {
pair.weight =
pair.weight *=
GetLambdaMAP(sorted_list, pair.pos_index,
pair.neg_index, &map_stats);
}
Expand Down

0 comments on commit e00ddec

Please sign in to comment.