Class: Legion::Extensions::Agentic::Self::Agency::Helpers::EfficacyModel
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Self::Agency::Helpers::EfficacyModel
- Defined in:
- lib/legion/extensions/agentic/self/agency/helpers/efficacy_model.rb
Instance Attribute Summary collapse
-
#domains ⇒ Object
readonly
Returns the value of attribute domains.
-
#history ⇒ Object
readonly
Returns the value of attribute history.
Instance Method Summary collapse
- #decay_all ⇒ Object
- #domain_count ⇒ Object
- #domain_history(domain) ⇒ Object
- #efficacy_for(domain) ⇒ Object
- #efficacy_label(domain) ⇒ Object
-
#initialize ⇒ EfficacyModel
constructor
A new instance of EfficacyModel.
- #overall_efficacy ⇒ Object
- #record_outcome(event) ⇒ Object
- #strongest_domains(count = 5) ⇒ Object
- #success_rate(domain) ⇒ Object
- #to_h ⇒ Object
- #weakest_domains(count = 5) ⇒ Object
Constructor Details
#initialize ⇒ EfficacyModel
Returns a new instance of EfficacyModel.
12 13 14 15 |
# File 'lib/legion/extensions/agentic/self/agency/helpers/efficacy_model.rb', line 12 def initialize @domains = {} @history = [] end |
Instance Attribute Details
#domains ⇒ Object (readonly)
Returns the value of attribute domains.
10 11 12 |
# File 'lib/legion/extensions/agentic/self/agency/helpers/efficacy_model.rb', line 10 def domains @domains end |
#history ⇒ Object (readonly)
Returns the value of attribute history.
10 11 12 |
# File 'lib/legion/extensions/agentic/self/agency/helpers/efficacy_model.rb', line 10 def history @history end |
Instance Method Details
#decay_all ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/legion/extensions/agentic/self/agency/helpers/efficacy_model.rb', line 37 def decay_all @domains.each_key do |domain| current = @domains[domain] diff = Constants::DEFAULT_EFFICACY - current @domains[domain] = (current + (diff * Constants::DECAY_RATE)).clamp( Constants::EFFICACY_FLOOR, Constants::EFFICACY_CEILING ) end trim_domains end |
#domain_count ⇒ Object
74 75 76 |
# File 'lib/legion/extensions/agentic/self/agency/helpers/efficacy_model.rb', line 74 def domain_count @domains.size end |
#domain_history(domain) ⇒ Object
48 49 50 |
# File 'lib/legion/extensions/agentic/self/agency/helpers/efficacy_model.rb', line 48 def domain_history(domain) @history.select { |e| e.domain == domain } end |
#efficacy_for(domain) ⇒ Object
17 18 19 20 |
# File 'lib/legion/extensions/agentic/self/agency/helpers/efficacy_model.rb', line 17 def efficacy_for(domain) @domains[domain] ||= Constants::DEFAULT_EFFICACY @domains[domain] end |
#efficacy_label(domain) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/legion/extensions/agentic/self/agency/helpers/efficacy_model.rb', line 22 def efficacy_label(domain) value = efficacy_for(domain) Constants::EFFICACY_LABELS.each do |range, label| return label if range.cover?(value) end :uncertain end |
#overall_efficacy ⇒ Object
68 69 70 71 72 |
# File 'lib/legion/extensions/agentic/self/agency/helpers/efficacy_model.rb', line 68 def overall_efficacy return Constants::DEFAULT_EFFICACY if @domains.empty? @domains.values.sum / @domains.size end |
#record_outcome(event) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/legion/extensions/agentic/self/agency/helpers/efficacy_model.rb', line 30 def record_outcome(event) @history << event update_efficacy(event) trim_history event end |
#strongest_domains(count = 5) ⇒ Object
60 61 62 |
# File 'lib/legion/extensions/agentic/self/agency/helpers/efficacy_model.rb', line 60 def strongest_domains(count = 5) @domains.sort_by { |_, v| -v }.first(count).to_h end |
#success_rate(domain) ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/legion/extensions/agentic/self/agency/helpers/efficacy_model.rb', line 52 def success_rate(domain) events = domain_history(domain) return 0.0 if events.empty? successes = events.count(&:success?) successes.to_f / events.size end |
#to_h ⇒ Object
78 79 80 81 82 83 84 85 |
# File 'lib/legion/extensions/agentic/self/agency/helpers/efficacy_model.rb', line 78 def to_h { domain_count: @domains.size, overall_efficacy: overall_efficacy.round(4), history_size: @history.size, domains: @domains.transform_values { |v| v.round(4) } } end |
#weakest_domains(count = 5) ⇒ Object
64 65 66 |
# File 'lib/legion/extensions/agentic/self/agency/helpers/efficacy_model.rb', line 64 def weakest_domains(count = 5) @domains.sort_by { |_, v| v }.first(count).to_h end |