Class: Legion::Extensions::Agentic::Affect::SomaticMarker::Helpers::SomaticMarker
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Affect::SomaticMarker::Helpers::SomaticMarker
- Includes:
- Constants
- Defined in:
- lib/legion/extensions/agentic/affect/somatic_marker/helpers/somatic_marker.rb
Constant Summary
Constants included from Constants
Constants::BODY_STATE_DECAY, Constants::DEFAULT_VALENCE, Constants::MARKER_ALPHA, Constants::MARKER_DECAY, Constants::MARKER_STRENGTH_FLOOR, Constants::MAX_BODY_STATES, Constants::MAX_DECISION_HISTORY, Constants::MAX_MARKERS, Constants::MAX_OPTIONS_PER_DECISION, Constants::NEGATIVE_BIAS, Constants::POSITIVE_BIAS, Constants::PUNISHMENT_PENALTY, Constants::REINFORCEMENT_BOOST, Constants::SIGNAL_LABELS, Constants::VALENCE_LABELS
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Returns the value of attribute action.
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#domain ⇒ Object
readonly
Returns the value of attribute domain.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
-
#strength ⇒ Object
readonly
Returns the value of attribute strength.
-
#valence ⇒ Object
readonly
Returns the value of attribute valence.
Instance Method Summary collapse
- #decay ⇒ Object
- #faded? ⇒ Boolean
-
#initialize(id:, action:, domain:, valence:, strength: 0.5, source: :experience) ⇒ SomaticMarker
constructor
A new instance of SomaticMarker.
- #reinforce(outcome_valence:) ⇒ Object
- #signal ⇒ Object
- #to_h ⇒ Object
- #valence_label ⇒ Object
Constructor Details
#initialize(id:, action:, domain:, valence:, strength: 0.5, source: :experience) ⇒ SomaticMarker
Returns a new instance of SomaticMarker.
14 15 16 17 18 19 20 21 22 |
# File 'lib/legion/extensions/agentic/affect/somatic_marker/helpers/somatic_marker.rb', line 14 def initialize(id:, action:, domain:, valence:, strength: 0.5, source: :experience) @id = id @action = action @domain = domain @valence = valence.clamp(-1.0, 1.0) @strength = strength.clamp(0.0, 1.0) @source = source @created_at = Time.now.utc end |
Instance Attribute Details
#action ⇒ Object (readonly)
Returns the value of attribute action.
12 13 14 |
# File 'lib/legion/extensions/agentic/affect/somatic_marker/helpers/somatic_marker.rb', line 12 def action @action end |
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
12 13 14 |
# File 'lib/legion/extensions/agentic/affect/somatic_marker/helpers/somatic_marker.rb', line 12 def created_at @created_at end |
#domain ⇒ Object (readonly)
Returns the value of attribute domain.
12 13 14 |
# File 'lib/legion/extensions/agentic/affect/somatic_marker/helpers/somatic_marker.rb', line 12 def domain @domain end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
12 13 14 |
# File 'lib/legion/extensions/agentic/affect/somatic_marker/helpers/somatic_marker.rb', line 12 def id @id end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
12 13 14 |
# File 'lib/legion/extensions/agentic/affect/somatic_marker/helpers/somatic_marker.rb', line 12 def source @source end |
#strength ⇒ Object (readonly)
Returns the value of attribute strength.
12 13 14 |
# File 'lib/legion/extensions/agentic/affect/somatic_marker/helpers/somatic_marker.rb', line 12 def strength @strength end |
#valence ⇒ Object (readonly)
Returns the value of attribute valence.
12 13 14 |
# File 'lib/legion/extensions/agentic/affect/somatic_marker/helpers/somatic_marker.rb', line 12 def valence @valence end |
Instance Method Details
#decay ⇒ Object
40 41 42 |
# File 'lib/legion/extensions/agentic/affect/somatic_marker/helpers/somatic_marker.rb', line 40 def decay @strength = (@strength - MARKER_DECAY).clamp(0.0, 1.0) end |
#faded? ⇒ Boolean
44 45 46 |
# File 'lib/legion/extensions/agentic/affect/somatic_marker/helpers/somatic_marker.rb', line 44 def faded? @strength <= MARKER_STRENGTH_FLOOR end |
#reinforce(outcome_valence:) ⇒ Object
34 35 36 37 38 |
# File 'lib/legion/extensions/agentic/affect/somatic_marker/helpers/somatic_marker.rb', line 34 def reinforce(outcome_valence:) @valence = (MARKER_ALPHA * outcome_valence) + ((1.0 - MARKER_ALPHA) * @valence) @valence = @valence.clamp(-1.0, 1.0) @strength = (@strength + REINFORCEMENT_BOOST).clamp(0.0, 1.0) end |
#signal ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/legion/extensions/agentic/affect/somatic_marker/helpers/somatic_marker.rb', line 24 def signal if @valence > POSITIVE_BIAS :approach elsif @valence < NEGATIVE_BIAS :avoid else :neutral end end |
#to_h ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/legion/extensions/agentic/affect/somatic_marker/helpers/somatic_marker.rb', line 55 def to_h { id: @id, action: @action, domain: @domain, valence: @valence, strength: @strength, source: @source, signal: signal, label: valence_label, created_at: @created_at } end |
#valence_label ⇒ Object
48 49 50 51 52 53 |
# File 'lib/legion/extensions/agentic/affect/somatic_marker/helpers/somatic_marker.rb', line 48 def valence_label VALENCE_LABELS.each do |range, label| return label if range.cover?(@valence) end :neutral end |