ModErn Text Analysis
META Enumerates Textual Applications
ir_eval.h
Go to the documentation of this file.
1 
9 #ifndef META_IR_EVAL_H_
10 #define META_IR_EVAL_H_
11 
12 #include <iostream>
13 #include <limits>
14 #include <stdexcept>
15 #include <string>
16 #include <unordered_map>
17 #include <utility>
18 #include <vector>
19 #include "meta.h"
20 
21 namespace meta
22 {
23 namespace index
24 {
25 
30 class ir_eval
31 {
32  public:
33  using result_type = std::vector<std::pair<doc_id, double>>;
34 
38  ir_eval(const std::string& config_file);
39 
47  double precision(const result_type& results, query_id q_id,
48  uint64_t num_docs = std::numeric_limits<uint64_t>::max()) const;
49 
57  double recall(const result_type& results, query_id q_id,
58  uint64_t num_docs = std::numeric_limits<uint64_t>::max()) const;
59 
69  double f1(const result_type& results, query_id q_id,
70  uint64_t num_docs = std::numeric_limits<uint64_t>::max(),
71  double beta = 1.0) const;
72 
82  double ndcg(const result_type& results, query_id q_id,
83  uint64_t num_docs = std::numeric_limits<uint64_t>::max()) const;
84 
88  double avg_p(const result_type& results, query_id q_id,
89  uint64_t num_docs = std::numeric_limits<uint64_t>::max());
90 
97  double map() const;
98 
107  double gmap() const;
108 
114  void print_stats(const result_type& results, query_id q_id,
115  std::ostream& out = std::cout);
116 
120  void reset_stats();
121 
122  private:
127  std::unordered_map<query_id, std::unordered_map<doc_id, uint8_t>> qrels_;
128 
130  std::vector<double> scores_;
131 
135  void init_index(const std::string& path);
136 
143  double relevant_retrieved(const result_type& results, query_id q_id,
144  uint64_t num_docs) const;
145 
146  public:
150  class ir_eval_exception : public std::runtime_error
151  {
152  public:
153  using std::runtime_error::runtime_error;
154  };
155 };
156 }
157 }
158 
159 #endif
Basic exception for ir_eval interactions.
Definition: ir_eval.h:150
std::unordered_map< query_id, std::unordered_map< doc_id, uint8_t > > qrels_
query_id -> (doc_id -> relevance) mapping If the doc_id isn't in the map, it is non-relevant.
Definition: ir_eval.h:127
void print_stats(const result_type &results, query_id q_id, std::ostream &out=std::cout)
Definition: ir_eval.cpp:202
Contains top-level namespace documentation for the META toolkit.
double avg_p(const result_type &results, query_id q_id, uint64_t num_docs=std::numeric_limits< uint64_t >::max())
Computes the average precision for a query.
Definition: ir_eval.cpp:160
double f1(const result_type &results, query_id q_id, uint64_t num_docs=std::numeric_limits< uint64_t >::max(), double beta=1.0) const
Definition: ir_eval.cpp:109
double gmap() const
Definition: ir_eval.cpp:194
ir_eval(const std::string &config_file)
Definition: ir_eval.cpp:22
double ndcg(const result_type &results, query_id q_id, uint64_t num_docs=std::numeric_limits< uint64_t >::max()) const
Definition: ir_eval.cpp:123
double relevant_retrieved(const result_type &results, query_id q_id, uint64_t num_docs) const
Definition: ir_eval.cpp:91
The ModErn Text Analysis toolkit is a suite of natural language processing, classification, information retreival, data mining, and other applications of text processing.
Definition: analyzer.h:24
std::vector< double > scores_
Collection of scores used to calculate MAP and gMAP.
Definition: ir_eval.h:130
Evaluates lists of ranked documents returned from a search engine; can give stats per-query (e...
Definition: ir_eval.h:30
void init_index(const std::string &path)
Definition: ir_eval.cpp:32
void reset_stats()
Clears saved scores for MAP and gMAP.
Definition: ir_eval.cpp:222
double recall(const result_type &results, query_id q_id, uint64_t num_docs=std::numeric_limits< uint64_t >::max()) const
Definition: ir_eval.cpp:78
double map() const
Definition: ir_eval.cpp:188
double precision(const result_type &results, query_id q_id, uint64_t num_docs=std::numeric_limits< uint64_t >::max()) const
Definition: ir_eval.cpp:64