Class: DSPy::Teleprompt::GEPA::FitnessScore
- Inherits:
-
T::Struct
- Object
- T::Struct
- DSPy::Teleprompt::GEPA::FitnessScore
- Extended by:
- T::Sig
- Defined in:
- lib/dspy/teleprompt/gepa.rb
Overview
FitnessScore represents multi-dimensional evaluation results
Instance Method Summary collapse
- #dominated_by?(other) ⇒ Boolean
-
#initialize(primary_score:, secondary_scores:, overall_score:, metadata: nil) ⇒ FitnessScore
constructor
A new instance of FitnessScore.
- #score_for_objectives(objectives) ⇒ Object
Constructor Details
#initialize(primary_score:, secondary_scores:, overall_score:, metadata: nil) ⇒ FitnessScore
Returns a new instance of FitnessScore.
1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 |
# File 'lib/dspy/teleprompt/gepa.rb', line 1588 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
#dominated_by?(other) ⇒ Boolean
1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 |
# File 'lib/dspy/teleprompt/gepa.rb', line 1612 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
1625 1626 1627 1628 1629 1630 |
# File 'lib/dspy/teleprompt/gepa.rb', line 1625 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 |