QuickRank  v2.0
QuickRank: A C++ suite of Learning to Rank algorithms
tndcg.h
Go to the documentation of this file.
1 /*
2  * QuickRank - A C++ suite of Learning to Rank algorithms
3  * Webpage: http://quickrank.isti.cnr.it/
4  * Contact: quickrank@isti.cnr.it
5  *
6  * Unless explicitly acquired and licensed from Licensor under another
7  * license, the contents of this file are subject to the Reciprocal Public
8  * License ("RPL") Version 1.5, or subsequent versions as allowed by the RPL,
9  * and You may not copy or use this file in either source code or executable
10  * form, except in compliance with the terms and conditions of the RPL.
11  *
12  * All software distributed under the RPL is provided strictly on an "AS
13  * IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, AND
14  * LICENSOR HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT
15  * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
16  * PURPOSE, QUIET ENJOYMENT, OR NON-INFRINGEMENT. See the RPL for specific
17  * language governing rights and limitations under the RPL.
18  *
19  * Contributor:
20  * HPC. Laboratory - ISTI - CNR - http://hpc.isti.cnr.it/
21  */
22 #pragma once
23 
24 #include "types.h"
25 #include "ndcg.h"
26 
27 namespace quickrank {
28 namespace metric {
29 namespace ir {
30 
31 /**
32  * This class implements a Tie-aware version of Normalized Discounted Cumulative Gain TNDCG\@k measure.
33  *
34  * see: McSherry, Frank, and Marc Najork. "Computing information retrieval
35  * performance measures efficiently in the presence of tied scores."
36  * In Advances in information retrieval, pp. 414-421. Springer Berlin Heidelberg, 2008.
37  */
38 class Tndcg: public Ndcg {
39  public:
40  explicit Tndcg(size_t k = NO_CUTOFF)
41  : Ndcg(k) {
42  }
43  virtual ~Tndcg() {
44  }
45 
46  /// Returns the name of the metric.
47  virtual std::string name() const {
48  return NAME_;
49  }
50 
51  static const std::string NAME_;
52 
53  /// \todo TODO: for only zero result slist Yahoo! LTR returns 0.5 instead of 0.0.
54  /// Make this choice available.
55  /// \param rl A results list.
56  /// \param scores a list of scores
57  /// \return The quality score of the result list.
59  const quickrank::data::QueryResults *rl, const Score *scores) const;
60 
61  virtual std::unique_ptr<Jacobian> jacobian(
62  std::shared_ptr<data::RankedResults> ranked) const;
63 
64  protected:
65  /// Computes the TNDCG\@K of a given list of labels.
66  /// \param rl The given results list. Only labels are actually used.
67  /// \param scores The scores to be used to re-order the result list.
68  /// \return TNDCG\@K for computed on the given labels.
70  const Score *scores) const;
71 
72  private:
73  friend std::ostream &operator<<(std::ostream &os, const Tndcg &tndcg) {
74  return tndcg.put(os);
75  }
76 
77  virtual std::ostream &put(std::ostream &os) const;
78 
79 };
80 
81 } // namespace ir
82 } // namespace metric
83 } // namespace quickrank
Definition: dataset.cc:28
MetricScore compute_tndcg(const quickrank::data::QueryResults *rl, const Score *scores) const
Computes the TNDCG@K of a given list of labels.
Definition: tndcg.cc:33
friend std::ostream & operator<<(std::ostream &os, const Tndcg &tndcg)
Definition: tndcg.h:73
virtual std::ostream & put(std::ostream &os) const
Prints the short name of the Metric, e.g., "NDCG@K".
Definition: tndcg.cc:127
static const std::string NAME_
Definition: tndcg.h:51
This class implements the Normalized Discounted cumulative Gain NDCG@k measure.
Definition: ndcg.h:38
double Score
data type for instance truth label
Definition: types.h:30
virtual MetricScore evaluate_result_list(const quickrank::data::QueryResults *rl, const Score *scores) const
Definition: tndcg.cc:65
static const size_t NO_CUTOFF
This should be used when no cut-off on the results list is required.
Definition: metric.h:46
This class implements a Tie-aware version of Normalized Discounted Cumulative Gain TNDCG@k measure...
Definition: tndcg.h:38
virtual std::string name() const
Returns the name of the metric.
Definition: tndcg.h:47
virtual ~Tndcg()
Definition: tndcg.h:43
This class wraps a set of results for a given query.
Definition: queryresults.h:36
virtual std::unique_ptr< Jacobian > jacobian(std::shared_ptr< data::RankedResults > ranked) const
Computes the Jacobian matrix.
Definition: tndcg.cc:75
Tndcg(size_t k=NO_CUTOFF)
Definition: tndcg.h:40
double MetricScore
data type for QueryID in L-t-R datasets
Definition: types.h:33