From 4d03729683a084162a7c8ca0de96ced85dae804b Mon Sep 17 00:00:00 2001 From: yepyao Date: Fri, 16 May 2014 23:06:24 +0800 Subject: [PATCH] use ndcg@all in lambdarank for ndcg --- regrank/xgboost_regrank_obj.hpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/regrank/xgboost_regrank_obj.hpp b/regrank/xgboost_regrank_obj.hpp index e0ef67f7a..5272b42fa 100644 --- a/regrank/xgboost_regrank_obj.hpp +++ b/regrank/xgboost_regrank_obj.hpp @@ -336,8 +336,15 @@ namespace xgboost{ public: virtual ~LambdaRankObj_NDCG(void){} - inline float DCG(const std::vector &labels){ - return 1.0; + inline float CalcDCG( const std::vector &labels ){ + double sumdcg = 0.0; + for( size_t i = 0; i < labels.size(); i ++ ){ + const unsigned rel = labels[i]; + if( rel != 0 ){ + sumdcg += logf(2.0f) * ((1<(sumdcg); } inline float GetIDCG(const std::vector &sorted_list){ @@ -347,7 +354,7 @@ namespace xgboost{ } std::sort(labels.begin(), labels.end(), std::greater()); - return DCG(labels); + return CalcDCG(labels); } /*