Class: DSPy::Teleprompt::GEPA::FitnessScore

Inherits:
T::Struct
  • Object
show all
Extended by:
T::Sig
Includes:
Comparable
Defined in:
lib/dspy/teleprompt/gepa.rb

Overview

FitnessScore represents multi-dimensional evaluation results

Instance Method Summary collapse

Constructor Details

#initialize(primary_score:, secondary_scores:, overall_score:, metadata: nil) ⇒ FitnessScore



1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
# File 'lib/dspy/teleprompt/gepa.rb', line 1321

def initialize(primary_score:, secondary_scores:, overall_score:, metadata: nil)
  # Validate score ranges
  [primary_score, overall_score].each do |score|
    if score < 0.0 || score > 1.0
      raise ArgumentError, "Score must be between 0.0 and 1.0, got #{score}"
    end
  end

  secondary_scores.each do |name, score|
    if score < 0.0 || score > 1.0
      raise ArgumentError, "Secondary score #{name} must be between 0.0 and 1.0, got #{score}"
    end
  end

  super(
    primary_score: primary_score,
    secondary_scores: secondary_scores.freeze,
    overall_score: overall_score,
    metadata: ( || {}).freeze
  )
end

Instance Method Details

#<=>(other) ⇒ Object



1345
1346
1347
1348
# File 'lib/dspy/teleprompt/gepa.rb', line 1345

def <=>(other)
  return nil unless other.is_a?(FitnessScore)
  overall_score <=> other.overall_score
end

#dominated_by?(other) ⇒ Boolean



1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
# File 'lib/dspy/teleprompt/gepa.rb', line 1352

def dominated_by?(other)
  return false if overall_score > other.overall_score
  return true if overall_score < other.overall_score

  # If overall scores are equal, check secondary metrics
  secondary_scores.all? do |metric, score|
    other_score = other.secondary_scores[metric] || 0.0
    score <= other_score
  end
end

#score_for_objectives(objectives) ⇒ Object



1365
1366
1367
1368
1369
1370
# File 'lib/dspy/teleprompt/gepa.rb', line 1365

def score_for_objectives(objectives)
  relevant_scores = objectives.map { |obj| secondary_scores[obj] || 0.0 }
  return primary_score if relevant_scores.empty?

  (primary_score + relevant_scores.sum) / (objectives.size + 1)
end