Class: DSPy::Teleprompt::GEPA::ParetoSelector
- Inherits:
-
Object
- Object
- DSPy::Teleprompt::GEPA::ParetoSelector
- Extended by:
- T::Sig
- Defined in:
- lib/dspy/teleprompt/gepa.rb
Overview
ParetoSelector: Multi-objective optimization using Pareto frontier analysis
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#evaluator ⇒ Object
readonly
Returns the value of attribute evaluator.
Instance Method Summary collapse
-
#initialize(evaluator:, config:) ⇒ ParetoSelector
constructor
A new instance of ParetoSelector.
- #select_parents(population_with_scores, count:) ⇒ Object
- #select_survivors(population_with_scores, count:) ⇒ Object
Constructor Details
#initialize(evaluator:, config:) ⇒ ParetoSelector
Returns a new instance of ParetoSelector.
2480 2481 2482 2483 |
# File 'lib/dspy/teleprompt/gepa.rb', line 2480 def initialize(evaluator:, config:) @evaluator = evaluator @config = config end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
2477 2478 2479 |
# File 'lib/dspy/teleprompt/gepa.rb', line 2477 def config @config end |
#evaluator ⇒ Object (readonly)
Returns the value of attribute evaluator.
2474 2475 2476 |
# File 'lib/dspy/teleprompt/gepa.rb', line 2474 def evaluator @evaluator end |
Instance Method Details
#select_parents(population_with_scores, count:) ⇒ Object
2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 |
# File 'lib/dspy/teleprompt/gepa.rb', line 2487 def select_parents(population_with_scores, count:) return [] if population_with_scores.empty? return population_with_scores.map(&:first) if count >= population_with_scores.size # Combine tournament and Pareto-based selection for parent selection selected = [] count.times do parent = tournament_selection(population_with_scores) selected << parent end selected end |
#select_survivors(population_with_scores, count:) ⇒ Object
2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 |
# File 'lib/dspy/teleprompt/gepa.rb', line 2504 def select_survivors(population_with_scores, count:) return [] if population_with_scores.empty? return population_with_scores.map(&:first) if count >= population_with_scores.size scores = population_with_scores.map(&:last) # Find Pareto frontier first pareto_frontier = find_pareto_frontier(scores) frontier_indices = scores.each_index.select { |i| pareto_frontier.include?(scores[i]) } frontier_programs = frontier_indices.map { |i| population_with_scores[i].first } if frontier_programs.size >= count # Use diversity selection within frontier frontier_with_scores = frontier_indices.map { |i| population_with_scores[i] } return diversity_selection(frontier_with_scores, count: count) else # Include all frontier + fill remaining with elite selection remaining_count = count - frontier_programs.size remaining_population = population_with_scores.reject.with_index { |_, i| frontier_indices.include?(i) } additional = elite_selection(remaining_population, count: remaining_count) frontier_programs + additional end end |