Class: Riffer::Evals::RunResult

Inherits:
Object
  • Object
show all
Defined in:
lib/riffer/evals/run_result.rb

Overview

Represents the complete result of an evaluation run across multiple scenarios.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(scenario_results:) ⇒ RunResult

– : (scenario_results: Array) -> void



11
12
13
# File 'lib/riffer/evals/run_result.rb', line 11

def initialize(scenario_results:)
  @scenario_results = scenario_results
end

Instance Attribute Details

#scenario_resultsObject (readonly)

Per-scenario evaluation results.



7
8
9
# File 'lib/riffer/evals/run_result.rb', line 7

def scenario_results
  @scenario_results
end

Instance Method Details

#scoresObject

Returns average scores keyed by evaluator class across all scenarios.

– : () -> Hash[singleton(Riffer::Evals::Evaluator), Float]



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/riffer/evals/run_result.rb', line 19

def scores
  return {} if scenario_results.empty?

  totals = Hash.new(0.0)
  counts = Hash.new(0)

  scenario_results.each do |scenario|
    scenario.scores.each do |evaluator, score|
      totals[evaluator] += score
      counts[evaluator] += 1
    end
  end

  averages = {} #: Hash[singleton(Riffer::Evals::Evaluator), Float]
  totals.each_with_object(averages) do |(evaluator, total), hash|
    hash[evaluator] = total / counts[evaluator]
  end
end

#to_hObject

Returns a hash representation of the run result.

– : () -> Hash[Symbol, untyped]



42
43
44
45
46
47
# File 'lib/riffer/evals/run_result.rb', line 42

def to_h
  {
    scores: scores.transform_keys(&:name),
    scenario_results: scenario_results.map(&:to_h)
  }
end