Gain-Based & Discounted Measures¶
Gain-based measures like NDCG evaluate rankings using graded relevance judgments where higher relevance grades contribute greater utility, discounted by rank position.
Discounted Cumulative Gain at Cutoffs (ndcg_cut, ndcg)¶
Normalized Discounted Cumulative Gain (NDCG) measures the ratio of actual Discounted Cumulative Gain to the ideal Discounted Cumulative Gain (IDCG) obtained by sorting all judged documents by relevance.
Mathematical Formulation¶
where:
- \(\text{gain}(r)\) is the gain assigned to relevance grade \(r\). In standard trec_eval, the default gain is the integer relevance level: \(\text{gain}(r) = r\).
- \(\text{IDCG}@k\) is the DCG computed on the ideal ranking formed by sorting all documents in the qrels by relevance grade in descending order.
Cutoffs (ndcg_cut)¶
- Default rank cutoffs: \(5, 10, 15, 20, 30, 100, 200, 500, 1000\).
- Usage:
-m ndcg_cut.10,20orndcg@10.
NDCG Variants¶
1. Exponential Gains (ndcg_p)¶
Computes NDCG using exponential gains \(\text{gain}(r) = 2^r - 1\):
- Usage:
-m ndcg_p
2. Relative Relevance Level Gains (ndcg_rel)¶
Maps relevance grades to binary indicators relative to the relevance threshold cutoff \(l\):
- Usage:
-m ndcg_rel
3. R-NDCG (Rndcg)¶
Computes NDCG evaluated at rank \(R\), where \(R\) is the total count of relevant documents in the collection:
Cumulative Gain (G, binG)¶
Evaluates undiscounted cumulative gain across the ranking.
Cumulative Gain (G)¶
Binary Cumulative Gain (binG)¶
Custom Relevance-to-Gain Mappings¶
Custom gain mappings can be passed globally via --global-gains (CLI) / global_gains (Python), or directly to the measure parameter string:
Syntax¶
- CLI flag:
--global-gains 1=1.0,2=3.0,3=7.0,4=15.0 - Metric parameter:
-m ndcg.1=1.0,2=3.0,3=7.0 - Python API:
evaluator = Evaluator(qrels, measures=["ndcg@10"], global_gains="1=1.0,2=3.0")