Class: Legion::Extensions::Agentic::Homeostasis::Neuromodulation::Helpers::Modulator
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Homeostasis::Neuromodulation::Helpers::Modulator
show all
- Includes:
- Constants
- Defined in:
- lib/legion/extensions/agentic/homeostasis/neuromodulation/helpers/modulator.rb
Constant Summary
collapse
- INFLUENCE_MAP =
{
dopamine: %i[learning_rate exploration_bias],
serotonin: %i[patience_factor],
norepinephrine: %i[arousal_level attention_precision],
acetylcholine: %i[memory_encoding attention_precision]
}.freeze
Constants included
from Constants
Constants::BASELINE_DRIFT, Constants::DEFAULT_LEVEL, Constants::LEVEL_CEILING, Constants::LEVEL_FLOOR, Constants::MAX_EVENTS, Constants::MODULATION_ALPHA, Constants::MODULATORS, Constants::OPTIMAL_RANGES, Constants::STATE_LABELS
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(name) ⇒ Modulator
Returns a new instance of Modulator.
14
15
16
17
18
19
|
# File 'lib/legion/extensions/agentic/homeostasis/neuromodulation/helpers/modulator.rb', line 14
def initialize(name)
@name = name
@level = DEFAULT_LEVEL
@baseline = DEFAULT_LEVEL
@events = []
end
|
Instance Attribute Details
#baseline ⇒ Object
Returns the value of attribute baseline.
12
13
14
|
# File 'lib/legion/extensions/agentic/homeostasis/neuromodulation/helpers/modulator.rb', line 12
def baseline
@baseline
end
|
#events ⇒ Object
Returns the value of attribute events.
12
13
14
|
# File 'lib/legion/extensions/agentic/homeostasis/neuromodulation/helpers/modulator.rb', line 12
def events
@events
end
|
#level ⇒ Object
Returns the value of attribute level.
12
13
14
|
# File 'lib/legion/extensions/agentic/homeostasis/neuromodulation/helpers/modulator.rb', line 12
def level
@level
end
|
#name ⇒ Object
Returns the value of attribute name.
12
13
14
|
# File 'lib/legion/extensions/agentic/homeostasis/neuromodulation/helpers/modulator.rb', line 12
def name
@name
end
|
Instance Method Details
#boost(amount, reason: nil) ⇒ Object
21
22
23
24
25
26
|
# File 'lib/legion/extensions/agentic/homeostasis/neuromodulation/helpers/modulator.rb', line 21
def boost(amount, reason: nil)
old_level = @level
@level = clamp(@level + amount)
record_event(:boost, amount, reason, old_level)
@level
end
|
#drift_to_baseline ⇒ Object
35
36
37
38
|
# File 'lib/legion/extensions/agentic/homeostasis/neuromodulation/helpers/modulator.rb', line 35
def drift_to_baseline
delta = @baseline - @level
@level = clamp(@level + (delta * BASELINE_DRIFT))
end
|
#influence_on(target_property) ⇒ Object
62
63
64
65
66
67
|
# File 'lib/legion/extensions/agentic/homeostasis/neuromodulation/helpers/modulator.rb', line 62
def influence_on(target_property)
relevant = INFLUENCE_MAP.fetch(@name, [])
return 0.0 unless relevant.include?(target_property)
scale(@level)
end
|
#optimal? ⇒ Boolean
40
41
42
|
# File 'lib/legion/extensions/agentic/homeostasis/neuromodulation/helpers/modulator.rb', line 40
def optimal?
OPTIMAL_RANGES.fetch(@name).include?(@level)
end
|
#state_label ⇒ Object
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/legion/extensions/agentic/homeostasis/neuromodulation/helpers/modulator.rb', line 44
def state_label
range = OPTIMAL_RANGES.fetch(@name)
if @level > range.end
STATE_LABELS.dig(@name, :high)
elsif @level < range.begin
STATE_LABELS.dig(@name, :low)
else
STATE_LABELS.dig(@name, :optimal)
end
end
|
#suppress(amount, reason: nil) ⇒ Object
28
29
30
31
32
33
|
# File 'lib/legion/extensions/agentic/homeostasis/neuromodulation/helpers/modulator.rb', line 28
def suppress(amount, reason: nil)
old_level = @level
@level = clamp(@level - amount)
record_event(:suppress, amount, reason, old_level)
@level
end
|
#to_h ⇒ Object
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/legion/extensions/agentic/homeostasis/neuromodulation/helpers/modulator.rb', line 69
def to_h
{
name: @name,
level: @level.round(4),
baseline: @baseline.round(4),
state: state_label,
optimal: optimal?,
event_count: @events.size
}
end
|