51 explicit Metric(
size_t k = NO_CUTOFF) {
58 virtual std::string
name()
const = 0;
66 cutoff_ = k == 0 ? NO_CUTOFF : k;
78 const std::shared_ptr<data::Dataset> dataset,
const Score *scores)
const {
79 if (dataset->num_queries() == 0)
82 for (
size_t q = 0; q < dataset->num_queries(); q++) {
83 std::shared_ptr<data::QueryResults> r = dataset->getQueryResults(q);
85 scores += r->num_results();
92 const std::shared_ptr<data::VerticalDataset> dataset,
93 const Score *scores)
const {
94 if (dataset->num_queries() == 0)
97 for (
unsigned int q = 0; q < dataset->num_queries(); q++) {
98 std::shared_ptr<data::QueryResults> r = dataset->getQueryResults(q);
100 scores += r->num_results();
113 std::shared_ptr<data::RankedResults> ranked)
const {
114 auto jacobian = std::unique_ptr<Jacobian>(
115 new Jacobian(ranked->num_results()));
116 auto results = std::shared_ptr<data::QueryResults>(
121 ranked->sorted_scores());
122 const size_t size = std::min(
cutoff(), results->num_results());
123 for (
size_t i = 0; i < size; ++i) {
124 double *p_jacobian =
jacobian->vectat(i, i + 1);
125 for (
size_t j = i + 1; j < results->num_results(); ++j) {
126 std::swap(ranked->sorted_scores()[i], ranked->sorted_scores()[j]);
128 ranked->sorted_scores());
129 *p_jacobian++ = new_score - orig_score;
130 std::swap(ranked->sorted_scores()[i], ranked->sorted_scores()[j]);
147 virtual std::ostream &
put(std::ostream &os)
const = 0;
Definition: dataset.cc:28
virtual MetricScore evaluate_dataset(const std::shared_ptr< data::Dataset > dataset, const Score *scores) const
Definition: metric.h:77
This class implements the basic functionalities of an IR evaluation metric.
Definition: metric.h:43
virtual MetricScore evaluate_dataset(const std::shared_ptr< data::VerticalDataset > dataset, const Score *scores) const
Definition: metric.h:91
SymMatrix< double > Jacobian
data type for evaluation metric final outcome
Definition: types.h:36
friend std::ostream & operator<<(std::ostream &os, const Metric &m)
The output stream operator.
Definition: metric.h:143
size_t cutoff() const
Returns the current cut-off of the Metric.
Definition: metric.h:61
size_t cutoff_
The metric cutoff.
Definition: metric.h:140
virtual std::ostream & put(std::ostream &os) const =0
Prints the short name of the Metric, e.g., "NDCG@K".
virtual std::string name() const =0
Returns the name of the metric.
virtual ~Metric()
Definition: metric.h:54
virtual std::unique_ptr< Jacobian > jacobian(std::shared_ptr< data::RankedResults > ranked) const
Computes the Jacobian matrix.
Definition: metric.h:112
double Score
data type for instance truth label
Definition: types.h:30
static const size_t NO_CUTOFF
This should be used when no cut-off on the results list is required.
Definition: metric.h:46
Metric(size_t k=NO_CUTOFF)
Creates a new metric with the specified cut-off threshold.
Definition: metric.h:51
virtual MetricScore evaluate_result_list(const quickrank::data::QueryResults *rl, const Score *scores) const =0
Measures the quality of the given results list according to the Metric.
This class wraps a set of results for a given query.
Definition: queryresults.h:36
void set_cutoff(size_t k)
Updates the cut-off of the Metric.
Definition: metric.h:65
double MetricScore
data type for QueryID in L-t-R datasets
Definition: types.h:33