correct CalcDCG in rank_metric.cc and rank_obj.cc (#1642)

* correct CalcDCG in rank_metric.cc

DCG use log base-2, however `std::log` returns log base-e.

* correct CalcDCG in rank_obj.cc

DCG use log base-2, however `std::log` returns log base-e.

* use std::log2 instead of std::log

 make it more elegant

* use std::log2 instead of std::log

make it more elegant
This commit is contained in:
Liam Huang 2016-10-19 01:23:41 +08:00 committed by Tianqi Chen
parent 94a9e3222e
commit 001d8c4023
2 changed files with 2 additions and 2 deletions

View File

@ -257,7 +257,7 @@ struct EvalNDCG : public EvalRankList{
for (size_t i = 0; i < rec.size() && i < this->topn_; ++i) {
const unsigned rel = rec[i].second;
if (rel != 0) {
sumdcg += ((1 << rel) - 1) / std::log(i + 2.0);
sumdcg += ((1 << rel) - 1) / std::log2(i + 2.0);
}
}
return static_cast<float>(sumdcg);

View File

@ -215,7 +215,7 @@ class LambdaRankObjNDCG : public LambdaRankObj {
for (size_t i = 0; i < labels.size(); ++i) {
const unsigned rel = static_cast<unsigned>(labels[i]);
if (rel != 0) {
sumdcg += ((1 << rel) - 1) / std::log(static_cast<float>(i + 2));
sumdcg += ((1 << rel) - 1) / std::log2(static_cast<float>(i + 2));
}
}
return static_cast<float>(sumdcg);