Class: GEPA::Core::Result
- Inherits:
-
T::Struct
- Object
- T::Struct
- GEPA::Core::Result
- Extended by:
- T::Sig
- Defined in:
- lib/gepa/core/result.rb
Overview
Snapshot of GEPA optimization output with helpers for common queries.
Class Method Summary collapse
Instance Method Summary collapse
- #best_candidate ⇒ Object
- #best_idx ⇒ Object
- #num_candidates ⇒ Object
- #num_val_instances ⇒ Object
- #to_h ⇒ Object
- #to_json(*_args) ⇒ Object
Class Method Details
.from_state(state, run_dir: nil, seed: nil) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/gepa/core/result.rb', line 75 def self.from_state(state, run_dir: nil, seed: nil) new( candidates: state.program_candidates.map(&:dup), parents: state.parent_program_for_candidate.map(&:dup), val_aggregate_scores: state.program_full_scores_val_set.map(&:to_f), best_outputs_valset: state.respond_to?(:best_outputs_valset) ? state.best_outputs_valset&.map(&:dup) : nil, val_subscores: state.prog_candidate_val_subscores.map { |scores| scores.map(&:to_f) }, per_val_instance_best_candidates: state.program_at_pareto_front_valset.map { |set| set.to_a }, discovery_eval_counts: state.num_metric_calls_by_discovery.map(&:to_i), total_metric_calls: state.respond_to?(:total_num_evals) ? state.total_num_evals : nil, num_full_val_evals: state.respond_to?(:num_full_ds_evals) ? state.num_full_ds_evals : nil, run_dir: run_dir, seed: seed ) end |
Instance Method Details
#best_candidate ⇒ Object
41 42 43 |
# File 'lib/gepa/core/result.rb', line 41 def best_candidate candidates.fetch(best_idx) end |
#best_idx ⇒ Object
36 37 38 |
# File 'lib/gepa/core/result.rb', line 36 def best_idx val_aggregate_scores.each_with_index.max_by { |score, _i| score }&.last || 0 end |
#num_candidates ⇒ Object
26 27 28 |
# File 'lib/gepa/core/result.rb', line 26 def num_candidates candidates.length end |
#num_val_instances ⇒ Object
31 32 33 |
# File 'lib/gepa/core/result.rb', line 31 def num_val_instances per_val_instance_best_candidates.length end |
#to_h ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/gepa/core/result.rb', line 46 def to_h { candidates: candidates.map(&:dup), parents: parents.map(&:dup), val_aggregate_scores: val_aggregate_scores.dup, val_subscores: val_subscores.map(&:dup), best_outputs_valset: best_outputs_valset&.map { |arr| arr.map(&:dup) }, per_val_instance_best_candidates: per_val_instance_best_candidates.map(&:dup), discovery_eval_counts: discovery_eval_counts.dup, total_metric_calls: total_metric_calls, num_full_val_evals: num_full_val_evals, run_dir: run_dir, seed: seed, best_idx: best_idx } end |
#to_json(*_args) ⇒ Object
64 65 66 |
# File 'lib/gepa/core/result.rb', line 64 def to_json(*_args) JSON.pretty_generate(to_h) end |