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.

Contains per-scenario results and provides aggregate scores.

run_result = Riffer::Evals::RunResult.new(
  scenario_results: [scenario_result1, scenario_result2]
)

run_result.scores   # => { MyEvaluator => 0.85 }

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(scenario_results:) ⇒ RunResult

Initializes a new run result.

– : (scenario_results: Array) -> void



22
23
24
# File 'lib/riffer/evals/run_result.rb', line 22

def initialize(scenario_results:)
  @scenario_results = scenario_results
end

Instance Attribute Details

#scenario_resultsObject (readonly)

Per-scenario evaluation results.



16
17
18
# File 'lib/riffer/evals/run_result.rb', line 16

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]



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/riffer/evals/run_result.rb', line 30

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

  totals.each_with_object({}) do |(evaluator, total), hash|
    hash[evaluator] = total / counts[evaluator]
  end
end

#to_hObject

Returns a hash representation of the run result.

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



52
53
54
55
56
57
# File 'lib/riffer/evals/run_result.rb', line 52

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