Class: Evalir::EvaliratorCollection
- Inherits:
-
Object
- Object
- Evalir::EvaliratorCollection
- Includes:
- Enumerable
- Defined in:
- lib/evalir/evalirator_collection.rb
Instance Method Summary collapse
-
#<<(evalirator) ⇒ Object
Adds an evalirator to the set over which calculations are done.
-
#add(relevant_docids, retrieved_docids) ⇒ Object
Adds a list of relevant documents, and a list of retrived documents.
-
#average_ndcg_at(k, logbase = 2) ⇒ Object
Gets the average Normalized Discounted Cumulative Gain over all queries.
-
#each(&block) ⇒ Object
Calls block once for each element in self, passing that element as a parameter.
-
#initialize ⇒ EvaliratorCollection
constructor
A new instance of EvaliratorCollection.
-
#lazy_map(&blk) ⇒ Object
Maps over all elements, executing blk on every evalirator.
-
#mean_average_precision ⇒ Object
Mean Average Precision - this is just a fancy way of saying ‘average average precision’!.
- #mean_reciprocal_rank ⇒ Object
-
#precision_recall_curve(from = 0, to = 100, step = 10) ⇒ Object
Gets the data for the precision-recall curve, ranging over the interval [from, to], with a step size of step.
- #size ⇒ Object
Constructor Details
#initialize ⇒ EvaliratorCollection
Returns a new instance of EvaliratorCollection.
5 6 7 |
# File 'lib/evalir/evalirator_collection.rb', line 5 def initialize @evalirators = [] end |
Instance Method Details
#<<(evalirator) ⇒ Object
Adds an evalirator to the set over which calculations are done.
21 22 23 |
# File 'lib/evalir/evalirator_collection.rb', line 21 def <<(evalirator) @evalirators << evalirator end |
#add(relevant_docids, retrieved_docids) ⇒ Object
Adds a list of relevant documents, and a list of retrived documents. This rep- resents one information need.
38 39 40 |
# File 'lib/evalir/evalirator_collection.rb', line 38 def add(relevant_docids, retrieved_docids) @evalirators << Evalirator.new(relevant_docids, retrieved_docids) end |
#average_ndcg_at(k, logbase = 2) ⇒ Object
Gets the average Normalized Discounted Cumulative Gain over all queries.
74 75 76 77 |
# File 'lib/evalir/evalirator_collection.rb', line 74 def average_ndcg_at(k, logbase = 2) values = self.lazy_map {|e| e.ndcg_at(k, logbase)} values.reduce(0.0) { |acc, v| acc + (v / self.size) } end |
#each(&block) ⇒ Object
Calls block once for each element in self, passing that element as a parameter.
15 16 17 |
# File 'lib/evalir/evalirator_collection.rb', line 15 def each(&block) @evalirators.each(&block) end |
#lazy_map(&blk) ⇒ Object
Maps over all elements, executing blk on every evalirator.
27 28 29 30 31 32 33 |
# File 'lib/evalir/evalirator_collection.rb', line 27 def lazy_map(&blk) Enumerator.new do |yielder| self.each do |e| yielder << blk[e] end end end |
#mean_average_precision ⇒ Object
Mean Average Precision - this is just a fancy way of saying ‘average average precision’!
45 46 47 |
# File 'lib/evalir/evalirator_collection.rb', line 45 def mean_average_precision @evalirators.reduce(0.0) {|avg,e| avg + (e.average_precision / @evalirators.size)} end |
#mean_reciprocal_rank ⇒ Object
49 50 51 |
# File 'lib/evalir/evalirator_collection.rb', line 49 def mean_reciprocal_rank self.reduce(0.0) { |avg,e| avg + (e.reciprocal_rank / self.size)} end |
#precision_recall_curve(from = 0, to = 100, step = 10) ⇒ Object
Gets the data for the precision-recall curve, ranging over the interval [from, to], with a step size of step. This is the average over all evalirators.
57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/evalir/evalirator_collection.rb', line 57 def precision_recall_curve(from = 0, to = 100, step = 10) raise "From must be in the interval [0, 100)" unless (from >= 0 and from < 100) raise "To must be in the interval (from, 100]" unless (to > from and to <= 100) raise "Invalid step size - (to-from) must be divisible by step." unless ((to - from) % step) == 0 return nil if @evalirators.empty? steps = ((to - from) / step) + 1 curves = self.lazy_map { |e| e.precision_recall_curve(from, to, step) } curves.reduce([0] * steps) do |acc, data| data.each_with_index.map do |d,i| acc[i] += d / self.size end end end |
#size ⇒ Object
9 10 11 |
# File 'lib/evalir/evalirator_collection.rb', line 9 def size @evalirators.size end |