Class: Legion::Extensions::Agentic::Attention::Focus::Helpers::Habituation
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Attention::Focus::Helpers::Habituation
- Defined in:
- lib/legion/extensions/agentic/attention/focus/helpers/habituation.rb
Instance Method Summary collapse
- #apply_novelty_reset(domain, novelty: 0.5) ⇒ Object
- #decay_all ⇒ Object
- #habituated_domains(threshold: 0.5) ⇒ Object
-
#initialize ⇒ Habituation
constructor
A new instance of Habituation.
- #level(domain) ⇒ Object
- #record(domain) ⇒ Object
- #stats ⇒ Object
Constructor Details
#initialize ⇒ Habituation
Returns a new instance of Habituation.
10 11 12 13 |
# File 'lib/legion/extensions/agentic/attention/focus/helpers/habituation.rb', line 10 def initialize @domain_exposure = Hash.new(0.0) @domain_last_seen = {} end |
Instance Method Details
#apply_novelty_reset(domain, novelty: 0.5) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/legion/extensions/agentic/attention/focus/helpers/habituation.rb', line 29 def apply_novelty_reset(domain, novelty: 0.5) domain = domain.to_sym return unless novelty > 0.5 reduction = (novelty - 0.5) * Constants::NOVELTY_RESET_FACTOR @domain_exposure[domain] = [@domain_exposure[domain] - reduction, 0.0].max end |
#decay_all ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/legion/extensions/agentic/attention/focus/helpers/habituation.rb', line 37 def decay_all @domain_exposure.each_key do |domain| @domain_exposure[domain] = [ @domain_exposure[domain] - Constants::HABITUATION_DECAY, 0.0 ].max end @domain_exposure.delete_if { |_, v| v <= 0.0 } end |
#habituated_domains(threshold: 0.5) ⇒ Object
52 53 54 |
# File 'lib/legion/extensions/agentic/attention/focus/helpers/habituation.rb', line 52 def habituated_domains(threshold: 0.5) @domain_exposure.select { |_, v| v >= threshold }.keys end |
#level(domain) ⇒ Object
24 25 26 27 |
# File 'lib/legion/extensions/agentic/attention/focus/helpers/habituation.rb', line 24 def level(domain) domain = domain.to_sym @domain_exposure[domain] end |
#record(domain) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/legion/extensions/agentic/attention/focus/helpers/habituation.rb', line 15 def record(domain) domain = domain.to_sym @domain_exposure[domain] = [ @domain_exposure[domain] + Constants::HABITUATION_RATE, Constants::HABITUATION_CEILING ].min @domain_last_seen[domain] = Time.now.utc end |
#stats ⇒ Object
48 49 50 |
# File 'lib/legion/extensions/agentic/attention/focus/helpers/habituation.rb', line 48 def stats @domain_exposure.transform_values { |v| v.round(3) } end |